Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run jest with electron instead of node

To make a long story short, I'd like to run my jest tests (using CLI) with electron instead of node.

It's relevant when using native module, because you need to build them using electron header while jest run them using plain node. So I must either build my native modules for my app (at least in dev mode) or my tests, I can't have both to work.

In this thread they propose to use mocha, but I want to use jest, which is far more advanced and interact well with React. Note that I don't want to mock the native module, since I write integration tests.

I opened an issue about the zmq github repo. One proposed solution is "to target your tests using ELECTRON_RUN_AS_NODE=true electron as your node runtime". This is a very good solution, since using electron will both make the test environment closer to the execution environment and solve my specific issue with native modules.

I'd like to apply that, but I do no seem to be able to setup the jest CLI to use electron instead of node, and I have no idea where to start. Maybe I should run jest programmatically without the CLI ? But I might lose the nice test filtering features of the CLI.

Has anyone solved this already?

like image 716
Eric Burel Avatar asked May 24 '17 17:05

Eric Burel


People also ask

Can you use Jest without Node?

To read TypeScript configuration files Jest requires ts-node . Make sure it is installed in your project.

Does Jest run in Node?

🃏 Delightful JavaScript Testing. Jest is a delightful JavaScript Testing Framework with a focus on simplicity. It works with projects using: Babel, TypeScript, Node, React, Angular, Vue and more!

How do I run a specific Jest in npm?

In order to run a specific test, you'll need to use the jest command. npm test will not work. To access jest directly on the command line, install it via npm i -g jest-cli or yarn global add jest-cli . Then simply run your specific test with jest bar.


1 Answers

"ELECTRON_RUN_AS_NODE=true ./node_modules/.bin/electron ./node_modules/.bin/jest works fine

like image 157
Eric Burel Avatar answered Oct 05 '22 23:10

Eric Burel