MCPcopy Create free account
hub / github.com/nodejs/node / test

Function test

test/parallel/test-require-symlink.js:67–119  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

65test();
66
67function test() {
68 fs.symlinkSync(linkTarget, linkDir, 'dir');
69 fs.symlinkSync(linkScriptTarget, linkScript);
70
71 // Load symlinked-module
72 const fooModule = require(path.join(tmpDirTarget, 'foo.js'));
73 assert.strictEqual(fooModule.dep1.bar.version, 'CORRECT_VERSION');
74 assert.strictEqual(fooModule.dep2.bar.version, 'CORRECT_VERSION');
75
76 // Load symlinked-script as main
77 const node = process.execPath;
78 const child = spawn(node, ['--preserve-symlinks', linkScript]);
79 child.on('close', common.mustCall((code, signal) => {
80 assert.strictEqual(code, 0);
81 assert(!signal);
82 }));
83
84 // Also verify that symlinks works for setting preserve via env variables
85 const childEnv = spawn(node, [linkScript], {
86 env: { ...process.env, NODE_PRESERVE_SYMLINKS: '1' }
87 });
88 childEnv.on('close', common.mustCall((code, signal) => {
89 assert.strictEqual(code, 0);
90 assert(!signal);
91 }));
92
93 // Also verify that symlinks works for setting preserve via env variables in
94 // Workers.
95 const worker = new Worker(linkScript, {
96 env: { ...process.env, NODE_PRESERVE_SYMLINKS: '1' }
97 });
98 worker.on('error', (err) => {
99 console.log('Worker failed');
100 throw err;
101 });
102 worker.on('exit', common.mustCall((code) => {
103 assert.strictEqual(code, 0);
104 }));
105
106 // Also verify that symlinks works for setting preserve via env variables in
107 // Workers with explicit execArgv.
108 const workerArgv = new Worker(linkScript, {
109 execArgv: [],
110 env: { ...process.env, NODE_PRESERVE_SYMLINKS: '1' }
111 });
112 workerArgv.on('error', (err) => {
113 console.log('Worker with execArgv failed');
114 throw err;
115 });
116 workerArgv.on('exit', common.mustCall((code) => {
117 assert.strictEqual(code, 0);
118 }));
119}

Callers 1

Calls 7

spawnFunction · 0.70
requireFunction · 0.50
assertFunction · 0.50
symlinkSyncMethod · 0.45
joinMethod · 0.45
onMethod · 0.45
logMethod · 0.45

Tested by

no test coverage detected