Ts-jest: The debugger doesn't stop at correct statements in VSCode in source files

Created on 6 Apr 2018  Â·  22Comments  Â·  Source: kulshekhar/ts-jest

  • Issue
    The debugger doesn't stop at correct statements in VSCode in source files

    • VSCode 1.21.1
    • jest 22.4.2
    • ts-jest 22.4.2
    • typescript 2.7.2
  • Expected behavior
    The debugger should stop at correct statements in VSCode for source files

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

    Screen recording

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

Help Wanted

Most helpful comment

Similar issue was discussed in #309
This issue is not reproducible if I remove "collectCoverage": true from Jest Config (code)

All 22 comments

Similar issue was discussed in #309
This issue is not reproducible if I remove "collectCoverage": true from Jest Config (code)

Confirmed that issue is reproducible with latest version [email protected], and updated repro repo and issue description

Same problem in Webstorm

I removed collectCoverage from jest.json and added --coverage in Jest CLI to avoid this bug

Thanks but no luck in my environment (Create-React-App-Typescript):


// package.json

// ...

  "scripts": {
    "test": "jest --verbose --notify",
    "test:watch": "jest --watch --notify",
    "test:debug": "jest --debug",
    "test:update": "jest -u",
    "coverage": "jest --coverage --silent"
  },
  "jest": {
    "setupFiles": [
      "<rootDir>/config/test-shim.js",
      "<rootDir>/config/test-setup.js"
    ],
    "globals": {
      "ts-jest": {
        "skipBabel": true
      }
    },
    "moduleFileExtensions": [
      "ts",
      "tsx",
      "js"
    ],
    "transform": {
      "^.+\\.(ts|tsx)$": "<rootDir>/config/test-preprocessor.js",
      "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/config/assetsTransformer.js",
      "\\.(css|less)$": "<rootDir>/config/assetsTransformer.js"
    },
    "roots": [
      "src"
    ],
    "testMatch": [
      "**/test/*.(test).(ts|tsx|js)"
    ],
    "collectCoverageFrom": [
      "src/orm/**/*.{js,tsx,ts}",
      "!src/index.tsx",
      "!src/App.tsx",
      "!src/orm/test/models/**"
    ]
  }

// ...

I've taken a look at the linked repo and can confirm noticing this issue. I tried debugging a bit but couldn't figure out the root cause.

Maybe the root cause has more to do with jest itself than with ts-jest

The fix for #485 (which seems to be in jest) might fix this but that's just a hunch and not based on any evidence

Indeed, it seems to be a jest issue
https://github.com/facebook/jest/issues/5925

@YagoLopez thanks for testing that out!

Is it https://github.com/facebook/jest/issues/5739? facebook/jest#5925 is for thrown errors, not source stepping

@SimenB that's correct, thanks for the clarification

@YagoLopez did you find a workaround?
I have exactly this problem :( but with IntelliJ

screen shot 2018-06-27 at 4 58 28 pm

Thanks

Running the test like
node --inspect-brk=0.0.0.0:5858 ../../node_modules/.bin/jest --no-cache --watch --runInBand

with the following config

module.exports = {
    transform: {
        "^.+\\.(t|j)sx?$": "ts-jest"
    },
    testRegex: "(/tests/.*.(test|spec)).(jsx?|tsx?)$",
    testPathIgnorePatterns: ["/lib/", "/node_modules/"],
    moduleFileExtensions: [
        "ts",
        "tsx",
        "js",
        "jsx",
        "json",
        "node"
    ],
    verbose: true,
    globals: {
        "ts-jest": {
            disableSourceMapSupport: true
        }
    }
}

Sorry but not. Are you in the latest versions of IntelliJ with all dependencies up to date (jest, ts-jest, etc)? May be that could help but I cannot confirm it.

IntelliJ IDEA 2018.1.5 (Ultimate Edition)
Build #IU-181.5281.24, built on June 13, 2018
JRE: 1.8.0_152-release-1136-b39 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.13.5
"jest": "23.2.0",
"ts-jest": "22.4.6",

Yeah yarn outdated spits nothing so I should be up to date.

Thanks for answering.

Take a look at this:
https://github.com/kulshekhar/ts-jest/issues/150#issuecomment-291209244

And a little of more info here:
http://jestjs.io/docs/en/troubleshooting.html

If you have luck, please report it here.

Having same issue here, I thought it was related to multiline import statement and/or multiline function (...) header that is why my minimal repo has such weird code, but after putting everything in one line I have still the same issue. @YagoLopez I've also tried setting inlineSourceMap without success (thought it should be the default now - as I am using latest jest and ts-jest).
Notice that running yarn test the throw is shown at correct line number:
screen shot 2018-07-05 at 09 02 35

But if you try to debug in vscode with debugger statement (putting a breakpoint will stop nowhere), it's totally at the wrong line:
screen shot 2018-07-05 at 08 43 47

Here is the minimal repo: https://github.com/huafu/issue-ts-jest-wrong-line

FYI my jest cache has been cleared, and I'm using an up to date vscode on latest macOS

...I've created a new issue #606, because it sounds like a different one from @trivikr – he is using version 22 of jest and ts-jest, while I'm using 23, and when I downgrade ts-jest to version @<23, vscode goes to the correct line, where debugger statement actually is.

tested as explained by @trivikr, #626 will fix this (tho you MUST remove the babelrc: false from jest config in package.json. (tested with and without coverage)

fixed in 23.1.2

Reproducible on ts-jest 24.0.2 and jest 24.8.0. Removing collectCoverage: true from jest.config.js helped

Here is new issue created #917 .

Was this page helpful?
0 / 5 - 0 ratings