Code Monkey home page Code Monkey logo

jest-electron-runner's Introduction

CircleCI

Jest electron runner

A custom test runner for Jest that runs tests inside an electron main or renderer process providing the following benefits:

  • Main

    • all electron instance modules (ipc, app, etc)
  • Renderer

    • full access to a browser environment without the need for jsdom or similar modules

Getting Started

NOTE: for jest@23 use the older version ~@jest-runner/[email protected]

  1. Install jest electron runner yarn add @jest-runner/electron --dev

  2. Add one of these lines to your jest config (in package.json or inside your jest.config.js file), depending on the process you wish to test. If you wish to test them in parallel, see the tips section below.

    • Main process
        {
          // ...
          runner: '@jest-runner/electron/main',
          testEnvironment: 'node',
        }
    • Renderer Process
        {
          // ...
          runner: '@jest-runner/electron',
          testEnvironment: '@jest-runner/electron/environment',
        }
  3. run jest!

Debugging

Normally jest-electron-runner runs a headless instance of electron when testing the renderer process. You may show the UI by adding this to your test:

require('electron').remote.getCurrentWindow().show();

Tips

  • The main process runner can be used to test any non-browser related code, which can speed up tests roughly 2x.
  • To run the main and renderer process tests in parallel, you can provide a config object to the projects array in a jest javascript config file like so:
// jest.config.js
const common = require('./jest.common.config')

module.exports = {
  projects: [
    {
      ...common,
      runner: '@jest-runner/electron/main',
      testEnvironment: 'node',
      testMatch: ['**/__tests__/**/*.(spec|test).ts']
    },
    {
      ...common,
      runner: '@jest-runner/electron',
      testEnvironment: '@jest-runner/electron/environment',
      testMatch: ['**/__tests__/**/*.(spec|test).tsx']
    }
  ]
}

Facebook has adopted a Code of Conduct that we expect project participants to adhere to. Please read the full text so that you can understand what actions will and will not be tolerated.

Read our contributing guide to learn about our development process, how to propose bugfixes and improvements, and how to build and test your changes to Jest.

License

MIT licensed.

jest-electron-runner's People

Contributors

aaronabramov avatar aguynamedben avatar bryanpierce avatar daniel-nagy avatar elliottsj avatar fitzpasd avatar jm-mendez avatar marcoancona avatar neojski avatar rajivshah3 avatar ralexmatthews avatar smacpherson64 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.