Sha256: 3be10dd53484d65e39d04a1617eb3946fd17eccd41b83dfde2465e2c4c95f468

Contents?: true

Size: 1.82 KB

Versions: 41

Compression:

Stored size: 1.82 KB

Contents

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(2);

    resolve('foo', { basedir: symlinkDir, preserveSymlinks: false }, function (err, res, pkg) {
        t.error(err);
        t.equal(res, path.join(__dirname, 'resolver', 'symlinked', '_', 'node_modules', 'foo.js'));
    });
});

test('sync symlink when preserveSymlinks = true', function (t) {
    t.plan(4);

    resolve('foo', { basedir: symlinkDir }, 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 \'' + symlinkDir + '\'',
            'can not find nonexistent module'
        );
    });
});

test('sync symlink', function (t) {
    var start = new Date();
    t.doesNotThrow(function () {
        t.equal(resolve.sync('foo', { basedir: symlinkDir, preserveSymlinks: false }), 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) {
    t.throws(function () {
        resolve.sync('foo', { basedir: symlinkDir });
    }, /Cannot find module 'foo'/);
    t.end();
});

Version data entries

41 entries across 41 versions & 2 rubygems

Version Path
govuk_publishing_components-17.4.0 node_modules/resolve/test/symlinks.js
govuk_publishing_components-17.3.0 node_modules/resolve/test/symlinks.js
govuk_publishing_components-17.2.0 node_modules/resolve/test/symlinks.js
govuk_publishing_components-17.1.1 node_modules/resolve/test/symlinks.js
govuk_publishing_components-17.1.0 node_modules/resolve/test/symlinks.js
govuk_publishing_components-17.0.0 node_modules/resolve/test/symlinks.js
govuk_publishing_components-16.29.0 node_modules/resolve/test/symlinks.js
govuk_publishing_components-16.28.0 node_modules/resolve/test/symlinks.js
govuk_publishing_components-16.27.1 node_modules/resolve/test/symlinks.js
govuk_publishing_components-16.27.0 node_modules/resolve/test/symlinks.js
govuk_publishing_components-16.26.0 node_modules/resolve/test/symlinks.js
govuk_publishing_components-16.25.0 node_modules/resolve/test/symlinks.js
govuk_publishing_components-16.24.0 node_modules/resolve/test/symlinks.js
govuk_publishing_components-16.23.0 node_modules/resolve/test/symlinks.js
govuk_publishing_components-16.22.0 node_modules/resolve/test/symlinks.js
govuk_publishing_components-16.21.0 node_modules/resolve/test/symlinks.js
govuk_publishing_components-16.20.1 node_modules/resolve/test/symlinks.js
govuk_publishing_components-16.20.0 node_modules/resolve/test/symlinks.js
govuk_publishing_components-16.19.0 node_modules/resolve/test/symlinks.js
govuk_publishing_components-16.18.0 node_modules/resolve/test/symlinks.js