question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot run Jest tests from Webstorm

See original GitHub issue

Prerequisites

  • I am running the latest version
  • I checked the documentation (nx.dev) and found no answer
  • I checked to make sure that this issue has not already been filed
  • I’m reporting the issue to the correct repository (not related to React, Angular or any dependency)

Expected Behavior

I just want to run the tests from app.component.spec.ts from IntelliJ IDEA/WebStorm UI.

Current Behavior

I get an error.

Steps to Reproduce

  1. Generate a new workspace (Angular+Nest).
  2. Run any test (or all of them) from app.component.spec.ts with IntelliJ IDEA/WebStorm UI (Click on green triangle(s) near the line numbers).

Failure Logs

Error: Failed: "Zone is needed for the async() test helper but could not be found. Please make sure that your environment includes zone.js/dist/zone.js"
Error: 
    at Env.beforeEach (E:\testing\node_modules\jest-jasmine2\build\jasmineAsyncInstall.js:41:24)
    at beforeEach (E:\testing\node_modules\jest-jasmine2\build\jasmine\jasmineLight.js:111:29)
    at Suite.Object.<anonymous>.describe (E:\testing\apps\client\src\app\app.component.spec.ts:7:3)
    at addSpecsToSuite (E:\testing\node_modules\jest-jasmine2\build\jasmine\Env.js:496:51)
    at Env.describe (E:\testing\node_modules\jest-jasmine2\build\jasmine\Env.js:466:11)
    at describe (E:\testing\node_modules\jest-jasmine2\build\jasmine\jasmineLight.js:81:18)
    at Object.<anonymous> (E:\testing\apps\client\src\app\app.component.spec.ts:6:1)
    at Runtime._execModule (E:\testing\node_modules\jest-runtime\build\index.js:867:68)
    at Runtime._loadModule (E:\testing\node_modules\jest-runtime\build\index.js:577:12)
    at Runtime.requireModule (E:\testing\node_modules\jest-runtime\build\index.js:433:10)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:7
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
wrslatzcommented, May 12, 2020

This solution works, but it’s a poor experience for new users onboarding to an existing repo. We have an large monorepo and each unique, one-off config like this makes onboarding more difficult.

2reactions
dsebastiencommented, Apr 30, 2020

I could make it work again with the following config, even though I’m really not sure of what’s going on and don’t have time now to dig deeper:

if (process.env.JETBRAINS !== undefined) {
  module.exports.globals = {
    "ts-jest": {
      ...tsJestBaseConfig,
      stringifyContentPathRegex: "\\.(html)$",
      astTransformers: [
        'jest-preset-angular/build/InlineFilesTransformer',
        'jest-preset-angular/build/StripStylesTransformer',
      ],
    },
  };
}

In my IDE, I have this as template for Jest tests:

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest | WebStorm Documentation - JetBrains
You can run and debug tests with Jest right in WebStorm. You can see the test results in a treeview and easily navigate...
Read more >
Can't run Jest tests from editor in WebStorm - Stack Overflow
I can run Jest via a run configuration and it works fine. However, I can't right-click on a test in the editor and...
Read more >
Troubleshooting - Jest
Tests are Failing and You Don't Know Why​ ... This will run Jest in a Node process that an external debugger can connect...
Read more >
Running and debugging Jest tests in WebStorm | jsPoland 2018
Filmed at http://js-poland.pl 2018 on November 16 in Warsaw. Jest is a testing platform that is very popular for testing React applications.
Read more >
[Solved]-Running jest tests directly in Intellij Idea/WebStorm?
[Solved]-Running jest tests directly in Intellij Idea/WebStorm?-Reactjs · Install Jest CLI: npm install --save-dev jest-cli · Create node run configuration with ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found