Browse Source

test: cleanup test require symlink

* 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>
v6.x
Paul Grock 8 years ago
committed by Jeremiah Senkpiel
parent
commit
cc61d1a3ba
  1. 17
      test/parallel/test-require-symlink.js

17
test/parallel/test-require-symlink.js

@ -7,6 +7,8 @@ const fs = require('fs');
const exec = require('child_process').exec; const exec = require('child_process').exec;
const spawn = require('child_process').spawn; const spawn = require('child_process').spawn;
common.refreshTmpDir();
const linkTarget = path.join(common.fixturesDir, const linkTarget = path.join(common.fixturesDir,
'/module-require-symlink/node_modules/dep2/'); '/module-require-symlink/node_modules/dep2/');
@ -22,8 +24,8 @@ if (common.isWindows) {
// On Windows, creating symlinks requires admin privileges. // On Windows, creating symlinks requires admin privileges.
// We'll only try to run symlink test if we have enough privileges. // We'll only try to run symlink test if we have enough privileges.
exec('whoami /priv', function(err, o) { exec('whoami /priv', function(err, o) {
if (err || o.indexOf('SeCreateSymbolicLinkPrivilege') == -1) { if (err || !o.includes('SeCreateSymbolicLinkPrivilege')) {
console.log('Skipped: insufficient privileges'); common.skip('insufficient privileges');
return; return;
} else { } else {
test(); test();
@ -36,21 +38,20 @@ if (common.isWindows) {
function test() { function test() {
process.on('exit', function() { process.on('exit', function() {
fs.unlinkSync(linkDir); fs.unlinkSync(linkDir);
fs.unlinkSync(linkScript);
}); });
fs.symlinkSync(linkTarget, linkDir); fs.symlinkSync(linkTarget, linkDir);
fs.symlinkSync(linkScriptTarget, linkScript); fs.symlinkSync(linkScriptTarget, linkScript);
// load symlinked-module // load symlinked-module
var fooModule = const fooModule =
require(path.join(common.fixturesDir, '/module-require-symlink/foo.js')); require(path.join(common.fixturesDir, '/module-require-symlink/foo.js'));
assert.equal(fooModule.dep1.bar.version, 'CORRECT_VERSION'); assert.strictEqual(fooModule.dep1.bar.version, 'CORRECT_VERSION');
assert.equal(fooModule.dep2.bar.version, 'CORRECT_VERSION'); assert.strictEqual(fooModule.dep2.bar.version, 'CORRECT_VERSION');
// load symlinked-script as main // load symlinked-script as main
var node = process.execPath; const node = process.execPath;
var child = spawn(node, ['--preserve-symlinks', linkScript]); const child = spawn(node, ['--preserve-symlinks', linkScript]);
child.on('close', function(code, signal) { child.on('close', function(code, signal) {
assert(!code); assert(!code);
assert(!signal); assert(!signal);

Loading…
Cancel
Save