Skip to content

Commit

Permalink
allow disabling sourcemap support
Browse files Browse the repository at this point in the history
  • Loading branch information
kulshekhar committed Mar 18, 2018
1 parent 50e9be7 commit e4bb8a9
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
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 e4bb8a9

Please sign in to comment.