Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Jest w/ Electron Runner so tests run & pass in a real browser #15

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

agilgur5
Copy link
Owner

@agilgur5 agilgur5 commented Nov 26, 2019

  • use a full browser for testing instead of running in Node and
    relying on JSDOM, which does not implement all of the features we
    use (namely worker-related stuff)

    • this ensures tests run without any errors
    • and @jest-runner/electron is surprisingly very fast, not much
      different from running in normal jest w/ jsdom
      • like 4s locally fast I mean
  • also update CI to work with electron and use Node 10 Active LTS

Fixes #7, Fixes #14

Unfortunately still having coverage problems as in #6 , so that hasn't changed between regular Jest and Jest w/ Electron runner, despite the bugs it should have fixed.

After having used Jest for a longer time period in some other projects, I've also come to prefer it to other test runners like AVA. I didn't like all the built-ins / stuff it does for you initially, but it's a lot less boilerplate and tends to be more intuitive. The runner output is also fantastic imo. Happy to change to it!

- use a full browser for testing instead of running in Node and
  relying on JSDOM, which does not implement all of the features we
  use (namely worker-related stuff)
  - this ensures tests run without any errors
  - and @jest-runner/electron is surprisingly **very fast**, not much
    different from running in normal jest w/ jsdom
    - like 4s locally fast I mean

- refactor tests to Jest style from AVA style
- remove all AVA-specifc config
- Node 8 Maintenance LTS is EOL in Jan 2020
- this also updates NPM to v6.9.0 (from v5.6.0)
- could add some CI perf, esp w/ new usage of `npm ci`
  - but we run in under a minute anyway, so hard to beat that!
@agilgur5
Copy link
Owner Author

agilgur5 commented Nov 26, 2019

Noting here that I ran into some CI issues with Electron needing xvfb running in order to run correctly. Had a few builds just hang when running jest with no errors what-so-ever, which was very confusing. Fortunately found some fixes here and was able to implement them successfully. Would be nice if common gotchas like these were documented better as I didn't have that Electron-specific knowledge (I also think Chrome headless errors in these cases? That was the last time I used xvfb and don't remember it just hanging?).

Also worthing noting is that Cypress doesn't seem to have this issue (it might wrap some xvfb logic for you though?). EDIT: yes, it does: https://github.com/cypress-io/xvfb

Copy link
Owner Author

@agilgur5 agilgur5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this took a bit to trial-and-error and get running correctly (and coverage took far longer and too long to not work), the actual code changes are quite small, seems good to go!

package.json Show resolved Hide resolved
- jest would just hang w/ no errors if xvfb wasn't configured
  - https://travis-ci.org/agilgur5/physijs-webpack/builds/617354543
  - for more details see #15 (comment)

- this fix is directly from the Electron CI instructions
  - https://github.com/electron/electron/blob/master/docs/tutorial/testing-on-headless-ci.md
  - not totally sure why it needs xvfb for headless, but it runs now
- per Travis CI's instructions
  - https://docs.travis-ci.com/user/gui-and-headless-browsers/#using-the-xvfb-run-wrapper
  - also apt addons doesn't seem to be needed
    - speeds up CI a bit too bc no apt-get update
- saw this on some blog posts, but caching on CI isn't directly
  documented in Electron for some reason
  - caching is mentioned in the installation docs though
    - https://github.com/electron/electron/blob/master/docs/tutorial/installation.md#cache
@agilgur5
Copy link
Owner Author

agilgur5 commented Jul 1, 2023

Jotting down here that https://github.com/facebook-atom/jest-electron-runner has been unmaintained and archived, but a quick search did find an updated fork: https://github.com/kayahr/jest-electron-runner. Thanks for supporting it!

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

Successfully merging this pull request may close these issues.

Fix browserify test to work without errors in Node v10 Fix webpack test to work without bugs
1 participant