GithubHelp home page GithubHelp logo

lencioni / create-jest-runner Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jest-community/create-jest-runner

0.0 2.0 0.0 284 KB

A highly opinionated way for creating Jest Runners

License: MIT License

JavaScript 98.68% Dockerfile 1.32%

create-jest-runner's Introduction

create-jest-runner

Build Status

A highly opinionated way for creating Jest Runners

Install

yarn add create-jest-runner

Usage

create-jest-runner takes care of handling the appropriate parallelization and creating a worker farm for your runner.

You simply need two files:

  • Entry file: Used by Jest as an entrypoint to your runner.
  • Run file: Runs once per test file, and it encapsulates the logic of your runner

1) Create your entry file

// index.js
const { createJestRunner } = require('create-jest-runner');
module.exports = createJestRunner(require.resolve('./run'));

createJestRunner(pathToRunFile, config?: { getExtraOptions })

  • pathToRunFile: path to your run file.
  • config: Optional argument for configuring the runner.
    • getExtraOptions: () => object used for passing extra options to the runner. It needs to be a serializable object because it will be send to a different Node process.

2) Create your run file

module.exports = options => {};

Run File API

This file should export a function that receives one parameter with the options

options: { testPath, config, globalConfig }

  • testPath: Path of the file that is going to be tests
  • config: Jest Project config used by this file
  • globalConfig: Jest global config
  • extraOptions: The return value of the { getExtraOptions } argument of createJestRunner(...) the entry file.

You can return one of the following values:

Example of a runner

This runner "blade-runner" makes sure that these two emojis โš”๏ธ ๐Ÿƒ are present in every file

// index.js
const { createJestRunner } = require('create-jest-runner');
module.exports = createJestRunner(require.resolve('./run'));
// run.js
const fs = require('fs');
const { pass, fail } = require('create-jest-runner');

module.exports = ({ testPath }) => {
  const start = Date.now();
  const contents = fs.readFileSync(testPath, 'utf8');
  const end = Date.now();

  if (contents.includes('โš”๏ธ๐Ÿƒ')) {
    return pass({ start, end, test: { path: testPath } });
  }
  const errorMessage = 'Company policies require โš”๏ธ ๐Ÿƒ in every file';
  return fail({
    start,
    end,
    test: { path: testPath, errorMessage, title: 'Check for โš”๏ธ ๐Ÿƒ' },
  });
};

Create runner from binary

yarn create jest-runner my-runner

# Or with npm
npm init jest-runner my-runner

Note: You will have to update the package name in package.json of the generated runner

Add your runner to Jest config

Once you have your Jest runner you can add it to your Jest config.

In your package.json

{
  "jest": {
    "runner": "/path/to/my-runner"
  }
}

Or in jest.config.js

module.exports = {
  runner: '/path/to/my-runner',
};

Run Jest

yarn jest

create-jest-runner's People

Contributors

rogeliog avatar simenb avatar stipsan avatar lgandecki avatar danielmschmidt avatar kesne avatar mark1626 avatar wheeler avatar thymikee avatar elliottsj avatar skratchdot avatar

Watchers

James Cloos avatar  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.