{"id":13724955,"url":"https://github.com/jest-community/create-jest-runner","last_synced_at":"2025-04-09T10:04:30.232Z","repository":{"id":26589399,"uuid":"107290794","full_name":"jest-community/create-jest-runner","owner":"jest-community","description":"A highly opinionated way for creating Jest Runners","archived":false,"fork":false,"pushed_at":"2024-04-08T04:25:17.000Z","size":14357,"stargazers_count":134,"open_issues_count":11,"forks_count":23,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-04-14T14:55:59.649Z","etag":null,"topics":["jest-runner"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jest-community.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2017-10-17T15:50:15.000Z","updated_at":"2024-03-08T02:35:26.000Z","dependencies_parsed_at":"2024-04-01T04:49:09.877Z","dependency_job_id":null,"html_url":"https://github.com/jest-community/create-jest-runner","commit_stats":{"total_commits":213,"total_committers":20,"mean_commits":10.65,"dds":0.6291079812206573,"last_synced_commit":"5675473b5247d788719711bec6f3ae2d941b169a"},"previous_names":["rogeliog/create-jest-runner"],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jest-community%2Fcreate-jest-runner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jest-community%2Fcreate-jest-runner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jest-community%2Fcreate-jest-runner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jest-community%2Fcreate-jest-runner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jest-community","download_url":"https://codeload.github.com/jest-community/create-jest-runner/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248018060,"owners_count":21034048,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["jest-runner"],"created_at":"2024-08-03T01:02:07.874Z","updated_at":"2025-04-09T10:04:30.207Z","avatar_url":"https://github.com/jest-community.png","language":"TypeScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# create-jest-runner\n\n[![Actions Status](https://github.com/jest-community/create-jest-runner/actions/workflows/nodejs.yml/badge.svg?branch=main)](https://github.com/jest-community/create-jest-runner/actions)\n\nA highly opinionated way for creating Jest Runners\n\n## Install\n\n```bash\nyarn add create-jest-runner\n```\n\n## Usage\n\ncreate-jest-runner takes care of handling the appropriate parallelization and creating a worker farm for your runner.\n\nYou simply need two files:\n\n- Entry file: Used by Jest as an entrypoint to your runner.\n- Run file: Runs once per test file, and it encapsulates the logic of your runner\n\n### 1) Create your entry file\n\n```js\n// index.js\nconst { createJestRunner } = require('create-jest-runner');\nmodule.exports = createJestRunner(require.resolve('./run'));\n```\n\n#### createJestRunner(pathToRunFile, config?: { getExtraOptions })\n\n- `pathToRunFile`: path to your run file. This must be an absolute path or a `file://` URL.\n- `config`: Optional argument for configuring the runner.\n  - `getExtraOptions`: `() =\u003e 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.\n\n### 2) Create your run file\n\n```js\nmodule.exports = options =\u003e {};\n```\n\n### Run File API\n\nThis file should export a function that receives one parameter with the options\n\n#### `options: { testPath, config, globalConfig }`\n\n- `testPath`: Path of the file that is going to be tests\n- `config`: Jest Project config used by this file\n- `globalConfig`: Jest global config\n- `extraOptions`: The return value of the `{ getExtraOptions }` argument of `createJestRunner(...)` the entry file.\n\nYou can return one of the following values:\n\n- `testResult`: Needs to be an object of type https://github.com/facebook/jest/blob/4d3c1a187bd429fd8611f6b0f19e4aa486fa2a85/packages/jest-test-result/src/types.ts#L103-L135\n- `Promise\u003ctestResult|Error\u003e`: needs to be of above type.\n- `Error`: good for reporting system error, not failed tests.\n\n## Example of a runner\n\nThis runner \"blade-runner\" makes sure that these two emojis `⚔️ 🏃` are present in every file\n\n```js\n// index.js\nconst { createJestRunner } = require('create-jest-runner');\nmodule.exports = createJestRunner(require.resolve('./run'));\n```\n\n```js\n// run.js\nconst fs = require('fs');\nconst { pass, fail } = require('create-jest-runner');\n\n/** @type {import('create-jest-runner').RunTest} */\nconst runTest = ({ testPath }) =\u003e {\n  const start = Date.now();\n  const contents = fs.readFileSync(testPath, 'utf8');\n  const end = Date.now();\n\n  if (contents.includes('⚔️🏃')) {\n    return pass({ start, end, test: { path: testPath } });\n  }\n  const errorMessage = 'Company policies require ⚔️ 🏃 in every file';\n  return fail({\n    start,\n    end,\n    test: { path: testPath, errorMessage, title: 'Check for ⚔️ 🏃' },\n  });\n};\n\nmodule.exports = runTest;\n```\n\n## Create runner from binary\n\n```shell\nyarn create jest-runner my-runner\n\n# Or with npm\nnpm init jest-runner my-runner\n```\n\n**Note:** You will have to update the package name in `package.json` of the generated runner.\n\n## Add your runner to Jest config\n\nOnce you have your Jest runner you can add it to your Jest config.\n\nIn your `package.json`\n\n```json\n{\n  \"jest\": {\n    \"runner\": \"/path/to/my-runner\"\n  }\n}\n```\n\nOr in `jest.config.js`\n\n```js\nmodule.exports = {\n  runner: '/path/to/my-runner',\n};\n```\n\n### Run Jest\n\n```bash\nyarn jest\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjest-community%2Fcreate-jest-runner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjest-community%2Fcreate-jest-runner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjest-community%2Fcreate-jest-runner/lists"}