How to use collectReusableMutantsByKey method in stryker-parent

Best JavaScript code snippet using stryker-parent

incremental-differ.ts

Source:incremental-differ.ts Github

copy

Full Screen

...61 // Expose the collectors for unit testing purposes62 this.mutantStatisticsCollector = mutantStatisticsCollector;63 this.testStatisticsCollector = testStatisticsCollector;64 // Collect what we can reuse, while correcting for diff in the locations65 const reusableMutantsByKey = collectReusableMutantsByKey(this.logger);66 const { byId: oldTestsById, byKey: oldTestInfoByKey } = collectReusableTestInfo(this.logger);67 // Collect some helper maps and sets68 const { oldCoverageByMutantKey: oldCoverageTestKeysByMutantKey, oldKilledByMutantKey: oldKilledTestKeysByMutantKey } =69 collectOldKilledAndCoverageMatrix();70 const oldTestKeys = new Set([...oldTestsById.values()].map(({ key }) => key));71 const newTestKeys = new Set(72 [...testCoverage.testsById].map(([, test]) => testToIdentifyingKey(test, toRelativeNormalizedFileName(test.fileName)))73 );74 // Create a dictionary to more easily get test information75 const testInfoByKey = collectCurrentTestInfo();76 // Mark which tests are added77 for (const [key, { relativeFileName }] of testInfoByKey) {78 if (!oldTestKeys.has(key)) {79 testStatisticsCollector.count(relativeFileName, 'added');80 }81 }82 // Make sure that tests that didn't run this time around aren't forgotten83 for (const [84 testKey,85 {86 test: { name, location },87 relativeFileName,88 },89 ] of oldTestInfoByKey) {90 if (!testInfoByKey.has(testKey)) {91 const test: TestResult = {92 status: TestStatus.Success,93 id: testKey,94 name,95 startPosition: location?.start,96 timeSpentMs: 0,97 fileName: path.resolve(relativeFileName),98 };99 testInfoByKey.set(testKey, { test, relativeFileName: relativeFileName });100 testCoverage.addTest(test);101 }102 }103 // Done with preparations, time to map over the mutants104 let reusedMutantCount = 0;105 const currentMutantKeys = new Set<string>();106 const mutants = currentMutants.map((mutant) => {107 const relativeFileName = toRelativeNormalizedFileName(mutant.fileName);108 const mutantKey = mutantToIdentifyingKey(mutant, relativeFileName);109 currentMutantKeys.add(mutantKey);110 if (!mutant.status && !this.options.force) {111 const oldMutant = reusableMutantsByKey.get(mutantKey);112 if (oldMutant) {113 const coveringTests = testCoverage.forMutant(mutant.id);114 const killedByTestKeys = oldKilledTestKeysByMutantKey.get(mutantKey);115 if (mutantCanBeReused(mutant, oldMutant, mutantKey, coveringTests, killedByTestKeys)) {116 reusedMutantCount++;117 const { status, statusReason, testsCompleted } = oldMutant;118 return {119 ...mutant,120 status,121 statusReason,122 testsCompleted,123 coveredBy: [...(coveringTests ?? [])].map(({ id }) => id),124 killedBy: testKeysToId(killedByTestKeys),125 };126 }127 } else {128 mutantStatisticsCollector.count(relativeFileName, 'added');129 }130 }131 return mutant;132 });133 // Make sure that old mutants that didn't run this time around aren't forgotten134 for (const [mutantKey, oldResult] of reusableMutantsByKey) {135 // Do an additional check to see if the mutant is in mutated range.136 //137 // For example:138 // ```diff139 // - return a || b;140 // + return a && b;141 // ```142 // The conditional expression mutator here decides to _not_ mutate b to `false` the second time around. (even though the text of "b" itself didn't change)143 // Not doing this additional check would result in a sticky mutant that is never removed144 if (!currentMutantKeys.has(mutantKey) && !this.isInMutatedScope(oldResult.relativeFileName, oldResult)) {145 const coverage = oldCoverageTestKeysByMutantKey.get(mutantKey) ?? [];146 const killed = oldKilledTestKeysByMutantKey.get(mutantKey) ?? [];147 const coveredBy = testKeysToId(coverage);148 const killedBy = testKeysToId(killed);149 const reusedMutant = {150 ...oldResult,151 id: mutantKey,152 fileName: path.resolve(oldResult.relativeFileName),153 replacement: oldResult.replacement ?? oldResult.mutatorName,154 coveredBy,155 killedBy,156 };157 mutants.push(reusedMutant);158 testCoverage.addCoverage(reusedMutant.id, coveredBy);159 }160 }161 if (this.logger.isInfoEnabled()) {162 const testInfo = testCoverage.hasCoverage ? `\n\tTests:\t\t${testStatisticsCollector.createTotalsReport()}` : '';163 this.logger.info(164 `Incremental report:\n\tMutants:\t${mutantStatisticsCollector.createTotalsReport()}` +165 testInfo +166 `\n\tResult:\t\t${chalk.yellowBright(reusedMutantCount)} of ${currentMutants.length} mutant result(s) are reused.`167 );168 }169 if (this.logger.isDebugEnabled()) {170 const lineSeparator = '\n\t\t';171 const noChanges = 'No changes';172 const detailedMutantSummary = `${lineSeparator}${mutantStatisticsCollector.createDetailedReport().join(lineSeparator) || noChanges}`;173 const detailedTestsSummary = `${lineSeparator}${testStatisticsCollector.createDetailedReport().join(lineSeparator) || noChanges}`;174 this.logger.debug(`Detailed incremental report:\n\tMutants: ${detailedMutantSummary}\n\tTests: ${detailedTestsSummary}`);175 }176 return mutants;177 function testKeysToId(testKeys: Iterable<string> | undefined) {178 return [...(testKeys ?? [])]179 .map((id) => testInfoByKey.get(id))180 .filter(notEmpty)181 .map(({ test: { id } }) => id);182 }183 function collectReusableMutantsByKey(log: Logger) {184 return new Map(185 Object.entries(files).flatMap(([fileName, oldFile]) => {186 const relativeFileName = toRelativeNormalizedFileName(fileName);187 const currentFileSource = currentRelativeFiles.get(relativeFileName);188 if (currentFileSource) {189 log.trace('Diffing %s', relativeFileName);190 const { results, removeCount } = performFileDiff(oldFile.source, currentFileSource, oldFile.mutants);191 mutantStatisticsCollector.count(relativeFileName, 'removed', removeCount);192 return results.map((m) => [193 mutantToIdentifyingKey(m, relativeFileName),194 {195 ...m,196 relativeFileName,197 },...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const strykerParent = require('stryker-parent');2const mutants = strykerParent.collectReusableMutantsByKey('test.js');3console.log(mutants);4const strykerParent = require('stryker-parent');5const mutants = strykerParent.collectReusableMutantsByKey('test.js');6console.log(mutants);7const strykerParent = require('stryker-parent');8const mutants = strykerParent.collectReusableMutantsByKey('test.js');9console.log(mutants);10const strykerParent = require('stryker-parent');11const mutants = strykerParent.collectReusableMutantsByKey('test.js');12console.log(mutants);13const strykerParent = require('stryker-parent');14const mutants = strykerParent.collectReusableMutantsByKey('test.js');15console.log(mutants);16const strykerParent = require('stryker-parent');17const mutants = strykerParent.collectReusableMutantsByKey('test.js');18console.log(mutants);19const strykerParent = require('stryker-parent');20const mutants = strykerParent.collectReusableMutantsByKey('test.js');21console.log(mutants);22const strykerParent = require('stryker-parent');23const mutants = strykerParent.collectReusableMutantsByKey('test.js');24console.log(mutants);25const strykerParent = require('stryker-parent');26const mutants = strykerParent.collectReusableMutantsByKey('test.js');27console.log(mutants);

