Skip to content

Commit c3a86aa

Browse files
committed
Simplify tests
1 parent 6ccb3f9 commit c3a86aa

3 files changed

Lines changed: 25 additions & 106 deletions

File tree

test/common/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "commonjs"
3+
}

test/es-module/test-esm-type-flag-loose-files.mjs

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Flags: --experimental-type=module --experimental-wasm-modules
12
import { spawnPromisified } from '../common/index.mjs';
23
import * as fixtures from '../common/fixtures.mjs';
34
import { describe, it } from 'node:test';
@@ -43,43 +44,18 @@ describe('the type flag should change the interpretation of certain files outsid
4344
});
4445

4546
it('should import as ESM a .js file that is outside of any package scope', async () => {
46-
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
47-
'--experimental-type=module',
48-
fixtures.path('es-modules/imports-loose.mjs'),
49-
]);
50-
51-
strictEqual(stderr, '');
52-
strictEqual(stdout, 'executed\n');
53-
strictEqual(code, 0);
54-
strictEqual(signal, null);
47+
const { default: defaultExport } = await import(fixtures.fileURL('es-modules/loose.js'));
48+
strictEqual(defaultExport, 'module');
5549
});
5650

5751
it('should import as ESM an extensionless JavaScript file that is outside of any package scope', async () => {
58-
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
59-
'--experimental-type=module',
60-
fixtures.path('es-modules/imports-noext.mjs'),
61-
]);
62-
63-
strictEqual(stderr, '');
64-
strictEqual(stdout, 'executed\n');
65-
strictEqual(code, 0);
66-
strictEqual(signal, null);
52+
const { default: defaultExport } = await import(fixtures.fileURL('es-modules/noext-esm'));
53+
strictEqual(defaultExport, 'module');
6754
});
6855

6956
it('should import as Wasm an extensionless Wasm file that is outside of any package scope', async () => {
70-
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
71-
'--experimental-type=module',
72-
'--experimental-wasm-modules',
73-
'--no-warnings',
74-
'--eval',
75-
`import { add } from ${JSON.stringify(fixtures.fileURL('es-modules/noext-wasm'))};
76-
console.log(add(1, 2));`,
77-
]);
78-
79-
strictEqual(stderr, '');
80-
strictEqual(stdout, '3\n');
81-
strictEqual(code, 0);
82-
strictEqual(signal, null);
57+
const { add } = await import(fixtures.fileURL('es-modules/noext-wasm'));
58+
strictEqual(add(1, 2), 3);
8359
});
8460

8561
it('should check as ESM input passed via --check', async () => {

test/es-module/test-esm-type-flag-package-scopes.mjs

Lines changed: 15 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Flags: --experimental-type=module --experimental-wasm-modules
12
import { spawnPromisified } from '../common/index.mjs';
23
import * as fixtures from '../common/fixtures.mjs';
34
import { describe, it } from 'node:test';
@@ -17,15 +18,8 @@ describe('the type flag should change the interpretation of certain files within
1718
});
1819

1920
it('should import an extensionless JavaScript file within a "type": "module" scope', async () => {
20-
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
21-
'--experimental-type=module',
22-
fixtures.path('es-modules/package-type-module/imports-noext.mjs'),
23-
]);
24-
25-
strictEqual(stderr, '');
26-
strictEqual(stdout, 'executed\n');
27-
strictEqual(code, 0);
28-
strictEqual(signal, null);
21+
const { default: defaultExport } = await import(fixtures.fileURL('es-modules/package-type-module/noext-esm'));
22+
strictEqual(defaultExport, 'module');
2923
});
3024

3125
it('should run as Wasm an extensionless Wasm file within a "type": "module" scope', async () => {
@@ -43,19 +37,8 @@ describe('the type flag should change the interpretation of certain files within
4337
});
4438

4539
it('should import as Wasm an extensionless Wasm file within a "type": "module" scope', async () => {
46-
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
47-
'--experimental-type=module',
48-
'--experimental-wasm-modules',
49-
'--no-warnings',
50-
'--eval',
51-
`import { add } from ${JSON.stringify(fixtures.fileURL('es-modules/package-type-module/noext-wasm'))};
52-
console.log(add(1, 2));`,
53-
]);
54-
55-
strictEqual(stderr, '');
56-
strictEqual(stdout, '3\n');
57-
strictEqual(code, 0);
58-
strictEqual(signal, null);
40+
const { add } = await import(fixtures.fileURL('es-modules/package-type-module/noext-wasm'));
41+
strictEqual(add(1, 2), 3);
5942
});
6043
});
6144

