11cb0ef41Sopenharmony_ci// Flags: --experimental-wasm-modules
21cb0ef41Sopenharmony_ciimport { mustNotCall, spawnPromisified } from '../common/index.mjs';
31cb0ef41Sopenharmony_ciimport * as fixtures from '../common/fixtures.mjs';
41cb0ef41Sopenharmony_ciimport { describe, it } from 'node:test';
51cb0ef41Sopenharmony_ciimport { match, ok, strictEqual } from 'node:assert';
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_cidescribe('extensionless ES modules within a "type": "module" package scope', { concurrency: true }, () => {
81cb0ef41Sopenharmony_ci  it('should run as the entry point', async () => {
91cb0ef41Sopenharmony_ci    const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
101cb0ef41Sopenharmony_ci      fixtures.path('es-modules/package-type-module/noext-esm'),
111cb0ef41Sopenharmony_ci    ]);
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ci    strictEqual(stderr, '');
141cb0ef41Sopenharmony_ci    strictEqual(stdout, 'executed\n');
151cb0ef41Sopenharmony_ci    strictEqual(code, 0);
161cb0ef41Sopenharmony_ci    strictEqual(signal, null);
171cb0ef41Sopenharmony_ci  });
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ci  it('should be importable', async () => {
201cb0ef41Sopenharmony_ci    const { default: defaultExport } =
211cb0ef41Sopenharmony_ci              await import(fixtures.fileURL('es-modules/package-type-module/noext-esm'));
221cb0ef41Sopenharmony_ci    strictEqual(defaultExport, 'module');
231cb0ef41Sopenharmony_ci  });
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ci  it('should be importable from a module scope under node_modules', async () => {
261cb0ef41Sopenharmony_ci    const { default: defaultExport } =
271cb0ef41Sopenharmony_ci      await import(fixtures.fileURL(
281cb0ef41Sopenharmony_ci        'es-modules/package-type-module/node_modules/dep-with-package-json-type-module/noext-esm'));
291cb0ef41Sopenharmony_ci    strictEqual(defaultExport, 'module');
301cb0ef41Sopenharmony_ci  });
311cb0ef41Sopenharmony_ci});
321cb0ef41Sopenharmony_cidescribe('extensionless Wasm modules within a "type": "module" package scope', { concurrency: true }, () => {
331cb0ef41Sopenharmony_ci  it('should run as the entry point', async () => {
341cb0ef41Sopenharmony_ci    const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
351cb0ef41Sopenharmony_ci      '--experimental-wasm-modules',
361cb0ef41Sopenharmony_ci      '--no-warnings',
371cb0ef41Sopenharmony_ci      fixtures.path('es-modules/package-type-module/noext-wasm'),
381cb0ef41Sopenharmony_ci    ]);
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_ci    strictEqual(stderr, '');
411cb0ef41Sopenharmony_ci    strictEqual(stdout, 'executed\n');
421cb0ef41Sopenharmony_ci    strictEqual(code, 0);
431cb0ef41Sopenharmony_ci    strictEqual(signal, null);
441cb0ef41Sopenharmony_ci  });
451cb0ef41Sopenharmony_ci
461cb0ef41Sopenharmony_ci  it('should be importable', async () => {
471cb0ef41Sopenharmony_ci    const { add } = await import(fixtures.fileURL('es-modules/package-type-module/noext-wasm'));
481cb0ef41Sopenharmony_ci    strictEqual(add(1, 2), 3);
491cb0ef41Sopenharmony_ci  });
501cb0ef41Sopenharmony_ci
511cb0ef41Sopenharmony_ci  it('should be importable from a module scope under node_modules', async () => {
521cb0ef41Sopenharmony_ci    const { add } = await import(fixtures.fileURL(
531cb0ef41Sopenharmony_ci      'es-modules/package-type-module/node_modules/dep-with-package-json-type-module/noext-wasm'));
541cb0ef41Sopenharmony_ci    strictEqual(add(1, 2), 3);
551cb0ef41Sopenharmony_ci  });
561cb0ef41Sopenharmony_ci});
571cb0ef41Sopenharmony_ci
581cb0ef41Sopenharmony_cidescribe('extensionless ES modules within no package scope', { concurrency: true }, () => {
591cb0ef41Sopenharmony_ci  // This succeeds with `--experimental-default-type=module`
601cb0ef41Sopenharmony_ci  it('should error as the entry point', async () => {
611cb0ef41Sopenharmony_ci    const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
621cb0ef41Sopenharmony_ci      fixtures.path('es-modules/noext-esm'),
631cb0ef41Sopenharmony_ci    ]);
641cb0ef41Sopenharmony_ci
651cb0ef41Sopenharmony_ci    match(stderr, /SyntaxError/);
661cb0ef41Sopenharmony_ci    strictEqual(stdout, '');
671cb0ef41Sopenharmony_ci    strictEqual(code, 1);
681cb0ef41Sopenharmony_ci    strictEqual(signal, null);
691cb0ef41Sopenharmony_ci  });
701cb0ef41Sopenharmony_ci
711cb0ef41Sopenharmony_ci  // This succeeds with `--experimental-default-type=module`
721cb0ef41Sopenharmony_ci  it('should error on import', async () => {
731cb0ef41Sopenharmony_ci    try {
741cb0ef41Sopenharmony_ci      await import(fixtures.fileURL('es-modules/noext-esm'));
751cb0ef41Sopenharmony_ci      mustNotCall();
761cb0ef41Sopenharmony_ci    } catch (err) {
771cb0ef41Sopenharmony_ci      ok(err instanceof SyntaxError);
781cb0ef41Sopenharmony_ci    }
791cb0ef41Sopenharmony_ci  });
801cb0ef41Sopenharmony_ci});
811cb0ef41Sopenharmony_ci
821cb0ef41Sopenharmony_cidescribe('extensionless Wasm within no package scope', { concurrency: true }, () => {
831cb0ef41Sopenharmony_ci  // This succeeds with `--experimental-default-type=module`
841cb0ef41Sopenharmony_ci  it('should error as the entry point', async () => {
851cb0ef41Sopenharmony_ci    const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
861cb0ef41Sopenharmony_ci      '--experimental-wasm-modules',
871cb0ef41Sopenharmony_ci      '--no-warnings',
881cb0ef41Sopenharmony_ci      fixtures.path('es-modules/noext-wasm'),
891cb0ef41Sopenharmony_ci    ]);
901cb0ef41Sopenharmony_ci
911cb0ef41Sopenharmony_ci    match(stderr, /SyntaxError/);
921cb0ef41Sopenharmony_ci    strictEqual(stdout, '');
931cb0ef41Sopenharmony_ci    strictEqual(code, 1);
941cb0ef41Sopenharmony_ci    strictEqual(signal, null);
951cb0ef41Sopenharmony_ci  });
961cb0ef41Sopenharmony_ci
971cb0ef41Sopenharmony_ci  // This succeeds with `--experimental-default-type=module`
981cb0ef41Sopenharmony_ci  it('should error on import', async () => {
991cb0ef41Sopenharmony_ci    try {
1001cb0ef41Sopenharmony_ci      await import(fixtures.fileURL('es-modules/noext-wasm'));
1011cb0ef41Sopenharmony_ci      mustNotCall();
1021cb0ef41Sopenharmony_ci    } catch (err) {
1031cb0ef41Sopenharmony_ci      ok(err instanceof SyntaxError);
1041cb0ef41Sopenharmony_ci    }
1051cb0ef41Sopenharmony_ci  });
1061cb0ef41Sopenharmony_ci});
107