1+ // Flags: --experimental-type=module --experimental-wasm-modules
12import { spawnPromisified } from '../common/index.mjs' ;
23import * as fixtures from '../common/fixtures.mjs' ;
34import { 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