Ts-jest: The debugger doesn't stop at debugger; statement in VSCode in source files when using Node v8.4.0

Created on 30 Aug 2017  路  17Comments  路  Source: kulshekhar/ts-jest

  • Issue
    The debugger doesn't stop at debugger; statement in VSCode in source files when using Node v8.4.0
    The earlier issue discussed in #299 is was with test files, and is fixed in v20.0.13 with PR #306
    This issue is with source files.

  • Expected behavior
    The debugger should stop at debugger; in VSCode for source files

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

    Screen recording

  • Optional (but highly recommended) - Configure Travis (or your favorite system) with the minimal repo
    Done

Most helpful comment

Thanks @morajabi for verifying the fix!
I've confirmed that both breakpoints and debugger statements work in VSCode in this private branch

Screen recording

@kulshekhar Yes, we can revert the documentation change done in #313

All 17 comments

While debugging, I put a breakpoint at https://github.com/kulshekhar/ts-jest/blob/a67fa3e79f729347c511a05637f1056d5c911e8d/src/preprocessor.ts#L37-L40

The compilerOptions when SystemUnderTest.test.ts is being transpiled

{
  "target": 4,
  "module": 1,
  "moduleResolution": 2,
  "outDir": "/Users/trivikr/workspace/ts-jest-node8-debugger-repro/build/",
  "inlineSourceMap": true,
  "inlineSources": true,
  "jsx": 2
}

and when SystemUnderTest.ts is being transpiled

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

When transpiling source files, the outDir parameter is not present.

The parameter outDir is removed for source files at https://github.com/kulshekhar/ts-jest/blob/a67fa3e79f729347c511a05637f1056d5c911e8d/src/utils.ts#L187-L191

However, the issue still exists if this code is removed.

Does it work with breakpoints? In general vscode isn't particularly fond of jest preprocessors for some reason.

It's funny, the debugger; statements work in Test files and breakpoints work in source files.
On the other hand, breakpoints don't work in test files and debugger; statements don't work in source files.

Is it possible to find out why breakpoints work in source files and implement it for test files?

@GeeWee The breakpoints will work in VSCode for test files if config.outDir is deleted without any condition in the code below https://github.com/kulshekhar/ts-jest/blob/64bbc6eacbe695056b5a064c6592e0224eb4b041/src/utils.ts#L187-L191

Is there some reason why config.outDir is deleted only when collectCoverage is set to true?

That's.. really weird haha. I think that's before my time - perhaps @kulshekhar can weigh in?

@kulshekhar and @GeeWee: I've created my first ever Open Source Contribution PR at #311
Do take a look when you're free. I would love to get your comments on it, and would like to be a contributor to ts-jest if it is safe to merge :)

I confirm this problem.

Reproduction: a project containing a file src/subdir/file.test.ts that throws an error (so the debugger stops at the exception) (1).

  • If tsconfig.json does not contain outDir
    => vscode detests file src/subdir/file.test.ts => OK

no-outdir

  • If tsconfig.json contains outDir
    => vscode detects file src/src/subdir/file.test.ts => BUG

outdir

To sum up, the problem happens when you have a subdirectory and outDir

See also https://github.com/kulshekhar/ts-jest/pull/313#issuecomment-326525758


(1) file.test.ts:

new Promise((resolve, reject) => {
  reject(new Error(''));
});

Thanks @tkrotoff for reproducing and confirming this error.
I confirmed that the issue is reproducible in sub directories, I've pushed my code in ts-jest-node8-debugger-repro/tree/subdir-test

The fix in PR #311 fixes the issue with breakpoints in both source and test files in VSCode for files in both rootDir and sub-directories.
The issue with debugger; statements is still reproducible though. But I was testing debugger; statements in the original request as breakpoints were not working in previous versions of ts-jest. Developers will always prefer breakpoints over debugger; statements.

Is there some reason why config.outDir is deleted only when collectCoverage is set to true?

iirc, it was done this way because outDir seemed to matter only in cases when collectCoverage was true. I try to avoid hard-coding things like these (setting inlineSourceMap to true, etc) because this has the potential of adding confusion. I realize that the current implementation also leads to some confusion but it seemed, to me, to be the lesser of the two evils

Can we document the debugger statements not working before we close this?

I agree with @GeeWee that README.md should have information about debugger; statements are not working.

It's funny that the documentation about breakpoints not working (and prefer debugger statements) in VSCode was removed just two days back :P https://github.com/kulshekhar/ts-jest/commit/9cb6f86d152773f2bddaf9234db99c89b5c4e568#diff-04c6e90faac2675aa89e2176d2eec7d8

@GeeWee I've added PR at #313 to update README with current limitations in debugger statements

@kulshekhar @GeeWee I cloned the repo and I think it's working with [email protected]

@trivikr can you confirm this so that we can then revert the documentation change that was merged earlier?

Thanks @morajabi for verifying the fix!
I've confirmed that both breakpoints and debugger statements work in VSCode in this private branch

Screen recording

@kulshekhar Yes, we can revert the documentation change done in #313

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jbreckmckye picture jbreckmckye  路  3Comments

remcohaszing picture remcohaszing  路  4Comments

RiJung picture RiJung  路  4Comments

GeeWee picture GeeWee  路  4Comments

bySabi picture bySabi  路  4Comments