vscode-jest icon indicating copy to clipboard operation
vscode-jest copied to clipboard

Breakpoints are not hit when debuging jest test in Angular on WSL

Open lechu1985 opened this issue 3 years ago • 4 comments
trafficstars

Environment

  1. vscode-jest version: 4.3.1
  2. node -v: 16.13.1
  3. npm -v or yarn --version: npm 8.1.2
  4. npm ls jest

├─┬ [email protected] │ └─┬ [email protected] │ └── [email protected] deduped └── [email protected]

  1. your vscode-jest settings if customized:
    • jest.jestCommandLine? "npm run test --"
    • jest.autoRun? "jest.autoRun": { "watch": false, "onSave": "test-src-file" }
  2. Operating system: WSL v2 (Ubuntu)

Prerequisite

  • are you able to run jest test from the command line? yes
  • how do you run your tests from the command line? (for example: npm run test or node_modules/.bin/jest) npm run test

Actual Behavior:

When hitting the debug tests button (in any place) - correct tests are bieing run, and status is reported, however... the breakpoints are not being hit.

Are there additional settings to be set in the jestCommandLine or in the lanunch.json file to make it work?

Launch.json

      {
        "type": "node",
        "name": "vscode-jest-tests.v2",
        "request": "launch",
        "runtimeExecutable": "npm",
        "args": [
          "test",
          "--run-in-band",
          "--watch-all=false",
          "--test-name-pattern",
          "${jest.testNamePattern}",
          "--test-path-pattern",
          "${jest.testFilePattern}"
        ],
        "cwd": "${workspaceFolder}",
        "console": "integratedTerminal",
        "internalConsoleOptions": "neverOpen",
        "disableOptimisticBPs": true
      }

EDIT: not sure it is relevant but here is my setupJest.ts file:

import 'zone.js/fesm2015/zone-testing-bundle.min.js';
import 'jest-preset-angular';
import { TestBed } from '@angular/core/testing';
import {
  BrowserDynamicTestingModule,
  platformBrowserDynamicTesting,
} from '@angular/platform-browser-dynamic/testing';

TestBed.initTestEnvironment(
  BrowserDynamicTestingModule,
  platformBrowserDynamicTesting()
);

and jest setup in package.json

  "jest": {
    "preset": "jest-preset-angular",
    "setupFilesAfterEnv": [
      "<rootDir>/setupJest.ts"
    ],
    "testPathIgnorePatterns": [
      "<rootDir>/node_modules/",
      "<rootDir>/dist/"
    ],
    "moduleNameMapper": {
      "@sth": "<rootDir>/projects/sth/src/public-api",
      "@sth2": "<rootDir>/projects/sth2/src/public-api"
    },
    "clearMocks": true,
    "globals": {
      "ts-jest": {
        "tsconfig": "<rootDir>/tsconfig.spec.json",
        "stringifyContentPathRegex": "\\.html$"
      }
    }
  }

lechu1985 avatar Feb 08 '22 17:02 lechu1985

hmmm... I have no problem with breakpoints in a vanilla angular project (created by angular-cli). Although I was running on mac. Do you happen to know if this issue only happens on WSL? Does it also happen without using the extension (create a non vscode-jest debug config for example)?

connectdotz avatar Feb 10 '22 21:02 connectdotz

Same issue started happening here after recent updates to VSCode. Using node+typescript (no Angular).

The breakpoints jump (see video). (Existing solutions seem outdated when googling).

VSCode version: 1.76.0
vscode-jest version: 5.2.3
node -v v16.13.1
npm -v 8.1.2

npm ls jest
functions@ [redacted]/functions
├─┬ [email protected]
│ └── [email protected] deduped
├── [email protected]
└─┬ [email protected]
  └── [email protected] deduped

"jest.jestCommandLine": "npm test -- --testTimeout=900000 --no-cache",

jest.config.js:

/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
  preset: 'ts-jest',
  testEnvironment: 'node',
  "roots": [
    "<rootDir>/src"
  ],
  "transform": {
    ".(ts|tsx)": "ts-jest"
  },
  "testRegex": "(\\.(test|spec))\\.(ts|tsx|js)$",
  "moduleFileExtensions": [
    "ts",
    "tsx",
    "js"
  ],
};

tsconfig.json:

{
  "compilerOptions": {
    "module": "commonjs",
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "outDir": "lib",
    "sourceMap": true,
    "strict": true,
    "target": "es2017",
    "allowJs": true,
    "esModuleInterop": true,
    "resolveJsonModule": true,
    "types": [
      "node",
      "jest"
    ]
  },
  "compileOnSave": true,
  "include": [
    "src",
    "src/__tests__/utils"
  ]
}

https://user-images.githubusercontent.com/4561505/223508404-2bbdac7e-beeb-4ed9-9218-8343333dfc6b.mov

isegal avatar Mar 07 '23 18:03 isegal

any progress on figuring out why this happens?

stefanrybacki avatar Sep 16 '23 08:09 stefanrybacki

Removing these from the args fixed it for me. But, of course that means focus debugging doesn't work anymore

      {
        "type": "node",
        "name": "vscode-jest-tests.v2",
        "request": "launch",
        "runtimeExecutable": "npm",
        "args": [
          "test",
          "--run-in-band",
          "--watch-all=false",
-        "--test-name-pattern",
-        "${jest.testNamePattern}",
          "--test-path-pattern",
          "${jest.testFilePattern}"
        ],
        "cwd": "${workspaceFolder}",
        "console": "integratedTerminal",
        "internalConsoleOptions": "neverOpen",
        "disableOptimisticBPs": true
      }

sfc-gh-selee avatar Dec 21 '23 21:12 sfc-gh-selee