Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add suffix 'config' to config filename #4308

Merged
merged 7 commits into from Oct 1, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 20 additions & 16 deletions docs/config-file.md
Expand Up @@ -3,15 +3,15 @@ title: Config file
custom_edit_url: https://github.com/stryker-mutator/stryker-js/edit/master/docs/config-file.md
---

Although a config file is not mandatory, it is recommended. You can define your Stryker configuration in either a `.js` or `.json` file. If you use a `.js` file, it should contain a NodeJS module that exports the configuration object. Autocompletion is supported using JSON schema or using [`@type` JS docs](https://jsdoc.app/).
Although a config file is not mandatory, it is recommended. You can define your Stryker configuration in either a JavaScript or JSON file. If you use a JavaScript file, it should export the configuration object. Autocompletion is supported using JSON schema or using [`@type` JS docs](https://jsdoc.app/).

## Configuration options

See [configuration](./configuration.md) for a list of available options.

## Setup

With a `stryker.conf.json`:
With a `stryker.config.json`:

```json
{
Expand All @@ -20,7 +20,7 @@ With a `stryker.conf.json`:
}
```

Or as `stryker.conf.js`:
Or as `stryker.config.js`:

```js
// @ts-check
Expand Down Expand Up @@ -48,36 +48,40 @@ You can use your editor's autocompletion to help you author your configuration f
![config file autocompletion](./images/config-file-autocompletion.gif)

## Usage
<details>

nicojs marked this conversation as resolved.
Show resolved Hide resolved
<summary>History</summary>

| Version | Changes |
| ------- | -------------------------------------------------- |
| 7.1 | Add `.config.{json,js,mjs,cjs}` as default suffix. |

</details>
By default, Stryker will look for a config file in the current working directory. The default config file names are:
- `stryker.conf.json`
- `stryker.conf.js`
- `stryker.conf.cjs`
- `stryker.conf.mjs`
- `.stryker.conf.json`
- `.stryker.conf.js`
- `.stryker.conf.cjs`
- `.stryker.conf.mjs`
- `stryker.conf.{json,js,mjs,cjs}`
- `.stryker.conf.{json,js,mjs,cjs}`
- `stryker.config.{json,js,mjs,cjs}`
- `.stryker.config.{json,js,mjs,cjs}`

You can also use a different configuration file with a second argument to the `run` command.
```shell
# Use "stryker.conf.[js,json,mjs]" or ".stryker.conf.[js,json,mjs]" in the cwd
# Use default config file names in the current working directory
npx stryker run
# Use "alternative-stryker.conf.json"
npx stryker run alternative-stryker.conf.json
# Use "alternative-stryker.config.json"
npx stryker run alternative-stryker.config.json
```

## Glob patterns

Some options allow for a glob pattern to be defined. These glob patterns are defined relative to the cwd.
Some options allow for a glob pattern to be defined. These glob patterns are defined relative to the cwd.

For example, using `"mutate": [ "src/components/**/*.component.js" ]` will make sure only files ending with ".component.js" in the "src/components" directory are mutated.

We suggest using [https://globster.xyz/](https://globster.xyz/) when auditing more complex glob expressions; it can help you get them just right.

## Example

The following is an example `stryker.conf.json` file. It specifies running mocha tests with the mocha test runner.
The following is an example `stryker.config.json` file. It specifies running mocha tests with the mocha test runner.

```json
{
Expand Down
4 changes: 2 additions & 2 deletions docs/cucumber-runner.md
Expand Up @@ -29,7 +29,7 @@ You can find the [`peerDependencies` in @stryker-mutator/cucumber-runner's packa

## Configuring

You can configure the cucumber test runner in the `stryker.conf.json` (or `stryker.conf.js`) file.
You can configure the cucumber test runner in the `stryker.config.json` (or `stryker.config.js`) file.

```json
{
Expand Down Expand Up @@ -68,4 +68,4 @@ The `@stryker-mutator/cucumber-runner` plugin supports coverage analysis, test f

## Non-standard feature file locations

As of `@stryker-mutator/cucumber-runner` version 6.1, non-standard feature file locations are supported out of the box.
As of `@stryker-mutator/cucumber-runner` version 6.1, non-standard feature file locations are supported out of the box.
2 changes: 1 addition & 1 deletion docs/getting-started.md
Expand Up @@ -48,7 +48,7 @@ If you're asked to install Stryker, choose **Yes**. Follow the questionnaire.

Please let us know if your option is missing here [by opening an issue](https://github.com/stryker-mutator/stryker-js/issues/new).

After the init is done, inspect the `stryker.conf.js` file.
After the init is done, inspect the `stryker.config.mjs` file.

For more information on what these options mean, take a look at [the Configuration docs page](./configuration.md)

Expand Down
4 changes: 2 additions & 2 deletions docs/guides/angular.md
Expand Up @@ -23,7 +23,7 @@ Recommended other packages:

### Configuration

The `stryker init` command also creates a `stryker.conf.json` or `stryker.conf.js` configuration in your repository
The `stryker init` command also creates a `stryker.config.json` or `stryker.config.mjs` configuration in your repository
like the one below which is a good starting point for Angular projects.
You may have to change some paths or config settings like the selected browsers.
We highly suggest using a headless browser when testing using Stryker.
Expand Down Expand Up @@ -52,7 +52,7 @@ Consider adding the Stryker TypeScript checker to increase mutation testing perf

1. Install `@stryker-mutator/typescript-checker` as a development dependency:
`npm install --save-dev @stryker-mutator/typescript-checker`
1. Configure the TypeScript checker in `stryker.conf.json`:
1. Configure the TypeScript checker in `stryker.config.json`:
```json
{
"checkers": ["typescript"],
Expand Down
2 changes: 1 addition & 1 deletion docs/guides/nodejs.md
Expand Up @@ -22,7 +22,7 @@ If you manage your code's compilation through a `tsconfig.json` file, this guide

## Configuration

Please follow this configuration guide. Place the configuration examples inside your `stryker.conf.json` file.
Please follow this configuration guide. Place the configuration examples inside your `stryker.config.json` file.

### Build command

Expand Down
2 changes: 1 addition & 1 deletion docs/guides/react.md
Expand Up @@ -15,7 +15,7 @@ Recommended other packages:

### Configuration

After installing the recommended packages, create the `stryker.conf.json` file in your repository.
After installing the recommended packages, create the `stryker.config.json` file in your repository.
The configuration below contains a good starting point for React projects.
You may have to change some paths like the [mutate](../configuration.md#mutate-string) array.

Expand Down
6 changes: 3 additions & 3 deletions docs/guides/vuejs.md
Expand Up @@ -17,8 +17,8 @@ Follow this guide if you're using the if you're using the [unit-jest](https://cl

1. Install the `@stryker-mutator/jest-runner` plugin: `npm i -D @stryker-mutator/jest-runner` or `yarn add --dev @stryker-mutator/jest-runner`.
1. Install `crossenv` plugin(if you haven't already): `npm i -D cross-env` or `yarn add -D cross-env`.
1. Create a "stryker.conf.json" file that looks like this:
```
1. Create a `stryker.config.json` file that looks like this:
```json
{
"$schema": "./node_modules/@stryker-mutator/core/schema/stryker-schema.json",
"mutator": {
Expand Down Expand Up @@ -110,7 +110,7 @@ This needs to work first before progressing to the next step. You might need to
Once mocha runs successfully on the webpack output, you're ready to install and run Stryker:

1. Install the `@stryker-mutator/mocha-runner` plugin: `npm i -D @stryker-mutator/mocha-runner` or `yarn add --dev @stryker-mutator/mocha-runner`.
2. Create your `stryker.conf.json` file:
2. Create your `stryker.config.json` file:
```json
{
"$schema": "./node_modules/@stryker-mutator/core/schema/stryker-schema.json",
Expand Down
2 changes: 1 addition & 1 deletion docs/incremental.md
Expand Up @@ -17,7 +17,7 @@ You enable incremental mode with the `--incremental` flag:
npx stryker run --incremental
```

_Setting `"incremental": true` in your stryker.conf.json file is also supported_
_Setting `"incremental": true` in your stryker.config.json file is also supported_

StrykerJS stores the previous result in a "reports/stryker-incremental.json" file (determined by the [--incrementalFile](./configuration.md#incrementalfile-string) option). The next time StrykerJS runs, it will read this JSON file and try to reuse as much of it as possible.

Expand Down
2 changes: 1 addition & 1 deletion docs/jasmine-runner.md
Expand Up @@ -24,7 +24,7 @@ As such, you should make sure you have the correct versions of its dependencies

## Example

You can configure the jasmine test runner in the `stryker.conf.js` (or `stryker.conf.json`) file.
You can configure the jasmine test runner in the `stryker.config.json` (or `stryker.config.js`) file.

```json
{
Expand Down
2 changes: 1 addition & 1 deletion docs/jest-runner.md
Expand Up @@ -77,7 +77,7 @@ Whether to run jest with the `--findRelatedTests` flag. When `true`, Jest will o

## ECMAScript Modules

Jest ships with [support for ECMAScript Modules (ESM)](https://jestjs.io/docs/ecmascript-modules). In order to provide the `--experimental-vm-modules` node option, you will need to add this to your stryker.conf.json file:
Jest ships with [support for ECMAScript Modules (ESM)](https://jestjs.io/docs/ecmascript-modules). In order to provide the `--experimental-vm-modules` node option, you will need to add this to your stryker.config.json file:

```json
{
Expand Down
6 changes: 3 additions & 3 deletions docs/karma-runner.md
Expand Up @@ -25,7 +25,7 @@ uses *your very own karma* version. It can also work with `@angular/cli`, see [C

## Configuring

You can configure the `@stryker-mutator/karma-runner` using the `stryker.conf.js` (or `stryker.conf.json`) config file.
You can configure the `@stryker-mutator/karma-runner` using the `stryker.config.json` (or `stryker.config.js`) config file.

```json
{
Expand Down Expand Up @@ -54,7 +54,7 @@ Specify which kind of project you're using. This determines which command is use
Default: `undefined`

Specify a ['karma.conf.js' file](http://karma-runner.github.io/2.0/config/configuration-file.html) to be loaded.
Options specified directly in your stryker.conf.js file using `karma.config` will overrule options in your karma.conf.js file.
Options specified directly in your stryker.config.js file using `karma.config` will overrule options in your karma.conf.js file.

### `karma.config` [`object`]

Expand Down Expand Up @@ -107,7 +107,7 @@ Please follow the [angular guide](./guides/angular.md).

As Stryker runs karma in its own process, its logging output will be consumed by Stryker.

To see all logging from karma, set the log level to `trace` in `stryker.conf.json`.
To see all logging from karma, set the log level to `trace` in `stryker.config.json`.

```json
{
Expand Down
4 changes: 2 additions & 2 deletions docs/mocha-runner.md
Expand Up @@ -23,7 +23,7 @@ As such, you should make sure you have the correct versions of its dependencies

## Configuring

You can configure the mocha test runner in the `stryker.conf.json` (or `stryker.conf.js`) file.
You can configure the mocha test runner in the `stryker.config.json` (or `stryker.config.js`) file.

```json
{
Expand Down Expand Up @@ -76,7 +76,7 @@ See https://mochajs.org/#-package-path.

Default: `"test/mocha.opts"`

Specify a ['mocha.opts' file](https://mochajs.org/#mochaopts) to be loaded. Options specified directly in your stryker.conf.js file will overrule options from the 'mocha.opts' file. Disable loading of an additional mocha.opts file with `false`.
Specify a ['mocha.opts' file](https://mochajs.org/#mochaopts) to be loaded. Options specified directly in your stryker.config.js file will overrule options from the 'mocha.opts' file. Disable loading of an additional mocha.opts file with `false`.

The only supported mocha options are used: `--ui`, `--require`, `--async-only`, `--timeout`, `--grep` (or their short form counterparts). Others are ignored by the @stryker-mutator/mocha-runner.

Expand Down
2 changes: 1 addition & 1 deletion docs/tap-runner.md
Expand Up @@ -29,7 +29,7 @@ npm i --save-dev @stryker-mutator/tap-runner

## Configuring

You can configure the tap test runner in the `stryker.conf.json` (or `stryker.conf.js`) file.
You can configure the tap test runner in the `stryker.config.json` (or `stryker.config.js`) file.

```json
{
Expand Down
6 changes: 3 additions & 3 deletions docs/troubleshooting.md
Expand Up @@ -151,7 +151,7 @@ If that happens, add `"skipLibCheck": true` to your `tsconfig` file.

When running Stryker mutations, you may get an error similar to the following one:
```
16:58:25 (17452) INFO ConfigReader Using stryker.conf.json
16:58:25 (17452) INFO ConfigReader Using stryker.config.json
16:58:26 (17452) INFO InputFileResolver Found 2 of 2557 file(s) to be mutated.
16:58:27 (17452) INFO Instrumenter Instrumented 2 source file(s) with 118 mutant(s)
16:58:28 (17452) INFO ConcurrencyTokenProvider Creating 6 checker process(es) and 5 test runner process(es).
Expand All @@ -170,7 +170,7 @@ FATAL ERROR: Committing semi space failed. Allocation failed - JavaScript heap o

**Solution**:

To solve that, you need to limit the number of workers. In the example about, 11 workers were created in total (6 checker processes and 5 test runner processes). In order to solve this issue, you may try to set `--concurrency` setting in your stryker config. In case of the sample issue, adding `"concurrency": 4` to `stryker.conf.json` solved the problem.
To solve that, you need to limit the number of workers. In the example about, 11 workers were created in total (6 checker processes and 5 test runner processes). In order to solve this issue, you may try to set `--concurrency` setting in your stryker config. In case of the sample issue, adding `"concurrency": 4` to `stryker.config.json` solved the problem.

### Mutating fails: Cannot use the decorators and decorators-legacy plugin together

Expand Down Expand Up @@ -253,7 +253,7 @@ It has to choose to either let this mutant go unchecked or throw an error and st

**Solution**

The solution is to include all files that are mutated in your project's tsconfig.json file. If you have multiple tsconfig.json files, you probably need to change the one you've configured in your stryker.conf.json. For example (for an angular project)
The solution is to include all files that are mutated in your project's tsconfig.json file. If you have multiple tsconfig.json files, you probably need to change the one you've configured in your stryker.config.json. For example (for an angular project)

```diff
{
Expand Down
2 changes: 1 addition & 1 deletion docs/typescript-checker.md
Expand Up @@ -25,7 +25,7 @@ npm install --save-dev @stryker-mutator/typescript-checker

## Configuring

You can configure the typescript checker in the `stryker.conf.js` (or `stryker.conf.json`) file.
You can configure the typescript checker in the `stryker.config.json` (or `stryker.config.js`) file.

```json
{
Expand Down
4 changes: 2 additions & 2 deletions docs/usage.md
Expand Up @@ -2,13 +2,13 @@
title: Usage
custom_edit_url: https://github.com/stryker-mutator/stryker-js/edit/master/docs/usage.md
---

```sh
npx stryker <command> [options] [configFile]
```

The main `command` for Stryker is `run`, which kicks off mutation testing.

By default, Stryker will look for a `stryker.conf.js` or `stryker.conf.json` file in the current working directory (if it exists). This can be overridden by specifying a different file as the last argument.
By default, Stryker will look for a `stryker.config.json`, `stryker.config.js` or [other variations](./config-file.md) files in the current working directory (if it exists). This can be overridden by specifying a different file as the last argument.

Before your first run, we recommend you try the `init` command, which helps you to set up this config file and install any missing packages needed for your specific configuration. We recommend you verify the contents of the configuration file after this initialization, to make sure everything is setup correctly. Of course, you can still make changes to it, before you run Stryker for the first time.
2 changes: 1 addition & 1 deletion docs/vitest-runner.md
Expand Up @@ -21,7 +21,7 @@ This plugin does not come packaged with it's own version of `vitest`, instead in

## Configuring

You can configure the `@stryker-mutator/vitest-runner` using the `stryker.conf.js` (or `stryker.conf.json`) config file.
You can configure the `@stryker-mutator/vitest-runner` using the `stryker.config.json` (or `stryker.config.js`) config file.

```json
{
Expand Down
29 changes: 27 additions & 2 deletions packages/core/src/config/config-file-formats.ts
@@ -1,2 +1,27 @@
export const SUPPORTED_CONFIG_FILE_BASE_NAMES = Object.freeze(['stryker.conf', '.stryker.conf'] as const);
export const SUPPORTED_CONFIG_FILE_EXTENSIONS = Object.freeze(['.json', '.js', '.mjs', '.cjs'] as const);
const combine = (prefixes: string[], suffixes: string[], extensions: string[]): string[] => {
const fileNames: string[] = [];
for (const prefix of prefixes) {
for (const suffix of suffixes) {
for (const extension of extensions) {
fileNames.push(`${prefix}stryker${suffix}.${extension}`);
}
}
}
return fileNames;
};

export const SUPPORTED_CONFIG_FILE_NAMES = Object.freeze(
combine(
// Prefixes.
['', '.'],
// Suffixes.
['.conf', '.config'],
// Extensions.
['json', 'js', 'mjs', 'cjs']
)
);

export const DEFAULT_CONFIG_FILE_NAMES = Object.freeze({
JSON: 'stryker.config.json',
JAVASCRIPT: 'stryker.config.mjs',
} as const);
10 changes: 4 additions & 6 deletions packages/core/src/config/config-reader.ts
Expand Up @@ -12,7 +12,7 @@ import { ConfigError } from '../errors.js';
import { fileUtils } from '../utils/file-utils.js';

import { OptionsValidator } from './options-validator.js';
import { SUPPORTED_CONFIG_FILE_BASE_NAMES, SUPPORTED_CONFIG_FILE_EXTENSIONS } from './config-file-formats.js';
import { SUPPORTED_CONFIG_FILE_NAMES } from './config-file-formats.js';

export const CONFIG_SYNTAX_HELP = `
Example of how a config file should look:
Expand Down Expand Up @@ -73,11 +73,9 @@ export class ConfigReader {
throw new ConfigReaderError('File does not exist!', configFileName);
}
}
for (const file of SUPPORTED_CONFIG_FILE_BASE_NAMES) {
for (const ext of SUPPORTED_CONFIG_FILE_EXTENSIONS) {
if (await fileUtils.exists(`${file}${ext}`)) {
return `${file}${ext}`;
}
for (const fileName of SUPPORTED_CONFIG_FILE_NAMES) {
if (await fileUtils.exists(fileName)) {
return fileName;
}
}
return undefined;
Expand Down