Jonathan Tuzman
Jonathan Tuzman

Reputation: 13283

Can't run Jest tests from editor in WebStorm

I'm looking at a file in WebStorm that contains Jest tests. 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 run it, nor do I get any gutter icons that would let me do so. I can right-click on a describe or it block and I have the option to run or debug, but it's trying to run/debug the file, not run the test:

(function (exports, require, module, __filename, __dirname) { import React from "react";
                                                                     ^^^^^

SyntaxError: Unexpected identifier
    at new Script (vm.js:80:7)
    at createScript (vm.js:274:10)
    at Object.runInThisContext (vm.js:326:10)
    at Module._compile (internal/modules/cjs/loader.js:664:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
    at startup (internal/bootstrap/node.js:283:19)

Process finished with exit code 1

This is a new installation on a new M1 MacBook Pro, but it's got my settings synced with my other machines, so I don't see any reason why this wouldn't work like all my other WebStorm installations. (And it's not just this file, it's any test file anywhere.)

Upvotes: 0

Views: 1556

Answers (2)

sevensevens
sevensevens

Reputation: 1750

I was able to fix this by adding "jest" to the types list in tsconfig.json

"types": ["node", "jest"]

Upvotes: 0

Jonathan Tuzman
Jonathan Tuzman

Reputation: 13283

The problem solved itself when I removed babel-jest from our dependencies and added jest, which hadn't previously been there even though the tests would run, including using the "Run tests" run config.

As @lena suggested, the problem appeared to be not having Jest in the package file.

Upvotes: 0

Related Questions