How to use hitsByMutantId method in stryker-parent

Best JavaScript code snippet using stryker-parent

test-coverage.spec.ts

Source:test-coverage.spec.ts Github

copy

Full Screen

1import { factory, testInjector } from '@stryker-mutator/test-helpers';2import { expect } from 'chai';3import { TestCoverage } from '../../../src/mutants/index.js';4describe(TestCoverage.name, () => {5 describe(TestCoverage.prototype.hasStaticCoverage.name, () => {6 it('should return false when no static coverage was reported', () => {7 expect(TestCoverage.from(factory.completeDryRunResult(), testInjector.logger).hasStaticCoverage('1')).false;8 });9 it('should return false when no static coverage was reported for the mutant', () => {10 const sut = TestCoverage.from(11 factory.completeDryRunResult({ mutantCoverage: factory.mutantCoverage({ static: { 1: 0, 2: 1 } }) }),12 testInjector.logger13 );14 expect(sut.hasStaticCoverage('1')).false;15 });16 it('should return true when static coverage was reported for the mutant', () => {17 const sut = TestCoverage.from(18 factory.completeDryRunResult({ mutantCoverage: factory.mutantCoverage({ static: { 1: 0, 2: 1 } }) }),19 testInjector.logger20 );21 expect(sut.hasStaticCoverage('2')).true;22 });23 });24 describe(TestCoverage.prototype.addTest.name, () => {25 it('should add the test', () => {26 const sut = TestCoverage.from(factory.completeDryRunResult(), testInjector.logger);27 const test = factory.successTestResult({ id: 'spec1' });28 sut.addTest(test);29 expect(sut.testsById.get('spec1')).eq(test);30 });31 });32 describe(TestCoverage.prototype.addCoverage.name, () => {33 it("should create new coverage if the mutant didn't have any", () => {34 const spec1 = factory.testResult({ id: 'spec1' });35 const sut = new TestCoverage(new Map(), new Map([['spec1', spec1]]), {}, new Map());36 sut.addCoverage('1', ['spec1']);37 expect(sut.forMutant('1')).deep.eq(new Set([spec1]));38 });39 it('should expand on existing coverage if the mutant already was covered', () => {40 const spec1 = factory.testResult({ id: 'spec1' });41 const spec2 = factory.testResult({ id: 'spec2' });42 const sut = new TestCoverage(43 new Map([['mutant1', new Set([spec1])]]),44 new Map([45 ['spec1', spec1],46 ['spec2', spec2],47 ]),48 {},49 new Map()50 );51 sut.addCoverage('mutant1', ['spec2']);52 expect(sut.forMutant('mutant1')).deep.eq(new Set([spec1, spec2]));53 });54 it('should ignore non-existing tests', () => {55 const spec1 = factory.testResult({ id: 'spec1' });56 const spec2 = factory.testResult({ id: 'spec2' });57 const sut = new TestCoverage(58 new Map([['mutant1', new Set([spec1])]]),59 new Map([60 ['spec1', spec1],61 ['spec2', spec2],62 ]),63 {},64 new Map()65 );66 sut.addCoverage('mutant1', ['spec2', 'spec3']);67 expect(sut.forMutant('mutant1')).deep.eq(new Set([spec1, spec2]));68 });69 });70 describe(TestCoverage.from.name, () => {71 it('should correctly determine the coverage be test', () => {72 // Arrange73 const spec1 = factory.successTestResult({ id: 'spec1' });74 const spec2 = factory.successTestResult({ id: 'spec2' });75 const spec3 = factory.successTestResult({ id: 'spec3' });76 const dryRunResult = factory.completeDryRunResult({77 tests: [spec1, spec2, spec3],78 mutantCoverage: { static: { 1: 1 }, perTest: { ['spec1']: { 1: 2, 2: 100 }, ['spec2']: { 2: 100 }, ['spec3']: { 1: 3, 2: 0 } } },79 });80 // Act81 const actualCoverage = TestCoverage.from(dryRunResult, testInjector.logger);82 // Assert83 expect(actualCoverage.testsByMutantId).lengthOf(2);84 expect(actualCoverage.forMutant('1')).deep.eq(new Set([spec1, spec3]));85 expect(actualCoverage.forMutant('2')).deep.eq(new Set([spec1, spec2]));86 });87 it('should set `hasCoverage` to false when coverage is missing', () => {88 expect(TestCoverage.from(factory.completeDryRunResult(), testInjector.logger).hasCoverage).false;89 });90 it('should set `hasCoverage` to true when coverage of any kind is reported', () => {91 expect(TestCoverage.from(factory.completeDryRunResult({ mutantCoverage: { perTest: {}, static: {} } }), testInjector.logger).hasCoverage).that;92 });93 it('should calculate total hits correctly (add perTest and static)', () => {94 const dryRunResult = factory.completeDryRunResult({95 mutantCoverage: { static: { 1: 1 }, perTest: { ['spec1']: { 1: 2, 2: 100 }, ['spec2']: { 2: 100 }, ['spec3']: { 1: 3 } } },96 });97 const actualCoverage = TestCoverage.from(dryRunResult, testInjector.logger);98 expect(actualCoverage.hitsByMutantId).lengthOf(2);99 expect(actualCoverage.hitsByMutantId.get('1')).eq(6);100 expect(actualCoverage.hitsByMutantId.get('2')).eq(200);101 });102 it('should allow log when a non-existing test is presented (#2485)', async () => {103 // Arrange104 const dryRunResult = factory.completeDryRunResult({105 tests: [factory.successTestResult({ id: 'spec1', timeSpentMs: 20 })], // test result for spec2 is missing106 mutantCoverage: { static: {}, perTest: { spec1: { 1: 1 }, spec2: { 1: 0, 2: 1 } } },107 });108 // Act109 TestCoverage.from(dryRunResult, testInjector.logger);110 // Assert111 expect(testInjector.logger.warn).calledWith(112 'Found test with id "spec2" in coverage data, but not in the test results of the dry run. Not taking coverage data for this test into account.'113 );114 });115 });...

Full Screen

Full Screen

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

test-coverage.ts

Source:test-coverage.ts Github

copy

Full Screen

...25 }26 public get testsById(): ReadonlyMap<string, TestResult> {27 return this.#testsById;28 }29 public get hitsByMutantId(): ReadonlyMap<string, number> {30 return this.#hitsByMutantId;31 }32 public get hasCoverage(): boolean {33 // Since static coverage should always be reported when coverage analysis succeeded (albeit an empty object),34 // we can use that to determine if there is any coverage at all35 return !!this.#staticCoverage;36 }37 public hasStaticCoverage(mutantId: string): boolean {38 return !!(this.#staticCoverage && this.#staticCoverage[mutantId] > 0);39 }40 public addTest(testResult: TestResult): void {41 this.#testsById.set(testResult.id, testResult);42 }43 public addCoverage(mutantId: string, testIds: string[]): void {...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const hitsByMutantId = require('stryker-parent').hitsByMutantId;2const hitsByMutantId = require('stryker-parent').hitsByMutantId;3const hitsByMutantId = require('stryker-parent').hitsByMutantId;4const hitsByMutantId = require('stryker-parent').hitsByMutantId;5const hitsByMutantId = require('stryker-parent').hitsByMutantId;6const hitsByMutantId = require('stryker-parent').hitsByMutantId;7const hitsByMutantId = require('stryker-parent').hitsByMutantId;8const hitsByMutantId = require('stryker-parent').hitsByMutantId;9const hitsByMutantId = require('stryker-parent').hitsByMutantId;10const hitsByMutantId = require('stryker-parent').hitsByMutantId;11const hitsByMutantId = require('stryker-parent').hitsByMutantId;12const hitsByMutantId = require('stryker-parent').hitsByMutantId;13const hitsByMutantId = require('stryker-parent').hitsByMutantId;14const hitsByMutantId = require('stryker-parent').hitsByMutantId;15const hitsByMutantId = require('

Full Screen

Using AI Code Generation

copy

Full Screen

1const { hitsByMutantId } = require('stryker-parent');2hitsByMutantId([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);3module.exports = {4 hitsByMutantId: function (ids) {5 return ids.map((id) => `Mutant ${id} was hit`);6 },7};8{9}10{11}12module.exports = {13 hitsByMutantId: function (ids) {14 return ids.map((id) => `Mutant ${id} was not hit`);15 },16};17{18}19module.exports = {20 hitsByMutantId: function (ids) {21 return ids.map((id) => `Mutant ${id} was not hit`);22 },23};24{25}26module.exports = {27 hitsByMutantId: function (ids) {28 return ids.map((id) => `Mutant ${id} was not hit`);29 },30};31{32}33module.exports = {

Full Screen

Using AI Code Generation

copy

Full Screen

1var hitsByMutantId = require('stryker-parent').hitsByMutantId;2var hits = hitsByMutantId([1,2,3,4,5,6,7,8,9,10]);3console.log(hits);4module.exports = {5 hitsByMutantId: function (mutantIds) {6 var hits = [];7 for (var i = 0; i < 10; i++) {8 hits.push(Math.floor(Math.random() * 10));9 }10 return hits;11 }12};13module.exports = function (config) {14 config.set({15 });16};

Full Screen

Using AI Code Generation

copy

Full Screen

1var strykerParent = require('stryker-parent');2var hitsByMutantId = strykerParent.hitsByMutantId;3var mutants = [{id:1},{id:2},{id:3}];4var hits = [1, 2, 3];5var hitsByMutantId = hitsByMutantId(mutants, hits);6console.log(hitsByMutantId);7var hitsByMutantId = require('stryker-parent').hitsByMutantId;8var mutants = [{id:1},{id:2},{id:3}];9var hits = [1, 2, 3];10var hitsByMutantId = hitsByMutantId(mutants, hits);11console.log(hitsByMutantId);12var strykerParent = require('stryker-parent');13var hitsByMutantId = strykerParent.hitsByMutantId;14var mutants = [{id:1},{id:2},{id:3}];15var hits = [1, 2, 3];16var hitsByMutantId = hitsByMutantId(mutants, hits);17console.log(hitsByMutantId);18var hitsByMutantId = require('stryker-parent').hitsByMutantId;19var mutants = [{id:1},{id:2},{id:3}];20var hits = [1, 2, 3];21var hitsByMutantId = hitsByMutantId(mutants, hits);22console.log(hitsByMutantId);23var strykerParent = require('stryker-parent');24var hitsByMutantId = strykerParent.hitsByMutantId;25var mutants = [{id:1},{id:2},{id:3}];26var hits = [1, 2, 3];

Full Screen

Using AI Code Generation

copy

Full Screen

1{2 "dependencies": {3 }4}5{6 "dependencies": {7 }8}9{10}

Full Screen

Using AI Code Generation

copy

Full Screen

1const hitsByMutantId = require('stryker-parent').hitsByMutantId;2const hitsByMutantId = require('stryker-parent/dist/src/ParentProcessTestRunner').hitsByMutantId;3const hitsByMutantId = require('stryker-parent/dist/src/ParentProcessTestRunner').default.hitsByMutantId;4const hitsByMutantId = require('stryker-parent/dist/src/ParentProcessTestRunner').default.default.hitsByMutantId;5const hitsByMutantId = require('stryker-parent/dist/src/ParentProcessTestRunner').default.default.default.hitsByMutantId;6const hitsByMutantId = require('stryker-parent/dist/src/ParentProcessTestRunner').default.default.default.default.hitsByMutantId;7const hitsByMutantId = require('stryker-parent/dist/src/ParentProcessTestRunner').default.default.default.default.default.hitsByMutantId;

Full Screen

Using AI Code Generation

copy

Full Screen

1const stryker = require('stryker-parent');2const config = {3};4const reporter = stryker.reporters.StrykerReporter.create(config);5reporter.onAllSourceFilesRead({ files: files });6reporter.onAllMutantsMatchedWithTests({ mutants: mutants });7reporter.onAllMutantsTested({8 {9 },10 {11 },12 {13 },14 {15 },16 {17 },18 {19 },20 {21 },22 {23 },24 {25 },26 {27 },28 {29 },30 {31 },32 {33 },34 {35 },36 {37 },38 {39 },40 {

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