• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Flags: --experimental-default-type=module --experimental-wasm-modules
2import { spawnPromisified } from '../common/index.mjs';
3import * as fixtures from '../common/fixtures.mjs';
4import { describe, it } from 'node:test';
5import { strictEqual } from 'node:assert';
6
7describe('the type flag should change the interpretation of certain files outside of any package scope',
8         { concurrency: true }, () => {
9           it('should run as ESM a .js file that is outside of any package scope', async () => {
10             const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
11               '--experimental-default-type=module',
12               fixtures.path('es-modules/loose.js'),
13             ]);
14
15             strictEqual(stderr, '');
16             strictEqual(stdout, 'executed\n');
17             strictEqual(code, 0);
18             strictEqual(signal, null);
19           });
20
21           it('should run as ESM an extensionless JavaScript file that is outside of any package scope', async () => {
22             const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
23               '--experimental-default-type=module',
24               fixtures.path('es-modules/noext-esm'),
25             ]);
26
27             strictEqual(stderr, '');
28             strictEqual(stdout, 'executed\n');
29             strictEqual(code, 0);
30             strictEqual(signal, null);
31           });
32
33           it('should run as Wasm an extensionless Wasm file that is outside of any package scope', async () => {
34             const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
35               '--experimental-default-type=module',
36               '--experimental-wasm-modules',
37               '--no-warnings',
38               fixtures.path('es-modules/noext-wasm'),
39             ]);
40
41             strictEqual(stderr, '');
42             strictEqual(stdout, '');
43             strictEqual(code, 0);
44             strictEqual(signal, null);
45           });
46
47           it('should import as ESM a .js file that is outside of any package scope', async () => {
48             const { default: defaultExport } = await import(fixtures.fileURL('es-modules/loose.js'));
49             strictEqual(defaultExport, 'module');
50           });
51
52           it('should import as ESM an extensionless JavaScript file that is outside of any package scope',
53              async () => {
54                const { default: defaultExport } = await import(fixtures.fileURL('es-modules/noext-esm'));
55                strictEqual(defaultExport, 'module');
56              });
57
58           it('should import as Wasm an extensionless Wasm file that is outside of any package scope', async () => {
59             const { add } = await import(fixtures.fileURL('es-modules/noext-wasm'));
60             strictEqual(add(1, 2), 3);
61           });
62
63           it('should check as ESM input passed via --check', async () => {
64             const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
65               '--experimental-default-type=module',
66               '--check',
67               fixtures.path('es-modules/loose.js'),
68             ]);
69
70             strictEqual(stderr, '');
71             strictEqual(stdout, '');
72             strictEqual(code, 0);
73             strictEqual(signal, null);
74           });
75         });
76