stryker-markdown-reporter 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Dmitriy Zverev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,84 @@
1
+ # stryker-markdown-reporter
2
+
3
+ A [StrykerJS](https://stryker-mutator.io/) reporter plugin that writes mutation
4
+ testing results as a Markdown table.
5
+
6
+ The report is plain Markdown, so it can be committed, attached to a pull request
7
+ comment or appended to a GitHub Actions job summary.
8
+
9
+ ## Example
10
+
11
+ | File | score | covered | killed | timeout | survived | no cov | ignored | errors |
12
+ | :------------------ | --------: | --------: | -----: | ------: | -------: | -----: | ------: | -----: |
13
+ | **All files** | 🟡 70.00% | 🟢 82.35% | 13 | 1 | 3 | 3 | 0 | 1 |
14
+ | src/math.ts | 🟢 90.00% | 🟢 90.00% | 8 | 1 | 1 | 0 | 0 | 0 |
15
+ | src/utils/format.ts | 🔴 50.00% | 🟡 71.43% | 5 | 0 | 2 | 3 | 0 | 1 |
16
+
17
+ Thresholds: 🟢 ≥ 80, 🟡 ≥ 60, 🔴 < 60, break < 50
18
+
19
+ ## Requirements
20
+
21
+ - Node.js 22 or later
22
+ - StrykerJS 10 (`@stryker-mutator/core`)
23
+
24
+ ## Installation
25
+
26
+ ```sh
27
+ npm install --save-dev stryker-markdown-reporter
28
+ ```
29
+
30
+ ## Usage
31
+
32
+ Add the plugin and the `markdown` reporter to your Stryker configuration, for
33
+ example `stryker.config.json`:
34
+
35
+ ```json
36
+ {
37
+ "appendPlugins": ["stryker-markdown-reporter"],
38
+ "reporters": ["clear-text", "progress", "markdown"]
39
+ }
40
+ ```
41
+
42
+ After a run, the report is written to `reports/mutation/mutation.md`.
43
+
44
+ ## Options
45
+
46
+ Options are set in the `markdownReporter` section of the Stryker configuration:
47
+
48
+ ```json
49
+ {
50
+ "markdownReporter": {
51
+ "fileName": "reports/mutation/mutation.md",
52
+ "splitErrors": false
53
+ }
54
+ }
55
+ ```
56
+
57
+ | Option | Type | Default | Description |
58
+ | ------------- | --------- | ------------------------------ | ---------------------------------------------------------------------------- |
59
+ | `fileName` | `string` | `reports/mutation/mutation.md` | Path of the report file, relative to the working directory. |
60
+ | `splitErrors` | `boolean` | `false` | Show runtime and compile errors in separate columns instead of a single one. |
61
+
62
+ ## Report
63
+
64
+ The first row contains the totals for the whole project, followed by one row per
65
+ mutated file.
66
+
67
+ | Column | Description |
68
+ | ---------- | --------------------------------------------------------------------------- |
69
+ | `score` | Mutation score: the share of detected mutants among all valid mutants. |
70
+ | `covered` | Mutation score based on covered code: mutants without coverage are ignored. |
71
+ | `killed` | Mutants detected by a failing test. |
72
+ | `timeout` | Mutants detected by a test timeout. |
73
+ | `survived` | Mutants that no test detected. |
74
+ | `no cov` | Mutants in code that no test covers. |
75
+ | `ignored` | Mutants excluded from the run. |
76
+ | `errors` | Mutants that caused a runtime or compile error. |
77
+
78
+ Scores are marked according to the `thresholds` option of Stryker: 🟢 at or
79
+ above `high`, 🟡 at or above `low`, 🔴 below `low`. A score is shown as `n/a`
80
+ when there are no valid mutants.
81
+
82
+ ## License
83
+
84
+ [MIT](LICENSE)
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './src/index.js';
package/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from './src/index.js';
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "stryker-markdown-reporter",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "exports": "./index.js",
6
+ "description": "StrykerJS reporter plugin that writes mutation testing results as a Markdown table",
7
+ "keywords": [
8
+ "stryker",
9
+ "stryker-plugin",
10
+ "stryker-reporter",
11
+ "mutation-testing",
12
+ "mutation-testing-report",
13
+ "reporter",
14
+ "markdown"
15
+ ],
16
+ "homepage": "https://github.com/DmitriyZverev/stryker-markdown-reporter",
17
+ "bugs": {
18
+ "url": "https://github.com/DmitriyZverev/stryker-markdown-reporter/issues",
19
+ "email": "opensource@zver.dev"
20
+ },
21
+ "license": "MIT",
22
+ "author": {
23
+ "name": "Dmitriy Zverev",
24
+ "email": "opensource@zver.dev"
25
+ },
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "https://github.com/DmitriyZverev/stryker-markdown-reporter.git"
29
+ },
30
+ "engines": {
31
+ "node": ">=22.0.0"
32
+ },
33
+ "scripts": {
34
+ "build": "rm -rf .package && npx tsc --outDir .package && cp package.json LICENSE README.md .package",
35
+ "analyzer:code:fix": "npx eslint --no-error-on-unmatched-pattern --fix --ext .ts,.tsx,.js .",
36
+ "analyzer:code:check": "npx eslint --no-error-on-unmatched-pattern --ext .ts,.tsx,.js .",
37
+ "analyzer:api:check": "npx api-extractor run --local --verbose",
38
+ "formatter:fix": "npx prettier --write \"**/*.{ts,tsx,js,json,yml,md,html}\"",
39
+ "formatter:check": "npx prettier --check \"**/*.{ts,tsx,js,json,yml,md,html}\"",
40
+ "test": "npx vitest run"
41
+ },
42
+ "dependencies": {
43
+ "@stryker-mutator/api": "^10.0.0"
44
+ },
45
+ "peerDependencies": {
46
+ "@stryker-mutator/core": "^10.0.0"
47
+ },
48
+ "devDependencies": {
49
+ "@dmitriyzverev/eslint-config": "3.0.1",
50
+ "@dmitriyzverev/prettier-config": "2.0.0",
51
+ "@dmitriyzverev/typescript-config": "1.1.1",
52
+ "@microsoft/api-extractor": "7.59.1",
53
+ "@stryker-mutator/core": "10.0.0",
54
+ "@types/node": "24.13.5",
55
+ "@vitest/coverage-v8": "5.0.1",
56
+ "eslint": "8.57.1",
57
+ "prettier": "3.9.7",
58
+ "typescript": "5.9.3",
59
+ "vitest": "5.0.1"
60
+ }
61
+ }
@@ -0,0 +1,14 @@
1
+ import type { StrykerOptions } from '@stryker-mutator/api/core';
2
+ import type { Logger } from '@stryker-mutator/api/logging';
3
+ import type { Reporter } from '@stryker-mutator/api/report';
4
+ import type { MutationTestMetricsResult } from './types.js';
5
+ export declare class MarkdownReporter implements Reporter {
6
+ static readonly inject: ["options", "logger"];
7
+ private readonly options;
8
+ private readonly log;
9
+ private mainPromise?;
10
+ constructor(options: StrykerOptions, log: Logger);
11
+ onMutationTestReportReady(_report: unknown, { systemUnderTestMetrics }: MutationTestMetricsResult): void;
12
+ wrapUp(): Promise<void> | undefined;
13
+ private generateReport;
14
+ }
@@ -0,0 +1,29 @@
1
+ import { mkdir, writeFile } from 'node:fs/promises';
2
+ import { dirname, resolve } from 'node:path';
3
+ import { pathToFileURL } from 'node:url';
4
+ import { commonTokens, tokens } from '@stryker-mutator/api/plugin';
5
+ import { formatReport } from './formatReport.js';
6
+ export class MarkdownReporter {
7
+ static inject = tokens(commonTokens.options, commonTokens.logger);
8
+ options;
9
+ log;
10
+ mainPromise;
11
+ constructor(options, log) {
12
+ this.options = options;
13
+ this.log = log;
14
+ }
15
+ onMutationTestReportReady(_report, { systemUnderTestMetrics }) {
16
+ this.mainPromise = this.generateReport(systemUnderTestMetrics);
17
+ }
18
+ wrapUp() {
19
+ return this.mainPromise;
20
+ }
21
+ async generateReport(systemUnderTestMetrics) {
22
+ const { markdownReporter: { fileName, splitErrors }, thresholds, } = this.options;
23
+ this.log.debug(`Using file "${fileName}"`);
24
+ const markdown = formatReport(systemUnderTestMetrics, { thresholds, splitErrors });
25
+ await mkdir(dirname(fileName), { recursive: true });
26
+ await writeFile(fileName, markdown, 'utf8');
27
+ this.log.info(`Your report can be found at: ${pathToFileURL(resolve(fileName)).href}`);
28
+ }
29
+ }
@@ -0,0 +1,7 @@
1
+ import type { MutationScoreThresholds } from '@stryker-mutator/api/core';
2
+ import type { MetricsResult } from './types.js';
3
+ export interface FormatOptions {
4
+ thresholds: MutationScoreThresholds;
5
+ splitErrors: boolean;
6
+ }
7
+ export declare const formatReport: (result: MetricsResult, formatOptions: FormatOptions) => string;
@@ -0,0 +1,70 @@
1
+ const ALIGNMENTS = Object.freeze({
2
+ left: {
3
+ formatMarker: (width) => `:${'-'.repeat(width - 1)}`,
4
+ pad: (value, width) => value.padEnd(width),
5
+ },
6
+ right: {
7
+ formatMarker: (width) => `${'-'.repeat(width - 1)}:`,
8
+ pad: (value, width) => value.padStart(width),
9
+ },
10
+ });
11
+ const MIN_COLUMN_WIDTH = 3;
12
+ const SCORE_MARKERS = Object.freeze({
13
+ GOOD: '🟢',
14
+ WARNING: '🟡',
15
+ DANGER: '🔴',
16
+ });
17
+ const formatTable = (columns, rows) => {
18
+ const sizedColumns = columns.map((column) => ({
19
+ ...column,
20
+ width: Math.max(MIN_COLUMN_WIDTH, column.name.length, ...rows.map((row) => column.getValue(row).length)),
21
+ }));
22
+ const formatLine = (getCell) => `| ${sizedColumns.map((column) => ALIGNMENTS[column.alignment].pad(getCell(column), column.width)).join(' | ')} |`;
23
+ return [
24
+ formatLine(({ name }) => name),
25
+ formatLine(({ alignment, width }) => ALIGNMENTS[alignment].formatMarker(width)),
26
+ ...rows.map((row) => formatLine(({ getValue }) => getValue(row))),
27
+ ];
28
+ };
29
+ const formatScore = (score, { high, low }) => {
30
+ if (Number.isNaN(score)) {
31
+ return 'n/a';
32
+ }
33
+ const status = score >= high ? SCORE_MARKERS.GOOD : score >= low ? SCORE_MARKERS.WARNING : SCORE_MARKERS.DANGER;
34
+ return `${status} ${score.toFixed(2)}%`;
35
+ };
36
+ const metricColumn = (name, getValue) => ({
37
+ name,
38
+ alignment: 'right',
39
+ getValue: ({ metrics }) => String(getValue(metrics)),
40
+ });
41
+ const createColumns = ({ thresholds, splitErrors }) => [
42
+ { name: 'File', alignment: 'left', getValue: ({ name }) => name },
43
+ metricColumn('score', (metrics) => formatScore(metrics.mutationScore, thresholds)),
44
+ metricColumn('covered', (metrics) => formatScore(metrics.mutationScoreBasedOnCoveredCode, thresholds)),
45
+ metricColumn('killed', (metrics) => metrics.killed),
46
+ metricColumn('timeout', (metrics) => metrics.timeout),
47
+ metricColumn('survived', (metrics) => metrics.survived),
48
+ metricColumn('no cov', (metrics) => metrics.noCoverage),
49
+ metricColumn('ignored', (metrics) => metrics.ignored),
50
+ ...(splitErrors
51
+ ? [
52
+ metricColumn('runtime errors', (metrics) => metrics.runtimeErrors),
53
+ metricColumn('compile errors', (metrics) => metrics.compileErrors),
54
+ ]
55
+ : [metricColumn('errors', (metrics) => metrics.runtimeErrors + metrics.compileErrors)]),
56
+ ];
57
+ const formatThresholds = ({ high, low, break: breaking }) => `Thresholds: ${SCORE_MARKERS.GOOD} ≥ ${high}, ${SCORE_MARKERS.WARNING} ≥ ${low}, ${SCORE_MARKERS.DANGER} < ${low}${breaking === null ? '' : `, break < ${breaking}`}`;
58
+ const escapeMarkdown = (value) => value.replace(/[\\`*_[\]<>|~&$]/g, '\\$&');
59
+ const collectFiles = (result, path = []) => result.childResults.flatMap((child) => child.file
60
+ ? [{ name: escapeMarkdown([...path, child.name].join('/')), metrics: child.metrics }]
61
+ : collectFiles(child, [...path, child.name]));
62
+ export const formatReport = (result, formatOptions) => [
63
+ ...formatTable(createColumns(formatOptions), [
64
+ { name: '**All files**', metrics: result.metrics },
65
+ ...collectFiles(result),
66
+ ]),
67
+ '',
68
+ formatThresholds(formatOptions.thresholds),
69
+ '',
70
+ ].join('\n');
package/src/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { PluginKind } from '@stryker-mutator/api/plugin';
2
+ export { strykerValidationSchema } from './strykerValidationSchema.js';
3
+ /**
4
+ * @public
5
+ */
6
+ export declare const strykerPlugins: import("@stryker-mutator/api/plugin").ClassPlugin<PluginKind.Reporter, ["options", "logger"]>[];
package/src/index.js ADDED
@@ -0,0 +1,7 @@
1
+ import { declareClassPlugin, PluginKind } from '@stryker-mutator/api/plugin';
2
+ import { MarkdownReporter } from './MarkdownReporter.js';
3
+ export { strykerValidationSchema } from './strykerValidationSchema.js';
4
+ /**
5
+ * @public
6
+ */
7
+ export const strykerPlugins = [declareClassPlugin(PluginKind.Reporter, 'markdown', MarkdownReporter)];
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @public
3
+ */
4
+ export declare const strykerValidationSchema: {
5
+ $schema: string;
6
+ type: string;
7
+ properties: {
8
+ markdownReporter: {
9
+ description: string;
10
+ type: string;
11
+ additionalProperties: boolean;
12
+ default: {};
13
+ properties: {
14
+ fileName: {
15
+ description: string;
16
+ type: string;
17
+ default: string;
18
+ };
19
+ splitErrors: {
20
+ description: string;
21
+ type: string;
22
+ default: boolean;
23
+ };
24
+ };
25
+ };
26
+ };
27
+ };
28
+ export interface MarkdownReporterOptions {
29
+ markdownReporter: {
30
+ fileName: string;
31
+ splitErrors: boolean;
32
+ };
33
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @public
3
+ */
4
+ export const strykerValidationSchema = {
5
+ $schema: 'http://json-schema.org/draft-07/schema',
6
+ type: 'object',
7
+ properties: {
8
+ markdownReporter: {
9
+ description: 'Configuration for the markdown reporter',
10
+ type: 'object',
11
+ additionalProperties: false,
12
+ default: {},
13
+ properties: {
14
+ fileName: {
15
+ description: 'The relative filename for the markdown report',
16
+ type: 'string',
17
+ default: 'reports/mutation/mutation.md',
18
+ },
19
+ splitErrors: {
20
+ description: 'Show runtime and compile errors in separate columns instead of a single one',
21
+ type: 'boolean',
22
+ default: false,
23
+ },
24
+ },
25
+ },
26
+ },
27
+ };
package/src/types.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ export interface Metrics {
2
+ mutationScore: number;
3
+ mutationScoreBasedOnCoveredCode: number;
4
+ killed: number;
5
+ timeout: number;
6
+ survived: number;
7
+ noCoverage: number;
8
+ ignored: number;
9
+ runtimeErrors: number;
10
+ compileErrors: number;
11
+ }
12
+ export interface MetricsResult {
13
+ name: string;
14
+ file?: object;
15
+ childResults: MetricsResult[];
16
+ metrics: Metrics;
17
+ }
18
+ export interface MutationTestMetricsResult {
19
+ systemUnderTestMetrics: MetricsResult;
20
+ }
package/src/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};