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

fix: unable to execute a specific test using `jest.virtualFolders`

Open kevinpastor opened this issue 1 year ago • 2 comments

Environment

  1. vscode-jest version: v6.0.0 pre-release
  2. node -v: v18.16.0
  3. npm -v or yarn --version: [email protected]
  4. npm ls jest or npm ls react-scripts (if you haven’t ejected): 28.0.0
  5. your vscode-jest settings if customized:
    • jest.jestCommandLine? pnpm run test
    • jest.autoRun? off
    • anything else that you think might be relevant?
  // ...
  "jest.virtualFolders": [
    {
      "name": "library",
      "rootPath": "path/to/library",
      "autoRun": "off",
      "jestCommandLine": "pnpm run test"
    }
  ]
  1. Operating system: Windows 10

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) pnpm run test

Relevant Debug Info

> [email protected] test F:\repositories\repository\path\to\library
> jest "--test-location-in-results" "--json" "--use-stderr" "--output-file" "C:\\Users\\kpastor\\AppData\\Local\\Temp\\jest_runner_path_to_library_kpastor_2.json" "--no-coverage" "--reporters" "default" "--reporters" "c:\\Users\\kpastor\\.vscode\\extensions\\orta.vscode-jest-6.0.0\\out\\reporter.js" "--colors" "--watch-all=false" "--test-path-pattern" "f:\\\\repositories\\\\repository\\\\__tests__"

No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0
In F:\repositories\repository\path\to\library
  97 files checked.
  testMatch: **/__tests__/**/*.[jt]s?(x), **/?(*.)+(spec|test).[tj]s?(x) - 2 matches
  testPathIgnorePatterns: \\node_modules\\ - 97 matches
  testRegex:  - 0 matches
Pattern: f:\\\\repositories\\\\repository\\\\__tests__ - 0 matches
 ELIFECYCLE  Test failed. See above for more details.

Notice the last parameter passed to jest. We would expect --test-path-pattern to have a value of f:\\\\repositories\\\\repository\\\\path\\\\to\\\\library\\\\__tests__.

Expected Behavior

When launching a specific test from the Testing sidebar while using virtualFolders, I would expect that the path used in for --test-path-pattern to contain the rootPath of the virtual folder.

A similar problem occurs when launching a specific test from the file it's defined. The --test-path-pattern is correct, but no tests can be found.

Actual Behavior

The --test-path-pattern only points to the root of the opened project when starting a specific test from the Testing sidebar.

Test should be found when starting a specific test from its implementation file.

I feel like the problem may be occuring because of the escaped characters (\\\\).

kevinpastor avatar Jul 24 '23 20:07 kevinpastor

The rootPath determines the jest process's "cwd' env variable. The --test-path-pattern should point at the test file (context menu) or the item (testExplorer sidebar). It would be easier to debug if there were a test repo...

A few questions might help us narrow it down:

  1. does it work without virtualFolders? For example you open the workspace at the library folder or use multiroot.
  2. you mentioned the CLI worked: where do you run the CLI? At the project root or the library folder?
  3. does your jest.config file specifies any roots to only scan certain folders, for example?
  4. if you copy the command line and run it directly from the terminal, does it work?

connectdotz avatar Jul 29 '23 16:07 connectdotz

@kevinpastor I took another look at your issue, and there seems to have 2 issues:

  1. the "\\\\" escape sequence doesn't look right. It was similar to the problem we identified for npm version 7/8. The bug was fixed in [email protected]. Not sure about how pnpm tracks npm, but something you might be able to look into.
  2. The path is apparently missing the root path. We have fixed a couple of bugs related to the path issue since. This might have been fixed in the latest pre-release version v6.1..2. Feel free to give it a try.

connectdotz avatar Feb 05 '24 17:02 connectdotz

Also, when enabling virtual folders right now I am losing all my test output color, and it's not properly listing test in the sidebar.

Is the virtualFolder feature experimental / broken?

Jason-Terry avatar May 14 '24 03:05 Jason-Terry

@Jason-Terry, the jest.virtualFolders is in production since v6.2. If it is not working for you, please create a new issue with your specific use case so we can investigate further.

connectdotz avatar May 18 '24 20:05 connectdotz

Hello again @connectdotz, sorry for the super late response. It seems like the initial issue was fixed with some update to the extension.

I have another issue only when trying to debug, but I'll open another ticket if I'm unable to fix it.

Thanks for the support!

kevinpastor avatar Jun 04 '24 19:06 kevinpastor