How to use coverageResultsPerMutant method in stryker-parent

Best JavaScript code snippet using stryker-parent

find-mutant-test-coverage.ts

Source:find-mutant-test-coverage.ts Github

copy

Full Screen

1import { CompleteDryRunResult, TestResult } from '@stryker-mutator/api/test-runner';2import { Mutant, CoveragePerTestId, MutantTestCoverage, MutantCoverage } from '@stryker-mutator/api/core';3import { commonTokens, tokens } from '@stryker-mutator/api/plugin';4import { Logger } from '@stryker-mutator/api/logging';5import { coreTokens } from '../di';6import { StrictReporter } from '../reporters/strict-reporter';7findMutantTestCoverage.inject = tokens(coreTokens.dryRunResult, coreTokens.mutants, coreTokens.reporter, commonTokens.logger);8export function findMutantTestCoverage(9 dryRunResult: CompleteDryRunResult,10 mutants: readonly Mutant[],11 reporter: StrictReporter,12 logger: Logger13): MutantTestCoverage[] {14 const mutantTestCoverage = mapToMutantTestCoverage(dryRunResult, mutants, logger);15 reporter.onAllMutantsMatchedWithTests(mutantTestCoverage);16 return mutantTestCoverage;17}18function mapToMutantTestCoverage(dryRunResult: CompleteDryRunResult, mutants: readonly Mutant[], logger: Logger): MutantTestCoverage[] {19 const testsByMutantId = findTestsByMutant(dryRunResult.mutantCoverage?.perTest, dryRunResult.tests, logger);20 const hitsByMutantId = findHitsByMutantId(dryRunResult.mutantCoverage);21 const timeSpentAllTests = calculateTotalTime(dryRunResult.tests);22 const mutantCoverage = mutants.map((mutant): MutantTestCoverage => {23 const hitCount = hitsByMutantId.get(mutant.id);24 if (mutant.status) {25 return {26 ...mutant,27 static: false,28 hitCount,29 estimatedNetTime: 0,30 };31 } else if (!dryRunResult.mutantCoverage || dryRunResult.mutantCoverage.static[mutant.id] > 0) {32 // When there is static coverage for this mutant, it is a static mutant.33 return {34 ...mutant,35 estimatedNetTime: timeSpentAllTests,36 hitCount,37 coveredBy: undefined,38 static: true,39 };40 } else {41 // If no static coverage, but there is test coverage, it is a non-static, covered mutant42 const tests = testsByMutantId.get(mutant.id);43 if (tests && tests.size > 0) {44 return {45 ...mutant,46 estimatedNetTime: calculateTotalTime(tests),47 hitCount,48 coveredBy: toTestIds(tests),49 static: false,50 };51 } else {52 // Otherwise it is has no coverage53 return {54 ...mutant,55 estimatedNetTime: 0,56 hitCount,57 coveredBy: [],58 static: false,59 };60 }61 }62 });63 return mutantCoverage;64}65function findTestsByMutant(coveragePerTest: CoveragePerTestId | undefined, allTests: TestResult[], logger: Logger) {66 const testsByMutantId = new Map<string, Set<TestResult>>();67 coveragePerTest &&68 Object.entries(coveragePerTest).forEach(([testId, mutantCoverage]) => {69 const foundTest = allTests.find((test) => test.id === testId);70 if (!foundTest) {71 logger.debug(72 `Found test with id "${testId}" in coverage data, but not in the test results of the dry run. Not taking coverage data for this test into account`73 );74 return;75 }76 Object.entries(mutantCoverage).forEach(([mutantId, count]) => {77 if (count) {78 let tests = testsByMutantId.get(mutantId);79 if (!tests) {80 tests = new Set();81 testsByMutantId.set(mutantId, tests);82 }83 tests.add(foundTest);84 }85 });86 });87 return testsByMutantId;88}89function calculateTotalTime(testResults: Iterable<TestResult>): number {90 let total = 0;91 for (const test of testResults) {92 total += test.timeSpentMs;93 }94 return total;95}96function toTestIds(testResults: Iterable<TestResult>): string[] {97 const result = [];98 for (const test of testResults) {99 result.push(test.id);100 }101 return result;102}103/**104 * Find the number of hits per mutant. This is the total amount of times the mutant was executed during the dry test run.105 * @param coverageData The coverage data from the initial test run106 * @returns The hits by mutant id107 */108function findHitsByMutantId(coverageData: MutantCoverage | undefined): Map<string, number> {109 const hitsByMutant = new Map<string, number>();110 if (coverageData) {111 // We don't care about the exact tests in this case, just the total number of hits112 const coverageResultsPerMutant = [coverageData.static, ...Object.values(coverageData.perTest)];113 coverageResultsPerMutant.forEach((coverageByMutantId) => {114 Object.entries(coverageByMutantId).forEach(([mutantId, count]) => {115 hitsByMutant.set(mutantId, (hitsByMutant.get(mutantId) ?? 0) + count);116 });117 });118 }119 return hitsByMutant;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { coverageResultsPerMutant } from 'stryker-parent';2const mutants = [/*...*/];3const coverageResults = [/*...*/];4const result = coverageResultsPerMutant(mutants, coverageResults);5export function coverageResultsPerMutant(mutants, coverageResults) {6 return perMutantCoverageResults;7}8{9}10export function coverageResultsPerMutant(mutants, coverageResults) {11 return perMutantCoverageResults;12}13{14}

Full Screen

Using AI Code Generation

copy

Full Screen

1const test = require('./test2');2const test2 = require('./test3');3test();4test2();5module.exports = function test() {6 console.log('test');7}8module.exports = function test2() {9 console.log('test2');10}11module.exports = function(config) {12 config.set({13 commandRunner: {14 },15 });16};

Full Screen

Using AI Code Generation

copy

Full Screen

1const { coverageResultsPerMutant } = require('stryker-parent');2 {3 perTest: {4 '1': {5 },6 '2': {7 },8 '3': {9 }10 }11 }12];13 {14 location: {15 start: {16 },17 end: {18 }19 },20 },21 {22 location: {23 start: {24 },25 end: {26 }27 },28 },29 {30 location: {31 start: {32 },33 end: {34 }35 },36 }37];38const results = coverageResultsPerMutant(coverageResults, mutants);39console.log(results);40[ { id: '1', coveredBy: [ '1' ], static: [ '1' ] },41 { id: '2', coveredBy: [ '2' ], static: [ '2' ] },42 { id: '3', coveredBy: [ '3' ], static: [ '3' ] } ]

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