|
| 1 | +import{spawnPromisified}from'../common/index.mjs'; |
| 2 | +import*asfixturesfrom'../common/fixtures.mjs'; |
| 3 | +import{describe,it}from'node:test'; |
| 4 | +import{match,strictEqual}from'node:assert'; |
| 5 | + |
| 6 | +describe('--experimental-default-type=module should not support extension searching',{concurrency: true},()=>{ |
| 7 | +it('should support extension searching under --experimental-default-type=commonjs',async()=>{ |
| 8 | +const{ code, signal, stdout, stderr }=awaitspawnPromisified(process.execPath,[ |
| 9 | +'--experimental-default-type=commonjs', |
| 10 | +'index', |
| 11 | +],{ |
| 12 | +cwd: fixtures.path('es-modules/package-without-type'), |
| 13 | +}); |
| 14 | + |
| 15 | +strictEqual(stdout,'package-without-type\n'); |
| 16 | +strictEqual(stderr,''); |
| 17 | +strictEqual(code,0); |
| 18 | +strictEqual(signal,null); |
| 19 | +}); |
| 20 | + |
| 21 | +it('should error with implicit extension under --experimental-default-type=module',async()=>{ |
| 22 | +const{ code, signal, stdout, stderr }=awaitspawnPromisified(process.execPath,[ |
| 23 | +'--experimental-default-type=module', |
| 24 | +'index', |
| 25 | +],{ |
| 26 | +cwd: fixtures.path('es-modules/package-without-type'), |
| 27 | +}); |
| 28 | + |
| 29 | +match(stderr,/ENOENT.*Didyoumeantoimport.*index\.js\?/s); |
| 30 | +strictEqual(stdout,''); |
| 31 | +strictEqual(code,1); |
| 32 | +strictEqual(signal,null); |
| 33 | +}); |
| 34 | +}); |
| 35 | + |
| 36 | +describe('--experimental-default-type=module should not parse paths as URLs',{concurrency: true},()=>{ |
| 37 | +it('should not parse a `?` in a filename as starting a query string',async()=>{ |
| 38 | +const{ code, signal, stdout, stderr }=awaitspawnPromisified(process.execPath,[ |
| 39 | +'--experimental-default-type=module', |
| 40 | +'file#1.js', |
| 41 | +],{ |
| 42 | +cwd: fixtures.path('es-modules/package-without-type'), |
| 43 | +}); |
| 44 | + |
| 45 | +strictEqual(stderr,''); |
| 46 | +strictEqual(stdout,'file#1\n'); |
| 47 | +strictEqual(code,0); |
| 48 | +strictEqual(signal,null); |
| 49 | +}); |
| 50 | + |
| 51 | +it('should resolve `..`',async()=>{ |
| 52 | +const{ code, signal, stdout, stderr }=awaitspawnPromisified(process.execPath,[ |
| 53 | +'--experimental-default-type=module', |
| 54 | +'../package-without-type/file#1.js', |
| 55 | +],{ |
| 56 | +cwd: fixtures.path('es-modules/package-without-type'), |
| 57 | +}); |
| 58 | + |
| 59 | +strictEqual(stderr,''); |
| 60 | +strictEqual(stdout,'file#1\n'); |
| 61 | +strictEqual(code,0); |
| 62 | +strictEqual(signal,null); |
| 63 | +}); |
| 64 | + |
| 65 | +it('should allow a leading `./`',async()=>{ |
| 66 | +const{ code, signal, stdout, stderr }=awaitspawnPromisified(process.execPath,[ |
| 67 | +'--experimental-default-type=module', |
| 68 | +'./file#1.js', |
| 69 | +],{ |
| 70 | +cwd: fixtures.path('es-modules/package-without-type'), |
| 71 | +}); |
| 72 | + |
| 73 | +strictEqual(stderr,''); |
| 74 | +strictEqual(stdout,'file#1\n'); |
| 75 | +strictEqual(code,0); |
| 76 | +strictEqual(signal,null); |
| 77 | +}); |
| 78 | + |
| 79 | +it('should not require a leading `./`',async()=>{ |
| 80 | +const{ code, signal, stdout, stderr }=awaitspawnPromisified(process.execPath,[ |
| 81 | +'--experimental-default-type=module', |
| 82 | +'file#1.js', |
| 83 | +],{ |
| 84 | +cwd: fixtures.path('es-modules/package-without-type'), |
| 85 | +}); |
| 86 | + |
| 87 | +strictEqual(stderr,''); |
| 88 | +strictEqual(stdout,'file#1\n'); |
| 89 | +strictEqual(code,0); |
| 90 | +strictEqual(signal,null); |
| 91 | +}); |
| 92 | +}); |
0 commit comments