1// Flags: --experimental-wasm-modules 2import { mustNotCall, spawnPromisified } from '../common/index.mjs'; 3import * as fixtures from '../common/fixtures.mjs'; 4import { describe, it } from 'node:test'; 5import { match, ok, strictEqual } from 'node:assert'; 6 7describe('extensionless ES modules within a "type": "module" package scope', { concurrency: true }, () => { 8 it('should run as the entry point', async () => { 9 const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [ 10 fixtures.path('es-modules/package-type-module/noext-esm'), 11 ]); 12 13 strictEqual(stderr, ''); 14 strictEqual(stdout, 'executed\n'); 15 strictEqual(code, 0); 16 strictEqual(signal, null); 17 }); 18 19 it('should be importable', async () => { 20 const { default: defaultExport } = 21 await import(fixtures.fileURL('es-modules/package-type-module/noext-esm')); 22 strictEqual(defaultExport, 'module'); 23 }); 24 25 it('should be importable from a module scope under node_modules', async () => { 26 const { default: defaultExport } = 27 await import(fixtures.fileURL( 28 'es-modules/package-type-module/node_modules/dep-with-package-json-type-module/noext-esm')); 29 strictEqual(defaultExport, 'module'); 30 }); 31}); 32describe('extensionless Wasm modules within a "type": "module" package scope', { concurrency: true }, () => { 33 it('should run as the entry point', async () => { 34 const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [ 35 '--experimental-wasm-modules', 36 '--no-warnings', 37 fixtures.path('es-modules/package-type-module/noext-wasm'), 38 ]); 39 40 strictEqual(stderr, ''); 41 strictEqual(stdout, 'executed\n'); 42 strictEqual(code, 0); 43 strictEqual(signal, null); 44 }); 45 46 it('should be importable', async () => { 47 const { add } = await import(fixtures.fileURL('es-modules/package-type-module/noext-wasm')); 48 strictEqual(add(1, 2), 3); 49 }); 50 51 it('should be importable from a module scope under node_modules', async () => { 52 const { add } = await import(fixtures.fileURL( 53 'es-modules/package-type-module/node_modules/dep-with-package-json-type-module/noext-wasm')); 54 strictEqual(add(1, 2), 3); 55 }); 56}); 57 58describe('extensionless ES modules within no package scope', { concurrency: true }, () => { 59 // This succeeds with `--experimental-default-type=module` 60 it('should error as the entry point', async () => { 61 const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [ 62 fixtures.path('es-modules/noext-esm'), 63 ]); 64 65 match(stderr, /SyntaxError/); 66 strictEqual(stdout, ''); 67 strictEqual(code, 1); 68 strictEqual(signal, null); 69 }); 70 71 // This succeeds with `--experimental-default-type=module` 72 it('should error on import', async () => { 73 try { 74 await import(fixtures.fileURL('es-modules/noext-esm')); 75 mustNotCall(); 76 } catch (err) { 77 ok(err instanceof SyntaxError); 78 } 79 }); 80}); 81 82describe('extensionless Wasm within no package scope', { concurrency: true }, () => { 83 // This succeeds with `--experimental-default-type=module` 84 it('should error as the entry point', async () => { 85 const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [ 86 '--experimental-wasm-modules', 87 '--no-warnings', 88 fixtures.path('es-modules/noext-wasm'), 89 ]); 90 91 match(stderr, /SyntaxError/); 92 strictEqual(stdout, ''); 93 strictEqual(code, 1); 94 strictEqual(signal, null); 95 }); 96 97 // This succeeds with `--experimental-default-type=module` 98 it('should error on import', async () => { 99 try { 100 await import(fixtures.fileURL('es-modules/noext-wasm')); 101 mustNotCall(); 102 } catch (err) { 103 ok(err instanceof SyntaxError); 104 } 105 }); 106}); 107