mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
2a1607cc2e
PR-URL: https://github.com/nodejs/node/pull/54935 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
98 lines
3.4 KiB
JavaScript
98 lines
3.4 KiB
JavaScript
// Flags: --experimental-wasm-modules
|
|
import { spawnPromisified } from '../common/index.mjs';
|
|
import * as fixtures from '../common/fixtures.mjs';
|
|
import { describe, it } from 'node:test';
|
|
import { match, strictEqual } from 'node:assert';
|
|
|
|
describe('extensionless ES modules within a "type": "module" package scope', {
|
|
concurrency: !process.env.TEST_PARALLEL,
|
|
}, () => {
|
|
it('should run as the entry point', async () => {
|
|
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
|
|
fixtures.path('es-modules/package-type-module/noext-esm'),
|
|
]);
|
|
|
|
strictEqual(stderr, '');
|
|
strictEqual(stdout, 'executed\n');
|
|
strictEqual(code, 0);
|
|
strictEqual(signal, null);
|
|
});
|
|
|
|
it('should be importable', async () => {
|
|
const { default: defaultExport } =
|
|
await import(fixtures.fileURL('es-modules/package-type-module/noext-esm'));
|
|
strictEqual(defaultExport, 'module');
|
|
});
|
|
|
|
it('should be importable from a module scope under node_modules', async () => {
|
|
const { default: defaultExport } =
|
|
await import(fixtures.fileURL(
|
|
'es-modules/package-type-module/node_modules/dep-with-package-json-type-module/noext-esm'));
|
|
strictEqual(defaultExport, 'module');
|
|
});
|
|
});
|
|
describe('extensionless Wasm modules within a "type": "module" package scope', {
|
|
concurrency: !process.env.TEST_PARALLEL,
|
|
}, () => {
|
|
it('should run as the entry point', async () => {
|
|
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
|
|
'--experimental-wasm-modules',
|
|
'--no-warnings',
|
|
fixtures.path('es-modules/package-type-module/noext-wasm'),
|
|
]);
|
|
|
|
strictEqual(stderr, '');
|
|
strictEqual(stdout, 'executed\n');
|
|
strictEqual(code, 0);
|
|
strictEqual(signal, null);
|
|
});
|
|
|
|
it('should be importable', async () => {
|
|
const { add } = await import(fixtures.fileURL('es-modules/package-type-module/noext-wasm'));
|
|
strictEqual(add(1, 2), 3);
|
|
});
|
|
|
|
it('should be importable from a module scope under node_modules', async () => {
|
|
const { add } = await import(fixtures.fileURL(
|
|
'es-modules/package-type-module/node_modules/dep-with-package-json-type-module/noext-wasm'));
|
|
strictEqual(add(1, 2), 3);
|
|
});
|
|
});
|
|
|
|
describe('extensionless ES modules within no package scope', { concurrency: !process.env.TEST_PARALLEL }, () => {
|
|
it('should run as the entry point', async () => {
|
|
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
|
|
fixtures.path('es-modules/noext-esm'),
|
|
]);
|
|
|
|
strictEqual(stdout, 'executed\n');
|
|
strictEqual(stderr, '');
|
|
strictEqual(code, 0);
|
|
strictEqual(signal, null);
|
|
});
|
|
|
|
it('should run on import', async () => {
|
|
await import(fixtures.fileURL('es-modules/noext-esm'));
|
|
});
|
|
});
|
|
|
|
describe('extensionless Wasm within no package scope', { concurrency: !process.env.TEST_PARALLEL }, () => {
|
|
// This succeeds with `--experimental-default-type=module`
|
|
it('should error as the entry point', async () => {
|
|
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
|
|
'--experimental-wasm-modules',
|
|
'--no-warnings',
|
|
fixtures.path('es-modules/noext-wasm'),
|
|
]);
|
|
|
|
match(stderr, /SyntaxError/);
|
|
strictEqual(stdout, '');
|
|
strictEqual(code, 1);
|
|
strictEqual(signal, null);
|
|
});
|
|
|
|
it('should run on import', async () => {
|
|
await import(fixtures.fileURL('es-modules/noext-wasm'));
|
|
});
|
|
});
|