Open florianzemma opened 1 year ago
This could be related to a known npm bug with TestPathPattern on windows when using the UI to run an explicit test (#838). Please see comment for the solution.
running npm v10.8 and same issue happens. testMatch: - 0 matches testPathIgnorePatterns: e2e, e2e - 895 matches testRegex: (\tests\.*|(.|\)(test|spec)).(jsx?|tsx?)$ - 105 matches Pattern: path\to\project\src__tests__\path\to\file.test.tsx - 0 matches
@josersleal, can you also show us the spawned command line and the expected pattern above?
@josersleal, can you also show us the spawned command line and the expected pattern above?
Not anymore. the tests run on terminal though. Also the tests are visible in the runner but will not run.
If you are still having problems running individual tests via the extension, please copy/paste the spawned command line from the console: see here. Or better yet, if you can create a sample repo so we can reproduce the issue here.
@connectdotz I think I encountered the same issue.
When debugging I see the spawn command is:
yarn test:jest:once --testLocationInResults --json --useStderr --outputFile C:\Users\<USER>\AppData\Local\Temp\jest_runner_package_asset_pipeline.json --testNamePattern AnimationSpinePixiInstance --coverage --reporters default --reporters "c:\Users\<USER>\.vscode\extensions\orta.vscode-jest-6.2.5\out\reporter.js" --colors --watchAll=false --testPathPattern "c:\\Projects\\Html5 - Packages\\Package Asset Pipeline\\tests\\jest\\assetLoader\\assetInstance\\animationSpineInstance\.test\.mts"
Which results in: (when running from the test explorer, or when entering the command in the terminal)
In C:\Projects\Html5 - Packages\Package Asset Pipeline
421 files checked.
roots: C:\Projects\Html5 - Packages\Package Asset Pipeline\tests\jest, C:\Projects\Html5 - Packages\Package Asset Pipeline\src - 421 matches
testMatch: **/__tests__/**/*.?(m|c)[jt]s?(x), **/*.(test|spec).?(m|c)[tj]s?(x) - 163 matches
testPathIgnorePatterns: \\node_modules\\ - 421 matches
testRegex: - 0 matches
Pattern: c:\Projects\Html5 - Packages\Package Asset Pipeline\tests\jest\assetLoader\assetInstance\animationSpineInstance\.test\.mts - 0 matches
When I change the slashes in the final argument en run in through the terminal, it works !!
yarn test:jest:once --testLocationInResults --json --useStderr --outputFile C:\Users\<USER>\AppData\Local\Temp\jest_runner_package_asset_pipeline.json --testNamePattern AnimationSpinePixiInstance --coverage --reporters default --reporters "c:\Users\<USER>\.vscode\extensions\orta.vscode-jest-6.2.5\out\reporter.js" --colors --watchAll=false --testPathPattern "c:/Projects/Html5 - Packages/Package Asset Pipeline/tests/jest/assetLoader/assetInstance/animationSpineInstance\.test\.mts"
Extra info: OS: Windows Terminal: Powershell 7.4 Node: 20.11.0 Yarn: 4.1.0
I can't reproduce this issue in my env. But something didn't look right in the terminal output...
Pattern: c:\Projects\Html5 - Packages\Package Asset Pipeline\tests\jest\assetLoader\assetInstance\animationSpineInstance\.test\.mts - 0 matches
The regex is missing the escape back-slash for some reason. The expected output should be
Pattern: c:\\Projects\\Html5 - Packages\\Package Asset Pipeline\\tests\\jest\\assetLoader\\assetInstance\\animationSpineInstance\.test\.mts - 0 matches
What is your test:jest:once
script defined as? Is there any other jest settings you have for this project?
The double backslashes are present in the command, but get probably stripped away as escape character. Not sure if that only happens in the output, or also internally when matching the regex. I also tried to run the command in CMD (instead of Powershell), but I get the same result.
From package.json
"test:jest:once": "cross-env TS_NODE_PROJECT='build/build/tsconfig.build.json' NODE_OPTIONS='--experimental-vm-modules' jest --config build/jest/jest.config.ts"
The jest config
import type { Config } from 'jest';
import { pathsToModuleNameMapper } from 'ts-jest';
import tsConfig from './tsconfig.jest.json';
import Path from 'path';
import _ from 'lodash';
import Fs from 'fs';
let config: Config = {
setupFiles: ['<rootDir>/build/common/jest.setup.js', 'jest-webgl-canvas-mock'],
globals: {
__DEV__: true,
__PROD__: false,
},
testEnvironment: 'jest-environment-jsdom',
resolver: 'ts-jest-resolver',
moduleFileExtensions: ['js', 'mjs', 'cjs', 'jsx', 'ts', 'mts', 'cts', 'tsx', 'json', 'node'],
extensionsToTreatAsEsm: ['.jsx', '.mjsx', '.ts', '.mts', '.tsx', '.mtsx'],
rootDir: '../../',
roots: ['<rootDir>/tests/jest', '<rootDir>/src'],
testMatch: ['**/__tests__/**/*.?(m|c)[jt]s?(x)', '**/*.(test|spec).?(m|c)[tj]s?(x)'],
moduleNameMapper: pathsToModuleNameMapper(tsConfig.compilerOptions.paths, { prefix: '<rootDir>/build/jest/' }),
transform: {
'^.+\\.m?tsx?$': [
'ts-jest',
{
useESM: true,
allowJs: true,
tsconfig: '<rootDir>/build/jest/tsconfig.jest.json',
},
],
'^.+\\.ctsx?$': [
'ts-jest',
{
useESM: false,
allowJs: true,
tsconfig: '<rootDir>/build/jest/tsconfig.jest.json',
},
],
},
verbose: true,
transformIgnorePatterns: ['/node_modules/', '<rootDir>/packages/'],
reporters: [
'default',
['jest-junit', { outputDirectory: 'reports/jest', outputName: 'junit.xml' }],
['github-actions', { silent: false }],
'summary',
],
coveragePathIgnorePatterns: ['/node_modules/', '<rootDir>/packages/'],
coverageDirectory: '<rootDir>/reports/coverage',
coverageReporters: ['text', 'text-summary', 'clover', 'lcovonly'],
coverageThreshold: {
global: {
branches: 85,
functions: 85,
lines: 90,
statements: -150,
},
},
};
"test:jest:once": "cross-env TS_NODE_PROJECT='build/build/tsconfig.build.json' NODE_OPTIONS='--experimental-vm-modules' jest --config build/jest/jest.config.ts"
I suspect cross-env
stripped off the escape backslash. You can try without cross-env and specify the env variables with jest.nodeEnv
instead.
Nice catch !! Removing the cross-env from the command solved it, thanks !!
Before I found this issue, and the effect crossenv
has, I'd traced it back to the slashes as well.
I edited the extension.js to replace the \\
with /
which jest will use and that seems to work, not sure what the impact of this would be on systems that allow backslash in the path.
I also spotted that running a specific test didn't work without wrapping "
around the value sent to testNamePattern
I'm not sure if this has anything to do with crossenv
Environment
vscode-jest version
: [5.2.3]node -v
: [v16.13.2]npm -v
: [8.1.2]Prerequisite
Relevant Debug Info
I can run all the tests using the UI and with command line with no problem.
I can't run test one by one by clicking the red or green arrow directly on the file this result to 'No test found error'
In C:\Users\Florian\Desktop\Apps\crm-ui 2570 files checked. testMatch: /tests//*.[jt]s?(x), */?(.)+(spec|test).[tj]s?(x) - 328 matches testPathIgnorePatterns: C:\Users\Florian\Desktop\Apps\crm-ui\dist\, C:\Users\Florian\Desktop\Apps\crm-ui\node_modules\, C:\Users\Florian\Desktop\Apps\crm-ui\src\config\test.ts - 2570 matches testRegex: - 0 matches Pattern: c:\\Users\\Florian\\Desktop\\Apps\\crm-ui\\src\\features\\offerComposition\\components\\tests\\ServiceDetailsBanner\.test\.tsx - 0 matches
But It's working when I run npm run test:dev ServiceDetailsBanner.test.tsx
Expected Behavior
Run the test when i click on the red or green arrow on a single file
Actual Behavior
No test found when I run the test by clicking on the green or red arrow on a test file
The fastest (and the most fun) way to resolve the issue is to submit a pull-request yourself. If you are interested, feel free to check out the contribution guide, we look forward to seeing your PR...