node/test/es-module/test-esm-cjs-load-error-note.mjs
Antoine du Hamel bae14b7914
test: do not set concurrency on parallelized runs
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>
2024-03-23 21:11:28 +00:00

97 lines
2.9 KiB
JavaScript

import { spawnPromisified } from '../common/index.mjs';
import * as fixtures from '../common/fixtures.mjs';
import assert from 'node:assert';
import { execPath } from 'node:process';
import { describe, it } from 'node:test';
// Expect note to be included in the error output
// Don't match the following sentence because it can change as features are
// added.
const expectedNote = 'Warning: To load an ES module';
const mustIncludeMessage = {
getMessage: (stderr) => `${expectedNote} not found in ${stderr}`,
includeNote: true,
};
const mustNotIncludeMessage = {
getMessage: (stderr) => `${expectedNote} must not be included in ${stderr}`,
includeNote: false,
};
describe('ESM: Errors for unexpected exports', { concurrency: !process.env.TEST_PARALLEL }, () => {
for (
const { errorNeedle, filePath, getMessage, includeNote }
of [
{
// name: '',
filePath: fixtures.path('/es-modules/es-note-unexpected-export-1.cjs'),
...mustIncludeMessage,
},
{
// name: '',
filePath: fixtures.path('/es-modules/es-note-unexpected-import-1.cjs'),
...mustIncludeMessage,
},
{
// name: '',
filePath: fixtures.path('/es-modules/es-note-promiserej-import-2.cjs'),
...mustNotIncludeMessage,
},
{
// name: '',
filePath: fixtures.path('/es-modules/es-note-unexpected-import-3.cjs'),
...mustIncludeMessage,
},
{
// name: '',
filePath: fixtures.path('/es-modules/es-note-unexpected-import-4.cjs'),
...mustIncludeMessage,
},
{
// name: '',
filePath: fixtures.path('/es-modules/es-note-unexpected-import-5.cjs'),
...mustNotIncludeMessage,
},
{
// name: '',
filePath: fixtures.path('/es-modules/es-note-error-1.mjs'),
...mustNotIncludeMessage,
errorNeedle: /Error: some error/,
},
{
// name: '',
filePath: fixtures.path('/es-modules/es-note-error-2.mjs'),
...mustNotIncludeMessage,
errorNeedle: /string/,
},
{
// name: '',
filePath: fixtures.path('/es-modules/es-note-error-3.mjs'),
...mustNotIncludeMessage,
errorNeedle: /null/,
},
{
// name: '',
filePath: fixtures.path('/es-modules/es-note-error-4.mjs'),
...mustNotIncludeMessage,
errorNeedle: /undefined/,
},
]
) {
it(`should ${includeNote ? '' : 'NOT'} include note`, async () => {
const { code, stderr } = await spawnPromisified(execPath, [filePath]);
assert.strictEqual(code, 1);
if (errorNeedle != null) assert.match(stderr, errorNeedle);
const shouldIncludeNote = stderr.includes(expectedNote);
assert.ok(
includeNote ? shouldIncludeNote : !shouldIncludeNote,
`${filePath} ${getMessage(stderr)}`,
);
});
}
});