@@ -99,45 +82,18 @@ describe('the type flag should change the interpretation of certain files within
9982
});
10083

10184
it('should import as ESM a .js file within package scope that has no defined "type" and is not under node_modules', async () => {
102-
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
103-
'--experimental-type=module',
104-
'--eval',
105-
`import ${JSON.stringify(fixtures.fileURL('es-modules/package-without-type/module.js'))};`,
106-
]);
107-
108-
strictEqual(stderr, '');
109-
strictEqual(stdout, 'executed\n');
110-
strictEqual(code, 0);
111-
strictEqual(signal, null);
85+
const { default: defaultExport } = await import(fixtures.fileURL('es-modules/package-without-type/module.js'));
86+
strictEqual(defaultExport, 'module');
11287
});
11388

11489
it('should import as ESM an extensionless JavaScript file within a package scope that has no defined "type" and is not under node_modules', async () => {
115-
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
116-
'--experimental-type=module',
117-
'--eval',
118-
`import ${JSON.stringify(fixtures.fileURL('es-modules/package-without-type/noext-esm'))};`,
119-
]);
120-
121-
strictEqual(stderr, '');
122-
strictEqual(stdout, 'executed\n');
123-
strictEqual(code, 0);
124-
strictEqual(signal, null);
90+
const { default: defaultExport } = await import(fixtures.fileURL('es-modules/package-without-type/noext-esm'));
91+
strictEqual(defaultExport, 'module');
12592
});
12693

12794
it('should import as Wasm an extensionless Wasm file within a package scope that has no defined "type" and is not under node_modules', async () => {
128-
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
129-
'--experimental-type=module',
130-
'--experimental-wasm-modules',
131-
'--no-warnings',
132-
'--eval',
133-
`import { add } from ${JSON.stringify(fixtures.fileURL('es-modules/noext-wasm'))};
134-
console.log(add(1, 2));`,
135-
]);
136-
137-
strictEqual(stderr, '');
138-
strictEqual(stdout, '3\n');
139-
strictEqual(code, 0);
140-
strictEqual(signal, null);
95+
const { add } = await import(fixtures.fileURL('es-modules/noext-wasm'));
96+
strictEqual(add(1, 2), 3);
14197
});
14298
});
14399

@@ -155,16 +111,8 @@ describe('the type flag should NOT change the interpretation of certain files wi
155111
});
156112

157113
it('should import as CommonJS a .js file within a package scope that has no defined "type" and is under node_modules', async () => {
158-
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
159-
'--experimental-type=module',
160-
'--eval',
161-
`import ${JSON.stringify(fixtures.fileURL('es-modules/package-type-module/node_modules/dep-with-package-json/run.js'))};`,
162-
]);
163-
164-
strictEqual(stderr, '');
165-
strictEqual(stdout, 'executed\n');
166-
strictEqual(code, 0);
167-
strictEqual(signal, null);
114+
const { default: defaultExport } = await import(fixtures.fileURL('es-modules/package-type-module/node_modules/dep-with-package-json/run.js'));
115+
strictEqual(defaultExport, 42);
168116
});
169117

170118
it('should run as CommonJS an extensionless JavaScript file within a package scope that has no defined "type" and is under node_modules', async () => {
@@ -180,15 +128,7 @@ describe('the type flag should NOT change the interpretation of certain files wi
180128
});
181129

182130
it('should import as CommonJS an extensionless JavaScript file within a package scope that has no defined "type" and is under node_modules', async () => {
183-
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
184-
'--experimental-type=module',
185-
'--eval',
186-
`import ${JSON.stringify(fixtures.fileURL('es-modules/package-type-module/node_modules/dep-with-package-json/noext-cjs'))};`,
187-
]);
188-
189-
strictEqual(stderr, '');
190-
strictEqual(stdout, 'executed\n');
191-
strictEqual(code, 0);
192-
strictEqual(signal, null);
131+
const { default: defaultExport } = await import(fixtures.fileURL('es-modules/package-type-module/node_modules/dep-with-package-json/noext-cjs'));
132+
strictEqual(defaultExport, 42);
193133
});
194134
});

0 commit comments

Comments
 (0)