From 230ff85dc15bbf216f09c6e4dce0a3fd43aa0a81 Mon Sep 17 00:00:00 2001 From: Dmitriy Kuznetsov Date: Tue, 2 Jul 2019 12:23:51 +0300 Subject: [PATCH] [Tests] add failing symlink tests --- .../resolver/symlinked/_/node_modules/package | 1 + test/resolver/symlinked/package/bar.js | 1 + test/resolver/symlinked/package/package.json | 3 +++ test/symlinks.js | 20 +++++++++++++++++++ 4 files changed, 25 insertions(+) create mode 120000 test/resolver/symlinked/_/node_modules/package create mode 100644 test/resolver/symlinked/package/bar.js create mode 100644 test/resolver/symlinked/package/package.json diff --git a/test/resolver/symlinked/_/node_modules/package b/test/resolver/symlinked/_/node_modules/package new file mode 120000 index 00000000..46c82413 --- /dev/null +++ b/test/resolver/symlinked/_/node_modules/package @@ -0,0 +1 @@ +../../package \ No newline at end of file diff --git a/test/resolver/symlinked/package/bar.js b/test/resolver/symlinked/package/bar.js new file mode 100644 index 00000000..cb1c2c01 --- /dev/null +++ b/test/resolver/symlinked/package/bar.js @@ -0,0 +1 @@ +module.exports = 'bar'; diff --git a/test/resolver/symlinked/package/package.json b/test/resolver/symlinked/package/package.json new file mode 100644 index 00000000..8e1b5859 --- /dev/null +++ b/test/resolver/symlinked/package/package.json @@ -0,0 +1,3 @@ +{ + "main": "bar.js" +} \ No newline at end of file diff --git a/test/symlinks.js b/test/symlinks.js index 54b883fd..b4e205eb 100644 --- a/test/symlinks.js +++ b/test/symlinks.js @@ -4,11 +4,13 @@ var test = require('tape'); var resolve = require('../'); var symlinkDir = path.join(__dirname, 'resolver', 'symlinked', 'symlink'); +var packageDir = path.join(__dirname, 'resolver', 'symlinked', '_', 'node_modules', 'package'); try { fs.unlinkSync(symlinkDir); } catch (err) {} try { fs.symlinkSync('./_/symlink_target', symlinkDir, 'dir'); + fs.symlinkSync('../../package', packageDir, 'dir'); } catch (err) { if (err.code !== 'EEXIST') { // if fails then it is probably on Windows and lets try to create a junction @@ -56,3 +58,21 @@ test('sync symlink when preserveSymlinks = true', function (t) { }, /Cannot find module 'foo'/); t.end(); }); + +test('sync symlink from node_modules to other dir when preserveSymlinks = false', function (t) { + var basedir = path.join(__dirname, 'resolver', 'symlinked', '_'); + var fn = resolve.sync('package', { basedir: basedir, preserveSymlinks: false }); + + t.equal(fn, path.resolve(__dirname, 'resolver/symlinked/package/bar.js')); + t.end(); +}); + +test('async symlink from node_modules to other dir when preserveSymlinks = false', function (t) { + t.plan(2); + var basedir = path.join(__dirname, 'resolver', 'symlinked', '_'); + resolve('package', { basedir: basedir, preserveSymlinks: false }, function (err, result) { + t.notOk(err, 'no error'); + t.equal(result, path.resolve(__dirname, 'resolver/symlinked/package/bar.js')); + t.end(); + }); +});