mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
Adds a new `../common/fixtures' module to begin normalizing `test/fixtures` use. Our test code is a bit inconsistent with regards to use of the fixtures directory. Some code uses `path.join()`, some code uses string concats, some other code uses template strings, etc. In mnay cases, significant duplication of code is seen when accessing fixture files, etc. This updates many (but by no means all) of the tests in the test suite to use the new consistent API. There are still many more to update, which would make an excelent Code-n-Learn exercise. Backport-PR-URL: https://github.com/nodejs/node/pull/16265 PR-URL: https://github.com/nodejs/node/pull/14332 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Michaël Zasso <targos@protonmail.com>
61 lines
1.8 KiB
JavaScript
61 lines
1.8 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, spawn } = require('child_process');
|
|
const fixtures = require('../common/fixtures');
|
|
|
|
common.refreshTmpDir();
|
|
|
|
const linkTarget = fixtures.path('module-require-symlink',
|
|
'node_modules',
|
|
'dep2');
|
|
|
|
const linkDir = fixtures.path('module-require-symlink',
|
|
'node_modules',
|
|
'dep1',
|
|
'node_modules',
|
|
'dep2');
|
|
|
|
const linkScriptTarget = fixtures.path('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');
|
|
|
|
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(fixtures.path('/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);
|
|
});
|
|
}
|