Ts-jest: The debugger doesn't stop at debugger; statement in VSCode with TypeScript compilerOptions.target="es2017"

Created on 26 Aug 2017  路  12Comments  路  Source: kulshekhar/ts-jest

  • Issue [FIXED - view comment]
    The debugger doesn't stop at debugger; statement in VSCode with Typescript compilerOptions.target="es2017"

  • Expected behavior
    The debugger should stop at debugger; in VSCode

  • Link to a minimal repo that reproduces this issue
    ts-jest-es2017-debugger-repro

    Screen recording

Is this an issue with my settings?

Bug

All 12 comments

The problem appears to be with sourceMaps.

The code is transformed in Jest here

const processed = transform.process(content, filename, this._config, {
  instrument,
});

And the sourceMaps are created here

const inlineSourceMap = convertSourceMap.fromSource(transformed.code);

For file SystemUnderTest.test.js in my repro project, the processed code is

'use strict';require('ts-jest').install();"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const SystemUnderTest_1 = require("../SystemUnderTest");
describe("Testing", () => {
    it("testing odd number", async () => {
        debugger;
        const output = await SystemUnderTest_1.oddOrEven(3);
        expect(output).toEqual("odd");
    });
    it("testing even number", async () => {
        debugger;
        const output = await SystemUnderTest_1.oddOrEven(2);
        expect(output).toEqual("even");
    });
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiU3lzdGVtVW5kZXJUZXN0LnRlc3QuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvX190ZXN0c19fL1N5c3RlbVVuZGVyVGVzdC50ZXN0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsd0RBQStDO0FBRS9DLFFBQVEsQ0FBQyxTQUFTLEVBQUU7SUFDbEIsRUFBRSxDQUFDLG9CQUFvQixFQUFFLEtBQUs7UUFDNUIsUUFBUSxDQUFDO1FBQ1QsTUFBTSxNQUFNLEdBQUcsTUFBTSwyQkFBUyxDQUFDLENBQUMsQ0FBQyxDQUFDO1FBQ2xDLE1BQU0sQ0FBQyxNQUFNLENBQUMsQ0FBQyxPQUFPLENBQUMsS0FBSyxDQUFDLENBQUM7SUFDaEMsQ0FBQyxDQUFDLENBQUM7SUFFSCxFQUFFLENBQUMscUJBQXFCLEVBQUUsS0FBSztRQUM3QixRQUFRLENBQUM7UUFDVCxNQUFNLE1BQU0sR0FBRyxNQUFNLDJCQUFTLENBQUMsQ0FBQyxDQUFDLENBQUM7UUFDbEMsTUFBTSxDQUFDLE1BQU0sQ0FBQyxDQUFDLE9BQU8sQ0FBQyxNQUFNLENBQUMsQ0FBQztJQUNqQyxDQUFDLENBQUMsQ0FBQztBQUNMLENBQUMsQ0FBQyxDQUFDIn0=

And the sourceMap is:

{
    "version": 3,
    "file": "SystemUnderTest.test.js",
    "sourceRoot": "",
    "sources": [
        "../src/__tests__/SystemUnderTest.test.ts"
    ],
    "names": [],
    "mappings": ";;AAAA,wDAA+C;AAE/C,QAAQ,CAAC,SAAS,EAAE;IAClB,EAAE,CAAC,oBAAoB,EAAE,KAAK;QAC5B,QAAQ,CAAC;QACT,MAAM,MAAM,GAAG,MAAM,2BAAS,CAAC,CAAC,CAAC,CAAC;QAClC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,qBAAqB,EAAE,KAAK;QAC7B,QAAQ,CAAC;QACT,MAAM,MAAM,GAAG,MAAM,2BAAS,CAAC,CAAC,CAAC,CAAC;QAClC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"
}

This seems to be an issue with sourceMaps since:

  • first debugger; statement stops at next line (as it's present in next line in processed code)
  • second debugger; statement stops at correct line (just because they're aligned in original and processed code)

Do I need to pass any special parameter for Jest? I'm already passing mapCoverage: true

The issue was fixed and verified in this commit in a private branch

The solution was to add inlineSourceMap and inlineSources instead of sourceMap in _tsconfig.json_ as follows:

- "sourceMap": true
+ "inlineSourceMap": true,
+ "inlineSources": true

This issue appears to be with NodeJS v8.4.0 and doesn't depend on value passed to compilerOptions. Keeping the issue open, so that documentation can be added in README.md explaining this issue.

@trivikr this is weird. We're already setting inlineSourceMap to true unless it has explicitly been set to false. You shouldn't need to do this explicitly. Can you just try again by just removing the sourceMap setting from the config?

Still, we might want to note this in the readme.

@kulshekhar

The contents of result in _getTSConfig()_: https://github.com/kulshekhar/ts-jest/blob/d8e03d67e06b49f4fb98c5e1889e38c6cf5fda2d/src/utils.ts#L230

With inlineSourceMap: true, inlineSources: true, sourceMap: undefined:
result:

{"target":4,"module":1,"moduleResolution":2,"inlineSourceMap":true,"inlineSources":true,"jsx":2}

With inlineSourceMap: undefined, inlineSources: undefined, sourceMap: true:
result:

{"target":4,"module":1,"moduleResolution":2,"inlineSourceMap":true,"inlineSources":true,"jsx":2}

So, the issue doesn't seem to be with getTSConfig() function.
@GeeWee If the bug can be fixed in code, we need not update README. I'll spend another 10-15 mins more debugging

The contents of modified are different in function _process()_ at https://github.com/kulshekhar/ts-jest/blob/a413a04f29c7b66e8d88b5555c25a2f59f40640a/src/preprocessor.ts#L68

With inlineSourceMap: undefined, inlineSources: undefined, sourceMap: true
modified.sourceMap.txt

With inlineSourceMap: true, inlineSources: true, sourceMap: undefined:
modified.inlineSourceMap.txt

The sourceMappingUrl is different

Issue: parameter _inlineSources_ is not set to true when it's not explicitly defined in compilerOptions https://github.com/kulshekhar/ts-jest/blob/a413a04f29c7b66e8d88b5555c25a2f59f40640a/src/preprocessor.ts#L18-L21

This happens when you place debug points in preprocessor.ts
However, when debug points are placed in utils.js the variable inlineSources is present in both cases.

Looks like this difference is because of tsConfigCacheKey: https://github.com/kulshekhar/ts-jest/blob/a413a04f29c7b66e8d88b5555c25a2f59f40640a/src/utils.ts#L156-L163

My repro repository does pass parameters _--runInBand_ and _--no-cache_ while debugging tests in VSCode in launch.json

@trivikr this has been fixed in 20.0.13. Could you confirm that this works for you?

Thank you @kulshekhar for taking up this bug fix.
I've verified this fix in this commit in my repo.

This issue can be closed.

@trivikr I'm testing vscode debug as well and found that there is no need for .vscode/tasks.json at all and thus also no need for preLaunchTask and outFiles inside .vscode/launch.json. Can you confirm?

@tkrotoff Yes, you're right. The repro repo ts-jest-es2017-debugger-repro just tests for test files and not build files.

So, file .vscode/tasks.json and params preLaunchTask and outFiles inside .vscode/launch.json are not required.
It's a repro repo, and presence of these files or values doesn't interfere with bug reproduction.

I was pulling the newest version of dependencies in my repo. I've changed it to pull specific versions so that bug will be reproducible in master branch of the repo.

As suggested by @tkrotoff I removed the commands unrelated to bug repro in this commit

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ahnpnl picture ahnpnl  路  3Comments

bruk1977 picture bruk1977  路  3Comments

stangerjm picture stangerjm  路  4Comments

RiJung picture RiJung  路  4Comments

jbreckmckye picture jbreckmckye  路  3Comments