How to use testRunnerPool method in stryker-parent

Best JavaScript code snippet using stryker-parent

4-mutation-test-executor.ts

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

copy

Full Screen

1import { from, partition, merge, Observable, lastValueFrom } from 'rxjs';2import { toArray, map, tap, shareReplay } from 'rxjs/operators';3import { tokens, commonTokens } from '@stryker-mutator/api/plugin';4import { MutantTestCoverage, MutantResult, StrykerOptions, MutantStatus } from '@stryker-mutator/api/core';5import { MutantRunOptions, TestRunner } from '@stryker-mutator/api/test-runner';6import { Logger } from '@stryker-mutator/api/logging';7import { I } from '@stryker-mutator/util';8import { CheckStatus, Checker, CheckResult, PassedCheckResult } from '@stryker-mutator/api/check';9import { coreTokens } from '../di';10import { StrictReporter } from '../reporters/strict-reporter';11import { MutationTestReportHelper } from '../reporters/mutation-test-report-helper';12import { Timer } from '../utils/timer';13import { Pool, ConcurrencyTokenProvider } from '../concurrent';14import { Sandbox } from '../sandbox';15import { DryRunContext } from './3-dry-run-executor';16export interface MutationTestContext extends DryRunContext {17 [coreTokens.testRunnerPool]: I<Pool<TestRunner>>;18 [coreTokens.timeOverheadMS]: number;19 [coreTokens.mutationTestReportHelper]: MutationTestReportHelper;20 [coreTokens.mutantsWithTestCoverage]: MutantTestCoverage[];21}22/**23 * The factor by which hit count from dry run is multiplied to calculate the hit limit for a mutant.24 * This is intentionally a high value to prevent false positives.25 *26 * For example, a property testing library might execute a failing scenario multiple times to determine the smallest possible counterexample.27 * @see https://jsverify.github.io/#minimal-counterexample28 */29const HIT_LIMIT_FACTOR = 100;30export class MutationTestExecutor {31 public static inject = tokens(32 commonTokens.options,33 coreTokens.reporter,34 coreTokens.checkerPool,35 coreTokens.testRunnerPool,36 coreTokens.timeOverheadMS,37 coreTokens.mutantsWithTestCoverage,38 coreTokens.mutationTestReportHelper,39 coreTokens.sandbox,40 commonTokens.logger,41 coreTokens.timer,42 coreTokens.concurrencyTokenProvider43 );44 constructor(45 private readonly options: StrykerOptions,46 private readonly reporter: StrictReporter,47 private readonly checkerPool: I<Pool<Checker>>,48 private readonly testRunnerPool: I<Pool<TestRunner>>,49 private readonly timeOverheadMS: number,50 private readonly matchedMutants: readonly MutantTestCoverage[],51 private readonly mutationTestReportHelper: I<MutationTestReportHelper>,52 private readonly sandbox: I<Sandbox>,53 private readonly log: Logger,54 private readonly timer: I<Timer>,55 private readonly concurrencyTokenProvider: I<ConcurrencyTokenProvider>56 ) {}57 public async execute(): Promise<MutantResult[]> {58 const { ignoredResult$, notIgnoredMutant$ } = this.executeIgnore(from(this.matchedMutants));59 const { passedMutant$, checkResult$ } = this.executeCheck(from(notIgnoredMutant$));60 const { coveredMutant$, noCoverageResult$ } = this.executeNoCoverage(passedMutant$);61 const testRunnerResult$ = this.executeRunInTestRunner(coveredMutant$);62 const results = await lastValueFrom(merge(testRunnerResult$, checkResult$, noCoverageResult$, ignoredResult$).pipe(toArray()));63 this.mutationTestReportHelper.reportAll(results);64 await this.reporter.wrapUp();65 this.logDone();66 return results;67 }68 private executeIgnore(input$: Observable<MutantTestCoverage>) {69 const [ignoredMutant$, notIgnoredMutant$] = partition(input$.pipe(shareReplay()), (mutant) => mutant.status === MutantStatus.Ignored);70 const ignoredResult$ = ignoredMutant$.pipe(map((mutant) => this.mutationTestReportHelper.reportMutantStatus(mutant, MutantStatus.Ignored)));71 return { ignoredResult$, notIgnoredMutant$ };72 }73 private executeNoCoverage(input$: Observable<MutantTestCoverage>) {74 const [noCoverageMatchedMutant$, coveredMutant$] = partition(75 input$.pipe(shareReplay()),76 (mutant) => !mutant.static && (mutant.coveredBy?.length ?? 0) === 077 );78 const noCoverageResult$ = noCoverageMatchedMutant$.pipe(79 map((mutant) => this.mutationTestReportHelper.reportMutantStatus(mutant, MutantStatus.NoCoverage))80 );81 return { noCoverageResult$, coveredMutant$ };82 }83 private executeCheck(input$: Observable<MutantTestCoverage>) {84 const checkTask$ = this.checkerPool85 .schedule(input$, async (checker, mutant) => {86 const checkResult = await checker.check(mutant);87 return {88 checkResult,89 mutant,90 };91 })92 .pipe(93 // Dispose when all checks are completed.94 // This will allow resources to be freed up and more test runners to be spined up.95 tap({96 complete: () => {97 this.checkerPool.dispose();98 this.concurrencyTokenProvider.freeCheckers();99 },100 }),101 shareReplay()102 );103 const [passedCheckResult$, failedCheckResult$] = partition(checkTask$, ({ checkResult }) => checkResult.status === CheckStatus.Passed);104 const checkResult$ = failedCheckResult$.pipe(105 map((failedMutant) =>106 this.mutationTestReportHelper.reportCheckFailed(failedMutant.mutant, failedMutant.checkResult as Exclude<CheckResult, PassedCheckResult>)107 )108 );109 const passedMutant$ = passedCheckResult$.pipe(map(({ mutant }) => mutant));110 return { checkResult$, passedMutant$ };111 }112 private executeRunInTestRunner(input$: Observable<MutantTestCoverage>): Observable<MutantResult> {113 return this.testRunnerPool.schedule(input$, async (testRunner, mutant) => {114 const mutantRunOptions = this.createMutantRunOptions(mutant);115 const result = await testRunner.mutantRun(mutantRunOptions);116 return this.mutationTestReportHelper.reportMutantRunResult(mutant, result);117 });118 }119 private createMutantRunOptions(activeMutant: MutantTestCoverage): MutantRunOptions {120 const timeout = this.options.timeoutFactor * activeMutant.estimatedNetTime + this.options.timeoutMS + this.timeOverheadMS;121 const hitLimit = activeMutant.hitCount === undefined ? undefined : activeMutant.hitCount * HIT_LIMIT_FACTOR;122 return {123 activeMutant,124 timeout,125 testFilter: activeMutant.coveredBy,126 sandboxFileName: this.sandbox.sandboxFileFor(activeMutant.fileName),127 hitLimit,128 disableBail: this.options.disableBail,129 };130 }131 private logDone() {132 this.log.info('Done in %s.', this.timer.humanReadableElapsed());133 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var testRunnerPool = require('stryker-parent').testRunnerPool;2testRunnerPool.run();3var testRunnerPool = require('stryker-parent').testRunnerPool;4testRunnerPool.run();5var testRunnerPool = require('stryker-parent').testRunnerPool;6testRunnerPool.run();7var testRunnerPool = require('stryker-parent').testRunnerPool;8testRunnerPool.run();9var testRunnerPool = require('stryker-parent').testRunnerPool;10testRunnerPool.run();11var testRunnerPool = require('stryker-parent').testRunnerPool;12testRunnerPool.run();13var testRunnerPool = require('stryker-parent').testRunnerPool;14testRunnerPool.run();15var testRunnerPool = require('stryker-parent').testRunnerPool;16testRunnerPool.run();17var testRunnerPool = require('stryker-parent').testRunnerPool;18testRunnerPool.run();19var testRunnerPool = require('stryker-parent').testRunnerPool;20testRunnerPool.run();21var testRunnerPool = require('stryker-parent').testRunnerPool;22testRunnerPool.run();23var testRunnerPool = require('stryker-parent').testRunnerPool;24testRunnerPool.run();25var testRunnerPool = require('

Full Screen

Using AI Code Generation

copy

Full Screen

1var testRunnerPool = require('stryker-parent').testRunnerPool;2var testRunner = testRunnerPool.testRunner;3var testFramework = testRunnerPool.testFramework;4var log = require('stryker-api').logging.getLogger('testRunnerPool');5log.debug('testRunnerPool loaded');6testRunner.run({port: 12345}, function (err, result) {7 if (err) {8 log.error(err);9 } else {10 log.debug('testRunnerPool run completed');11 log.debug(result);12 }13});14testRunnerPool.dispose();

Full Screen

Using AI Code Generation

copy

Full Screen

1var testRunnerPool = require('stryker-parent').testRunnerPool;2var testRunner = testRunnerPool.create('mocha');3testRunner.run({ files: ['test.js'] }).then(function (result) {4 console.log(result);5});6var testRunnerPool = require('stryker-parent').testRunnerPool;7var testRunner = testRunnerPool.create('mocha');8testRunner.run({ files: ['test.js'] }).then(function (result) {9 console.log(result);10});11var testRunnerPool = require('stryker-parent').testRunnerPool;12var testRunner = testRunnerPool.create('mocha');13testRunner.run({ files: ['test.js'] }).then(function (result) {14 console.log(result);15});16var testRunnerPool = require('stryker-parent').testRunnerPool;17var testRunner = testRunnerPool.create('mocha');18testRunner.run({ files: ['test.js'] }).then(function (result) {19 console.log(result);20});21var testRunnerPool = require('stryker-parent').testRunnerPool;22var testRunner = testRunnerPool.create('mocha');23testRunner.run({ files: ['test.js'] }).then(function (result) {24 console.log(result);25});26var testRunnerPool = require('stryker-parent').testRunnerPool;27var testRunner = testRunnerPool.create('mocha');28testRunner.run({ files: ['test.js'] }).then(function (result) {29 console.log(result);30});31var testRunnerPool = require('stryker

Full Screen

Using AI Code Generation

copy

Full Screen

1var testRunnerPool = require('stryker-parent').testRunnerPool;2var testRunner = testRunnerPool.create('myTestRunner');3testRunner.run({ files: ['a.js', 'b.js'] });4var TestRunner = require('stryker-api/test_runner').TestRunner;5var MyTestRunner = function () { /* ... */ };6MyTestRunner.prototype = Object.create(TestRunner.prototype);7MyTestRunner.prototype.run = function (runOptions) {8 this.emit('testResult', { name: 'a.js', status: 'failed' });9 this.emit('testResult', { name: 'b.js', status: 'passed' });10 this.emit('allTestsDone');11}12module.exports = MyTestRunner;13: the name of the test (e.g. the name of the test function)

Full Screen

Using AI Code Generation

copy

Full Screen

1const testRunnerPool = require('stryker-parent').testRunnerPool;2testRunnerPool.run({port: 12345});3const testRunnerPool = require('stryker-parent').testRunnerPool;4testRunnerPool.run({port: 12345});5const testRunnerPool = require('stryker-parent').testRunnerPool;6testRunnerPool.run({port: 12345});7const testRunnerPool = require('stryker-parent').testRunnerPool;8testRunnerPool.run({port: 12345});9const testRunnerPool = require('stryker-parent').testRunnerPool;10testRunnerPool.run({port: 12345});11const testRunnerPool = require('stryker-parent').testRunnerPool;12testRunnerPool.run({port: 12345});13const testRunnerPool = require('stryker-parent').testRunnerPool;14testRunnerPool.run({port: 12345});15const testRunnerPool = require('stryker-parent').testRunnerPool;16testRunnerPool.run({port: 12345});17const testRunnerPool = require('stryker-parent').testRunnerPool;

Full Screen

Using AI Code Generation

copy

Full Screen

1var childProcess = require("child_process");2var stryker = childProcess.fork("node_modules/stryker-parent/src/testRunnerPool.js", ["testRunnerPool"], {3 cwd: process.cwd(),4});5stryker.on("message", function(message) {6 console.log("message from child: " + message);7});8stryker.send("Hello from parent");9var childProcess = require("child_process");10var stryker = childProcess.fork("node_modules/stryker-parent/src/childProcessTestRunner.js", ["childProcessTestRunner"], {11 cwd: process.cwd(),12});13stryker.on("message", function(message) {14 console.log("message from child: " + message);15});16stryker.send("Hello from parent");17var childProcess = require("child_process");18var stryker = childProcess.fork("node_modules/stryker/src/TestRunner.js", ["TestRunner"], {19 cwd: process.cwd(),20});21stryker.on("message", function(message) {22 console.log("message from child: " + message);23});24stryker.send("Hello from parent");

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