Skip to content

Commit

Permalink
Merge pull request #470 from kulshekhar/sms-flag
Browse files Browse the repository at this point in the history
Allow disabling sourcemap support
  • Loading branch information
kulshekhar committed Mar 18, 2018
2 parents 17c6872 + e4bb8a9 commit b4628f0
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 6 deletions.
2 changes: 1 addition & 1 deletion 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",
Expand Down
1 change: 1 addition & 0 deletions src/jest-types.ts
Expand Up @@ -85,4 +85,5 @@ export interface TsJestConfig {
tsConfigFile?: string;
enableInternalCache?: boolean;
enableTsDiagnostics?: boolean;
disableSourceMapSupport?: boolean;
}
9 changes: 4 additions & 5 deletions src/preprocessor.ts
Expand Up @@ -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();

Expand Down
43 changes: 43 additions & 0 deletions 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();
});
});

0 comments on commit b4628f0

Please sign in to comment.