2023-09-30 05:01:55 +00:00
|
|
|
// Flags: --experimental-wasm-modules
|
2024-09-20 10:42:59 +00:00
|
|
|
import { spawnPromisified } from '../common/index.mjs';
|
2023-09-30 05:01:55 +00:00
|
|
|
import * as fixtures from '../common/fixtures.mjs';
|
|
|
|
import { describe, it } from 'node:test';
|
2024-09-20 10:42:59 +00:00
|
|
|
import { match, strictEqual } from 'node:assert';
|
2023-09-30 05:01:55 +00:00
|
|
|
|
2024-03-23 21:11:28 +00:00
|
|
|
describe('extensionless ES modules within a "type": "module" package scope', {
|
|
|
|
concurrency: !process.env.TEST_PARALLEL,
|
|
|
|
}, () => {
|
2023-09-30 05:01:55 +00:00
|
|
|
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');
|
|
|
|
});
|
|
|
|
});
|
2024-03-23 21:11:28 +00:00
|
|
|
describe('extensionless Wasm modules within a "type": "module" package scope', {
|
|
|
|
concurrency: !process.env.TEST_PARALLEL,
|
|
|
|
}, () => {
|
2023-09-30 05:01:55 +00:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2024-03-23 21:11:28 +00:00
|
|
|
describe('extensionless ES modules within no package scope', { concurrency: !process.env.TEST_PARALLEL }, () => {
|
2024-07-20 18:30:46 +00:00
|
|
|
it('should run as the entry point', async () => {
|
2023-09-30 05:01:55 +00:00
|
|
|
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
|
|
|
|
fixtures.path('es-modules/noext-esm'),
|
|
|
|
]);
|
|
|
|
|
2024-07-20 18:30:46 +00:00
|
|
|
strictEqual(stdout, 'executed\n');
|
|
|
|
strictEqual(stderr, '');
|
|
|
|
strictEqual(code, 0);
|
2023-09-30 05:01:55 +00:00
|
|
|
strictEqual(signal, null);
|
|
|
|
});
|
|
|
|
|
2024-07-20 18:30:46 +00:00
|
|
|
it('should run on import', async () => {
|
|
|
|
await import(fixtures.fileURL('es-modules/noext-esm'));
|
2023-09-30 05:01:55 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2024-03-23 21:11:28 +00:00
|
|
|
describe('extensionless Wasm within no package scope', { concurrency: !process.env.TEST_PARALLEL }, () => {
|
2023-09-30 05:01:55 +00:00
|
|
|
// 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);
|
|
|
|
});
|
|
|
|
|
2024-09-20 10:42:59 +00:00
|
|
|
it('should run on import', async () => {
|
|
|
|
await import(fixtures.fileURL('es-modules/noext-wasm'));
|
2023-09-30 05:01:55 +00:00
|
|
|
});
|
|
|
|
});
|