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

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

Open
kevinpastor opened this issue Jul 24, 2023 · 3 comments
Open

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

kevinpastor opened this issue Jul 24, 2023 · 3 comments
Labels
need sample repo needs a sample repo to further investigate stage: awaiting response

Comments

@kevinpastor
Copy link

kevinpastor commented Jul 24, 2023

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 (\\\\).

@connectdotz
Copy link
Collaborator

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 connectdotz added stage: awaiting response need sample repo needs a sample repo to further investigate labels Jul 29, 2023
@connectdotz
Copy link
Collaborator

@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.

@Jason-Terry
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need sample repo needs a sample repo to further investigate stage: awaiting response
Projects
None yet
Development

No branches or pull requests

3 participants