mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
bae14b7914
Our CI already run test files in parallel, having `node:test` spawns child processes concurrently could lead to oversubscribing the CI machine. This commit sets the `concurrency` depending on the presence of `TEST_PARALLEL` in the env, so running the test file individually still spawns child processes concurrently, and running the whole test suite does not oversubscribe the machine. PR-URL: https://github.com/nodejs/node/pull/52177 Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
77 lines
2.4 KiB
JavaScript
77 lines
2.4 KiB
JavaScript
'use strict';
|
|
|
|
const { spawnPromisified, skip } = require('../common');
|
|
const tmpdir = require('../common/tmpdir');
|
|
|
|
// Invoke the main file via a symlink. In this case --preserve-symlinks-main
|
|
// dictates that it'll resolve relative imports in the main file relative to
|
|
// the symlink, and not relative to the symlink target; the file structure set
|
|
// up below requires this to not crash when loading ./submodule_link.js
|
|
|
|
const assert = require('node:assert');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const { execPath } = require('node:process');
|
|
const { describe, it } = require('node:test');
|
|
|
|
tmpdir.refresh();
|
|
const tmpDir = tmpdir.path;
|
|
|
|
fs.mkdirSync(path.join(tmpDir, 'nested'));
|
|
fs.mkdirSync(path.join(tmpDir, 'nested2'));
|
|
|
|
const entry = path.join(tmpDir, 'nested', 'entry.js');
|
|
const entry_link_absolute_path = path.join(tmpDir, 'index.js');
|
|
const submodule = path.join(tmpDir, 'nested2', 'submodule.js');
|
|
const submodule_link_absolute_path = path.join(tmpDir, 'submodule_link.js');
|
|
|
|
fs.writeFileSync(entry, `
|
|
const assert = require('assert');
|
|
|
|
// this import only resolves with --preserve-symlinks-main set
|
|
require('./submodule_link.js');
|
|
`);
|
|
fs.writeFileSync(submodule, '');
|
|
|
|
try {
|
|
fs.symlinkSync(entry, entry_link_absolute_path);
|
|
fs.symlinkSync(submodule, submodule_link_absolute_path);
|
|
} catch (err) {
|
|
if (err.code !== 'EPERM') throw err;
|
|
skip('insufficient privileges for symlinks');
|
|
}
|
|
|
|
describe('Invoke the main file via a symlink.', { concurrency: !process.env.TEST_PARALLEL }, () => {
|
|
it('should resolve relative imports in the main file', async () => {
|
|
const { code } = await spawnPromisified(execPath, [
|
|
'--preserve-symlinks',
|
|
'--preserve-symlinks-main',
|
|
entry_link_absolute_path,
|
|
]);
|
|
|
|
assert.strictEqual(code, 0);
|
|
});
|
|
|
|
it('should resolve relative imports in the main file when file extension is omitted', async () => {
|
|
const entry_link_absolute_path_without_ext = path.join(tmpDir, 'index');
|
|
|
|
const { code } = await spawnPromisified(execPath, [
|
|
'--preserve-symlinks',
|
|
'--preserve-symlinks-main',
|
|
entry_link_absolute_path_without_ext,
|
|
]);
|
|
|
|
assert.strictEqual(code, 0);
|
|
});
|
|
|
|
it('should resolve relative imports in the main file when filename(index.js) is omitted', async () => {
|
|
const { code } = await spawnPromisified(execPath, [
|
|
'--preserve-symlinks',
|
|
'--preserve-symlinks-main',
|
|
tmpDir,
|
|
]);
|
|
|
|
assert.strictEqual(code, 0);
|
|
});
|
|
});
|