|
| 1 | +import{spawnPromisified}from'../common/index.mjs'; |
| 2 | +import*asfixturesfrom'../common/fixtures.mjs'; |
| 3 | +importassertfrom'node:assert'; |
| 4 | +import{execPath}from'node:process'; |
| 5 | +import{describe,it}from'node:test'; |
| 6 | + |
| 7 | +describe('esm source-map',{concurrency: true},()=>{ |
| 8 | +// Issue: https://github.com/nodejs/node/issues/51522 |
| 9 | + |
| 10 | +[ |
| 11 | +[ |
| 12 | +'in middle from esm', |
| 13 | +'source-map/extract-url/esm-url-in-middle.mjs', |
| 14 | +true, |
| 15 | +], |
| 16 | +[ |
| 17 | +'inside string from esm', |
| 18 | +'source-map/extract-url/esm-url-in-string.mjs', |
| 19 | +false, |
| 20 | +], |
| 21 | +].forEach(([name,path,shouldExtract])=>{ |
| 22 | +it((shouldExtract ? 'should extract source map url' : 'should not extract source map url')+name,async()=>{ |
| 23 | +const{ code, signal, stdout, stderr }=awaitspawnPromisified(execPath,[ |
| 24 | +'--no-warnings', |
| 25 | +'--enable-source-maps', |
| 26 | +fixtures.path(path), |
| 27 | +]); |
| 28 | + |
| 29 | +assert.strictEqual(stdout,''); |
| 30 | +if(shouldExtract){ |
| 31 | +assert.match(stderr,/index\.ts/); |
| 32 | +}else{ |
| 33 | +assert.doesNotMatch(stderr,/index\.ts/); |
| 34 | +} |
| 35 | +assert.strictEqual(code,1); |
| 36 | +assert.strictEqual(signal,null); |
| 37 | +}); |
| 38 | +}); |
| 39 | + |
| 40 | +[ |
| 41 | +[ |
| 42 | +'in middle from esm imported by esm', |
| 43 | +`import ${JSON.stringify(fixtures.fileURL('source-map/extract-url/esm-url-in-middle.mjs'))}`, |
| 44 | +true, |
| 45 | +], |
| 46 | +[ |
| 47 | +'in middle from cjs imported by esm', |
| 48 | +`import ${JSON.stringify(fixtures.fileURL('source-map/extract-url/cjs-url-in-middle.js'))}`, |
| 49 | +true, |
| 50 | +], |
| 51 | +[ |
| 52 | +'in middle from cjs required by esm', |
| 53 | +"import { createRequire } from 'module';"+ |
| 54 | +'const require = createRequire(import.meta.url);'+ |
| 55 | +`require(${JSON.stringify(fixtures.path('source-map/extract-url/cjs-url-in-middle.js'))})`, |
| 56 | +true, |
| 57 | +], |
| 58 | + |
| 59 | +[ |
| 60 | +'inside string from esm imported by esm', |
| 61 | +`import ${JSON.stringify(fixtures.fileURL('source-map/extract-url/esm-url-in-string.mjs'))}`, |
| 62 | +false, |
| 63 | +], |
| 64 | +[ |
| 65 | +'inside string from cjs imported by esm', |
| 66 | +`import ${JSON.stringify(fixtures.fileURL('source-map/extract-url/cjs-url-in-string.js'))}`, |
| 67 | +false, |
| 68 | +], |
| 69 | +[ |
| 70 | +'inside string from cjs required by esm', |
| 71 | +"import { createRequire } from 'module';"+ |
| 72 | +'const require = createRequire(import.meta.url);'+ |
| 73 | +`require(${JSON.stringify(fixtures.path('source-map/extract-url/cjs-url-in-string.js'))})`, |
| 74 | +false, |
| 75 | +], |
| 76 | +].forEach(([name,evalCode,shouldExtract])=>{ |
| 77 | +it((shouldExtract ? 'should extract source map url' : 'should not extract source map url')+name,async()=>{ |
| 78 | +const{ code, signal, stdout, stderr }=awaitspawnPromisified(execPath,[ |
| 79 | +'--no-warnings', |
| 80 | +'--enable-source-maps', |
| 81 | +'--input-type=module', |
| 82 | +'--eval', |
| 83 | +evalCode, |
| 84 | +]); |
| 85 | + |
| 86 | +assert.strictEqual(stdout,''); |
| 87 | +if(shouldExtract){ |
| 88 | +assert.match(stderr,/index\.ts/); |
| 89 | +}else{ |
| 90 | +assert.doesNotMatch(stderr,/index\.ts/); |
| 91 | +} |
| 92 | +assert.strictEqual(code,1); |
| 93 | +assert.strictEqual(signal,null); |
| 94 | +}); |
| 95 | +}); |
| 96 | +}); |
0 commit comments