jest-community / vscode-jest

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

On Win10 Extraneous Backslashes are Present in Filenames When using "Run Test". #1070

Open ScottSEA opened 1 year ago

ScottSEA commented 1 year ago

Environment

  1. vscode-jest version: 5.2.3
  2. node -v: v14.17.0
  3. npm -v: 7.24.2
  4. npm ls jest: bananaProject@1.1.0 C:\git\Banana\application\bananaFolder ├─┬ react-scripts@4.0.1 │ ├─┬ jest-watch-typeahead@0.6.1 │ │ └── jest@26.6.0 deduped │ └── jest@26.6.0 └─┬ bananaMan-common@2.3.1017 └─┬ jest-enzyme@7.1.2 ├─┬ jest-environment-enzyme@7.1.2 │ └── jest@26.6.0 deduped └── jest@26.6.0 deduped
  5. your vscode-jest settings if customized:
    • jest.jestCommandLine? n/a
    • jest.autoRun? off
    • anything else that you think might be relevant? [fill]
  6. Operating system: Edition

    Windows 10 Pro Version 22H2 Installed on ‎8/‎16/‎2022 OS build 19045.3448 Experience Windows Feature Experience Pack 1000.19044.1000.0

Prerequisite

Steps to Reproduce

When running all tests in the project with Run Test (either from menu or green play button), the command generated is:

> react-scripts test --env=jsdom "--testLocationInResults" "--json" "--useStderr" 
  "--outputFile" "C:\\Users\\myName\\AppData\\Local\\Temp\\jest_runner_banana_web_frontend_myname_2.json" 
  "--no-coverage" "--reporters" "default" 
  "--reporters" "c:\\Users\\MyName\\.vscode\\extensions\\orta.vscode-jest-5.2.3\\out\\reporter.js" 
  "--colors" "--watchAll=false"

When running a test in Debug for a single test or single file (either from the Menu or green debug button) the command generated is:

${env:NODE_OPTIONS}=' --require "c:/Users/MyName/AppData/Local/Programs/Microsoft VS Code/resources/app/extensions/ms-vscode.js-debug/src/bootloader.js"  
--inspect-publish-uid=http'; 
${env:VSCODE_INSPECTOR_OPTIONS}=':::{"inspectorIpc":"\\\\.\\pipe\\node-cdp.19832-57a36fbd-1.sock",
"deferredMode":false,"waitForDebugger":"",
"execPath":"C:\\nodejs\\node.exe",
"onlyEntrypoint":false,"autoAttachMode":"always",
"fileCallback":"C:\\Users\\MyName\\AppData\\Local\\Temp\\node-debug-callback-4a66926ce44c1ec6"}';
 & 'C:\nodejs\npm.cmd' 'test' '--' 'test' '--env=jsdom' '--runInBand' '--watchAll=false' 
'--testNamePattern' 'Permission Util' 
'--runTestsByPath' 'C:\git\Banana\application\banana-web-frontend\src\test\util\permissionUtil.test.ts' 

When running a Run Test for a single test or single file (either from the Menu or green play button) the command generated is:

> react-scripts test --env=jsdom "--testLocationInResults" "--json" "--useStderr" 
"--outputFile" "C:\\Users\\MyName\\AppData\\Local\\Temp\\jest_runner_banana_web_frontend_myname_2.json" 
"--testNamePattern" "Permission Util" "--no-coverage" "--reporters" "default"
 "--reporters" "c:\\Users\\MyName\\.vscode\\extensions\\orta.vscode-jest-5.2.3\\out\\reporter.js" 
"--colors" "--watchAll=false" 
"--testPathPattern" "c:\\\\git\\\\Banana\\\\application\\\\banana-web-frontend\\\\src\\\\test\\\\util\\\\permissionUtil\\.test\\.ts"

Note the file name has extraneous backslashes inside the name of the file and all the backslashes are escaped unlike the paths in the Debug mode (which works as expected).

Relevant Debug Info

Here is the output:

No tests found, exiting with code 1 Run with --passWithNoTests to exit with code 0 In C:\git\Banana\application\banana-web-frontend 719 files checked. testMatch: C:/git/Banana/application/banana-web-frontend/src//tests//*.{js,jsx,ts,tsx}, C:/git/Banana/application/banana-web-frontend/src/*/.{spec,test}.{js,jsx,ts,tsx} - 303 matches testPathIgnorePatterns: \node_modules\ - 719 matches testRegex: - 0 matches Pattern: c:\\git\\Banana\\application\\banana-web-frontend\\src\\test\\util\\permissionUtil\.test\.ts - 0 matches

Expected Behavior

Test is found and runs.

Actual Behavior

see above


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

connectdotz commented 1 year ago

noticed you are using npm 7.x, which had issue with pass-through argument interpretation, see comment. Can you try with npm >= 8.15?

ecl1ps commented 1 week ago

Hi, I had the same problem before, but now (in v6.3.1), with npm 10.8.2, it seems to work correctly.