mirror of
https://github.com/nodejs/node.git
synced 2025-05-02 03:31:35 +00:00

* Changed `==` to `includes` for clarity. * Switched to `assert.strictEqual` from `assert.equal` * Changed some `var` to `const` * Test cleanup with `common.refreshTmpDir` PR-URL: https://github.com/nodejs/node/pull/8305 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
60 lines
1.7 KiB
JavaScript
60 lines
1.7 KiB
JavaScript
// Flags: --preserve-symlinks
|
|
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const path = require('path');
|
|
const fs = require('fs');
|
|
const exec = require('child_process').exec;
|
|
const spawn = require('child_process').spawn;
|
|
|
|
common.refreshTmpDir();
|
|
|
|
const linkTarget = path.join(common.fixturesDir,
|
|
'/module-require-symlink/node_modules/dep2/');
|
|
|
|
const linkDir = path.join(common.fixturesDir,
|
|
'/module-require-symlink/node_modules/dep1/node_modules/dep2');
|
|
|
|
const linkScriptTarget = path.join(common.fixturesDir,
|
|
'/module-require-symlink/symlinked.js');
|
|
|
|
const linkScript = path.join(common.tmpDir, 'module-require-symlink.js');
|
|
|
|
if (common.isWindows) {
|
|
// On Windows, creating symlinks requires admin privileges.
|
|
// We'll only try to run symlink test if we have enough privileges.
|
|
exec('whoami /priv', function(err, o) {
|
|
if (err || !o.includes('SeCreateSymbolicLinkPrivilege')) {
|
|
common.skip('insufficient privileges');
|
|
return;
|
|
} else {
|
|
test();
|
|
}
|
|
});
|
|
} else {
|
|
test();
|
|
}
|
|
|
|
function test() {
|
|
process.on('exit', function() {
|
|
fs.unlinkSync(linkDir);
|
|
});
|
|
|
|
fs.symlinkSync(linkTarget, linkDir);
|
|
fs.symlinkSync(linkScriptTarget, linkScript);
|
|
|
|
// load symlinked-module
|
|
const fooModule =
|
|
require(path.join(common.fixturesDir, '/module-require-symlink/foo.js'));
|
|
assert.strictEqual(fooModule.dep1.bar.version, 'CORRECT_VERSION');
|
|
assert.strictEqual(fooModule.dep2.bar.version, 'CORRECT_VERSION');
|
|
|
|
// load symlinked-script as main
|
|
const node = process.execPath;
|
|
const child = spawn(node, ['--preserve-symlinks', linkScript]);
|
|
child.on('close', function(code, signal) {
|
|
assert(!code);
|
|
assert(!signal);
|
|
});
|
|
}
|