-
-
Notifications
You must be signed in to change notification settings - Fork 183
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
2 changed files
with
17 additions
and
11 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
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 |
---|---|---|
@@ -1,46 +1,54 @@ | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
var test = require('tape'); | ||
var resolve = require('../'); | ||
|
||
var symlinkDir = path.join(__dirname, 'resolver', 'symlinked', 'symlink'); | ||
try { | ||
fs.unlinkSync(symlinkDir); | ||
} catch (err) {} | ||
try { | ||
fs.symlinkSync('./_/symlink_target', symlinkDir, 'dir'); | ||
} catch (err) { | ||
// if fails then it is probably on Windows and lets try to create a junction | ||
fs.symlinkSync(path.join(__dirname, 'resolver', 'symlinked', '_', 'symlink_target') + '\\', symlinkDir, 'junction'); | ||
} | ||
|
||
test('symlink', function (t) { | ||
t.plan(1); | ||
var dir = path.join(__dirname, 'resolver', 'symlinked', 'symlink'); | ||
|
||
resolve('foo', { basedir: dir }, function (err, res, pkg) { | ||
resolve('foo', { basedir: symlinkDir }, function (err, res, pkg) { | ||
if (err) t.fail(err); | ||
t.equal(res, path.join(__dirname, 'resolver', 'symlinked', '_', 'node_modules', 'foo.js')); | ||
}); | ||
}); | ||
|
||
test('sync symlink when preserveSymlinks = true', function (t) { | ||
t.plan(4); | ||
var dir = path.join(__dirname, 'resolver', 'symlinked', 'symlink'); | ||
|
||
resolve('foo', { basedir: dir, preserveSymlinks: true }, function (err, res, pkg) { | ||
resolve('foo', { basedir: symlinkDir, preserveSymlinks: true }, function (err, res, pkg) { | ||
t.ok(err, 'there is an error'); | ||
t.notOk(res, 'no result'); | ||
|
||
t.equal(err && err.code, 'MODULE_NOT_FOUND', 'error code matches require.resolve'); | ||
t.equal( | ||
err && err.message, | ||
'Cannot find module \'foo\' from \'' + dir + '\'', | ||
'Cannot find module \'foo\' from \'' + symlinkDir + '\'', | ||
'can not find nonexistent module' | ||
); | ||
}); | ||
}); | ||
|
||
test('sync symlink', function (t) { | ||
var start = new Date(); | ||
var dir = path.join(__dirname, 'resolver', 'symlinked', 'symlink'); | ||
t.equal(resolve.sync('foo', { basedir: dir }), path.join(__dirname, 'resolver', 'symlinked', '_', 'node_modules', 'foo.js')); | ||
t.equal(resolve.sync('foo', { basedir: symlinkDir }), path.join(__dirname, 'resolver', 'symlinked', '_', 'node_modules', 'foo.js')); | ||
t.ok(new Date() - start < 50, 'resolve.sync timedout'); | ||
t.end(); | ||
}); | ||
|
||
test('sync symlink when preserveSymlinks = true', function (t) { | ||
var dir = path.join(__dirname, 'resolver', 'symlinked', 'symlink'); | ||
t.throws(function () { | ||
resolve.sync('foo', { basedir: dir, preserveSymlinks: true }); | ||
resolve.sync('foo', { basedir: symlinkDir, preserveSymlinks: true }); | ||
}, /Cannot find module 'foo'/); | ||
t.end(); | ||
}); |