Jest: Webstorm Jest Runner Broken

Created on 13 Mar 2019  路  10Comments  路  Source: facebook/jest

馃挜 Regression Report

Webstorm has it's own jasmine reporter, it seems like due to the typescript rewrite classes got stricter and now it no longer runs as it did

    TypeError: Class constructor Spec cannot be invoked without 'new'

      85 | function createdPatchedSpec(OriginalSpec, registry) {
      86 |   function PatchedSpec(attrs) {
    > 87 |     OriginalSpec.apply(this, arguments);
         |                  ^
      88 |     if (attrs && attrs.id) {
      89 |       registry[attrs.id] = this;
      90 |     }

Last working version

Worked up to version:

24.1.0

Stopped working in version:

24.3.0

To Reproduce

Steps to reproduce the behavior:

Try to run a jest test suite in webstorm

Expected behavior

It runs the test suite fine like before

Link to repl or repo (highly encouraged)

Sadly somewhat hard to make a repl, I can't even revert back to the previous version because of all the semver ranges

Run npx envinfo --preset jest

Paste the results here:

  System:
    OS: Windows 10
    CPU: (16) x64 AMD Ryzen 7 2700X Eight-Core Processor
  Binaries:
    Node: 11.10.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.13.0 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.8.0 - C:\Users\harmony\Code\Web\WebstormProjects\preact-cli\node_modules\.bin\npm.CMD
Regression

Most helpful comment

This has already been fixed on IntelliJs side, but is not included in the latest EAP yet.

There is a workaround. Have a look in the IntelliJ ticket:

https://intellij-support.jetbrains.com/hc/en-us/community/posts/360003251559-Error-running-tests-from-editor-with-jest-24-?page=1

All 10 comments

Yeah, it turned into an actual class. Can you report this on youtrack? Even if we revert the change, we'll want it back in the future

This has already been fixed on IntelliJs side, but is not included in the latest EAP yet.

There is a workaround. Have a look in the IntelliJ ticket:

https://intellij-support.jetbrains.com/hc/en-us/community/posts/360003251559-Error-running-tests-from-editor-with-jest-24-?page=1

Problem is it's a breaking change in a minor release

It's not a public API - they are overriding internals. I don't think it should be expected for Jest to not be able to change its internals.

Their reporter should be a Jest reporter, not a refurbished Jasmine reporter. Jasmine will stop being the default runner in the next major of Jest, and will be removed at some point in the future.

I'm not sure if Jest's current reporter API provide the hooks needed for IntelliJ to do its thing. Happy to work with them to make it happen, if needed. I wanna revamp our reporters anyways, so this is a good time to look into IDE integrations (#4471 & #7900)

/cc @segrey

The issue in IntelliJ tracker: https://youtrack.jetbrains.com/issue/WEB-37680.
Will be fixed in 2018.3.6 (ETA: end of March). Until then, please use the workaround.

@SimenB Yeah, IntelliJ can use both reporters: a Jest reporter and a Jasmine reporter. Jasmine reporter is preferred as it allows to fetch expected and actual values for failed assertions (useful for snapshot testing), see https://github.com/facebook/jest/issues/5034. Another benefit is ability to receive events about started/finished tests during a single test file run (https://github.com/facebook/jest/issues/4471): it allows to debug a test and see it and its output in the test tree.

It'd be great to extend Jest reporter API and switch to it in next IntelliJ versions. Looking forward to it :)

Awesome, thanks for those links @segrey! We're all meeting up in London next week, I'll be sure to come out with a plan for reporters after that. I added them to the Jest 25 milestone for now so I don't forget.

Just to be sure I understood correctly - the reason you prefer the jasmine reporter is that it provides information not available in the jest reporter? Concretely missing:

  • The assertion result in a structured format (specifically for snapshots, but all assertion errors in general)
  • Events for when a test/it starts and completes (which is #4471 or maybe even #6616)

Anything else? And beyond parity with the Jasmine reporter, could we add something more you think would be useful?

@SimenB Great! Regarding benefits of using Jasmine reporter, I don't have a complete list unfortunately.
Some of them I could recall:

  • An implication of sending events about describe/test/it: it allows to attach output to correct node in a test tree, and, when debugging, you can see live output of console.log/process.stdout.write.
  • Failed assertions provide separate compact error messages and error stacks whereas Jest reporter provides a single merged error message+stack making it's hard to show a compact error message for a failed element in the editor. It'd be great to provide separate values: expected/actual/message/stack.

The same issue is there with intellij as well

Just had the same issue with older version but updating to the latest version of IntelliJ and WebStorm the issue was fixed. This ticket seems to be good to be close.

Great, thanks!

Was this page helpful?
0 / 5 - 0 ratings