Skip to content

Commit

Permalink
feat(api): Document StrykerOptions in JSON schema
Browse files Browse the repository at this point in the history
Document the `StrykerOptions` using a JSON schema. The TypeScript files representing the `StrykerOptions` are now generated from this file.

This clears a path to validate StrykerOptions using JSON Schema in the future, as wel as helps with authoring a Stryker config file.
  • Loading branch information
Bartosz Leoniak authored and nicojs committed Jan 25, 2020
1 parent aa21dc0 commit 4bdb7a1
Show file tree
Hide file tree
Showing 17 changed files with 352 additions and 239 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@ jobs:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: npm install
- name: Run linting
run: npm run lint
- name: Build packages
run: npm run build
- name: Run unit tests and integration tests
run: npm test
- name: Build & lint & test
run: npm run all

e2e:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ packages/*/test/**/*.d.ts
package-lock.json
.DS_Store
tsconfig.*.tsbuildinfo
src-generated
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"install-local": "~2.0.0",
"jasmine": "^3.1.0",
"jasmine-core": "^3.1.0",
"json-schema-to-typescript": "~7.1.0",
"lerna": "^3.10.7",
"link-parent-bin": "~1.0.0",
"mocha": "^6.1.2",
Expand All @@ -41,15 +42,18 @@
"sinon": "^8.0.0",
"sinon-chai": "3.4.0",
"source-map-support": "^0.5.6",
"ts-json-schema-generator": "^0.58.1",
"typescript": "~3.7.2"
},
"scripts": {
"all": "npm run clean && npm run lint && npm run build && npm run test && npm run e2e",
"all": "npm run clean && npm run build && npm run lint && npm run test",
"postinstall": "lerna bootstrap --no-ci && link-parent-bin",
"lint": "eslint . --ext .ts,.tsx",
"lint:log": "eslint . --ext .ts,.tsx -f compact -o lint.log",
"lint:fix": "eslint . --ext .ts,.tsx --fix",
"clean": "rimraf \"packages/api/!(stryker.conf)+(.d.ts|.js|.map)\" \"packages/*/+(test|src)/**/*+(.d.ts|.js|.map)\" \"packages/*/{.nyc_output,reports,coverage,*.tsbuildinfo}\"",
"clean": "rimraf \"packages/api/!(stryker.conf)+(.d.ts|.js|.map)\" \"packages/*/+(test|src)/**/*+(.d.ts|.js|.map)\" \"packages/*/{.nyc_output,reports,coverage,src-generated,*.tsbuildinfo}\"",
"generate": "lerna run generate",
"prebuild": "npm run generate",
"build": "tsc -b && lerna run build",
"test": "npm run mocha",
"mocha": "lerna run test --stream --concurrency 4",
Expand Down
2 changes: 1 addition & 1 deletion packages/api/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
!*.js
src/**/*.map
src/**/*.ts
!src/**/*.d.ts
!{src,src-generated}/**/*.d.ts
!readme.md
!LICENSE
!CHANGELOG.md
7 changes: 2 additions & 5 deletions packages/api/core.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
export { default as StrykerOptions } from './src/core/StrykerOptions';
export { default as File } from './src/core/File';
export { default as Position } from './src/core/Position';
export { default as Location } from './src/core/Location';
export { default as Range } from './src/core/Range';
export { default as MutatorDescriptor } from './src/core/MutatorDescriptor';
export { default as MutationScoreThresholds } from './src/core/MutationScoreThresholds';
export { default as LogLevel } from './src/core/LogLevel';
export * from './src/core/DashboardOptions';
export * from './src-generated/core';
export * from './src/core/ReportTypes';
1 change: 1 addition & 0 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"url": "https://github.com/stryker-mutator/stryker"
},
"scripts": {
"generate": "node tasks/generate-json-schema-to-ts.js",
"stryker": "node ../core/bin/stryker run",
"test": "nyc --exclude-after-remap=false --exclude 'testResources/**/*.js' --check-coverage --reporter=html --report-dir=reports/coverage --lines 85 --functions 85 --branches 85 npm run mocha",
"mocha": "mocha \"test/helpers/**/*.js\" \"test/unit/**/*.js\" && mocha --timeout 60000 \"test/helpers/**/*.js\" \"test/integration/**/*.js\""
Expand Down
260 changes: 260 additions & 0 deletions packages/api/schema/stryker-core.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,260 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "StrykerOptions",
"description": "JSON schema for the Stryker Mutator configuration file",
"type": "object",
"definitions": {
"logLevel": {
"title": "LogLevel",
"type": "string",
"enum": [
"off",
"fatal",
"error",
"warn",
"info",
"debug",
"trace"
],
"tsEnumNames": [
"Off",
"Fatal",
"Error",
"Warning",
"Information",
"Debug",
"Trace"
]
},
"reportType": {
"title": "ReportType",
"type": "string",
"enum": [
"full",
"mutationScore"
],
"tsEnumNames": [
"Full",
"MutationScore"
]
},
"dashboardOptions": {
"title": "DashboardOptions",
"additionalProperties": false,
"type": "object",
"properties": {
"project": {
"description": "Indicates which project to use if the \"dashboard\" reporter is enabled.",
"type": "string"
},
"version": {
"description": "Indicates which version to use if the \"dashboard\" reporter is enabled.",
"type": "string"
},
"module": {
"description": "Indicates which module to use if the \"dashboard\" reporter is enabled.",
"type": "string"
},
"baseUrl": {
"description": "Indicates the base url of the stryker dashboard.",
"type": "string",
"default": "https://dashboard.stryker-mutator.io/api/reports"
},
"reportType": {
"description": "Indicates wether to send a full report (inc. source code and mutant results) or only the mutation score.",
"$ref": "#/definitions/reportType",
"default": "mutationScore"
}
}
},
"mutationScoreThresholds": {
"title": "MutationScoreThresholds",
"additionalProperties": false,
"type": "object",
"properties": {
"high": {
"type": "number",
"default": 80
},
"low": {
"type": "number",
"default": 60
},
"break": {
"type": [
"number",
"null"
],
"default": null
}
}
},
"mutatorDescriptor": {
"description": "Thresholds for mutation score. Disable a score with `null`.\n\nmutation score < break => exit build process with exit code 1. By default this is disabled (null).\nmutation score < low => score is in danger zone, display in red.\nmutation score < high >= low => score is in warning zone, display in yellow.\nmutation score >= high => score is in awesome zone, display in green.",
"type": "object",
"additionalProperties": false,
"properties": {
"name": {
"type": "string",
"default": "javascript"
},
"plugins": {
"anyOf": [
{
"type": "array",
"items": {
"type": "string"
}
},
{
"type": "null"
}
],
"default": null
},
"excludedMutations": {
"type": "array",
"items": {
"type": "string"
},
"default": []
}
},
"required": [
"name"
]
}
},
"properties": {
"allowConsoleColors": {
"description": "The 'allowConsoleColors' value indicates whether Stryker should use colors in console.",
"type": "boolean",
"default": true
},
"coverageAnalysis": {
"description": "Indicates which coverage analysis strategy to use. During mutation testing, stryker will try to only run the tests that cover a particular line of code.\n\n'perTest': Analyse coverage per test.\n'all': Analyse the coverage for the entire test suite.\n'off' (default): Don't use coverage analysis",
"type": "string",
"enum": [
"off",
"all",
"perTest"
],
"default": "off"
},
"dashboard": {
"description": "The options for the dashboard reporter",
"$ref": "#/definitions/dashboardOptions",
"default": {}
},
"fileLogLevel": {
"description": "Set the log level that Stryker uses to write to the \"stryker.log\" file",
"$ref": "#/definitions/logLevel",
"default": "off"
},
"files": {
"description": "With `files` you can choose which files should be included in your test runner sandbox.\nThis is normally not needed as it defaults to all files not ignored by git.\nTry it out yourself with this command: `git ls-files --others --exclude-standard --cached --exclude .stryker-tmp`.\n\nIf you do need to override `files` (for example: when your project does not live in a git repository),\nyou can override the files here.\n\nWhen using the command line, the list can only contain a comma separated list of globbing expressions.\nWhen using the config file you can provide an array with `string`s",
"type": "array",
"items": {
"type": "string"
}
},
"logLevel": {
"description": "Set the log level that Stryker uses to write to the console.",
"$ref": "#/definitions/logLevel",
"default": "info"
},
"maxConcurrentTestRunners": {
"description": "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`).",
"type": "number",
"default": 9007199254740991
},
"mutate": {
"description": "With mutate you configure the subset of files to use for mutation testing. Generally speaking, these should be your own source files.",
"type": "array",
"items": {
"type": "string"
},
"default": [
"{src,lib}/**/*.js?(x)",
"!{src,lib}/**/__tests__/**/*.js?(x)",
"!{src,lib}/**/?(*.)+(spec|test).js?(x)",
"!{src,lib}/**/*+(Spec|Test).js?(x)"
]
},
"mutator": {
"description": "With mutator you configure which mutator plugin you want to use, and optionally, which mutation types to exclude from the test run.",
"oneOf": [
{
"type": "string"
},
{
"$ref": "#/definitions/mutatorDescriptor"
}
],
"default": "javascript"
},
"plugins": {
"description": "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.'",
"type": "array",
"items": {
"type": "string"
},
"default": [
"@stryker-mutator/*"
]
},
"reporters": {
"description": "With reporters, you can set the reporters for stryker to use.",
"type": "array",
"items": {
"type": "string"
},
"default": [
"clear-text",
"progress"
]
},
"symlinkNodeModules": {
"description": "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.",
"type": "boolean",
"default": true
},
"tempDirName": {
"description": "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.",
"type": "string",
"default": ".stryker-tmp"
},
"testFramework": {
"description": "Configure which test framework you are using. This option is not mandatory, as Stryker is test framework agnostic (it doesn't care what framework you use), However, it is required when coverageAnalysis is set to 'perTest', because Stryker needs to hook into the test framework in order to measure code coverage results per test and filter tests to run.",
"type": "string"
},
"testRunner": {
"description": "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.",
"type": "string",
"default": "command"
},
"thresholds": {
"description": "Specify the thresholds for mutation score.",
"$ref": "#/definitions/mutationScoreThresholds",
"default": {}
},
"timeoutFactor": {
"description": "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`)",
"type": "number",
"default": 1.5
},
"timeoutMS": {
"description": "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.",
"type": "number",
"default": 5000
},
"transpilers": {
"description": "Configure which transpiler plugins should transpile the code before it's executed. This is an array where the transpilers are called in the other of the array. This defaults to an empty array meaning no transpilation will be done.",
"type": "array",
"items": {
"type": "string"
},
"default": []
}
}
}
3 changes: 1 addition & 2 deletions packages/api/src/config/Config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { LogLevel, MutationScoreThresholds, MutatorDescriptor, StrykerOptions, DashboardOptions } from '../../core';
import { ReportType } from '../core/DashboardOptions';
import { LogLevel, MutationScoreThresholds, MutatorDescriptor, StrykerOptions, DashboardOptions, ReportType } from '../../core';

import defaultTempDirName from './DefaultTempDirName';

Expand Down
32 changes: 0 additions & 32 deletions packages/api/src/core/DashboardOptions.ts

This file was deleted.

11 changes: 0 additions & 11 deletions packages/api/src/core/LogLevel.ts

This file was deleted.

Loading

0 comments on commit 4bdb7a1

Please sign in to comment.