Skip to content

Commit

Permalink
fix(testing): spec source maps works in node debugger
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed Aug 19, 2019
1 parent 110d5e4 commit 225f488
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/testing/jest/jest-preprocessor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { formatDiagnostic, getCompilerOptions, transpile } from '../test-transpile';
import { basename } from 'path';


export const jestPreprocessor = {
Expand All @@ -20,11 +21,17 @@ export const jestPreprocessor = {
const msg = results.diagnostics.map(formatDiagnostic).join('\n\n');
throw new Error(msg);
}
const mapObject = JSON.parse(results.map);
const base = basename(filePath);
mapObject.file = filePath;
mapObject.sources = [filePath];
delete mapObject.sourceRoot;

return {
code: results.code,
map: results.map
};
const mapBase64 = Buffer.from(JSON.stringify(mapObject), 'utf8').toString('base64');
const sourceMapInlined = `data:application/json;charset=utf-8;base64,${mapBase64}`;
const sourceMapLength = `${base}.map`.length;

return results.code.slice(0, -sourceMapLength) + sourceMapInlined;
}

return sourceText;
Expand Down

0 comments on commit 225f488

Please sign in to comment.