Skip to content

Commit 225f488

Browse files
committed
fix(testing): spec source maps works in node debugger
1 parent 110d5e4 commit 225f488

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/testing/jest/jest-preprocessor.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { formatDiagnostic, getCompilerOptions, transpile } from '../test-transpile';
2+
import { basename } from 'path';
23

34

45
export const jestPreprocessor = {
@@ -20,11 +21,17 @@ export const jestPreprocessor = {
2021
const msg = results.diagnostics.map(formatDiagnostic).join('\n\n');
2122
throw new Error(msg);
2223
}
24+
const mapObject = JSON.parse(results.map);
25+
const base = basename(filePath);
26+
mapObject.file = filePath;
27+
mapObject.sources = [filePath];
28+
delete mapObject.sourceRoot;
2329

24-
return {
25-
code: results.code,
26-
map: results.map
27-
};
30+
const mapBase64 = Buffer.from(JSON.stringify(mapObject), 'utf8').toString('base64');
31+
const sourceMapInlined = `data:application/json;charset=utf-8;base64,${mapBase64}`;
32+
const sourceMapLength = `${base}.map`.length;
33+
34+
return results.code.slice(0, -sourceMapLength) + sourceMapInlined;
2835
}
2936

3037
return sourceText;

0 commit comments

Comments
 (0)