From f8cc8dfe4d792df401477b8e339ea9874e0acef0 Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Wed, 8 Apr 2020 23:00:34 -0700 Subject: [PATCH] build: add tests --- packages/node-patches/test/fs/lstat.ts | 43 ++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/packages/node-patches/test/fs/lstat.ts b/packages/node-patches/test/fs/lstat.ts index 34db0ff15d..5cecd219a2 100644 --- a/packages/node-patches/test/fs/lstat.ts +++ b/packages/node-patches/test/fs/lstat.ts @@ -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); @@ -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( { @@ -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); @@ -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); @@ -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);