How to use testRunnerTask method in stryker-parent

Best JavaScript code snippet using stryker-parent

4-mutation-test-executor.spec.ts

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

copy

Full Screen

1import sinon from 'sinon';2import { expect } from 'chai';3import { testInjector, factory, tick } from '@stryker-mutator/test-helpers';4import { Reporter } from '@stryker-mutator/api/report';5import { TestRunner, MutantRunOptions, MutantRunResult, MutantRunStatus } from '@stryker-mutator/api/test-runner';6import { Checker, CheckResult, CheckStatus } from '@stryker-mutator/api/check';7import { mergeMap } from 'rxjs/operators';8import { Observable } from 'rxjs';9import { Mutant, MutantStatus, MutantTestCoverage } from '@stryker-mutator/api/core';10import { I, Task } from '@stryker-mutator/util';11import { MutationTestExecutor } from '../../../src/process';12import { coreTokens } from '../../../src/di';13import { createTestRunnerPoolMock, createCheckerPoolMock } from '../../helpers/producers';14import { MutationTestReportHelper } from '../../../src/reporters/mutation-test-report-helper';15import { Timer } from '../../../src/utils/timer';16import { ConcurrencyTokenProvider, Pool } from '../../../src/concurrent';17import { Sandbox } from '../../../src/sandbox';18describe(MutationTestExecutor.name, () => {19 let reporterMock: Required<Reporter>;20 let testRunnerPoolMock: sinon.SinonStubbedInstance<Pool<TestRunner>>;21 let checkerPoolMock: sinon.SinonStubbedInstance<Pool<Checker>>;22 let sut: MutationTestExecutor;23 let mutants: MutantTestCoverage[];24 let checker: sinon.SinonStubbedInstance<Checker>;25 let mutationTestReportCalculatorMock: sinon.SinonStubbedInstance<MutationTestReportHelper>;26 let timerMock: sinon.SinonStubbedInstance<Timer>;27 let testRunner: sinon.SinonStubbedInstance<Required<TestRunner>>;28 let concurrencyTokenProviderMock: sinon.SinonStubbedInstance<ConcurrencyTokenProvider>;29 let sandboxMock: sinon.SinonStubbedInstance<Sandbox>;30 beforeEach(() => {31 reporterMock = factory.reporter();32 mutationTestReportCalculatorMock = sinon.createStubInstance(MutationTestReportHelper);33 timerMock = sinon.createStubInstance(Timer);34 testRunner = factory.testRunner();35 testRunnerPoolMock = createTestRunnerPoolMock();36 checkerPoolMock = createCheckerPoolMock();37 checker = factory.checker();38 concurrencyTokenProviderMock = sinon.createStubInstance(ConcurrencyTokenProvider);39 sandboxMock = sinon.createStubInstance(Sandbox);40 (41 checkerPoolMock.schedule as sinon.SinonStub<42 [Observable<Mutant>, (testRunner: Checker, arg: Mutant) => Promise<CheckResult>],43 Observable<CheckResult>44 >45 ).callsFake((item$, task) => item$.pipe(mergeMap((item) => task(checker, item))));46 (47 testRunnerPoolMock.schedule as sinon.SinonStub<48 [Observable<MutantTestCoverage>, (testRunner: TestRunner, arg: MutantTestCoverage) => Promise<MutantRunResult>],49 Observable<MutantRunResult>50 >51 ).callsFake((item$, task) => item$.pipe(mergeMap((item) => task(testRunner, item))));52 mutants = [];53 sut = testInjector.injector54 .provideValue(coreTokens.reporter, reporterMock)55 .provideValue(coreTokens.checkerPool, checkerPoolMock as I<Pool<Checker>>)56 .provideValue(coreTokens.testRunnerPool, testRunnerPoolMock)57 .provideValue(coreTokens.timeOverheadMS, 42)58 .provideValue(coreTokens.mutantsWithTestCoverage, mutants)59 .provideValue(coreTokens.mutationTestReportHelper, mutationTestReportCalculatorMock)60 .provideValue(coreTokens.sandbox, sandboxMock)61 .provideValue(coreTokens.timer, timerMock)62 .provideValue(coreTokens.testRunnerPool, testRunnerPoolMock as I<Pool<TestRunner>>)63 .provideValue(coreTokens.concurrencyTokenProvider, concurrencyTokenProviderMock)64 .injectClass(MutationTestExecutor);65 });66 function arrangeScenario(overrides?: { checkResult?: CheckResult; mutantRunResult?: MutantRunResult }) {67 checker.check.resolves(overrides?.checkResult ?? factory.checkResult());68 testRunner.mutantRun.resolves(overrides?.mutantRunResult ?? factory.survivedMutantRunResult());69 }70 it('should schedule mutants to be tested', async () => {71 // Arrange72 arrangeScenario();73 mutants.push(factory.mutantTestCoverage({ id: '1', static: true }));74 mutants.push(factory.mutantTestCoverage({ id: '2', coveredBy: ['1'] }));75 // Act76 await sut.execute();77 // Assert78 expect(testRunnerPoolMock.schedule).calledOnce;79 expect(testRunner.mutantRun).calledWithMatch({ activeMutant: mutants[0] });80 expect(testRunner.mutantRun).calledWithMatch({ activeMutant: mutants[1] });81 });82 it('should short circuit ignored mutants (not check them or run them)', async () => {83 // Arrange84 mutants.push(factory.mutantTestCoverage({ id: '1', status: MutantStatus.Ignored, statusReason: '1 is ignored' }));85 mutants.push(factory.mutantTestCoverage({ id: '2', status: MutantStatus.Ignored, statusReason: '2 is ignored' }));86 // Act87 const actualResults = await sut.execute();88 // Assert89 expect(testRunner.mutantRun).not.called;90 expect(checker.check).not.called;91 expect(actualResults).lengthOf(2);92 });93 it('should check the mutants before running them', async () => {94 // Arrange95 arrangeScenario();96 mutants.push(factory.mutantTestCoverage({ id: '1' }));97 mutants.push(factory.mutantTestCoverage({ id: '2' }));98 // Act99 await sut.execute();100 // Assert101 expect(checker.check).calledTwice;102 expect(checker.check).calledWithMatch(mutants[0]);103 expect(checker.check).calledWithMatch(mutants[1]);104 });105 it('should calculate timeout correctly', async () => {106 // Arrange107 arrangeScenario();108 mutants.push(factory.mutantTestCoverage({ id: '1', estimatedNetTime: 10, coveredBy: ['1'] }));109 testInjector.options.timeoutFactor = 1.5;110 testInjector.options.timeoutMS = 27;111 // Act112 await sut.execute();113 // Assert114 const expected: Partial<MutantRunOptions> = { timeout: 84 }; // 42 (overhead) + 10*1.5 + 27115 expect(testRunner.mutantRun).calledWithMatch(expected);116 });117 it('should calculate the hit limit correctly', async () => {118 arrangeScenario();119 mutants.push(factory.mutantTestCoverage({ hitCount: 7, static: true }));120 // Act121 await sut.execute();122 // Assert123 const expected: Partial<MutantRunOptions> = { hitLimit: 700 }; // 7 * 100124 expect(testRunner.mutantRun).calledWithMatch(expected);125 });126 it('should set the hit limit to undefined when there was no hit count', async () => {127 arrangeScenario();128 mutants.push(factory.mutantTestCoverage({ hitCount: undefined, static: true }));129 const expected: Partial<MutantRunOptions> = { hitLimit: undefined };130 // Act131 await sut.execute();132 // Assert133 expect(testRunner.mutantRun).calledWithMatch(expected);134 });135 it('should passthrough the test filter', async () => {136 // Arrange137 arrangeScenario();138 const expectedTestFilter = ['spec1', 'foo', 'bar'];139 mutants.push(factory.mutantTestCoverage({ coveredBy: expectedTestFilter }));140 testInjector.options.timeoutFactor = 1.5;141 testInjector.options.timeoutMS = 27;142 // Act143 await sut.execute();144 // Assert145 const expected: Partial<MutantRunOptions> = { testFilter: expectedTestFilter };146 expect(testRunner.mutantRun).calledWithMatch(expected);147 });148 it('should provide the sandboxFileName', async () => {149 // Arrange150 arrangeScenario();151 const expectedTestFilter = ['spec1', 'foo', 'bar'];152 sandboxMock.sandboxFileFor.returns('.stryker-tmp/sandbox1234/src/foo.js');153 mutants.push(factory.mutantTestCoverage({ coveredBy: expectedTestFilter, fileName: 'src/foo.js' }));154 testInjector.options.timeoutFactor = 1.5;155 testInjector.options.timeoutMS = 27;156 // Act157 await sut.execute();158 // Assert159 const expected: Partial<MutantRunOptions> = { sandboxFileName: '.stryker-tmp/sandbox1234/src/foo.js' };160 expect(testRunner.mutantRun).calledWithMatch(expected);161 expect(sandboxMock.sandboxFileFor).calledWithExactly('src/foo.js');162 });163 it('should pass disableBail to test runner', async () => {164 // Arrange165 arrangeScenario();166 mutants.push(factory.mutantTestCoverage({ id: '1', coveredBy: ['1'] }));167 testInjector.options.disableBail = true;168 // Act169 await sut.execute();170 // Assert171 const expected: Partial<MutantRunOptions> = { disableBail: true };172 expect(testRunner.mutantRun).calledWithMatch(expected);173 });174 it('should not run mutants that are uncovered by tests', async () => {175 // Arrange176 arrangeScenario();177 mutants.push(factory.mutantTestCoverage({ id: '1', coveredBy: undefined, static: false }));178 // Act179 await sut.execute();180 // Assert181 expect(testRunner.mutantRun).not.called;182 });183 it('should report an ignored mutant as `Ignored`', async () => {184 // Arrange185 arrangeScenario();186 mutants.push(factory.mutantTestCoverage({ id: '1', status: MutantStatus.Ignored, statusReason: '1 is ignored' }));187 // Act188 await sut.execute();189 // Assert190 expect(mutationTestReportCalculatorMock.reportMutantStatus).calledWithExactly(mutants[0], MutantStatus.Ignored);191 });192 it('should report an uncovered mutant with `NoCoverage`', async () => {193 // Arrange194 arrangeScenario();195 mutants.push(factory.mutantTestCoverage({ id: '1', coveredBy: undefined, status: MutantStatus.NoCoverage }));196 // Act197 await sut.execute();198 // Assert199 expect(mutationTestReportCalculatorMock.reportMutantStatus).calledWithExactly(mutants[0], MutantStatus.NoCoverage);200 });201 it('should report non-passed check results as "checkFailed"', async () => {202 // Arrange203 const mutant = factory.mutantTestCoverage({ id: '1' });204 const failedCheckResult = factory.checkResult({ reason: 'Cannot find foo() of `undefined`', status: CheckStatus.CompileError });205 checker.check.resolves(failedCheckResult);206 mutants.push(mutant);207 // Act208 await sut.execute();209 // Assert210 expect(mutationTestReportCalculatorMock.reportCheckFailed).calledWithExactly(mutant, failedCheckResult);211 });212 it('should free checker resources after checking stage is complete', async () => {213 // Arrange214 mutants.push(factory.mutantTestCoverage({ id: '1' }));215 const checkTask = new Task<CheckResult>();216 const testRunnerTask = new Task<MutantRunResult>();217 testRunner.mutantRun.returns(testRunnerTask.promise);218 checker.check.returns(checkTask.promise);219 // Act & assert220 const executePromise = sut.execute();221 checkTask.resolve(factory.checkResult());222 await tick(2);223 expect(checkerPoolMock.dispose).called;224 expect(concurrencyTokenProviderMock.freeCheckers).called;225 testRunnerTask.resolve(factory.killedMutantRunResult());226 await executePromise;227 });228 it('should report mutant run results', async () => {229 // Arrange230 const mutant = factory.mutantTestCoverage({ static: true });231 const mutantRunResult = factory.killedMutantRunResult({ status: MutantRunStatus.Killed });232 mutants.push(mutant);233 arrangeScenario({ mutantRunResult });234 // Act235 await sut.execute();236 // Assert237 expect(mutationTestReportCalculatorMock.reportMutantRunResult).calledWithExactly(mutant, mutantRunResult);238 });239 it('should log a done message when it is done', async () => {240 // Arrange241 timerMock.humanReadableElapsed.returns('2 seconds, tops!');242 // Act243 await sut.execute();244 // Assert245 expect(testInjector.logger.info).calledWithExactly('Done in %s.', '2 seconds, tops!');246 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { testRunnerTask } = require('stryker-parent');2module.exports = function (config) {3 return testRunnerTask(config);4};5module.exports = function (config) {6 config.set({7 });8};9{10 "scripts": {11 },12 "repository": {

Full Screen

Using AI Code Generation

copy

Full Screen

1const testRunnerTask = require('stryker-parent').testRunnerTask;2module.exports = function (grunt) {3 testRunnerTask(grunt, {4 });5};6{7 "scripts": {8 },9 "repository": {

Full Screen

Using AI Code Generation

copy

Full Screen

1const testRunnerTask = require('stryker-parent').testRunnerTask;2module.exports = function (grunt) {3 grunt.registerTask('test', testRunnerTask(grunt));4};5module.exports = function (config) {6 config.set({7 });8};9{10 "scripts": {11 },12 "devDependencies": {13 }14}

Full Screen

Using AI Code Generation

copy

Full Screen

1var testRunnerTask = require('stryker-parent').testRunnerTask;2module.exports = function (grunt) {3 grunt.registerTask('test', testRunnerTask(grunt));4};5module.exports = function (config) {6 config.set({7 });8};9module.exports = function (config) {10 config.set({11 });12};13{14 "scripts": {15 },16 "dependencies": {17 },18 "devDependencies": {19 }20}

Full Screen

Using AI Code Generation

copy

Full Screen

1const testRunnerTask = require('stryker-parent').testRunnerTask;2module.exports = function (grunt) {3 grunt.registerTask('test', testRunnerTask(grunt, {4 { pattern: 'src/**/*.js', mutated: true, included: false },5 { pattern: 'test/**/*.js', mutated: false, included: false }6 karma: {7 }8 }));9};10module.exports = function(config) {11 config.set({12 });13};14module.exports = function(config) {15 config.set({16 { pattern: 'src/**/*.js', mutated: true, included: false },17 { pattern: 'test/**/*.js', mutated: false, included: false }18 karma: {19 }20 });21};22{23 "scripts": {24 },25 "devDependencies": {

Full Screen

Using AI Code Generation

copy

Full Screen

1const testRunnerTask = require('stryker-parent').testRunnerTask;2testRunnerTask(__dirname);3module.exports = function (config) {4 config.set({5 { pattern: 'test.js', mutated: false, included: true },6 { pattern: 'src/**/*.js', mutated: true, included: false },7 })8}9module.exports = function (config) {10 config.set({11 karma: {12 }13 });14};

Full Screen

Using AI Code Generation

copy

Full Screen

1const testRunnerTask = require('stryker-parent').testRunnerTask;2module.exports = function(config){3 testRunnerTask(config);4}5module.exports = function(config){6 config.set({7 });8};9const testRunnerTask = require('stryker-parent').testRunnerTask;10module.exports = function(config){11 testRunnerTask(config);12}13module.exports = function(config){14 config.set({15 });16};17const testRunnerTask = require('stryker-parent').testRunnerTask;18module.exports = function(config){19 testRunnerTask(config);20}21module.exports = function(config){22 config.set({23 });24};25const testRunnerTask = require('stryker-parent').testRunnerTask;26module.exports = function(config){27 testRunnerTask(config);28}29module.exports = function(config){30 config.set({31 });32};33const testRunnerTask = require('stryker-parent').testRunnerTask;34module.exports = function(config){35 testRunnerTask(config);36}37module.exports = function(config){38 config.set({39 });40};41const testRunnerTask = require('stryker-parent').testRunnerTask;42module.exports = function(config){43 testRunnerTask(config);44}45module.exports = function(config){46 config.set({47 });48};49const testRunnerTask = require('stryker-parent').testRunnerTask;50module.exports = function(config){51 testRunnerTask(config);52}

Full Screen

Using AI Code Generation

copy

Full Screen

1var testRunnerTask = require('stryker-parent').testRunnerTask;2testRunnerTask({3});4module.exports = function(config) {5 config.set({6 });7};8{9 "devDependencies": {10 }11}12module.exports = function(config) {13 config.set({14 });15};16module.exports = function(config) {17 config.set({18 });19};20module.exports = function(config) {21 config.set({22 });23};24module.exports = function(config) {25 config.set({26 });27};28module.exports = function(config) {29 config.set({30 });31};32module.exports = function(config) {33 config.set({34 });35};36module.exports = function(config) {37 config.set({38 });39};40module.exports = function(config) {41 config.set({42 });43};44module.exports = function(config) {45 config.set({

Full Screen

Using AI Code Generation

copy

Full Screen

1const testRunnerTask = require('stryker-parent').testRunnerTask;2module.exports = function (grunt) {3 grunt.registerTask('testRunner', testRunnerTask(grunt));4};5module.exports = function(grunt) {6 grunt.loadNpmTasks('grunt-contrib-clean');7 grunt.loadNpmTasks('grunt-mocha-test');8 grunt.loadNpmTasks('grunt-ts');9 grunt.loadTasks('tasks');10 grunt.initConfig({11 clean: {12 build: {13 }14 },15 mochaTest: {16 unit: {17 options: {18 },19 }20 },21 ts: {22 build: {23 }24 }25 });26 grunt.registerTask('default', ['clean', 'ts:build', 'testRunner']);27};28module.exports = function(config) {29 config.set({30 });31};32{33 "scripts": {34 },35 "devDependencies": {

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