1 | [![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fstryker-mutator%2Fstryker-js%2Fmaster%3Fmodule%3Dcore)](https://dashboard.stryker-mutator.io/reports/github.com/stryker-mutator/stryker-js/master?module=core)
|
2 | [![Build Status](https://github.com/stryker-mutator/stryker-js/workflows/CI/badge.svg)](https://github.com/stryker-mutator/stryker-js/actions?query=workflow%3ACI+branch%3Amaster)
|
3 | [![NPM](https://img.shields.io/npm/dm/@stryker-mutator/core.svg)](https://www.npmjs.com/package/@stryker-mutator/core)
|
4 | [![Node version](https://img.shields.io/node/v/@stryker-mutator/core.svg)](https://img.shields.io/node/v/@stryker-mutator/core.svg)
|
5 | [![Slack Chat](https://img.shields.io/badge/slack-chat-brightgreen.svg?logo=slack)](https://join.slack.com/t/stryker-mutator/shared_invite/enQtOTUyMTYyNTg1NDQ0LTU4ODNmZDlmN2I3MmEyMTVhYjZlYmJkOThlNTY3NTM1M2QxYmM5YTM3ODQxYmJjY2YyYzllM2RkMmM1NjNjZjM)
|
6 |
|
7 | ![StrykerJS](https://github.com/stryker-mutator/stryker-js/raw/master/stryker-80x80.png)
|
8 |
|
9 | # StrykerJS
|
10 | *Professor X: For someone who hates mutants... you certainly keep some strange company.*
|
11 | *William Stryker: Oh, they serve their purpose... as long as they can be controlled.*
|
12 |
|
13 | ## Introduction
|
14 | For an introduction to mutation testing and StrykerJS features, see [stryker-mutator.io](https://stryker-mutator.io/).
|
15 |
|
16 | ## Getting started
|
17 |
|
18 | Please follow the [quickstart on the website](https://stryker-mutator.io/docs/stryker-js/getting-started/).
|
19 |
|
20 | For small js projects, you can try the following command:
|
21 |
|
22 | ```
|
23 | npm install --save-dev @stryker-mutator/core
|
24 | # Only for small projects:
|
25 | npx stryker run
|
26 | ```
|
27 |
|
28 | It will run stryker with default values:
|
29 |
|
30 | * Uses `npm test` as your test command
|
31 | * Searches for files to mutate in the `lib` and `src` directories
|
32 |
|
33 | ## Usage
|
34 |
|
35 | ```sh
|
36 | $ npx stryker <command> [options] [configFile]
|
37 | ```
|
38 |
|
39 | See [usage on stryker-mutator.io](https://stryker-mutator.io/docs/stryker-js/usage)
|
40 |
|
41 | ## Supported mutators
|
42 |
|
43 | See our website for the [list of currently supported mutators](https://stryker-mutator.io/docs/mutation-testing-elements/supported-mutators).
|
44 |
|
45 | ## Configuration
|
46 |
|
47 | See [configuration on stryker-mutator.io](https://stryker-mutator.io/docs/stryker-js/configuration).
|
48 |
|
49 | ## Programmatic use
|
50 |
|
51 | Stryker can also be used programmatically from nodejs. It exports 2 classes for you to use: `Stryker` and `StrykerCli`.
|
52 |
|
53 | ```ts
|
54 | import { Stryker, StrykerCli } from '@stryker-mutator/core';
|
55 | ```
|
56 |
|
57 | Both classes can be used to run Stryker. The main difference is that `Stryker` is a slightly more low-level approach, while `StrykerCli` is the straight up CLI api.
|
58 |
|
59 | In this example you can see how to use both.
|
60 |
|
61 | ```ts
|
62 | async function main() {
|
63 | // Runs Stryker as if it was called directly from the cli. Not even returns a promise, it assumes to be allowed to call `process.exit`.
|
64 | new StrykerCli(process.argv /* RAW argv array */ ).run();
|
65 |
|
66 | // Runs Stryker, will not assume to be allowed to exit the process.
|
67 | const stryker = new Stryker({ concurrency: 4 } /* Partial Stryker options object */ );
|
68 | const mutantResults = await stryker.runMutationTest();
|
69 | // mutantResults or rejected with an error.
|
70 | }
|
71 | ```
|
72 |
|
73 | Stryker is written in TypeScript, so it is recommended to use Typescript as well to get the best developer experience.
|