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

add support to webstorme #1871

Closed
shai32 opened this issue Mar 21, 2017 · 40 comments
Closed

add support to webstorme #1871

shai32 opened this issue Mar 21, 2017 · 40 comments

Comments

@shai32
Copy link

shai32 commented Mar 21, 2017

webStorm support native jest
image
but when I run yarn test, I see all the tests in the terminal.
Is there any way to integrate the testing with webStorm?
it's much more convenient to use the webStorm Gui to see the errors

@gaearon
Copy link
Contributor

gaearon commented Mar 21, 2017

cc @prigara, anything we can do on our side?

@prigara
Copy link
Contributor

prigara commented Mar 21, 2017

This new run configuration for Jest can only run Jest directly. In create-react-app, unfortunately for WebStorm, Jest is run via a wrapper script react-scripts/scripts/test.js. If it were possible to do the same but with running jest with some environment variables, configs and CLI options, that would help us.
Specifying the path to test.js instead of the path to Jest in the run configuration is also not an option: WebStorm builds up the path from node_modules/jest to .bin/jest itself.

@gaearon
Copy link
Contributor

gaearon commented Mar 22, 2017

Is there any reason WebStorm can't recognize react-scripts test as another way to run Jest? We're not going to change Jest to anything else so it should be safe to extend integration to support that. Or are there other technical challenges here?

@prigara
Copy link
Contributor

prigara commented Mar 22, 2017

At this specific moment it's implemented the way that it can only recognize and run Jest itself.
Today we tested whether we can run react-scripts test instead, but it didn't work: react-scripts test passes a config to Jest and so does WebStorm; with 2 --config flags everything breaks.
That will be fixed, when we transition to jest-editor-support. We don't have ETA for that, may be some time later this year.
There's aslo a bunch of other concerns:

  • is debugging tests possible with create-react-app?
  • is it possible to run a single test?

@gaearon
Copy link
Contributor

gaearon commented Mar 22, 2017

Thanks for looking into it. What config options does WebStorm need to pass? We could merge them on our side.

That will be fixed, when we transition to jest-editor-support. We don't have ETA for that, may be some time later this year.

Sounds like a plan. 👍

is debugging tests possible with create-react-app?

I actually don't know. I haven't looked into Node debugging for a while because Jest was waiting for some Node bugfix which I don't know whether it landed or not. But if Jest supports it, so should we.

is it possible to run a single test?

react-scripts test TestName should probably work, although it'll run in watch mode. If you want to disable watch mode, you can set CI environment variable to true.

@segrey
Copy link

segrey commented Mar 22, 2017

@gaearon

What config options does WebStorm need to pass?

Since currently WebStorm integrates with jest via --setupTestFrameworkScriptFile, it needs to disable transforming it using transformIgnorePatterns. It is done by passing whole jest configuration as --config=<JSON>, e.g.:

--config '{"rootDir":"/path/to/project-root","transformIgnorePatterns":["/node_modules/","^/home/segrey/programs/webstorms/WebStorm-171.3780.79/plugins/JavaScriptLanguage/helpers"]}'

In case of create-react-app, where no external jest configuration is expected, only these two JSON keys will be passed.

@shai32
Copy link
Author

shai32 commented Apr 5, 2017

I tried to run with jest webstorm, but I am getting this errors, what should I DO?
image

And this is my Edit configurations settings
image

@prigara
Copy link
Contributor

prigara commented Apr 6, 2017

@shai32 please see my comment above - it's not possible to use WebStorm Jest run/debug configuration to run tests in the app created with creat-react-app. Please follow this issue for updates.

@kalinchernev
Copy link

@shai32 use the command line directly - there's an integrated terminal in the IDE.

@shai32
Copy link
Author

shai32 commented Apr 6, 2017

@prigara are you working for webStorm?

@prigara
Copy link
Contributor

prigara commented Apr 7, 2017

@shai32 yes

@quantuminformation
Copy link

@segrey
Copy link

segrey commented Apr 14, 2017

Ah, it turned out there is no need to disable transforming/mocking IDE sources using transformIgnorePatterns and unmockedModulePathPatterns for create-react-app projects. Therefore this issue can be fixed on IDE side. Fix will be available in WebStorm 2017.1.2, planned in a few weeks (no strict ETA). This issue can be closed now.

