vscode-jest
vscode-jest copied to clipboard
fix: unable to execute a specific test using `jest.virtualFolders`
Environment
-
vscode-jest version
: v6.0.0 pre-release -
node -v
: v18.16.0 -
npm -v
oryarn --version
: [email protected] -
npm ls jest
ornpm ls react-scripts
(if you haven’t ejected): 28.0.0 - your vscode-jest settings if customized:
- jest.jestCommandLine?
pnpm run test
- jest.autoRun?
off
- anything else that you think might be relevant?
- jest.jestCommandLine?
// ...
"jest.virtualFolders": [
{
"name": "library",
"rootPath": "path/to/library",
"autoRun": "off",
"jestCommandLine": "pnpm run test"
}
]
- 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
ornode_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 (\\\\
).
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:
- does it work without virtualFolders? For example you open the workspace at the library folder or use multiroot.
- you mentioned the CLI worked: where do you run the CLI? At the project root or the library folder?
- does your jest.config file specifies any roots to only scan certain folders, for example?
- if you copy the command line and run it directly from the terminal, does it work?
@kevinpastor I took another look at your issue, and there seems to have 2 issues:
- 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. - 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.
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, 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.
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!