Skip to content

Commit

Permalink
feat(checker): add checker api (#2240)
Browse files Browse the repository at this point in the history
Adds `Checker` plugin type, to be used in #1514 (and can later be used to filter mutants in #1980).

The idea is that, before mutation testing (or even before files are instrumented), we initialize the checker. It can be used as a sanity check. The `TypescriptChecker` can use this to load all files and compile once (with `--no-emit`) to make sure errors don't occur under normal circumstances. 

The `check` method is called one-by-one on each mutant. A checker can decide to assign any of a `CheckStatus`. If it `Passed` it proceeds to the next checker, or if it was the last checker it will be run in a test runner. If another status is assigned, it will stop processing that mutant and report it as done.
  • Loading branch information
nicojs committed Jun 9, 2020
1 parent 7e9fdb6 commit d463f86
Show file tree
Hide file tree
Showing 28 changed files with 49 additions and 33 deletions.
3 changes: 3 additions & 0 deletions packages/api/check.ts
@@ -0,0 +1,3 @@
export * from './src/check/Checker';
export * from './src/check/CheckResult';
export * from './src/check/CheckStatus';
1 change: 1 addition & 0 deletions packages/api/core.ts
Expand Up @@ -2,6 +2,7 @@ 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 Mutant } from './src/core/Mutant';
export * from './src-generated/stryker-core';
export * from './src/core/ReportTypes';
export * from './src/core/StrykerOptionsSchema';
Expand Down
1 change: 0 additions & 1 deletion packages/api/mutant.ts
@@ -1,2 +1 @@
export { default as Mutant } from './src/mutant/Mutant';
export { default as Mutator } from './src/mutant/Mutator';
6 changes: 6 additions & 0 deletions packages/api/src/check/CheckResult.ts
@@ -0,0 +1,6 @@
import { CheckStatus } from './CheckStatus';

export interface CheckResult {
reason?: string;
status: CheckStatus;
}
4 changes: 4 additions & 0 deletions packages/api/src/check/CheckStatus.ts
@@ -0,0 +1,4 @@
export enum CheckStatus {
Passed = 'passed',
CompileError = 'compileError',
}
9 changes: 9 additions & 0 deletions packages/api/src/check/Checker.ts
@@ -0,0 +1,9 @@
import { Mutant } from '../../core';

import { CheckResult } from './CheckResult';

export interface Checker {
init(): Promise<void>;

check(mutant: Mutant): Promise<CheckResult>;
}
File renamed without changes.
4 changes: 1 addition & 3 deletions packages/api/src/mutant/Mutator.ts
@@ -1,6 +1,4 @@
import { File } from '../../core';

import Mutant from './Mutant';
import { File, Mutant } from '../../core';

export default interface Mutator {
mutate(inputFiles: readonly File[]): readonly Mutant[];
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/plugin/Contexts.ts
Expand Up @@ -48,4 +48,5 @@ export interface PluginContexts {
[PluginKind.TestFramework]: OptionsContext;
[PluginKind.TestRunner]: TestRunnerPluginContext;
[PluginKind.Transpiler]: TranspilerPluginContext;
[PluginKind.Checker]: OptionsContext;
}
1 change: 1 addition & 0 deletions packages/api/src/plugin/PluginKind.ts
Expand Up @@ -7,6 +7,7 @@ export enum PluginKind {
*/
ConfigEditor = 'ConfigEditor',
OptionsEditor = 'OptionsEditor',
Checker = 'Checker',
TestRunner = 'TestRunner',
TestFramework = 'TestFramework',
Transpiler = 'Transpiler',
Expand Down
2 changes: 2 additions & 0 deletions packages/api/src/plugin/Plugins.ts
Expand Up @@ -7,6 +7,7 @@ import { TestFramework } from '../../test_framework';
import { TestRunner } from '../../test_runner';
import { Transpiler } from '../../transpile';
import { OptionsEditor } from '../core/OptionsEditor';
import { Checker } from '../../check';

import { PluginContexts } from './Contexts';
import { PluginKind } from './PluginKind';
Expand Down Expand Up @@ -90,6 +91,7 @@ export interface PluginInterfaces {
[PluginKind.TestFramework]: TestFramework;
[PluginKind.TestRunner]: TestRunner;
[PluginKind.Transpiler]: Transpiler;
[PluginKind.Checker]: Checker;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/api/test/unit/plugin/Plugins.spec.ts
Expand Up @@ -4,7 +4,7 @@ import { declareClassPlugin, declareFactoryPlugin } from '../../../src/plugin/Pl
import { PluginKind } from '../../../src/plugin/PluginKind';
import { tokens, commonTokens } from '../../../src/plugin/tokens';
import { Logger } from '../../../logging';
import { Mutant } from '../../../mutant';
import { Mutant } from '../../../core';

describe('plugins', () => {
describe(declareClassPlugin.name, () => {
Expand Down
1 change: 1 addition & 0 deletions packages/api/tsconfig.src.json
Expand Up @@ -7,6 +7,7 @@
"src",
"src-generated",
"schema/*.json",
"check.ts",
"config.ts",
"core.ts",
"logging.ts",
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/TestableMutant.ts
@@ -1,5 +1,4 @@
import { Location } from '@stryker-mutator/api/core';
import { Mutant } from '@stryker-mutator/api/mutant';
import { Mutant, Location } from '@stryker-mutator/api/core';
import { MutantResult, MutantStatus } from '@stryker-mutator/api/report';
import { TestSelection } from '@stryker-mutator/api/test_framework';
import { RunResult, TestResult } from '@stryker-mutator/api/test_runner';
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/mutants/MutantTestMatcher.ts
@@ -1,6 +1,5 @@
import { StrykerOptions } from '@stryker-mutator/api/core';
import { Mutant, StrykerOptions } from '@stryker-mutator/api/core';
import { Logger } from '@stryker-mutator/api/logging';
import { Mutant } from '@stryker-mutator/api/mutant';
import { commonTokens, tokens } from '@stryker-mutator/api/plugin';
import { MatchedMutant } from '@stryker-mutator/api/report';
import { CoverageCollection, CoveragePerTestResult, CoverageResult, StatementMap } from '@stryker-mutator/api/test_runner';
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/mutants/MutatorFacade.ts
@@ -1,6 +1,6 @@
import { File, MutatorDescriptor } from '@stryker-mutator/api/core';
import { Mutant, File, MutatorDescriptor } from '@stryker-mutator/api/core';
import { Logger } from '@stryker-mutator/api/logging';
import { Mutant, Mutator } from '@stryker-mutator/api/mutant';
import { Mutator } from '@stryker-mutator/api/mutant';
import { commonTokens, PluginKind, tokens } from '@stryker-mutator/api/plugin';

import { coreTokens, PluginCreator } from '../di';
Expand Down
3 changes: 1 addition & 2 deletions packages/core/test/unit/Sandbox.spec.ts
@@ -1,8 +1,7 @@
import * as path from 'path';

import { File, LogLevel, StrykerOptions } from '@stryker-mutator/api/core';
import { Mutant, File, LogLevel, StrykerOptions } from '@stryker-mutator/api/core';
import { Logger } from '@stryker-mutator/api/logging';
import { Mutant } from '@stryker-mutator/api/mutant';
import { MutantStatus } from '@stryker-mutator/api/report';
import { TestFramework } from '@stryker-mutator/api/test_framework';
import { RunResult, RunStatus } from '@stryker-mutator/api/test_runner';
Expand Down
3 changes: 1 addition & 2 deletions packages/core/test/unit/TestableMutant.spec.ts
@@ -1,5 +1,4 @@
import { File } from '@stryker-mutator/api/core';
import { Mutant } from '@stryker-mutator/api/mutant';
import { Mutant, File } from '@stryker-mutator/api/core';
import { mutant, runResult, testResult } from '@stryker-mutator/test-helpers/src/factory';
import { expect } from 'chai';

Expand Down
3 changes: 1 addition & 2 deletions packages/core/test/unit/mutants/MutantTestMatcher.spec.ts
@@ -1,5 +1,4 @@
import { File } from '@stryker-mutator/api/core';
import { Mutant } from '@stryker-mutator/api/mutant';
import { Mutant, File } from '@stryker-mutator/api/core';
import { MatchedMutant } from '@stryker-mutator/api/report';
import { TestSelection } from '@stryker-mutator/api/test_framework';
import { CoverageCollection, CoveragePerTestResult, RunStatus, TestResult, TestStatus } from '@stryker-mutator/api/test_runner';
Expand Down
4 changes: 2 additions & 2 deletions packages/javascript-mutator/src/JavaScriptMutator.ts
@@ -1,7 +1,7 @@
import * as types from '@babel/types';
import { File } from '@stryker-mutator/api/core';
import { Mutant, File } from '@stryker-mutator/api/core';
import { Logger } from '@stryker-mutator/api/logging';
import { Mutant, Mutator } from '@stryker-mutator/api/mutant';
import { Mutator } from '@stryker-mutator/api/mutant';
import { commonTokens, tokens } from '@stryker-mutator/api/plugin';

import BabelParser from './helpers/BabelParser';
Expand Down
@@ -1,5 +1,4 @@
import { File } from '@stryker-mutator/api/core';
import { Mutant } from '@stryker-mutator/api/mutant';
import { Mutant, File } from '@stryker-mutator/api/core';
import ExpectMutation from '@stryker-mutator/mutator-specification/src/ExpectMutation';
import { testInjector } from '@stryker-mutator/test-helpers';
import { expect } from 'chai';
Expand Down
2 changes: 1 addition & 1 deletion packages/test-helpers/src/factory.ts
Expand Up @@ -8,9 +8,9 @@ import {
MutatorDescriptor,
strykerCoreSchema,
WarningOptions,
Mutant,
} from '@stryker-mutator/api/core';
import { Logger } from '@stryker-mutator/api/logging';
import { Mutant } from '@stryker-mutator/api/mutant';
import { MatchedMutant, MutantResult, MutantStatus, mutationTestReportSchema, Reporter } from '@stryker-mutator/api/report';
import { TestFramework, TestSelection } from '@stryker-mutator/api/test_framework';
import { RunResult, RunStatus, TestResult, TestStatus } from '@stryker-mutator/api/test_runner';
Expand Down
3 changes: 1 addition & 2 deletions packages/typescript/src/TypescriptMutator.ts
@@ -1,5 +1,4 @@
import { File, StrykerOptions } from '@stryker-mutator/api/core';
import { Mutant } from '@stryker-mutator/api/mutant';
import { Mutant, File, StrykerOptions } from '@stryker-mutator/api/core';
import { commonTokens, Injector, OptionsContext, tokens } from '@stryker-mutator/api/plugin';
import * as ts from 'typescript';

Expand Down
2 changes: 1 addition & 1 deletion packages/typescript/src/mutator/NodeMutator.ts
@@ -1,6 +1,6 @@
import * as path from 'path';

import { Mutant } from '@stryker-mutator/api/mutant';
import { Mutant } from '@stryker-mutator/api/core';
import * as ts from 'typescript';

export interface NodeReplacement {
Expand Down
3 changes: 1 addition & 2 deletions packages/typescript/test/integration/sample.it.spec.ts
@@ -1,8 +1,7 @@
import * as fs from 'fs';
import * as path from 'path';

import { File } from '@stryker-mutator/api/core';
import { Mutant } from '@stryker-mutator/api/mutant';
import { Mutant, File } from '@stryker-mutator/api/core';
import { testInjector, factory } from '@stryker-mutator/test-helpers';
import { expect } from 'chai';

Expand Down
3 changes: 1 addition & 2 deletions packages/typescript/test/unit/mutator/mutatorAssertions.ts
@@ -1,5 +1,4 @@
import { File } from '@stryker-mutator/api/core';
import { Mutant } from '@stryker-mutator/api/mutant';
import { Mutant, File } from '@stryker-mutator/api/core';
import ExpectMutation from '@stryker-mutator/mutator-specification/src/ExpectMutation';
import { expect } from 'chai';
import * as ts from 'typescript';
Expand Down
4 changes: 2 additions & 2 deletions packages/vue-mutator/src/VueMutator.ts
@@ -1,5 +1,5 @@
import { File } from '@stryker-mutator/api/core';
import { Mutant, Mutator } from '@stryker-mutator/api/mutant';
import { Mutant, File } from '@stryker-mutator/api/core';
import { Mutator } from '@stryker-mutator/api/mutant';
import { tokens } from '@stryker-mutator/api/plugin';

import { MUTATORS_TOKEN } from './helpers/MutatorHelpers';
Expand Down
4 changes: 2 additions & 2 deletions packages/vue-mutator/test/unit/VueMutator.spec.ts
@@ -1,5 +1,5 @@
import { File } from '@stryker-mutator/api/core';
import { Mutant, Mutator } from '@stryker-mutator/api/mutant';
import { Mutant, File } from '@stryker-mutator/api/core';
import { Mutator } from '@stryker-mutator/api/mutant';
import { testInjector } from '@stryker-mutator/test-helpers';
import { expect } from 'chai';
import { SinonStubbedInstance } from 'sinon';
Expand Down

0 comments on commit d463f86

Please sign in to comment.