-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { createSymlinks } from '../symlink'; | ||
import { withTempDir } from '../files'; | ||
import { promises as fsPromises } from 'fs'; | ||
|
||
import * as path from 'path'; | ||
|
||
describe('createSymlinks', () => { | ||
it.each([ | ||
{ | ||
_name: 'major version upgrade', | ||
oldVersion: '0.9.0', | ||
newVersion: '1.0.0', | ||
expectedSymlinks: ['1.json', '1.0.json', 'latest.json'], | ||
}, | ||
{ | ||
_name: 'minor version upgrade', | ||
oldVersion: '0.2.3', | ||
newVersion: '0.3.0', | ||
expectedSymlinks: ['0.json', '0.3.json', 'latest.json'], | ||
}, | ||
{ | ||
_name: 'path version upgrade', | ||
oldVersion: '0.2.3', | ||
newVersion: '0.2.4', | ||
expectedSymlinks: ['0.json', '0.2.json', 'latest.json'], | ||
}, | ||
{ | ||
_name: 'old version is undefined', | ||
oldVersion: undefined, | ||
newVersion: '1.2.3', | ||
expectedSymlinks: ['1.json', '1.2.json', 'latest.json'], | ||
}, | ||
{ | ||
_name: 'updating older major', | ||
oldVersion: '2.3.4', | ||
newVersion: '1.2.3', | ||
expectedSymlinks: ['1.2.json'], | ||
}, | ||
])('$_name', async ({ oldVersion, newVersion, expectedSymlinks }) => { | ||
await withTempDir(async tmpDir => { | ||
const versionFile = `${newVersion}.json`; | ||
const versionFilePath = path.join(tmpDir, versionFile); | ||
|
||
createSymlinks(versionFilePath, newVersion, oldVersion); | ||
|
||
// Check that there are no other files in the directory | ||
const filesInDir = await fsPromises.readdir(tmpDir); | ||
expect(filesInDir.sort()).toStrictEqual(expectedSymlinks.sort()); | ||
|
||
for (const symlinkFile of filesInDir) { | ||
const symlinkFilePath = path.join(tmpDir, symlinkFile); | ||
|
||
// Make sure it's a symbolic link | ||
const fileStat = await fsPromises.lstat(symlinkFilePath); | ||
expect(fileStat.isSymbolicLink()).toBe(true); | ||
|
||
// Make sure it points to the right file | ||
const symlinkDestination = await fsPromises.readlink(symlinkFilePath); | ||
expect(symlinkDestination).toBe(versionFile); | ||
} | ||
}); | ||
}); | ||
}); |