Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow disabling sourcemap support #470

Merged
merged 2 commits into from Mar 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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();
});
});