• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import * as common from '../common/index.mjs';
2import * as fixtures from '../common/fixtures.mjs';
3import * as snapshot from '../common/assertSnapshot.js';
4import * as path from 'node:path';
5import { describe, it } from 'node:test';
6
7describe('sourcemaps output', { concurrency: true }, () => {
8  function normalize(str) {
9    const result = str
10    .replaceAll(snapshot.replaceWindowsPaths(process.cwd()), '')
11    .replaceAll('//', '*')
12    .replaceAll('/Users/bencoe/oss/coffee-script-test', '')
13    .replaceAll(/\/(\w)/g, '*$1')
14    .replaceAll('*test*', '*')
15    .replaceAll('*fixtures*source-map*', '*')
16    .replaceAll(/(\W+).*node:internal\*modules.*/g, '$1*');
17    if (common.isWindows) {
18      const currentDeviceLetter = path.parse(process.cwd()).root.substring(0, 1).toLowerCase();
19      const regex = new RegExp(`${currentDeviceLetter}:/?`, 'gi');
20      return result.replaceAll(regex, '');
21    }
22    return result;
23  }
24  const defaultTransform = snapshot
25    .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths,
26               normalize, snapshot.replaceNodeVersion);
27
28  const tests = [
29    { name: 'source-map/output/source_map_disabled_by_api.js' },
30    { name: 'source-map/output/source_map_enabled_by_api.js' },
31    { name: 'source-map/output/source_map_enclosing_function.js' },
32    { name: 'source-map/output/source_map_eval.js' },
33    { name: 'source-map/output/source_map_no_source_file.js' },
34    { name: 'source-map/output/source_map_reference_error_tabs.js' },
35    { name: 'source-map/output/source_map_sourcemapping_url_string.js' },
36    { name: 'source-map/output/source_map_throw_catch.js' },
37    { name: 'source-map/output/source_map_throw_first_tick.js' },
38    { name: 'source-map/output/source_map_throw_icu.js' },
39    { name: 'source-map/output/source_map_throw_set_immediate.js' },
40  ];
41  for (const { name, transform } of tests) {
42    it(name, async () => {
43      await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform);
44    });
45  }
46});
47