electron-boilerplate
electron-boilerplate copied to clipboard
Npm test fails
I just cloned this repo and run npm i and npm test. I have not made any changes. The test fails with the following error:
mocha temp/e2e.js --require source-map-support/register
application launch √ shows hello world text on screen after launch 1) "after each" hook: afterEach for "shows hello world text on screen after launch"
1 passing (4s) 1 failing
- application launch "after each" hook: afterEach for "shows hello world text on screen after launch": Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users----\source\repos\electron-boilerplate\temp\e2e.js) at listOnTimeout (internal/timers.js:554:17) at processTimers (internal/timers.js:497:7)
Same here!
os: Windows 10
npm: 6.14.14
node: 14.17.3
Did a fresh clone.
npm install
=> npm start
=> WORKS!
But npm test
fails with the same error. The unit-tests are working.
Console Ouput
> mocha temp/e2e.js --require source-map-support/register
application launch
√ shows hello world text on screen after launch
1) "after each" hook: afterEach for "shows hello world text on screen after launch"
1 passing (4s)
1 failing
1) application launch
"after each" hook: afterEach for "shows hello world text on screen after launch":
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\patri\Documents\projekte\electron-boilerplate\temp\e2e.js)
at listOnTimeout (internal/timers.js:557:17)
at processTimers (internal/timers.js:500:7)
As we see the error got thrown in the afterEach
in ./app/e2e/utils.js
after the second e2e test.
The console output can be confusing when the error gets thrown in a hook.
The test itself is alright.
- I tried adding a
done()
to the test and get a expected overspecifing error when usingdone()
withreturn <Promise>
. - looked at how the *.config.js are build. Dont know much about it.
- I
console.log(app);
inafterEach
and it's defined andrunning: true
. -
Adding a timeout to the
afterEach
Root-Hook of10000
resulted in another error =>TypeError: Cannot read property 'client' of undefined
, because as I removde the timeout from thebeforeEach
I ran into the same error but from thebeforeEach
and got curious
"before each" hook: beforeEach for "shows hello world text on screen after launch":
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\patri\Documents\projekte\electron-boilerplate\temp\e2e.js)
at listOnTimeout (internal/timers.js:557:17)
at processTimers (internal/timers.js:500:7)
As I struggle myself to get electron-mocha running and just running into different problems across the way, I wanted to join the conversation.
Spectron defines default timeout for a test of 2000ms, the test setup takes more than that hence the error. I've risen the timeout to 10000ms in the code long time ago: https://github.com/szwacz/electron-boilerplate/blob/master/e2e/utils.js#L5 That means Spectron in your case ignored this timeout change.
The code works fine on my MacOS machine, can you test in yours moving the this.timeout(10000)
into test itself, as it's done in Spectron readme: https://github.com/electron-userland/spectron/blob/master/README.md
Maybe this issue is only reproducable on Windows platform, to which I don't have easy access right now (need to install a VM).
The e2e/utils.js already has a timeout of 10 seconds. This is not the solution to the problem. Yes this might only be a windows platform issue.
Ah, right, I was combating the timeouts in beforeEach
so much in the past, that didn't notice the afterEach
word in your logs. Man, Spectron (webdriver?) is a flaky thing. I suspect this is a problem with Spectron itself, since afterEach
function is just closing the app window, don't see what might take long there.
Unfortunately Cypress doesn't have Electron support on their roadmap so far.
The e2e/utils.js already has a timeout of 10 seconds. This is not the solution to the problem. Yes this might only be a windows platform issue.
The timeout is specified in beforeEach
but not in afterEach
. The error occurs in afterEach
. I added the timeout to afterEach
and the error is no longer present.
const afterEach = function() {
this.timeout(10000);
if (this.app && this.app.isRunning()) {
return this.app.stop();
}
return undefined;
};
> [email protected] e2e
> mocha temp/e2e.js --require source-map-support/register
application launch
√ shows hello world text on screen after launch
1 passing (8s)
C:\Projects\Development\electron-boilerplate>
FYI, Spectron just announced sun-setting the project: https://github.com/electron-userland/spectron/issues/1045 Interesting how situation is going to unwind.