• 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
7function replaceNodeVersion(str) {
8  return str.replaceAll(process.version, '*');
9}
10
11describe('sourcemaps output', { concurrency: true }, () => {
12  function normalize(str) {
13    const result = str
14    .replaceAll(snapshot.replaceWindowsPaths(process.cwd()), '')
15    .replaceAll('//', '*')
16    .replaceAll('/Users/bencoe/oss/coffee-script-test', '')
17    .replaceAll(/\/(\w)/g, '*$1')
18    .replaceAll('*test*', '*')
19    .replaceAll('*fixtures*source-map*', '*');
20    if (common.isWindows) {
21      const currentDeviceLetter = path.parse(process.cwd()).root.substring(0, 1).toLowerCase();
22      const regex = new RegExp(`${currentDeviceLetter}:/?`, 'gi');
23      return result.replaceAll(regex, '');
24    }
25    return result;
26  }
27  const defaultTransform = snapshot
28    .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths, normalize, replaceNodeVersion);
29
30  const tests = [
31    { name: 'source-map/output/source_map_disabled_by_api.js' },
32    { name: 'source-map/output/source_map_enabled_by_api.js' },
33    { name: 'source-map/output/source_map_eval.js' },
34    { name: 'source-map/output/source_map_no_source_file.js' },
35    { name: 'source-map/output/source_map_throw_first_tick.js' },
36  ];
37  for (const { name, transform } of tests) {
38    it(name, async () => {
39      await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform);
40    });
41  }
42});
43