Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Npm test fails #320

Open
cool-html5 opened this issue Jul 21, 2021 · 6 comments
Open

Npm test fails #320

cool-html5 opened this issue Jul 21, 2021 · 6 comments

Comments

@cool-html5
Copy link

cool-html5 commented Jul 21, 2021

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)
@PxlCode
Copy link

PxlCode commented Jul 29, 2021

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.

@szwacz
Copy link
Owner

szwacz commented Jul 31, 2021

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

@cool-html5
Copy link
Author

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.

@szwacz
Copy link
Owner

szwacz commented Jul 31, 2021

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.

@jjasiunas
Copy link

jjasiunas commented Oct 27, 2021

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;
};

> electron-boilerplate@0.0.0 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>

@szwacz
Copy link
Owner

szwacz commented Nov 3, 2021

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants