node/test/parallel/test-source-map-invalid-url.js
Chengzhong Wu afc30b71a8
lib: fix source map url parse in dynamic imports
PR-URL: https://github.com/nodejs/node/pull/61990
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
2026-03-03 20:35:35 +00:00

56 lines
1.4 KiB
JavaScript

// Flags: --enable-source-maps
'use strict';
const common = require('../common');
const assert = require('node:assert');
const childProcess = require('node:child_process');
// TODO(legendecas): c8 will complain if non-file-scheme is used in source maps.
// https://github.com/bcoe/c8/blob/ee2f1cfc5584d41bb2d51b788d0953dab0c798f8/lib/report.js#L517
if (process.env.NODE_V8_COVERAGE) {
console.log('Spawning with coverage disabled.');
const { status } = childProcess.spawnSync(
process.execPath,
[__filename],
{
stdio: 'inherit',
env: {
...process.env,
NODE_V8_COVERAGE: '',
},
},
);
assert.strictEqual(status, 0);
return;
}
const sources = [
`
//# sourceMappingURL=unknown-protocol://invalid/url
//# sourceURL=unknown-protocol://invalid/url
`,
`
//# sourceMappingURL=file://invalid:/file/url
//# sourceURL=file://invalid:/file/url
`,
`
//# sourceMappingURL=invalid-url
//# sourceURL=invalid-url
`,
];
sources.forEach(test);
function test(source) {
// Eval should tolerate invalid source map url
eval(source);
const base64 = Buffer.from(source).toString('base64url');
// Dynamic import should tolerate invalid source map url
import(`data:text/javascript;base64,${base64}`)
.then(common.mustCall());
}
// eslint-disable-next-line @stylistic/js/spaced-comment
//# sourceMappingURL=invalid-url