electron-boilerplate icon indicating copy to clipboard operation
electron-boilerplate copied to clipboard

Npm test fails

Open cool-html5 opened this issue 3 years ago • 6 comments

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

  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----\source\repos\electron-boilerplate\temp\e2e.js) at listOnTimeout (internal/timers.js:554:17) at processTimers (internal/timers.js:497:7)

cool-html5 avatar Jul 21 '21 14:07 cool-html5

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 using done() with return <Promise>.
  • looked at how the *.config.js are build. Dont know much about it.
  • I console.log(app); in afterEach and it's defined and running: true.
  • Adding a timeout to the afterEach Root-Hook of 10000 resulted in another error => TypeError: Cannot read property 'client' of undefined, because as I removde the timeout from the beforeEach I ran into the same error but from the beforeEach 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.

PxlCode avatar Jul 29 '21 23:07 PxlCode

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).

szwacz avatar Jul 31 '21 19:07 szwacz

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.

cool-html5 avatar Jul 31 '21 20:07 cool-html5

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.

szwacz avatar Jul 31 '21 20:07 szwacz

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>

jjasiunas avatar Oct 27 '21 19:10 jjasiunas

FYI, Spectron just announced sun-setting the project: https://github.com/electron-userland/spectron/issues/1045 Interesting how situation is going to unwind.

szwacz avatar Nov 03 '21 10:11 szwacz