Stryker Mutator
Configuration file for Stryker Mutator, the mutation testing framework for JavaScript and friends. Documentation: https://stryker-mutator.io
| Type | object |
|---|---|
| File match |
stryker.conf.json
stryker-*.conf.json
|
| Schema URL | https://catalog.lintel.tools/schemas/schemastore/stryker-mutator/latest.json |
| Source | https://raw.githubusercontent.com/stryker-mutator/stryker/master/packages/api/schema/stryker-core.json |
Validate with Lintel
npx @lintel/lintel check
JSON schema for the Stryker Mutator configuration file
Properties
The 'allowConsoleColors' value indicates whether Stryker should use colors in console.
Configure a build command to run after mutating the code, but before mutants are tested. This is generally used to transpile your code before testing. Only configure this if your test runner doesn't take care of this already and you're not using just-in-time transpiler like babel/register or ts-node.
Enable checker plugins here. A checker plugin will be invoked for each mutant before it is run in a test runner. It can check to see of a given mutant is valid, by for example validate that it won't result in a type error
[]
Configure arguments to be passed as exec arguments to the checker child process(es). For example, running Stryker with --concurrency 1 --checkerNodeArgs --inspect-brk will allow you to debug the checker child process. See execArgv of child_process.fork
[]
Set the concurrency of workers. Stryker will always run checkers and test runners in parallel by creating worker processes (note, not worker_threads). This defaults to n-1 where n is the number of logical CPU cores available on your machine, unless n <= 4, in that case it uses n. This is a sane default for most use cases. You can also specify a percentage string (e.g., "50%") to compute the worker count as a percentage of the logical CPU cores available (0%-100%).
1 nested properties
The command to test each mutant. For example "npm run mocha". Defaults to "npm test".
8 nested properties
Indicates whether or not to use color coding in output.
Enable emojis in your clear text report (experimental).
Indicates whether or not to log which tests were executed for a given mutant.
Indicates the maximum amount of test to log when logTests is enabled
Indicates whether or not to log all tests.
Indicates whether or not to log all mutants.
Indicates whether or not to log score table.
Indicates whether rows with 100% mutation score are hidden in the score table.
5 nested properties
Indicates which project to use if the "dashboard" reporter is enabled.
Indicates which version to use if the "dashboard" reporter is enabled.
Indicates which module to use if the "dashboard" reporter is enabled.
Indicates the base url of the stryker dashboard.
Execute the initial test run only without doing actual mutation testing. Dry run only will still mutate your code before doing the dry run without those mutants being active, thus can be used to test that StrykerJS can run your test setup. This can be useful, for example, in CI pipelines.
1 nested properties
The base dir to write the events to
A comma separated list of patterns used for specifying which files need to be ignored. This should only be used in cases where you experience a slow Stryker startup, because too many (or too large) files are copied to the sandbox that are not needed to run the tests. For example, image or movie directories. Note: This option will have NO effect when using the --inPlace option. The directories node_modules, .git and some others are always ignored. Example: --ignorePatterns dist. These patterns are ALWAYS ignored: [node_modules, .git, /reports, *.tsbuildinfo, /stryker.log, .stryker-tmp]. Because Stryker always ignores these, you should rarely have to adjust the ignorePatterns setting at all. This is useful to speed up Stryker by ignoring big directories/files you might have in your repo that has nothing to do with your code. For example, 1.5GB of movie/image files. Specify the patterns to all files or directories that are not used to run your tests and thus should NOT be copied to the sandbox directory for mutation testing. Each patterns in this array should be a glob pattern. If a glob pattern starts with /, the pattern is relative to the current working directory. For example, /foo.js matches to foo.js but not subdir/foo.js. However to SELECT specific files TO BE mutated, you better use --mutate.
[]
Ignore static mutants. Static mutants are mutants which are only executed during the loading of a file. This means that Stryker has to reload the entire environment in order to test the mutant AND has to run all tests. Therefore, it might make sense to ignore static mutants.
Enable 'incremental mode'. Stryker will store results in a file and use that file to speed up the next --incremental run
Specify the file to use for incremental mode.
Run all mutants, even if --incremental is provided and an incremental file exists. Can be used to force a rebuild of the incremental file.
Determines whether or not Stryker should mutate your files in place. Note: mutating your files in place is generally not needed for mutation testing, unless you have a dependency in your project that is really dependent on the file locations (like "app-root-path" for example).
When true, Stryker will override your files, but it will keep a copy of the originals in the temp directory (using tempDirName) and it will place the originals back after it is done. Also with true the ignorePatterns has no effect any more.
When false (default) Stryker will work in the copy of your code inside the temp directory.
[DEPRECATED please use "concurrency" instead]. Specifies the maximum number of concurrent test runners to spawn. Mutation testing is time consuming. By default, Stryker tries to make the most of your CPU's, by spawning as many test runners as you have CPU cores (Number.MAX_SAFE_INTEGER).
Restart each test runner worker process after n runs. Not recommended unless you are experiencing memory leaks that you are unable to resolve. Configuring 0 here means infinite reuse.
With mutate you configure the subset of files or just one specific file to be mutated. These should be your production code files, and definitely not your test files.
(Whereas with ignorePatterns you prevent non-relevant files from being copied to the sandbox directory in the first place)
The default will try to guess your production code files based on sane defaults. It reads like this:
- Include all js-like files inside the
srcorlibdir - Except files inside
__tests__directories and file names ending withtestorspec. If the defaults are not sufficient for you, for example in a angular project you might want to exclude not only the*.spec.tsfiles but other files too, just like the default already does. It is possible to specify exactly which code blocks to mutate by means of a mutation range. This can be done postfixing your file with:startLine[:startColumn]-endLine[:endColumn]. Example: src/index.js:1:3-1:5
[
"{src,lib}/**/!(*.+(s|S)pec|*.+(t|T)est).+(cjs|mjs|js|ts|mts|cts|jsx|tsx|html|vue|svelte)",
"!{src,lib}/**/__tests__/**/*.+(cjs|mjs|js|ts|mts|cts|jsx|tsx|html|vue|svelte)"
]
2 nested properties
Override the default babel plugins Stryker uses to parse your JavaScript files. The default list of plugins is extensive and normally doesn't need overriding. Stryker also loads your babel plugins by default (if you have them). If Stryker's default babel plugins conflicts with your plugins, try to override this list with an empty array.
[]
The package manager Stryker can use to install missing dependencies.
With 'plugins', you can add additional Node modules for Stryker to load (or require). By default, all node_modules starting with @stryker-mutator/* will be loaded, so you would normally not need to specify this option. These modules should be installed right next to stryker. For a current list of plugins, you can consult 'npm' or 'stryker-mutator.io.'
[
"@stryker-mutator/*"
]
A list of additional plugins you want Stryker to load (require) without overwriting the (default) plugins.
[]
With reporters, you can set the reporters for stryker to use.
[
"clear-text",
"progress",
"html"
]
1 nested properties
The fileName of the html report.
1 nested properties
The relative filename for the json report.
Set to 'true' to disable type checking, or 'false' to enable it. For more control, configure a pattern that matches the files of which type checking has to be disabled. This is needed because Stryker will create (typescript) type errors when inserting the mutants in your code. Stryker disables type checking by inserting // @ts-nocheck atop those files and removing other // @ts-xxx directives (so they won't interfere with @ts-nocheck). The default setting allows these directives to be stripped from all JavaScript and friend files in lib, src and test directories.
The 'symlinkNodeModules' value indicates whether Stryker should create a symbolic link to your current node_modules directory in the sandbox directories. This makes running your tests by Stryker behave more like your would run the tests yourself in your project directory. Only disable this setting if you really know what you are doing.
Choose a different temp dir that Stryker uses for mutation testing. This directory will contain copies of your source code during a mutation test run. It will be created if it not exists and is entirely deleted after a successful run, so change this with caution.
Choose whether or not to clean the temp dir (which is ".stryker-tmp" inside the current working directory by default).
- false: Never delete the temp dir;
- true: Delete the tmp dir after a successful run;
- "always": Always delete the temp dir, regardless of whether the run was successful.
With 'testRunner' you specify the test runner that Stryker uses to run your tests. The default value is command. The command runner runs a configurable bash/cmd command and bases the result on the exit code of that program (0 for success, otherwise failed). You can configure this command via the config file using the 'commandRunner: { command: 'npm run mocha' }'. It uses 'npm test' as the command by default.
Configure arguments to be passed as exec arguments to the test runner child process. For example, running Stryker with --timeoutMS 9999999 --concurrency 1 --testRunnerNodeArgs --inspect-brk will allow you to debug the test runner child process. See execArgv of child_process.fork
[]
3 nested properties
Configure the allowed timeout deviation relative to the time of a normal test run. Tweak this if you notice that mutants are prone to creating slower code, but not infinite loops (for that, use timeoutMS)
Configure an absolute timeout deviation. Tweak this if you run Stryker on a busy machine and you need to wait longer to make sure that the code indeed entered an infinite loop.
Configure an absolute timeout for the initial test run. (It can take a while, therefore we use minutes as time unit.)
Configure the (root) tsconfig file for typescript projects. This will allow Stryker to rewrite the extends and references settings in this and related tsconfig files in your sandbox. Defaults to tsconfig.json. This setting is also used when you enable the `@stryker-mutator/typescript-checker plugin
Enable or disable certain warnings
Disables the default of bailing after first failing test. When true runs all tests covering a mutant. Useful when the subject under test is not completely isolated by mocks and you want to know which tests are killing the mutants. This will impact performance.
Allows stryker to exit without any errors in cases where no tests are found
Specify which ignore-plugins to use. With an ignore-plugin you can ignore mutants inside common code patterns that you don't want to test for some reason. For example, you can use this to ignore all console.debug() statements from being mutated.
[]
With testFiles you can limit which test files are executed during mutation testing. When specified, only tests from these files will be run, allowing you to verify that a module's dedicated unit tests can kill all its mutants independently. Glob patterns are supported.
[]
Definitions
The command to test each mutant. For example "npm run mocha". Defaults to "npm test".
Indicates whether or not to use color coding in output.
Enable emojis in your clear text report (experimental).
Indicates whether or not to log which tests were executed for a given mutant.
Indicates the maximum amount of test to log when logTests is enabled
Indicates whether or not to log all tests.
Indicates whether or not to log all mutants.
Indicates whether or not to log score table.
Indicates whether rows with 100% mutation score are hidden in the score table.
Indicates which project to use if the "dashboard" reporter is enabled.
Indicates which version to use if the "dashboard" reporter is enabled.
Indicates which module to use if the "dashboard" reporter is enabled.
Indicates the base url of the stryker dashboard.
The base dir to write the events to
The fileName of the html report.
The relative filename for the json report.
Override the default babel plugins Stryker uses to parse your JavaScript files. The default list of plugins is extensive and normally doesn't need overriding. Stryker also loads your babel plugins by default (if you have them). If Stryker's default babel plugins conflicts with your plugins, try to override this list with an empty array.
[]
decide whether or not to log warnings when additional stryker options are configured
decide whether or not to log warnings when a preprocessor error occurs. For example, when the disabling of type errors fails.
decide whether or not to log warnings when a configuration options are unserializable. For example, using a /regex/ or function in your configuration options.
decide whether or not to log warnings when Stryker detects a slow part of mutation that can be sped up by changing some configuration. For example using --ignoreStatic.