Skip to content

Commit

Permalink
feat(reporter api): unify reporter api with mutation-testing-elements (
Browse files Browse the repository at this point in the history
…#2798)

This change brings the `Reporter` API more in line with the schema of [`mutation-testing-elements`](https://github.com/stryker-mutator/mutation-testing-elements). It also adds the metrics result to the `onMutationTestReportReady` for convenience.

| Old | New |
|-|-|
| `MutantStatus.TimedOut` | `MutantStatus.Timeout` |
| `mutant.coveredByTests` (boolean) | `mutant.coveredBy` (array, an empty array means not covered) |
| `mutant.testFilter` (array) | `mutant.coveredBy` |
| `mutant.testFilter` (undefined) | `mutant.static` (true/false) |
| `mutant.runAllTests` (boolean) | `mutant.static` (true/false) |
| `mutant.errorMessage`, `mutant.ignoreReason` | `mutant.statusReason` |
| `mutant.nrOfTestsRan` | `mutant.testsCompleted` |
| `mutant.id` (number) | `mutant.id` (string) |
| `MatchedMutant` | `MutantTestCoverage` (name change) |

This has also a small impact on the `TestRunner` API, because the `Mutant` is used there as well.

BREAKING CHANGE: Changes to `Reporter` and `TestRunner` plugin API of Stryker

Fixes #2766
  • Loading branch information
nicojs committed Mar 11, 2021
1 parent c536567 commit d173b27
Show file tree
Hide file tree
Showing 107 changed files with 2,672 additions and 2,817 deletions.
14 changes: 7 additions & 7 deletions e2e/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion e2e/package.json
Expand Up @@ -31,7 +31,7 @@
"link-parent-bin": "^2.0.0",
"load-grunt-tasks": "~5.1.0",
"mocha": "~8.2.0",
"mutation-testing-metrics": "~1.5.2",
"mutation-testing-metrics": "~1.6.2",
"rxjs": "~6.5.3",
"semver": "~6.3.0",
"ts-jest": "~26.3.0",
Expand Down
6 changes: 3 additions & 3 deletions e2e/test/coverage-analysis/verify/verify.ts
Expand Up @@ -59,7 +59,7 @@ describe('Coverage analysis', () => {
const stryker = new Stryker(strykerOptions);

// Act
const testsRan = (await stryker.runMutationTest()).reduce((a, b) => a + b.nrOfTestsRan, 0);
const testsRan = (await stryker.runMutationTest()).reduce((a, b) => a + (b.testsCompleted ?? 0), 0);

// Assert
const metricsResult = calculateMetrics(CoverageAnalysisReporter.instance?.report.files);
Expand All @@ -79,7 +79,7 @@ describe('Coverage analysis', () => {
const stryker = new Stryker(strykerOptions);

// Act
const testsRan = (await stryker.runMutationTest()).reduce((a, b) => a + b.nrOfTestsRan, 0);
const testsRan = (await stryker.runMutationTest()).reduce((a, b) => a + (b.testsCompleted ?? 0), 0);

// Assert
const metricsResult = calculateMetrics(CoverageAnalysisReporter.instance?.report.files);
Expand All @@ -99,7 +99,7 @@ describe('Coverage analysis', () => {
const stryker = new Stryker(strykerOptions);

// Act
const testsRan = (await stryker.runMutationTest()).reduce((a, b) => a + b.nrOfTestsRan, 0);
const testsRan = (await stryker.runMutationTest()).reduce((a, b) => a + (b.testsCompleted ?? 0), 0);

// Assert
const metricsResult = calculateMetrics(CoverageAnalysisReporter.instance?.report.files);
Expand Down
14 changes: 7 additions & 7 deletions e2e/test/karma-webpack-with-ts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions e2e/test/karma-webpack-with-ts/package.json
Expand Up @@ -8,8 +8,8 @@
},
"dependencies": {
"lit-element": "~2.3.1",
"mutation-testing-metrics": "~1.5.2",
"mutation-testing-report-schema": "~1.5.2"
"mutation-testing-metrics": "~1.6.2",
"mutation-testing-report-schema": "~1.6.0"
},
"devDependencies": {
"@types/webpack-env": "~1.15.2"
Expand Down
3 changes: 2 additions & 1 deletion packages/api/package.json
Expand Up @@ -38,7 +38,8 @@
"node": ">=10"
},
"dependencies": {
"mutation-testing-report-schema": "~1.5.2",
"mutation-testing-report-schema": "~1.6.0",
"mutation-testing-metrics": "~1.6.2",
"surrial": "~2.0.2",
"tslib": "~2.1.0"
},
Expand Down
7 changes: 6 additions & 1 deletion packages/api/src/core/index.ts
Expand Up @@ -2,10 +2,15 @@ export { File } from './file';
export { Position } from './position';
export { Location } from './location';
export { Range } from './range';
export { Mutant } from './mutant';
export * from './mutant';
export * from '../../src-generated/stryker-core';
export * from './report-types';
export * from './stryker-options-schema';
export * from './partial-stryker-options';
export * from './instrument';
export * from './mutant-coverage';

/**
* Re-export all members from "mutation-testing-report-schema" under the `schema` key
*/
export * as schema from 'mutation-testing-report-schema';
2 changes: 1 addition & 1 deletion packages/api/src/core/instrument.ts
Expand Up @@ -12,7 +12,7 @@ export const INSTRUMENTER_CONSTANTS = Object.freeze({
} as const);

export interface InstrumenterContext {
activeMutant?: number;
activeMutant?: string;
currentTestId?: string;
mutantCoverage?: MutantCoverage;
}
Expand Down
5 changes: 4 additions & 1 deletion packages/api/src/core/mutant-coverage.ts
Expand Up @@ -5,4 +5,7 @@ export interface MutantCoverage {

export type CoveragePerTestId = Record<string, CoverageData>;

export type CoverageData = Record<number, number>;
/**
* Keys are mutant ids, the numbers are the amount of times it was hit.
*/
export type CoverageData = Record<string, number>;
43 changes: 25 additions & 18 deletions packages/api/src/core/mutant.ts
@@ -1,36 +1,43 @@
import * as schema from 'mutation-testing-report-schema';

import { Range } from './range';
import { Location } from './location';

export { MutantStatus } from 'mutation-testing-report-schema';

// We're reusing the `MutantResult` interface here to acquire uniformity.

/**
* Represents a mutant
* Represents a mutant in its initial state.
*/
export interface Mutant {
/**
* The id of the mutant. Unique within a run.
*/
id: number;
/**
* The name of the mutator that generated this mutant.
*/
mutatorName: string;
export interface Mutant extends Pick<schema.MutantResult, 'id' | 'location' | 'mutatorName' | 'replacement' | 'statusReason'> {
/**
* The file name from which this mutant originated
*/
fileName: string;
/**
* The range of this mutant (from/to within the file)
* deprecate?
*/
range: Range;
/**
* The line number/column location of this mutant
*/
location: Location;
/**
* The replacement (actual mutated code)
* Actual mutation that has been applied.
*/
replacement: string;
/**
* If the mutant was ignored during generation, the reason for ignoring it, otherwise `undefined`
* The status if a mutant if known. This should be undefined for a mutant that still needs testing.
*/
ignoreReason?: string;
status?: schema.MutantStatus;
}

/**
* Represents a mutant in its matched-with-the-tests state, ready to be tested.
*/
export type MutantTestCoverage = Mutant &
Pick<schema.MutantResult, 'coveredBy' | 'static'> & {
estimatedNetTime: number;
};

/**
* Represents a mutant in its final state, ready to be reported.
*/
export type MutantResult = Mutant & schema.MutantResult;
12 changes: 0 additions & 12 deletions packages/api/src/report/index.ts
@@ -1,14 +1,2 @@
import * as mutationTestReportSchema from 'mutation-testing-report-schema';

export { Reporter } from './reporter';
export * from './mutant-result';
export { MutantStatus } from './mutant-status';
export { SourceFile } from './source-file';
export { MatchedMutant } from './matched-mutant';
export {
/**
* Types exported directly from mutation-testing-schema
* @see https://github.com/stryker-mutator/mutation-testing-elements/tree/master/packages/mutation-testing-report-schema
*/
mutationTestReportSchema,
};
30 changes: 0 additions & 30 deletions packages/api/src/report/matched-mutant.ts

This file was deleted.

41 changes: 0 additions & 41 deletions packages/api/src/report/mutant-result.ts

This file was deleted.

44 changes: 0 additions & 44 deletions packages/api/src/report/mutant-status.ts

This file was deleted.

0 comments on commit d173b27

Please sign in to comment.