@quantuminformation
Copy link

Thanks @segrey

@shai32
Copy link
Author

shai32 commented Apr 14, 2017

@segrey
after WebStorm 2017.1.2 will be released, How do I configure webStorm to run client tests?

maybe we need to add these to the docs

@quantuminformation
Copy link

@shai32 add the Jest entry point as a node debug config

@segrey
Copy link

segrey commented Apr 14, 2017

@shai32 Just as normal Jest run configuration, only specify react-scripts package instead of jest package in "Jest package" field.

@shai32
Copy link
Author

shai32 commented Apr 21, 2017

So WebStorm 2017.1.2 is out, so I added a configuration to run my tests.

Its seems to work (Thanks WebStorm devs !!) but there is still some problems:

This works:
image

But when I Moved global.a to setupTests.js its fails (console.log doesn't print on console as well)
image

It seems that setupTests isn't been run before each test, because all my test depends on setupTests.js, I can run any test.
notice that in terminal the same test is passes
also adding import '../../setupTests' in the test file will make it work in WebStorm also.
so the issue is that in WebStorm, setupTests.js does not run before each test.

@quantuminformation
Copy link

Is it letting you debug in webstorme?

@segrey
Copy link

segrey commented Apr 21, 2017

@shai32 Does it work when tests are run in a terminal, outside IDE?

@shai32
Copy link
Author

shai32 commented Apr 21, 2017

@quantuminformation: yes it let me debug

@segrey yes it does run in terminal, and it passes.

@quantuminformation
Copy link

2017.2 Doesn't work for me:

image

@quantuminformation
Copy link

/Users/nikos/.nvm/versions/node/v7.8.0/bin/node --harmony /Users/nikos/WebstormProjects/Javascript-code-generation-tools/node_modules/jest-cli/bin/jest.js --runInBand
 FAIL  src/features/editor/Editor.test.js
  ● Test suite failed to run

    /Users/nikos/WebstormProjects/Javascript-code-generation-tools/src/features/editor/Editor.test.js: Unexpected token (11:9)
         9 |  it('renders code controls without crashing', () => {
        10 |  const div = document.createElement('div');
      > 11 |  shallow(<Editor />, div);
           |          ^
        12 |  });
        13 | 
        14 | 

 FAIL  src/reducers/jsonCodeTools.test.js
  ● Test suite failed to run

    /Users/nikos/WebstormProjects/Javascript-code-generation-tools/src/reducers/jsonCodeTools.test.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import jsonCodeTools from './jsonCodeTools';
                                                                                             ^^^^^^
    SyntaxError: Unexpected token import
      
      at transformAndBuildScript (node_modules/jest-cli/node_modules/jest-runtime/build/transform.js:320:12)
      at process._tickCallback (internal/process/next_tick.js:109:7)

 FAIL  src/features/codeControls/CodeControls.test.jsx
  ● Test suite failed to run

    /Users/nikos/WebstormProjects/Javascript-code-generation-tools/src/features/codeControls/CodeControls.test.jsx: Unexpected token (12:32)
        10 |   }
        11 | 
      > 12 |   const enzymeWrapper = shallow(<CodeControls {...props} />)
           |                                 ^
        13 | 
        14 |   return {
        15 |     props,

 FAIL  src/App.test.jsx
  ● Test suite failed to run

    /Users/nikos/WebstormProjects/Javascript-code-generation-tools/src/App.test.jsx: Unexpected token (8:10)
         6 | it('renders without crashing', () => {
         7 |   const div = document.createElement('div');
      >  8 |   shallow(<App />, div);
           |           ^
         9 | });
        10 | 

Test Suites: 4 failed, 4 total
Tests:       0 total
Snapshots:   0 total
Time:        3.227s
Ran all test suites.
(node:54648) DeprecationWarning: `DEBUG_FD` is deprecated. Override `debug.log` if you want to use a different log function (https://git.io/vMUyr)

Process finished with exit code 1

@shai32
Copy link
Author

shai32 commented Apr 22, 2017

@quantuminformation: did you set Jest Package to be react-scripts?
image

@quantuminformation
Copy link

opps I was a node config, thx it works now.

@segrey
Copy link

segrey commented Apr 22, 2017

@shai32 I couldn't reproduce the issue with setupTest.js (tried with setupFiles and setupTestFrameworkScriptFile). How is it configured in your project? Could you file a separate issue with details in the https://youtrack.jetbrains.com/issues/WEB?

@shai32
Copy link
Author

shai32 commented Apr 23, 2017

@segrey so setupTest.js is actually running before your test?
can you stop on debug there?
can you see console.log printed in the terminal?

setupTest.js should be run without require it

@yonatanmn
Copy link

it's working!
except one test for a function that uses fetch.
from npm test jest is running ok, but from the IDE it fails with fetch is not defined

@segrey
Copy link

segrey commented Apr 23, 2017

@shai32 With configuration "setupTestFrameworkScriptFile": "<rootDir>/setupTests.js", console.log are printed, it's possible to stop on debug, the test is passing and setupTest.js is run without require. I'd appreciate if you could provide details about your configuration in a separate issue. An example project reproducing your issue would be great.

@segrey
Copy link

segrey commented Apr 23, 2017

@yonatanmn Sorry, not sure I can reproduce the problem from your description. Please file an issue in the https://youtrack.jetbrains.com/issues/WEB with an example project that allows to reproduce the issue. Thanks

@shai32
Copy link
Author

shai32 commented Apr 23, 2017

@segrey how do I configure "setupTestFrameworkScriptFile": "/setupTests.js"?
should I Do it in edit configuration in WebStorm?
can u send a screenshot?

@segrey
Copy link

segrey commented Apr 24, 2017

@shai32 If I understood correctly, your configuration works in terminal (outside IDE) and fails in IDE. This is a bug, but I can't reproduce it. Thus, I'd like to hear more input from you to be able to reproduce the issue. My configuration is simple:

// package.json
{
  "jest": {
    "setupTestFrameworkScriptFile": "<rootDir>/setupTests.js"
  }
}

@shai32
Copy link
Author

shai32 commented Apr 26, 2017

@segrey it now works, when I run in terminal, there is no need to add "setupTestFrameworkScriptFile" to package.json.
but in IDE its needed, and it works if defined in pakcgae.json

@segrey
Copy link

segrey commented Apr 26, 2017

@shai32 Thanks, I see. Unfortunately, I couldn't setup such a configuration that can be run in terminal successfully, but fails in IDE. Could you file an issue in https://youtrack.jetbrains.com/issues/WEB with details allowing to reproduce it? An example project would be just great.

@shai32
Copy link
Author

shai32 commented Apr 27, 2017

@segrey I don't think it need any fix, it was a configuration issue.
If its important I can still add a bug details, how to I add in issue to youtrack,
Do I need to register before I can add an issue?

where to click to add an issue?
image

@segrey
Copy link

segrey commented Apr 27, 2017

@shai32 You could be right as it depends on how configuration looks like. E.g. IDE needs configuration duplication if jests tests are running as a npm script, in this case all jest parameters specified in the script should be copied in "Jest options" field in Jest RC. Filing an issue makes sense If you are not OK with current behavior.
Yes, you need to register first (click "Log In..."). Once you're registered, there will be "Create Issue" button.

@shai32
Copy link
Author

shai32 commented Apr 27, 2017

@shai32 shai32 closed this as completed Apr 27, 2017
@shai32 shai32 reopened this May 2, 2017
@shai32
Copy link
Author

shai32 commented May 2, 2017

I am getting a warning, when debugging from IDE:
image

@segrey
Copy link

segrey commented May 2, 2017

(node:60434) DeprecationWarning: node --debug is deprecated. Please use node --inspect instead.

This warning is caused by using old V8 debugger protocol (--debug-brk). New inspector protocol (--inspect) is not yet supported by jest (jestjs/jest#1652).

@shai32 Probably, it's worth to file a new issue to discuss a separate topic.

@gaearon
Copy link
Contributor

gaearon commented May 8, 2017

Yea, probably going to close this as it's unrelated.

@gaearon gaearon closed this as completed May 8, 2017
@lock lock bot locked and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants