mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00

Files in `node_modules` are not authored by the user directly and the original sources are less relevant to the user. Skipping source maps in `node_modules` improves the general performance. Add `module.setSourceMapsSupport(enabled, options)` to skip source maps in `node_modules` if it is needed. This moves all source maps related API to `node:module` and this a step to promote the source maps API to stable. PR-URL: https://github.com/nodejs/node/pull/56639 Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
52 lines
2.4 KiB
JavaScript
52 lines
2.4 KiB
JavaScript
import * as common from '../common/index.mjs';
|
|
import * as fixtures from '../common/fixtures.mjs';
|
|
import * as snapshot from '../common/assertSnapshot.js';
|
|
import * as path from 'node:path';
|
|
import { describe, it } from 'node:test';
|
|
|
|
describe('sourcemaps output', { concurrency: !process.env.TEST_PARALLEL }, () => {
|
|
function normalize(str) {
|
|
const result = str
|
|
.replaceAll(snapshot.replaceWindowsPaths(process.cwd()), '')
|
|
.replaceAll('//', '*')
|
|
.replaceAll('/Users/bencoe/oss/coffee-script-test', '')
|
|
.replaceAll(/\/(\w)/g, '*$1')
|
|
.replaceAll('*test*', '*')
|
|
.replaceAll('*fixtures*source-map*', '*')
|
|
.replaceAll(/(\W+).*node:.*/g, '$1*');
|
|
if (common.isWindows) {
|
|
const currentDeviceLetter = path.parse(process.cwd()).root.substring(0, 1).toLowerCase();
|
|
const regex = new RegExp(`${currentDeviceLetter}:/?`, 'gi');
|
|
return result.replaceAll(regex, '');
|
|
}
|
|
return result;
|
|
}
|
|
const defaultTransform = snapshot
|
|
.transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths,
|
|
normalize, snapshot.replaceNodeVersion);
|
|
|
|
const tests = [
|
|
{ name: 'source-map/output/source_map_disabled_by_api.js' },
|
|
{ name: 'source-map/output/source_map_disabled_by_process_api.js' },
|
|
{ name: 'source-map/output/source_map_enabled_by_api.js' },
|
|
{ name: 'source-map/output/source_map_enabled_by_api_node_modules.js' },
|
|
{ name: 'source-map/output/source_map_enabled_by_process_api.js' },
|
|
{ name: 'source-map/output/source_map_enclosing_function.js' },
|
|
{ name: 'source-map/output/source_map_eval.js' },
|
|
{ name: 'source-map/output/source_map_no_source_file.js' },
|
|
{ name: 'source-map/output/source_map_prepare_stack_trace.js' },
|
|
{ name: 'source-map/output/source_map_reference_error_tabs.js' },
|
|
{ name: 'source-map/output/source_map_sourcemapping_url_string.js' },
|
|
{ name: 'source-map/output/source_map_throw_async_stack_trace.mjs' },
|
|
{ name: 'source-map/output/source_map_throw_catch.js' },
|
|
{ name: 'source-map/output/source_map_throw_construct.mjs' },
|
|
{ name: 'source-map/output/source_map_throw_first_tick.js' },
|
|
{ name: 'source-map/output/source_map_throw_icu.js' },
|
|
{ name: 'source-map/output/source_map_throw_set_immediate.js' },
|
|
];
|
|
for (const { name, transform } of tests) {
|
|
it(name, async () => {
|
|
await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform);
|
|
});
|
|
}
|
|
});
|