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 in source files when using Node v8.4.0 #309

Closed
trivikr opened this issue Aug 30, 2017 · 17 comments

Comments

@trivikr
Copy link
Contributor

trivikr commented Aug 30, 2017

@trivikr
Copy link
Contributor Author

trivikr commented Aug 30, 2017

While debugging, I put a breakpoint at

const tsTranspiled = tsc.transpileModule(src, {
compilerOptions,
fileName: path,
});

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.

@trivikr
Copy link
Contributor Author

trivikr commented Aug 30, 2017

The parameter outDir is removed for source files at

ts-jest/src/utils.ts

Lines 187 to 191 in a67fa3e

if (collectCoverage) {
// the coverage report is broken if `.outDir` is set
// see https://github.com/kulshekhar/ts-jest/issues/201
delete config.outDir;
}

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

@GeeWee
Copy link
Collaborator

GeeWee commented Aug 31, 2017

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

@trivikr
Copy link
Contributor Author

trivikr commented Aug 31, 2017

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?

@trivikr
Copy link
Contributor Author

trivikr commented Aug 31, 2017

@GeeWee The breakpoints will work in VSCode for test files if config.outDir is deleted without any condition in the code below

ts-jest/src/utils.ts

Lines 187 to 191 in 64bbc6e

if (collectCoverage) {
// the coverage report is broken if `.outDir` is set
// see https://github.com/kulshekhar/ts-jest/issues/201
delete config.outDir;
}

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

@GeeWee
Copy link
Collaborator

GeeWee commented Aug 31, 2017

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

@trivikr
Copy link
Contributor Author

trivikr commented Aug 31, 2017

@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 :)

@tkrotoff
Copy link
Contributor

tkrotoff commented Aug 31, 2017

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 #313 (comment)


(1) file.test.ts:

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

@trivikr
Copy link
Contributor Author

trivikr commented Sep 1, 2017

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.

@kulshekhar
Copy link
Owner

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

@GeeWee
Copy link
Collaborator

GeeWee commented Sep 1, 2017

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

@GeeWee GeeWee reopened this Sep 1, 2017
@trivikr
Copy link
Contributor Author

trivikr commented Sep 1, 2017

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 9cb6f86#diff-04c6e90faac2675aa89e2176d2eec7d8

@trivikr
Copy link
Contributor Author

trivikr commented Sep 1, 2017

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

@morajabi
Copy link
Contributor

morajabi commented Sep 1, 2017

@morajabi morajabi reopened this Sep 1, 2017
@morajabi
Copy link
Contributor

morajabi commented Sep 1, 2017

@kulshekhar @GeeWee I cloned the repo and I think it's working with ts-jest@20.0.14

@kulshekhar
Copy link
Owner

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

@trivikr
Copy link
Contributor Author

trivikr commented Sep 1, 2017

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

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

No branches or pull requests

5 participants