Full Screen

Using AI Code Generation

copy

Full Screen

1const mutants = collectReusableMutantsByKey('test', 'test.js');2console.log(mutants);3const mutants = collectReusableMutantsByPath('test.js');4console.log(mutants);5const mutants = collectReusableMutantsByMutator('test');6console.log(mutants);7const mutants = collectReusableMutantsByMutatorAndPath('test', 'test.js');8console.log(mutants);9const mutants = collectReusableMutantsByMutatorAndKey('test', 'test.js');10console.log(mutants);11const mutants = collectReusableMutantsByMutatorAndKeyAndPath('test', 'test.js');12console.log(mutants);13const mutants = collectReusableMutantsByMutatorAndKeyAndPath('test', 'test.js');14console.log(mutants);15const mutants = collectReusableMutantsByMutatorAndKeyAndPath('test', 'test.js');16console.log(mutants);17const mutants = collectReusableMutantsByMutatorAndKeyAndPath('test', 'test.js');18console.log(mutants);19const mutants = collectReusableMutantsByMutatorAndKeyAndPath('test', 'test.js');20console.log(mutants);21const mutants = collectReusableMutantsByMutatorAndKeyAndPath('test', 'test.js');22console.log(mutants);

Full Screen

Using AI Code Generation

copy

Full Screen

1const { collectReusableMutantsByKey } = require('stryker-parent');2const mutants = collectReusableMutantsByKey('test', 'test.js');3const { collectReusableMutantsByKey } = require('stryker-parent');4module.exports = function(config) {5 config.set({6 mutatorOptions: {7 }8 });9};

Full Screen

Using AI Code Generation

copy

Full Screen

1const { collectReusableMutantsByKey } = require('stryker-parent');2const { parentPort } = require('worker_threads');3parentPort.on('message', async (message) => {4 if (message === 'start') {5 const reusableMutants = await collectReusableMutantsByKey();6 parentPort.postMessage(reusableMutants);7 }8});9const path = require('path');10module.exports = {11 strykerOptions: {12 childProcess: {13 args: [path.join(__dirname, 'test.js')],14 },15 },16};

Full Screen

Using AI Code Generation

copy

Full Screen

1const mutants = collectReusableMutantsByKey(config);2const child = new ChildProcessProxy(config, mutants);3child.runMutant(mutant);4const child = new ChildProcessProxy(config, mutants);5child.runMutant(mutant);6runMutant(mutant: Mutant) {7 this.log.debug(`Running mutant ${mutant.id}`);8 this.child.send({ kind: ChildMessageKind.RunMutant, mutant });9 return this.mutantResultSubject.asObservable().pipe(10 filter((result) => result.id === mutant.id),11 take(1)12 );13 }14private sendMutants(mutants: Mutant[]) {15 this.child.send({ kind: ChildMessageKind.Mutants, mutants });16 }17private sendConfig(config: Config) {18 this.child.send({ kind: ChildMessageKind.Config, config });19 }20private sendTestRunner(testRunner: TestRunner) {21 this.child.send({ kind: ChildMessageKind.TestRunner, testRunner });22 }23private sendTestFramework(testFramework: TestFramework) {24 this.child.send({ kind: ChildMessageKind.TestFramework, testFramework });25 }26private sendLoggingContext(loggingContext: LoggingClientContext) {27 this.child.send({ kind: ChildMessageKind.LoggingContext, loggingContext });28 }

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