Open NodeGuy opened 6 years ago
Jest runs in node, not sure if it can run in Electron - I haven't seen anyone using Jest with Electron (even without wallaby). Even if plain Jest works with Electron, we will need to add the support separately.
We're using Jest with Electron: https://github.com/cosmos/voyager
I look forward to you adding support.
@NodeGuy Thanks for the repo link!
Correct me me if I'm wrong, but I can't see where you are running Jest with Electron, from what I can see, your package.json
is running Jest tests in node:
"test:unit": "cross-env LOGGING=false MOCK=false ANALYTICS=false NODE_ENV=testing jest --maxWorkers=2",
To do the same in wallaby you may use
env: {
type: 'node'
}
instead of
env: {
kind: 'electron'
},
Oh dear, how embarrassing. I'm new to the project and to Jest and made an incorrect assumption; thanks for pointing it out.
@ArtemGovorov according to the Wallaby Jest is not supported to run in Node. Here it sounds, it is supported. What is the current status? Thanks!
Jest is not supported to run in Node
Jest is supported to run in Node in Wallaby. You may find the sample config in our docs.
@ArtemGovorov Thanks. You might want to update the info in https://wallabyjs.com/docs/integration/overview.html Under Supported testing frameworks Jest is only listed under "for browser" and not under "for Node"
@marcelh-gh Thanks for the note. The docs had been updated.
There is an option in Electron to run as a normal Node process by setting the ENV variable ELECTRON_RUN_AS_NODE=true. This is how we're using Jest with Electron. The command that we use to run our tests is ELECTRON_RUN_AS_NODE=true ./node_modules/.bin/electron ./node_modules/.bin/jest
Perhaps this could be leveraged to run Wallaby on Electron apps with Jest?
https://electronjs.org/docs/api/environment-variables#electron_run_as_node
@TreTuna I haven't tried, but if Electron starts as node with the flag, then maybe this could work:
module.exports = function () {
return {
...
env: {
type: 'node',
runner: require('electron'), // this should return electron binary path
params: {
env: 'ELECTRON_RUN_AS_NODE=true'
}
}
};
};
@ArtemGovorov Well, that seems to work! I don't have any tests written in this repo yet that involve Electron processes, but it's running the very basic ones I have going on this. However, it does load up 6 Electron processes in the process. Which seems a bit excessive.
@TreTuna Awesome, thanks for the update.
However, it does load up 6 Electron processes in the process. Which seems a bit excessive.
Wallaby runs tests in parallel using multiple worker processes. You may control the number of workers with the workers
setting.
Jest runs in node, not sure if it can run in Electron - I haven't seen anyone using Jest with Electron (even without wallaby). Even if plain Jest works with Electron, we will need to add the support separately.
I'm using jest with electron.
@kashaiahyah85 - were you able to get this working with @ArtemGovorov's previous suggested fix mentioned in this issue?
Actually, @smcenlly , I'm just using facebook-atom/jest-electron-runner more or less according to its documentation, and selectively mocking things when necessary. You'll need two different jest configurations (projects), one for main and one for the renderer. I go the route of trying the tests all in main, then separating what I need to, because the main process is a little faster on average for testing.
This is how I've configured that.
Hey, I also use jest with electron,facebook-atom/jest-electron-runner
works quite well, but I haven't been able to get wallaby to work with this, it would be very useful if this was supported.
Issue description or question
When I try to run my Jest tests in Electron I see the following error message:
Wallaby.js configuration file
Code editor or IDE name and version
Visual Studio Code v1.21.1
OS name and version
macOS 10.13.3