# create-jest-runner-with-skip

> A simple way of creating a Jest runner

Latest version **0.1.1** (published 2018-01-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install create-jest-runner-with-skip
pnpm add create-jest-runner-with-skip
yarn add create-jest-runner-with-skip
bun add create-jest-runner-with-skip
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: no vulnerabilities; high maintenance score.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2018-01-20 |
| First published | 2018-01-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 10 |
| Known vulnerabilities | 0 (+14 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 137 |
| Author | Rogelio Guzman |
| Maintainers | lgandecki |

## Links

- npm: https://www.npmjs.com/package/create-jest-runner-with-skip
- Repository: https://github.com/rogeliog/create-jest-runner
- Issues: https://github.com/rogeliog/create-jest-runner/issues
- npm.io page: https://npm.io/package/create-jest-runner-with-skip

## Dependencies (10)

- [pify](https://npm.io/package/pify.md) 3.0.0
- [mocha](https://npm.io/package/mocha.md) 3.5.0
- [lodash](https://npm.io/package/lodash.md) 4.17.4
- [throat](https://npm.io/package/throat.md) 4.1.0
- [minimatch](https://npm.io/package/minimatch.md) 3.0.4
- [jest-worker](https://npm.io/package/jest-worker.md) 21.3.0-beta.9
- [worker-farm](https://npm.io/package/worker-farm.md) 1.5.0
- [babel-polyfill](https://npm.io/package/babel-polyfill.md) ^6.26.0
- [babel-register](https://npm.io/package/babel-register.md) 6.26.0
- [babel-plugin-istanbul](https://npm.io/package/babel-plugin-istanbul.md) 4.1.4

## Recent versions

- 0.1.1 (latest) — 2018-01-20

## README

# create-jest-runner

A highly opinionated way for creating Jest Runners

## Install

```bash
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

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

### 2) Create your run file

```js
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

You can return one of the following values:
- `testResult`: Needs to be an object of type https://github.com/facebook/jest/blob/master/types/TestResult.js#L131-L157
- `Promise<testResult|Error>`: needs to be of above type.
- `Error`: good for reporting system error, not failed tests.



## Example of a runner

This runner "blade-runner" makes sure that these two emojis `⚔️ 🏃` are present in every file


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

```js
// run.js
const fs = require('fs');
const { pass, fail } = require('create-jest-runner');

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

  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 ⚔️ 🏃' },
  });
};
```


## Add your runner to Jest config

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

In your `package.json`
```json
{
  "jest": {
    "runner": "/path/to/my-runner"
  }
}
```

Or in `jest.config.js`
```js
module.exports = {
  runner: '/path/to/my-runner',
}
```

### Run Jest
```bash
yarn jest
```

---
_Source: https://npm.io/package/create-jest-runner-with-skip · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
