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

Tests are failing when running with plugin but working fine with command line #408

Open
unfalse opened this issue Nov 28, 2018 · 10 comments

Comments

@unfalse
Copy link

commented Nov 28, 2018

Environment

  1. node -v: v10.13.0

  2. npm -v: 6.4.1

  3. npm ls jest or npm ls react-scripts (if you haven’t ejected):
    $ npm ls jest
    jest_vscode_failing_example_app@1.0.0 C:\MyExperiments\jest_vscode_failing_example_app
    `-- jest@22.4.4
    (also tried 23.6.0 with the same results)

  4. your vscode-jest settings if customized:

    • jest.pathToJest? null
    • jest.pathToConfig? ""
    • anything else that you think might be relevant? no
  5. Operating system: Windows 10 Version 1803 (OS Build 17134.407)

Prerequisite

  • are you able to run jest test from command line? yes
  • how do you run your tests from command line? (for example: npm run test or node_modules/.bin/jest) npm run test

Steps to Reproduce

https://github.com/unfalse/vscode_jest_fail

Relevant Debug Info

This is the messages from the output window.

--watch is not supported without git/hg, please use --watchAll 

  console.warn node_modules/react-addons-test-utils/index.js:31
    Warning: ReactTestUtils has been moved to react-dom/test-utils. Update references to remove this warning.


FAIL src/index.test.js

  ● Test suite failed to run

    Jest encountered an unexpected token

    This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.

    By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".

    Here's what you can do:
     • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
     • If you need a custom transformation specify a "transform" option in your config.
     • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

    You'll find more details and examples of these config options in the docs:
    https://jestjs.io/docs/en/configuration.html

    Details:

    SyntaxError: C:\MyExperiments\jest_vscode_failing_example_app\src\index.test.js: Unexpected token (7:30)

       5 | describe('App: ', () => {
       6 |     it('renders withour crash', () => {
    >  7 |         var wrapper = shallow(<App/>);
         |                               ^
       8 |         expect(wrapper.find('div').length).toEqual(1);
       9 |     });
      10 | });

      at Parser.raise (node_modules/@babel/parser/lib/index.js:4028:15)
      at Parser.unexpected (node_modules/@babel/parser/lib/index.js:5343:16)
      at Parser.parseExprAtom (node_modules/@babel/parser/lib/index.js:6432:20)
      at Parser.parseExprSubscripts (node_modules/@babel/parser/lib/index.js:6019:21)
      at Parser.parseMaybeUnary (node_modules/@babel/parser/lib/index.js:5998:21)
      at Parser.parseExprOps (node_modules/@babel/parser/lib/index.js:5907:21)
      at Parser.parseMaybeConditional (node_modules/@babel/parser/lib/index.js:5879:21)
      at Parser.parseMaybeAssign (node_modules/@babel/parser/lib/index.js:5826:21)
      at Parser.parseExprListItem (node_modules/@babel/parser/lib/index.js:7111:18)
      at Parser.parseCallExpressionArguments (node_modules/@babel/parser/lib/index.js:6227:22)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        4.518s
Ran all test suites.

Expected Behavior

vscode-jest is not failing on tests.

Actual Behavior

vscode-jest failing on tests but npm run test works fine.


@connectdotz

This comment has been minimized.

Copy link
Collaborator

commented Nov 28, 2018

from toubleshooting :

you can easily use the jest.pathToJest or jest.pathToConfig settings to instruct the plugin on how to start jest. You can even use the scripts from package.json, such as npm run test -- or yarn test.

@unfalse

This comment has been minimized.

Copy link
Author

commented Nov 29, 2018

from toubleshooting :

you can easily use the jest.pathToJest or jest.pathToConfig settings to instruct the plugin on how to start jest. You can even use the scripts from package.json, such as npm run test -- or yarn test.

Tried

jest.pathToConfig: src/test/testSetup.js
jest.pathToJest: node_modules/.bin/jest

output:

Warning: ReactTestUtils has been moved to react-dom/test-utils. Update references to remove this warning.

No tests found
In c:\MyExperiments\jest_vscode_failing_example_app\src\test
  3 files checked.
  testMatch: **/__tests__/**/*.js?(x),**/?(*.)+(spec|test).js?(x) - 0 matches
  testPathIgnorePatterns: \\node_modules\\ - 3 matches
Pattern:  - 0 matches

Finished running all tests. Starting watch mode.
@connectdotz

This comment has been minimized.

Copy link
Collaborator

commented Nov 29, 2018

how do you run your tests from command line? (for example: npm run test or node_modules/.bin/jest) npm run test

did you try jest.pathToConfig: npm run test --?

@unfalse

This comment has been minimized.

Copy link
Author

commented Nov 29, 2018

how do you run your tests from command line? (for example: npm run test or node_modules/.bin/jest) npm run test

did you try jest.pathToConfig: npm run test --?

you mean "jest.pathToJest" ?
Yes it helped but i'm not sure if it really works. I'll check it later.

@unfalse

This comment has been minimized.

Copy link
Author

commented Nov 29, 2018

Jest shows that tests are ok but I changed intentionally one test and reloaded vscode window. Nothing has changed.
Also it doesn't work without jest.pathToConfig: src/test/testSetup.js

@connectdotz

This comment has been minimized.

Copy link
Collaborator

commented Nov 29, 2018

ok, you are making progress...

Also it doesn't work without jest.pathToConfig: src/test/testSetup.js

Basically you need to tell the plugin about your env, which means to setup jest.pathToJest and jest.pathToConfig if needed.

Jest shows that tests are ok but I changed intentionally one test and reloaded vscode window. Nothing has changed.

meaning every tests shows empty circle? What does the output console show? Also in your post, I saw

--watch is not supported without git/hg, please use --watchAll

is your repo under git? The plugin does run watch mode, if your repo can't be "watched", it won't show status...

@unfalse

This comment has been minimized.

Copy link
Author

commented Nov 29, 2018

meaning every tests shows empty circle?

Yes an empty green circle.

is your repo under git?

Yes it is.

Output:

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Username\AppData\Roaming\npm-cache\_logs\2018-11-29T14_50_52_307Z-debug.log

> jest_vscode_failing_example_app@1.0.0 test-fast c:\MyExperiments\jest_vscode_failing_example_app
> jest "--json" "--useStderr" "--outputFile" "C:\Users\Username\AppData\Local\Temp/jest_runner.json" "--watchAll" "--no-color" "--config" "src\test\testSetup.js"


Warning: ReactTestUtils has been moved to react-dom/test-utils. Update references to remove this warning.

No tests found
In c:\MyExperiments\jest_vscode_failing_example_app\src\test
  3 files checked.
  testMatch: **/__tests__/**/*.js?(x),**/?(*.)+(spec|test).js?(x) - 0 matches
  testPathIgnorePatterns: \\node_modules\\ - 3 matches
Pattern:  - 0 matches
@connectdotz

This comment has been minimized.

Copy link
Collaborator

commented Nov 30, 2018

I downloaded your repo to my mac, vscode-jest worked flawlessly without any customization as far as I can see. Change the test file also reflected as expected.

the error:

No tests found
In c:\MyExperiments\jest_vscode_failing_example_app\src\test

I looked at your repo, there is indeed no test in that directory...

not sure if this is a windows specific issue, in that case maybe somebody else with a windows env is better suited to help...

@unfalse

This comment has been minimized.

Copy link
Author

commented Dec 4, 2018

I have even moved testSetup.js to src and now I got just the same output as in my first message.

@SgtPooki

This comment has been minimized.

Copy link

commented Aug 2, 2019

@connectdotz I am also getting this issue on macosx high sierra .. I'm running a monorepo though. When I open the workspace at my monorepo root, the test is failing. When I open the individual package root directly in vscode, it passes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.