firsttris / vscode-jest-runner

Simple way to run or debug one or more tests from context menu, codelens or command plalette
https://marketplace.visualstudio.com/items?itemName=firsttris.vscode-jest-runner
MIT License
265 stars 124 forks source link

Test does not run in CRA #209

Closed bitops closed 2 years ago

bitops commented 3 years ago

Hello! I am trying to set up the plugin with a React app from CRA. I have the plugin installed in VSCode and I have followed the configuration instructions in the README. I do see the "Run" and "Debug" options in my test file. However when I click "Run" nothing happens, it seems that the tests never really get started.

Here is my extension configuration:

# "jestrunner.jestCommand"
npm run test --

The target definition:

# package.json
"test": "react-scripts test",

Output seen in terminal:

me@mymachine web % cd '/Users/me/src/foo-app/web'
npm run test -- '/Users/me/src/foo-app/web/src/hooks/useTheStuff.spec.js' -c '/Users/me/src/foo-app/web/jest.config.js' -t 'useTheStuff%
me@mymachine web % npm run test -- '/Users/me/src/foo-app/web/src/hooks/useTheStuff.spec.js' -c '/Users/me/src/foo-app/web/jest.config.js' -t 'useTheStuff renders'

> foo-app-web@0.1.0 test /Users/me/src/foo-app/web
> react-scripts test "/Users/me/src/foo-app/web/src/hooks/useTheStuff.spec.js" "-c" "/Users/me/src/foo-app/web/jest.config.js" "-t" "useTheStuff renders"

Usage: test.js [--config=<pathToConfigFile>] [TestPathPattern]

Options:
  --help, -h                    Show help                              [boolean]
  --version, -v                 Print the version and exit             [boolean]
... rest of content omitted ...

I am on version v0.4.44.

bitops commented 3 years ago

Also, after some searching online, I tried changing my test target definition to this:

"test": "react-scripts test --",

That seems to do something but then I am confronted with this error and a huge list of stack traces.

Invalid testPattern ... crazy gobbledygook ...
ianldgs commented 2 years ago

What seems like is causing problem is the -c flag.

This started to fail recently for me. I think because of https://github.com/firsttris/vscode-jest-runner/pull/270, that was merged today.

The command that runs on the terminal now has the -c flag pointing to the package.json. If I remove it and try again, everything works.

firsttris commented 2 years ago

can you verfiy if this happens with the latest version 0.4.56.

because i was not able to reproduce it?

ianldgs commented 2 years ago

I'm afraid I still have the issue :/

Relevant info:

"jest": "27.5.1",

  "jestrunner.projectPath": "./frontend/ui/",
  "jestrunner.jestCommand": "npm run test -- --watchAll=false",

Output:

cd './frontend/ui/'
npm run test -- --watchAll=false '/Users/iserpa/code/project/frontend/ui/src/shared/Component.spec.tsx' -c '/Users/iserpa/code/project/frontend/ui/package.json' -t 'Component should allow doing something'
iserpa@amsmac6y3f project % cd './frontend/ui/'
iserpa@amsmac6y3f ui % npm run test -- --watchAll=false '/Users/iserpa/code/project/frontend/ui/src/shared/Component.spec.tsx' -c '/Users/iserpa/code/project/frontend/ui/package.json' -t 'Component should allow doing something'

> frontend@1.0.0 test
> tsc && craco test "--watchAll=false" "/Users/iserpa/code/project/frontend/ui/src/shared/Component.spec.tsx" "-c" "/Users/iserpa/code/project/frontend/ui/package.json" "-t" "Component should allow doing something"

Usage: test.js [--config=<pathToConfigFile>] [TestPathPattern]

If I edit the command and remove the -c '/Users/iserpa/code/project/frontend/ui/package.json' part, everything works fine.

firsttris commented 2 years ago

okay i reverted it.

ianldgs commented 2 years ago

I have updated to 0.4.57 and can confirm this no longer happens. Thank you!