Skip to content

Commit

Permalink
build: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gregmagolan committed Apr 9, 2020
1 parent c48b447 commit f8cc8df
Showing 1 changed file with 37 additions and 6 deletions.
43 changes: 37 additions & 6 deletions packages/node-patches/test/fs/lstat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('testing lstat', () => {
},
async fixturesDir => {
fixturesDir = fs.realpathSync(fixturesDir);
// create symlink from a to b
// create symlink from a/link to b/file
fs.symlinkSync(path.join(fixturesDir, 'b', 'file'), path.join(fixturesDir, 'a', 'link'));

const patchedFs = Object.assign({}, fs);
Expand All @@ -55,6 +55,37 @@ describe('testing lstat', () => {
});
});

it('can lstat symlink in guard is file', async () => {
await withFixtures(
{
a: {g: {}},
b: {file: 'contents'},
},
async fixturesDir => {
fixturesDir = fs.realpathSync(fixturesDir);
// create symlink from a/g/link to b/file
fs.symlinkSync(
path.join(fixturesDir, 'b', 'file'), path.join(fixturesDir, 'a', 'g', 'link'));

const patchedFs = Object.assign({}, fs);
patchedFs.promises = Object.assign({}, fs.promises);
patcher(patchedFs, path.join(fixturesDir), [path.join(fixturesDir, 'a', 'g')]);

const linkPath = path.join(fixturesDir, 'a', 'g', 'link');
assert.ok(
patchedFs.lstatSync(linkPath).isFile(),
'lstatSync should find file if link is in guard');

assert.ok(
(await util.promisify(patchedFs.lstat)(linkPath)).isFile(),
'lstat should find file if link is in guard');

assert.ok(
(await patchedFs.promises.lstat(linkPath)).isFile(),
'promises.lstat should find file if link is in guard');
});
});

it('lstat of symlink out of root is file.', async () => {
await withFixtures(
{
Expand All @@ -63,7 +94,7 @@ describe('testing lstat', () => {
},
async fixturesDir => {
fixturesDir = fs.realpathSync(fixturesDir);
// create symlink from a to b
// create symlink from a/link to b/file
fs.symlinkSync(path.join(fixturesDir, 'b', 'file'), path.join(fixturesDir, 'a', 'link'));

const patchedFs = Object.assign({}, fs);
Expand All @@ -74,15 +105,15 @@ describe('testing lstat', () => {

assert.ok(
patchedFs.lstatSync(linkPath).isFile(),
'lstatSync should find file it file linked is out of root');
'lstatSync should find file it file link is out of root');

assert.ok(
(await util.promisify(patchedFs.lstat)(linkPath)).isFile(),
'lstat should find file it file linked is out of root');
'lstat should find file it file link is out of root');

assert.ok(
(await patchedFs.promises.lstat(linkPath)).isFile(),
'promises.lstat should find file it file linked is out of root');
'promises.lstat should find file it file link is out of root');

let brokenLinkPath = path.join(fixturesDir, 'a', 'broken-link');
fs.symlinkSync(path.join(fixturesDir, 'doesnt-exist'), brokenLinkPath);
Expand All @@ -109,7 +140,7 @@ describe('testing lstat', () => {
},
async fixturesDir => {
fixturesDir = fs.realpathSync(fixturesDir);
// create symlink from a to b
// create symlink from a/link to b/file
fs.symlinkSync(path.join(fixturesDir, 'b', 'file'), path.join(fixturesDir, 'b', 'link'));

const patchedFs = Object.assign({}, fs);
Expand Down

0 comments on commit f8cc8df

Please sign in to comment.