From 50e9be7bf8943ed7aa2d820a8759ffbb2a33d764 Mon Sep 17 00:00:00 2001 From: kulshekhar Date: Mon, 19 Mar 2018 02:37:36 +0530 Subject: [PATCH 1/2] bump version patch --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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", From e4bb8a9fdd234acc5e2497c29d596bd7d0c5d366 Mon Sep 17 00:00:00 2001 From: kulshekhar Date: Mon, 19 Mar 2018 02:38:11 +0530 Subject: [PATCH 2/2] allow disabling sourcemap support --- src/jest-types.ts | 1 + src/preprocessor.ts | 9 ++-- .../disable-sourcemap-support.spec.ts | 43 +++++++++++++++++++ 3 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 tests/__tests__/disable-sourcemap-support.spec.ts 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(); + }); +});