Skip to content

Commit

Permalink
[Tests] add failing symlink tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitriy Kuznetsov authored and ljharb committed Jul 2, 2019
1 parent f6d8f23 commit 230ff85
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/resolver/symlinked/_/node_modules/package

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/resolver/symlinked/package/bar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 'bar';
3 changes: 3 additions & 0 deletions test/resolver/symlinked/package/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"main": "bar.js"
}
20 changes: 20 additions & 0 deletions test/symlinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
});
});

0 comments on commit 230ff85

Please sign in to comment.