diff --git a/package.json b/package.json index 5f175a7921..160dbd3955 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ts-jest", - "version": "22.4.1", + "version": "22.4.2", "main": "index.js", "types": "./dist/index.d.ts", "description": "A preprocessor with sourcemap support to help use Typescript with Jest", diff --git a/src/jest-types.ts b/src/jest-types.ts index 893e917d14..cc60c276c7 100644 --- a/src/jest-types.ts +++ b/src/jest-types.ts @@ -85,4 +85,5 @@ export interface TsJestConfig { tsConfigFile?: string; enableInternalCache?: boolean; enableTsDiagnostics?: boolean; + disableSourceMapSupport?: boolean; } diff --git a/src/preprocessor.ts b/src/preprocessor.ts index e5aa403fd6..3026b43f0a 100644 --- a/src/preprocessor.ts +++ b/src/preprocessor.ts @@ -68,11 +68,10 @@ export function process( transformOptions, ); - const modified = injectSourcemapHook( - filePath, - tsTranspiled.outputText, - outputText, - ); + const modified = + tsJestConfig.disableSourceMapSupport === true + ? outputText + : injectSourcemapHook(filePath, tsTranspiled.outputText, outputText); flushLogs(); diff --git a/tests/__tests__/disable-sourcemap-support.spec.ts b/tests/__tests__/disable-sourcemap-support.spec.ts new file mode 100644 index 0000000000..89f614f4e6 --- /dev/null +++ b/tests/__tests__/disable-sourcemap-support.spec.ts @@ -0,0 +1,43 @@ +import runJest from '../__helpers__/runJest'; +import { process } from '../../src/preprocessor'; +import * as utils from '../../src/utils'; + +describe('sourcemap-support', () => { + function runProcess(jestConfig = {}) { + return process('input_code', 'fake_file.ts', jestConfig, { + instrument: false, + }); + } + + it('should be used by default', () => { + const spy = jest.spyOn(utils, 'injectSourcemapHook'); + + runProcess(); + expect(spy).toHaveBeenCalled(); + + spy.mockReset(); + spy.mockRestore(); + }); + + it(`should not be used when the disableSourceMapSupport flag is set to true`, async () => { + const spy = jest.spyOn(utils, 'injectSourcemapHook'); + + runProcess({ globals: { 'ts-jest': { disableSourceMapSupport: true } } }); + expect(spy).not.toHaveBeenCalled(); + + spy.mockReset(); + spy.mockRestore(); + }); + + it(`should be used when the disableSourceMapSupport flag is set to anything other than true`, async () => { + const spy = jest.spyOn(utils, 'injectSourcemapHook'); + + runProcess({ globals: { 'ts-jest': { disableSourceMapSupport: 'true' } } }); + expect(spy).toHaveBeenCalled(); + runProcess({ globals: { 'ts-jest': { disableSourceMapSupport: 1 } } }); + expect(spy).toHaveBeenCalled(); + + spy.mockReset(); + spy.mockRestore(); + }); +});