node/test/es-module/test-esm-type-flag-loose-files.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

76 lines
3.3 KiB
JavaScript

// Flags: --experimental-default-type=module --experimental-wasm-modules
import { spawnPromisified } from '../common/index.mjs';
import * as fixtures from '../common/fixtures.mjs';
import { describe, it } from 'node:test';
import { strictEqual } from 'node:assert';
describe('the type flag should change the interpretation of certain files outside of any package scope',
{ concurrency: !process.env.TEST_PARALLEL }, () => {
it('should run as ESM a .js file that is outside of any package scope', async () => {
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
'--experimental-default-type=module',
fixtures.path('es-modules/loose.js'),
]);
strictEqual(stderr, '');
strictEqual(stdout, 'executed\n');
strictEqual(code, 0);
strictEqual(signal, null);
});
it('should run as ESM an extensionless JavaScript file that is outside of any package scope', async () => {
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
'--experimental-default-type=module',
fixtures.path('es-modules/noext-esm'),
]);
strictEqual(stderr, '');
strictEqual(stdout, 'executed\n');
strictEqual(code, 0);
strictEqual(signal, null);
});
it('should run as Wasm an extensionless Wasm file that is outside of any package scope', async () => {
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
'--experimental-default-type=module',
'--experimental-wasm-modules',
'--no-warnings',
fixtures.path('es-modules/noext-wasm'),
]);
strictEqual(stderr, '');
strictEqual(stdout, '');
strictEqual(code, 0);
strictEqual(signal, null);
});
it('should import as ESM a .js file that is outside of any package scope', async () => {
const { default: defaultExport } = await import(fixtures.fileURL('es-modules/loose.js'));
strictEqual(defaultExport, 'module');
});
it('should import as ESM an extensionless JavaScript file that is outside of any package scope',
async () => {
const { default: defaultExport } = await import(fixtures.fileURL('es-modules/noext-esm'));
strictEqual(defaultExport, 'module');
});
it('should import as Wasm an extensionless Wasm file that is outside of any package scope', async () => {
const { add } = await import(fixtures.fileURL('es-modules/noext-wasm'));
strictEqual(add(1, 2), 3);
});
it('should check as ESM input passed via --check', async () => {
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
'--experimental-default-type=module',
'--check',
fixtures.path('es-modules/loose.js'),
]);
strictEqual(stderr, '');
strictEqual(stdout, '');
strictEqual(code, 0);
strictEqual(signal, null);
});
});