jest-community / vscode-jest

The optimal flow for Jest based testing in VS Code
MIT License
2.82k stars 291 forks source link

Extension is unable to locate tests because path segments are omitted from --testPathPattern #1112

Closed yegorpetrov closed 4 months ago

yegorpetrov commented 4 months ago

Environment

  1. vscode-jest version: 6.2.0
  2. node -v: v20.9.0
  3. npm -v: 10.1.0
  4. npm ls jest:
    ├── jest@29.7.0
    └─┬ ts-jest@29.1.2
    └── jest@29.7.0 deduped
  5. your vscode-jest settings if customized:
    • jest.jestCommandLine? no
    • jest.autoRun? "off"
    • anything else that you think might be relevant? nope
  6. Operating system: Win 11

Prerequisite

Steps to Reproduce

Upgrade to 6.2.0

Expected Behavior

Ability to run tests at any level of the tests tree view

Actual Behavior

Unable to run tests at many levels of the tests tree view. In the "Test results" panel it looks like the extension is omitting path segments for no apparent reason. In comparison with v.5.2.3, the tree view is also missing those segments. The typical output is as follows:

No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0
In [REDACTED]\backend\src\nodejs
  298 files checked.
  testMatch: **/__tests__/**/*.[jt]s?(x), **/?(*.)+(spec|test).[jt]s?(x) - 68 matches
  testPathIgnorePatterns: \\node_modules\\ - 298 matches
  testRegex:  - 0 matches
Pattern: [REDACTED]\\backend\\handlers\\store - 0 matches

The correct path is \backend\src\nodejs\handlers\store. If I copy the command (as shown on screenshots) and run it manualy with a fixed path, then it works.

image

connectdotz commented 4 months ago

This looked like a bug, but I can't repro in any of my test projects... Do you have a sample repo we can take a look at?

Otherwise, we have to dig into it manually:

  1. Do you happen to have a jest.rootPathsetting?
  2. Do you open vscode project workspace from the "backend" folder?
  3. Just to confirm that restarting vscode didn't make any difference?
  4. Are you able to use the test file editor's gutter menu to run tests?
  5. Any other jest settings we should know about?
yegorpetrov commented 4 months ago

@connectdotz

Do you have a sample repo we can take a look at?

YES

Otherwise, we have to dig into it manually

I will answer regardless.

  1. Do you happen to have a jest.rootPathsetting?

Nope.

  1. Do you open vscode project workspace from the "backend" folder?

Yes.

  1. Just to confirm that restarting vscode didn't make any difference?

Nope.

  1. Are you able to use the test file editor's gutter menu to run tests?

Yes, even in 6.2.0 I can run individual tests from the editor and in that case testPathPattern is correct and points to the file with all path segments in place. The issue is being unable to run on directories, except may be the root directory.

  1. Any other jest settings we should know about?

No. I left as much as I could from the problematic project in the repro so you can check. I don't see any relevant OS user settings for jest.

etnoy commented 4 months ago

If you need a sample repo I am experiencing this bug in the following repo: https://github.com/immich-app/immich/

Using v6.2.0 I want to run the spec.ts tests in the server/ folder. I set the Jest configuration to the following: image

I am not using a monorepo setup in vscode-jest even though the repo is a monorepo

I am able to run individual test files (like the activity folder in the below screenshot) from the test panel in vscode, but when I move to running all tests, it removes the server/ folder from the testPathPattern argument, resulting in no tests.

image

etnoy commented 4 months ago

Can confirm that rolling back to 5.2.3 fixes the issue.

On 5.2.3: jest --testLocationInResults --json --useStderr --outputFile /tmp/jest_runner_immich_1000_2.json --no-coverage --reporters default --reporters /home/etnoy/.vscode-server/extensions/orta.vscode-jest-5.2.3/out/reporter.js --colors --watchAll=false --testPathPattern /home/etnoy/code/immich/server/src

On 6.2.0: jest --testLocationInResults --json --useStderr --outputFile /tmp/jest_runner_immich_1000_2.json --no-coverage --reporters default --reporters /home/etnoy/.vscode-server/extensions/orta.vscode-jest-6.2.0/out/reporter.js --colors --watchAll=false --testPathPattern /home/etnoy/code/immich/src

note that the testPatPattern is incorrect on 6.2.0

connectdotz commented 4 months ago

Thanks for the sample repo! It helped me to locate and fix the issue in v6.2.1.

Please don't hesitate to let me know if there are any other issues.

etnoy commented 4 months ago

Thanks, 6.2.1 fixed the issue for me :)

yegorpetrov commented 4 months ago

I too, can confirm it was fixed.