Skip to content

Commit b4628f0

Browse files
authored
Merge pull request #470 from kulshekhar/sms-flag
Allow disabling sourcemap support
2 parents 17c6872 + e4bb8a9 commit b4628f0

File tree

4 files changed

+49
-6
lines changed

4 files changed

+49
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ts-jest",
3-
"version": "22.4.1",
3+
"version": "22.4.2",
44
"main": "index.js",
55
"types": "./dist/index.d.ts",
66
"description": "A preprocessor with sourcemap support to help use Typescript with Jest",

src/jest-types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,5 @@ export interface TsJestConfig {
8585
tsConfigFile?: string;
8686
enableInternalCache?: boolean;
8787
enableTsDiagnostics?: boolean;
88+
disableSourceMapSupport?: boolean;
8889
}

src/preprocessor.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,10 @@ export function process(
6868
transformOptions,
6969
);
7070

71-
const modified = injectSourcemapHook(
72-
filePath,
73-
tsTranspiled.outputText,
74-
outputText,
75-
);
71+
const modified =
72+
tsJestConfig.disableSourceMapSupport === true
73+
? outputText
74+
: injectSourcemapHook(filePath, tsTranspiled.outputText, outputText);
7675

7776
flushLogs();
7877

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import runJest from '../__helpers__/runJest';
2+
import { process } from '../../src/preprocessor';
3+
import * as utils from '../../src/utils';
4+
5+
describe('sourcemap-support', () => {
6+
function runProcess(jestConfig = {}) {
7+
return process('input_code', 'fake_file.ts', jestConfig, {
8+
instrument: false,
9+
});
10+
}
11+
12+
it('should be used by default', () => {
13+
const spy = jest.spyOn(utils, 'injectSourcemapHook');
14+
15+
runProcess();
16+
expect(spy).toHaveBeenCalled();
17+
18+
spy.mockReset();
19+
spy.mockRestore();
20+
});
21+
22+
it(`should not be used when the disableSourceMapSupport flag is set to true`, async () => {
23+
const spy = jest.spyOn(utils, 'injectSourcemapHook');
24+
25+
runProcess({ globals: { 'ts-jest': { disableSourceMapSupport: true } } });
26+
expect(spy).not.toHaveBeenCalled();
27+
28+
spy.mockReset();
29+
spy.mockRestore();
30+
});
31+
32+
it(`should be used when the disableSourceMapSupport flag is set to anything other than true`, async () => {
33+
const spy = jest.spyOn(utils, 'injectSourcemapHook');
34+
35+
runProcess({ globals: { 'ts-jest': { disableSourceMapSupport: 'true' } } });
36+
expect(spy).toHaveBeenCalled();
37+
runProcess({ globals: { 'ts-jest': { disableSourceMapSupport: 1 } } });
38+
expect(spy).toHaveBeenCalled();
39+
40+
spy.mockReset();
41+
spy.mockRestore();
42+
});
43+
});

0 commit comments

Comments
 (0)