How to use isEarlyResult method in stryker-parent

Best JavaScript code snippet using stryker-parent

mutant-test-planner.ts

Source:mutant-test-planner.ts Github

copy

Full Screen

...238 result.push(test.id);239 }240 return result;241}242export function isEarlyResult(mutantPlan: MutantTestPlan): mutantPlan is MutantEarlyResultPlan {243 return mutantPlan.plan === PlanKind.EarlyResult;244}245export function isRunPlan(mutantPlan: MutantTestPlan): mutantPlan is MutantRunPlan {246 return mutantPlan.plan === PlanKind.Run;...

Full Screen

Full Screen

4-mutation-test-executor.ts

Source:4-mutation-test-executor.ts Github

copy

Full Screen

1import { from, partition, merge, Observable, lastValueFrom, EMPTY, concat, bufferTime, mergeMap } from 'rxjs';2import { toArray, map, shareReplay, tap } from 'rxjs/operators';3import { tokens, commonTokens } from '@stryker-mutator/api/plugin';4import { MutantResult, MutantStatus, Mutant, StrykerOptions, PlanKind, MutantTestPlan, MutantRunPlan } from '@stryker-mutator/api/core';5import { TestRunner } from '@stryker-mutator/api/test-runner';6import { Logger } from '@stryker-mutator/api/logging';7import { I } from '@stryker-mutator/util';8import { CheckStatus } from '@stryker-mutator/api/check';9import { coreTokens } from '../di/index.js';10import { StrictReporter } from '../reporters/strict-reporter.js';11import { MutationTestReportHelper } from '../reporters/mutation-test-report-helper.js';12import { Timer } from '../utils/timer.js';13import { ConcurrencyTokenProvider, Pool } from '../concurrent/index.js';14import { isEarlyResult, MutantTestPlanner } from '../mutants/index.js';15import { CheckerFacade } from '../checker/index.js';16import { DryRunContext } from './3-dry-run-executor.js';17export interface MutationTestContext extends DryRunContext {18 [coreTokens.testRunnerPool]: I<Pool<TestRunner>>;19 [coreTokens.timeOverheadMS]: number;20 [coreTokens.mutationTestReportHelper]: MutationTestReportHelper;21 [coreTokens.mutantTestPlanner]: MutantTestPlanner;22}23const CHECK_BUFFER_MS = 10_000;24/**25 * Sorting the tests just before running them can yield a significant performance boost,26 * because it can reduce the number of times a test runner process needs to be recreated.27 * However, we need to buffer the results in order to be able to sort them.28 *29 * This value is very low, since it would halt the test execution otherwise.30 * @see https://github.com/stryker-mutator/stryker-js/issues/346231 */32const BUFFER_FOR_SORTING_MS = 0;33export class MutationTestExecutor {34 public static inject = tokens(35 coreTokens.reporter,36 coreTokens.testRunnerPool,37 coreTokens.checkerPool,38 coreTokens.mutants,39 coreTokens.mutantTestPlanner,40 coreTokens.mutationTestReportHelper,41 commonTokens.logger,42 commonTokens.options,43 coreTokens.timer,44 coreTokens.concurrencyTokenProvider45 );46 constructor(47 private readonly reporter: StrictReporter,48 private readonly testRunnerPool: I<Pool<TestRunner>>,49 private readonly checkerPool: I<Pool<I<CheckerFacade>>>,50 private readonly mutants: readonly Mutant[],51 private readonly planner: MutantTestPlanner,52 private readonly mutationTestReportHelper: I<MutationTestReportHelper>,53 private readonly log: Logger,54 private readonly options: StrykerOptions,55 private readonly timer: I<Timer>,56 private readonly concurrencyTokenProvider: I<ConcurrencyTokenProvider>57 ) {}58 public async execute(): Promise<MutantResult[]> {59 const mutantTestPlans = await this.planner.makePlan(this.mutants);60 const { earlyResult$, runMutant$ } = this.executeEarlyResult(from(mutantTestPlans));61 const { passedMutant$, checkResult$ } = this.executeCheck(runMutant$);62 const { coveredMutant$, noCoverageResult$ } = this.executeNoCoverage(passedMutant$);63 const testRunnerResult$ = this.executeRunInTestRunner(coveredMutant$);64 const results = await lastValueFrom(merge(testRunnerResult$, checkResult$, noCoverageResult$, earlyResult$).pipe(toArray()));65 await this.mutationTestReportHelper.reportAll(results);66 await this.reporter.wrapUp();67 this.logDone();68 return results;69 }70 private executeEarlyResult(input$: Observable<MutantTestPlan>) {71 const [earlyResultMutants$, runMutant$] = partition(input$.pipe(shareReplay()), isEarlyResult);72 const earlyResult$ = earlyResultMutants$.pipe(map(({ mutant }) => this.mutationTestReportHelper.reportMutantStatus(mutant, mutant.status)));73 return { earlyResult$, runMutant$ };74 }75 private executeNoCoverage(input$: Observable<MutantRunPlan>) {76 const [noCoverageMatchedMutant$, coveredMutant$] = partition(input$.pipe(shareReplay()), ({ runOptions }) => runOptions.testFilter?.length === 0);77 const noCoverageResult$ = noCoverageMatchedMutant$.pipe(78 map(({ mutant }) => this.mutationTestReportHelper.reportMutantStatus(mutant, MutantStatus.NoCoverage))79 );80 return { noCoverageResult$, coveredMutant$ };81 }82 private executeRunInTestRunner(input$: Observable<MutantRunPlan>): Observable<MutantResult> {83 const sortedPlan$ = input$.pipe(84 bufferTime(BUFFER_FOR_SORTING_MS),85 mergeMap((plans) => plans.sort(reloadEnvironmentLast))86 );87 return this.testRunnerPool.schedule(sortedPlan$, async (testRunner, { mutant, runOptions }) => {88 const result = await testRunner.mutantRun(runOptions);89 return this.mutationTestReportHelper.reportMutantRunResult(mutant, result);90 });91 }92 private logDone() {93 this.log.info('Done in %s.', this.timer.humanReadableElapsed());94 }95 /**96 * Checks mutants against all configured checkers (if any) and returns steams for failed checks and passed checks respectively97 * @param input$ The mutant run plans to check98 */99 public executeCheck(input$: Observable<MutantRunPlan>): {100 checkResult$: Observable<MutantResult>;101 passedMutant$: Observable<MutantRunPlan>;102 } {103 let checkResult$: Observable<MutantResult> = EMPTY;104 let passedMutant$ = input$;105 for (const checkerName of this.options.checkers) {106 // Use this checker107 const [checkFailedResult$, checkPassedResult$] = partition(108 this.executeSingleChecker(checkerName, passedMutant$).pipe(shareReplay()),109 isEarlyResult110 );111 // Prepare for the next one112 passedMutant$ = checkPassedResult$;113 checkResult$ = concat(checkResult$, checkFailedResult$.pipe(map(({ mutant }) => mutant)));114 }115 return {116 checkResult$,117 passedMutant$: passedMutant$.pipe(118 tap({119 complete: async () => {120 await this.checkerPool.dispose();121 this.concurrencyTokenProvider.freeCheckers();122 },123 })124 ),125 };126 }127 /**128 * Executes the check task for one checker129 * @param checkerName The name of the checker to execute130 * @param input$ The mutants tasks to check131 * @returns An observable stream with early results (check failed) and passed results132 */133 private executeSingleChecker(checkerName: string, input$: Observable<MutantRunPlan>): Observable<MutantTestPlan> {134 const group$ = this.checkerPool135 .schedule(input$.pipe(bufferTime(CHECK_BUFFER_MS)), (checker, mutants) => checker.group(checkerName, mutants))136 .pipe(mergeMap((mutantGroups) => mutantGroups));137 const checkTask$ = this.checkerPool138 .schedule(group$, (checker, group) => checker.check(checkerName, group))139 .pipe(140 mergeMap((mutantGroupResults) => mutantGroupResults),141 map(([mutantRunPlan, checkResult]) =>142 checkResult.status === CheckStatus.Passed143 ? mutantRunPlan144 : {145 plan: PlanKind.EarlyResult as const,146 mutant: this.mutationTestReportHelper.reportCheckFailed(mutantRunPlan.mutant, checkResult),147 }148 )149 );150 return checkTask$;151 }152}153/**154 * Sorting function that sorts mutant run plans that reload environments last.155 * This can yield a significant performance boost, because it reduces the times a test runner process needs to restart.156 * @see https://github.com/stryker-mutator/stryker-js/issues/3462157 */158function reloadEnvironmentLast(a: MutantRunPlan, b: MutantRunPlan): number {159 if (a.plan === PlanKind.Run && b.plan === PlanKind.Run) {160 if (a.runOptions.reloadEnvironment && !b.runOptions.reloadEnvironment) {161 return 1;162 }163 if (!a.runOptions.reloadEnvironment && b.runOptions.reloadEnvironment) {164 return -1;165 }166 return 0;167 }168 return 0;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { isEarlyResult } = require('stryker-parent');2console.log(isEarlyResult('earlyResult'));3{4 "scripts": {5 },6 "dependencies": {7 }8}

Full Screen

Using AI Code Generation

copy

Full Screen

1const { isEarlyResult } = require('stryker-parent');2const result = isEarlyResult({ killed: 1, survived: 1, timeout: 1, noCoverage: 1, error: 1, totalDetected: 1, totalUndetected: 1, totalMutants: 1, mutationScore: 1, mutationScoreBasedOnCoveredCode: 1, compileErrors: 1, runtimeErrors: 1, killedBy: { '1': 1 } }, 1, 1);3const { isEarlyResult } = require('stryker-parent');4const result = isEarlyResult({ killed: 1, survived: 1, timeout: 1, noCoverage: 1, error: 1, totalDetected: 1, totalUndetected: 1, totalMutants: 1, mutationScore: 1, mutationScoreBasedOnCoveredCode: 1, compileErrors: 1, runtimeErrors: 1, killedBy: { '1': 1 } }, 1, 1);5const { isEarlyResult } = require('stryker-parent');6const result = isEarlyResult({ killed: 1, survived: 1, timeout: 1, noCoverage: 1, error: 1, totalDetected: 1, totalUndetected: 1, totalMutants: 1, mutationScore: 1, mutationScoreBasedOnCoveredCode: 1, compileErrors: 1, runtimeErrors: 1, killedBy: { '1': 1 } }, 1, 1);7const { isEarlyResult } = require('stryker-parent');8const result = isEarlyResult({ killed: 1, survived: 1, timeout: 1, noCoverage: 1, error: 1, totalDetected: 1, totalUndetected: 1, totalMutants: 1, mutationScore: 1, mutationScoreBasedOnCoveredCode: 1, compileErrors: 1, runtimeErrors: 1, killedBy: { '1': 1 } }, 1, 1);

Full Screen

Using AI Code Generation

copy

Full Screen

1const { isEarlyResult } = require('stryker-parent');2const isEarlyResult = isEarlyResult(process.argv);3if (isEarlyResult) {4 console.log('Early result from stryker');5 process.exit(0);6}7const Stryker = require('stryker');8const stryker = new Stryker();9stryker.runMutationTest().then(() => {10 console.log('Mutation test completed');11 process.exit(0);12});13{14 "scripts": {15 },16 "dependencies": {17 }18}

Full Screen

Using AI Code Generation

copy

Full Screen

1const strykerParent = require('stryker-parent');2const earlyResult = strykerParent.isEarlyResult();3console.log(earlyResult);4const isEarlyResult = () => {5 return process.env['STRYKER_TEST_RUNNER'] === 'early';6};7module.exports = {8};

Full Screen

Using AI Code Generation

copy

Full Screen

1var earlyResult = require('stryker-parent').isEarlyResult;2if (earlyResult) {3 console.log('Early result detected');4}5var earlyResult = require('stryker-parent').isEarlyResult;6if (earlyResult) {7 console.log('Early result detected');8}9var earlyResult = require('stryker-parent').isEarlyResult;10if (earlyResult) {11 console.log('Early result detected');12}13var earlyResult = require('stryker-parent').isEarlyResult;14if (earlyResult) {15 console.log('Early result detected');16}

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run stryker-parent automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful