|
1 | 1 | import{spawnPromisified}from'../common/index.mjs'; |
2 | 2 | import*asfixturesfrom'../common/fixtures.mjs'; |
3 | 3 | import{describe,it}from'node:test'; |
4 | | -import{match,strictEqual}from'node:assert'; |
5 | | - |
6 | | -describe('--experimental-default-type=module should not affect the interpretation of files with unknown extensions', |
7 | | -{concurrency: true},()=>{ |
8 | | -it('should error on an entry point with an unknown extension',async()=>{ |
9 | | -const{ code, signal, stdout, stderr }=awaitspawnPromisified(process.execPath,[ |
10 | | -'--experimental-default-type=module', |
11 | | -fixtures.path('es-modules/package-type-module/extension.unknown'), |
12 | | -]); |
13 | | - |
14 | | -match(stderr,/ERR_UNKNOWN_FILE_EXTENSION/); |
15 | | -strictEqual(stdout,''); |
16 | | -strictEqual(code,1); |
17 | | -strictEqual(signal,null); |
18 | | -}); |
19 | | - |
20 | | -it('should error on an import with an unknown extension',async()=>{ |
21 | | -const{ code, signal, stdout, stderr }=awaitspawnPromisified(process.execPath,[ |
22 | | -'--experimental-default-type=module', |
23 | | -fixtures.path('es-modules/package-type-module/imports-unknownext.mjs'), |
24 | | -]); |
25 | | - |
26 | | -match(stderr,/ERR_UNKNOWN_FILE_EXTENSION/); |
27 | | -strictEqual(stdout,''); |
28 | | -strictEqual(code,1); |
29 | | -strictEqual(signal,null); |
30 | | -}); |
31 | | -}); |
| 4 | +import{deepStrictEqual,match,strictEqual}from'node:assert'; |
| 5 | + |
| 6 | +describe('--experimental-default-type=module',{concurrency: true},()=>{ |
| 7 | +describe('should not affect the interpretation of files with unknown extensions',{concurrency: true},()=>{ |
| 8 | +it('should error on an entry point with an unknown extension',async()=>{ |
| 9 | +const{ code, signal, stdout, stderr }=awaitspawnPromisified(process.execPath,[ |
| 10 | +'--experimental-default-type=module', |
| 11 | +fixtures.path('es-modules/package-type-module/extension.unknown'), |
| 12 | +]); |
| 13 | + |
| 14 | +match(stderr,/ERR_UNKNOWN_FILE_EXTENSION/); |
| 15 | +strictEqual(stdout,''); |
| 16 | +strictEqual(code,1); |
| 17 | +strictEqual(signal,null); |
| 18 | +}); |
| 19 | + |
| 20 | +it('should error on an import with an unknown extension',async()=>{ |
| 21 | +const{ code, signal, stdout, stderr }=awaitspawnPromisified(process.execPath,[ |
| 22 | +'--experimental-default-type=module', |
| 23 | +fixtures.path('es-modules/package-type-module/imports-unknownext.mjs'), |
| 24 | +]); |
| 25 | + |
| 26 | +match(stderr,/ERR_UNKNOWN_FILE_EXTENSION/); |
| 27 | +strictEqual(stdout,''); |
| 28 | +strictEqual(code,1); |
| 29 | +strictEqual(signal,null); |
| 30 | +}); |
| 31 | +}); |
| 32 | + |
| 33 | +it('should affect CJS .js files (imported, required, entry points)',async()=>{ |
| 34 | +constresult=awaitspawnPromisified(process.execPath,[ |
| 35 | +'--experimental-default-type=module', |
| 36 | +fixtures.path('es-modules/package-type-commonjs/echo-require-cache.js'), |
| 37 | +]); |
| 38 | + |
| 39 | +deepStrictEqual(result,{ |
| 40 | +code: 0, |
| 41 | +stderr: '', |
| 42 | +stdout: 'undefined\n', |
| 43 | +signal: null, |
| 44 | +}); |
| 45 | +}); |
| 46 | + |
| 47 | +it('should affect .cjs files that are imported',async()=>{ |
| 48 | +constresult=awaitspawnPromisified(process.execPath,[ |
| 49 | +'--experimental-default-type=module', |
| 50 | +'-e', |
| 51 | +`import ${JSON.stringify(fixtures.fileURL('es-module-require-cache/echo.cjs'))}`, |
| 52 | +]); |
| 53 | + |
| 54 | +deepStrictEqual(result,{ |
| 55 | +code: 0, |
| 56 | +stderr: '', |
| 57 | +stdout: 'undefined\n', |
| 58 | +signal: null, |
| 59 | +}); |
| 60 | +}); |
| 61 | + |
| 62 | +it('should affect entry point .cjs files (with no hooks)',async()=>{ |
| 63 | +const{ stderr, stdout, code }=awaitspawnPromisified(process.execPath,[ |
| 64 | +'--experimental-default-type=module', |
| 65 | +fixtures.path('es-module-require-cache/echo.cjs'), |
| 66 | +]); |
| 67 | + |
| 68 | +strictEqual(stderr,''); |
| 69 | +match(stdout,/^undefined\n$/); |
| 70 | +strictEqual(code,0); |
| 71 | +}); |
| 72 | + |
| 73 | +it('should affect entry point .cjs files (when any hooks is registered)',async()=>{ |
| 74 | +constresult=awaitspawnPromisified(process.execPath,[ |
| 75 | +'--experimental-default-type=module', |
| 76 | +'--import', |
| 77 | +'data:text/javascript,import{register}from"node:module"register("data:text/javascript,");', |
| 78 | +fixtures.path('es-module-require-cache/echo.cjs'), |
| 79 | +]); |
| 80 | + |
| 81 | +deepStrictEqual(result,{ |
| 82 | +code: 0, |
| 83 | +stderr: '', |
| 84 | +stdout: 'undefined\n', |
| 85 | +signal: null, |
| 86 | +}); |
| 87 | +}); |
| 88 | + |
| 89 | +it('should not affect CJS from input-type',async()=>{ |
| 90 | +const{ stderr, stdout, code }=awaitspawnPromisified(process.execPath,[ |
| 91 | +'--experimental-default-type=module', |
| 92 | +'--input-type=commonjs', |
| 93 | +'-p', |
| 94 | +'require.cache', |
| 95 | +]); |
| 96 | + |
| 97 | +strictEqual(stderr,''); |
| 98 | +match(stdout,/^\[Object:nullprototype\]\{\}\n$/); |
| 99 | +strictEqual(code,0); |
| 100 | +}); |
| 101 | +}); |
0 commit comments