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

The debugger doesn't stop at debugger; statement in VSCode with TypeScript compilerOptions.target="es2017" #299

Closed
trivikr opened this issue Aug 26, 2017 · 12 comments
Labels

Comments

@trivikr
Copy link
Contributor

trivikr commented Aug 26, 2017

  • 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?

@trivikr
Copy link
Contributor Author

trivikr commented Aug 28, 2017

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

@trivikr
Copy link
Contributor Author

trivikr commented Aug 28, 2017

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.

@kulshekhar
Copy link
Owner

kulshekhar commented Aug 29, 2017

@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?

@GeeWee
Copy link
Collaborator

GeeWee commented Aug 29, 2017

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

@trivikr
Copy link
Contributor Author

trivikr commented Aug 29, 2017

@kulshekhar

The contents of result in getTSConfig():

return result;

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

@trivikr
Copy link
Contributor Author

trivikr commented Aug 29, 2017

The contents of modified are different in function process() at

return modified;

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

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

The sourceMappingUrl is different

@trivikr
Copy link
Contributor Author

trivikr commented Aug 29, 2017

Issue: parameter inlineSources is not set to true when it's not explicitly defined in compilerOptions

const compilerOptions = getTSConfig(
config.globals,
transformOptions.instrument,
);

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:

ts-jest/src/utils.ts

Lines 156 to 163 in a413a04

const tsConfigCacheKey = JSON.stringify([
skipBabel,
collectCoverage,
isReferencedExternalFile ? config : undefined,
]);
if (tsConfigCacheKey in tsConfigCache) {
return tsConfigCache[tsConfigCacheKey];
}

My repro repository does pass parameters --runInBand and --no-cache while debugging tests in VSCode in launch.json

@kulshekhar
Copy link
Owner

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

@trivikr
Copy link
Contributor Author

trivikr commented Aug 30, 2017

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.

@tkrotoff
Copy link
Contributor

tkrotoff commented Aug 30, 2017

@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?

@trivikr
Copy link
Contributor Author

trivikr commented Aug 30, 2017

@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.

@trivikr
Copy link
Contributor Author

trivikr commented Aug 31, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants