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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(reload test environment): implement test environment reload #3369

Merged
merged 4 commits into from
Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 1 addition & 6 deletions packages/api/src/core/mutant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ export interface Mutant extends Pick<schema.MutantResult, 'id' | 'location' | 'm
/**
* 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;
hitCount?: number;
testFilter: string[] | undefined;
};
export type MutantTestCoverage = Mutant & Pick<schema.MutantResult, 'coveredBy' | 'static'>;

/**
* Represents a mutant in its final state, ready to be reported.
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/test-runner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export * from './run-options';
export * from './mutant-run-result';
export * from './dry-run-status';
export * from './run-result-helpers';
export * from './test-runner-capabilities';
7 changes: 7 additions & 0 deletions packages/api/src/test-runner/run-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,11 @@ export interface MutantRunOptions extends RunOptions {
hitLimit?: number;
activeMutant: Mutant;
sandboxFileName: string;
/**
* Determines whether or not the test environment should be reloaded.
* This is necessary when testing static mutants, where the mutant is only executed when the test environment is loaded.
* A test runner might be unable to reload the test environment, i.e. when the files were loaded via `import` in nodejs.
* In which case the test runner should report `reloadEnvironment: false` in it's capabilities.
*/
reloadEnvironment: boolean;
}
11 changes: 11 additions & 0 deletions packages/api/src/test-runner/test-runner-capabilities.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Represents the capabilities of a test runner.
*/
export interface TestRunnerCapabilities {
/**
* When true, the test runner is capable of reloading the test environment. Otherwise false.
* Reloading means creating a new nodejs process, or reloading the browser.
* When true, the test runner should reload the test environment when `reloadEnvironment` is present in the run options.
*/
reloadEnvironment: boolean;
}
2 changes: 2 additions & 0 deletions packages/api/src/test-runner/test-runner.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { DryRunOptions, MutantRunOptions } from './run-options';
import { DryRunResult } from './dry-run-result';
import { MutantRunResult } from './mutant-run-result';
import { TestRunnerCapabilities } from './test-runner-capabilities';

export interface TestRunner {
capabilities(): Promise<TestRunnerCapabilities> | TestRunnerCapabilities;
init?(): Promise<void>;
dryRun(options: DryRunOptions): Promise<DryRunResult>;
mutantRun(options: MutantRunOptions): Promise<MutantRunResult>;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/di/core-tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const inputFiles = 'inputFiles';
export const dryRunResult = 'dryRunResult';
export const files = 'files';
export const mutants = 'mutants';
export const mutantsWithTestCoverage = 'mutantsWithTestCoverage';
export const mutantTestPlanner = 'mutantTestPlanner';
export const process = 'process';
export const temporaryDirectory = 'temporaryDirectory';
export const unexpectedExitRegistry = 'unexpectedExitRegistry';
Expand Down
158 changes: 0 additions & 158 deletions packages/core/src/mutants/find-mutant-test-coverage.ts

This file was deleted.

3 changes: 2 additions & 1 deletion packages/core/src/mutants/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './find-mutant-test-coverage';
export * from './mutant-test-plan';
export * from './mutant-test-planner';
23 changes: 23 additions & 0 deletions packages/core/src/mutants/mutant-test-plan.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { MutantStatus, MutantTestCoverage } from '@stryker-mutator/api/core';
import { MutantRunOptions } from '@stryker-mutator/api/test-runner';

/**
* Represents an internal object
*/
export type MutantTestPlan = MutantEarlyResultPlan | MutantRunPlan;

export enum PlanKind {
EarlyResult = 'EarlyResult',
Run = 'Run',
}

export interface MutantEarlyResultPlan {
plan: PlanKind.EarlyResult;
mutant: MutantTestCoverage & { status: MutantStatus };
}

export interface MutantRunPlan {
plan: PlanKind.Run;
mutant: MutantTestCoverage;
runOptions: MutantRunOptions;
}