How to use childSuite method in stryker-parent

Best JavaScript code snippet using stryker-parent

suite.unit.js

Source:suite.unit.js Github

copy

Full Screen

1'use strict';2const { expect, use: chaiUse } = require('chai');3const sinon = require('sinon');4const sinonChai = require('sinon-chai');5const Suite = require('../lib/suite');6chaiUse(sinonChai);7describe('Suite', () => {8 describe('Title', () => {9 it('should set the suite title', () => {10 const suite = new Suite('my title');11 expect(suite.title).to.equal('my title');12 });13 it('should set the title property to be readonly', () => {14 const suite = new Suite();15 expect(() => { suite.title = 'sup'; }).to.throw(TypeError);16 });17 });18 describe('Add Service', () => {19 it('should set the service property to be readonly', () => {20 const suite = new Suite();21 expect(() => { suite.services = {}; }).to.throw(TypeError);22 });23 it('should add a service', () => {24 const suite = new Suite();25 expect(suite.services).to.deep.equals({});26 suite.addServiceHook('my service', 'http://localhost:1234');27 suite.setServiceHooks[0]();28 expect(suite.services).to.deep.equals({29 'my service': 'http://localhost:1234',30 });31 });32 it('should get services from parent suite', () => {33 const parentSuite = new Suite();34 parentSuite.addServiceHook('my service', 'http://localhost:1234');35 parentSuite.setServiceHooks[0]();36 expect(parentSuite.services).to.deep.equals({37 'my service': 'http://localhost:1234',38 });39 // Test...40 const childSuite = new Suite('child', parentSuite);41 expect(childSuite.services).to.deep.equals({42 'my service': 'http://localhost:1234',43 });44 });45 it('should concat child and parent services', () => {46 const parentSuite = new Suite();47 parentSuite.addServiceHook('my service', 'http://localhost:1234');48 parentSuite.setServiceHooks[0]();49 expect(parentSuite.services).to.deep.equals({50 'my service': 'http://localhost:1234',51 });52 // Test...53 const childSuite = new Suite('child', parentSuite);54 childSuite.addServiceHook('my other service', 'http://localhost:5678');55 childSuite.setServiceHooks[0]();56 expect(childSuite.services).to.deep.equals({57 'my service': 'http://localhost:1234',58 'my other service': 'http://localhost:5678',59 });60 });61 it('should concat child and parent services even if parent added service later', () => {62 const parentSuite = new Suite();63 parentSuite.addServiceHook('my service', 'http://localhost:1234');64 const childSuite = new Suite('child', parentSuite);65 childSuite.addServiceHook('my other service', 'http://localhost:5678');66 childSuite.setServiceHooks[0]();67 parentSuite.setServiceHooks[0]();68 expect(parentSuite.services).to.deep.equals({69 'my service': 'http://localhost:1234',70 });71 expect(childSuite.services).to.deep.equals({72 'my service': 'http://localhost:1234',73 'my other service': 'http://localhost:5678',74 });75 });76 });77 describe('Route', () => {78 it('should set the routes property to be readonly', () => {79 const suite = new Suite();80 expect(() => { suite.routes = {}; }).to.throw(TypeError);81 });82 it('should add a route', () => {83 const suite = new Suite();84 expect(suite.routes).to.deep.equals({});85 suite.addRoute('status', {86 method: 'get',87 route: 'status',88 expectedStatusCode: 200,89 maxMean: 0.2, // 200ms90 });91 expect(suite.routes).to.deep.equals({92 status: {93 method: 'get',94 route: 'status',95 expectedStatusCode: 200,96 maxMean: 0.2, // 200ms97 },98 });99 });100 it('should get services from parent suite', () => {101 const parentSuite = new Suite();102 parentSuite.addRoute('status', {103 method: 'get',104 route: 'status',105 expectedStatusCode: 200,106 maxMean: 0.2, // 200ms107 });108 expect(parentSuite.routes).to.deep.equals({109 status: {110 method: 'get',111 route: 'status',112 expectedStatusCode: 200,113 maxMean: 0.2, // 200ms114 },115 });116 // Test...117 const childSuite = new Suite('child', parentSuite);118 expect(childSuite.routes).to.deep.equals({119 status: {120 method: 'get',121 route: 'status',122 expectedStatusCode: 200,123 maxMean: 0.2, // 200ms124 },125 });126 });127 it('should concat child and parent routes', () => {128 const parentSuite = new Suite();129 parentSuite.addRoute('status', {130 method: 'get',131 route: 'status',132 expectedStatusCode: 200,133 maxMean: 0.2, // 200ms134 });135 expect(parentSuite.routes).to.deep.equals({136 status: {137 method: 'get',138 route: 'status',139 expectedStatusCode: 200,140 maxMean: 0.2, // 200ms141 },142 });143 // Test...144 const childSuite = new Suite('child', parentSuite);145 childSuite.addRoute('version', {146 method: 'get',147 route: 'version',148 expectedStatusCode: 200,149 maxMean: 0.2, // 200ms150 });151 expect(childSuite.routes).to.deep.equals({152 status: {153 method: 'get',154 route: 'status',155 expectedStatusCode: 200,156 maxMean: 0.2, // 200ms157 },158 version: {159 method: 'get',160 route: 'version',161 expectedStatusCode: 200,162 maxMean: 0.2, // 200ms163 },164 });165 });166 });167 describe('Options', () => {168 it('should set the options property to be readonly', () => {169 const suite = new Suite();170 expect(() => { suite.options = {}; }).to.throw(TypeError);171 });172 it('should initialize to default options', () => {173 const suite = new Suite();174 expect(suite.options).to.deep.equals({175 debug: false,176 runMode: 'sequence',177 maxConcurrentRequests: 100,178 delay: 0,179 maxTime: 10,180 minSamples: 20,181 stopOnError: true,182 });183 });184 it('should set options', () => {185 const suite = new Suite();186 suite.setOptions({187 debug: true,188 runMode: 'parallel',189 minSamples: 200,190 maxTime: 20,191 });192 expect(suite.options).to.deep.equals({193 debug: true,194 delay: 0,195 maxConcurrentRequests: 100,196 runMode: 'parallel',197 minSamples: 200,198 maxTime: 20,199 stopOnError: true,200 });201 });202 it('should over write options', () => {203 const suite = new Suite();204 suite.setOptions({205 debug: true,206 runMode: 'parallel',207 minSamples: 200,208 maxTime: 20,209 });210 expect(suite.options).to.deep.equals({211 debug: true,212 delay: 0,213 maxConcurrentRequests: 100,214 runMode: 'parallel',215 minSamples: 200,216 maxTime: 20,217 stopOnError: true,218 });219 suite.setOptions({220 debug: false,221 runMode: 'sequential',222 minSamples: 400,223 });224 expect(suite.options).to.deep.equals({225 debug: false,226 delay: 0,227 maxConcurrentRequests: 100,228 runMode: 'sequential',229 minSamples: 400,230 maxTime: 10,231 stopOnError: true,232 });233 });234 it('should reset to default options', () => {235 const suite = new Suite();236 suite.setOptions({237 debug: true,238 runMode: 'parallel',239 minSamples: 200,240 maxTime: 20,241 });242 expect(suite.options).to.deep.equals({243 debug: true,244 delay: 0,245 maxConcurrentRequests: 100,246 runMode: 'parallel',247 minSamples: 200,248 maxTime: 20,249 stopOnError: true,250 });251 suite.setOptions({});252 expect(suite.options).to.deep.equals({253 debug: false,254 delay: 0,255 maxConcurrentRequests: 100,256 runMode: 'sequence',257 minSamples: 20,258 maxTime: 10,259 stopOnError: true,260 });261 });262 it('should get options from parent suite', () => {263 const parentSuite = new Suite();264 parentSuite.setOptions({265 debug: true,266 runMode: 'parallel',267 minSamples: 200,268 maxTime: 20,269 });270 // Test...271 const childSuite = new Suite('child', parentSuite);272 expect(childSuite.options).to.deep.equals({273 debug: true,274 delay: 0,275 maxConcurrentRequests: 100,276 runMode: 'parallel',277 minSamples: 200,278 maxTime: 20,279 stopOnError: true,280 });281 });282 it('should overwrite parent options', () => {283 const parentSuite = new Suite();284 parentSuite.setOptions({285 debug: true,286 runMode: 'parallel',287 minSamples: 200,288 maxTime: 20,289 });290 // Test...291 const childSuite = new Suite('child', parentSuite);292 childSuite.setOptions({293 runMode: 'parallel',294 minSamples: 200,295 maxTime: 20,296 });297 expect(childSuite.options).to.deep.equals({298 debug: false,299 delay: 0,300 maxConcurrentRequests: 100,301 runMode: 'parallel',302 minSamples: 200,303 maxTime: 20,304 stopOnError: true,305 });306 });307 });308 describe('Add After', () => {309 it('should add a after hook', () => {310 const suite = new Suite();311 expect(suite.afters).to.be.empty;312 suite.addAfter(() => {});313 expect(suite.afters).to.have.length(1);314 });315 it('should not add an undefined after hook', () => {316 const suite = new Suite();317 expect(suite.afters).to.be.empty;318 suite.addAfter();319 expect(suite.afters).to.have.length(0);320 });321 it('should not add a non function as an after hook', () => {322 const suite = new Suite();323 expect(suite.afters).to.be.empty;324 suite.addAfter(42);325 expect(suite.afters).to.have.length(0);326 });327 });328 describe('Add Before', () => {329 it('should add a before hook', () => {330 const suite = new Suite();331 expect(suite.befores).to.be.empty;332 suite.addBefore(() => {});333 expect(suite.befores).to.have.length(1);334 });335 it('should not add an undefined before hook', () => {336 const suite = new Suite();337 expect(suite.befores).to.be.empty;338 suite.addBefore();339 expect(suite.befores).to.have.length(0);340 });341 it('should not add a non function as an before hook', () => {342 const suite = new Suite();343 expect(suite.befores).to.be.empty;344 suite.addBefore(42);345 expect(suite.befores).to.have.length(0);346 });347 });348 describe('Invoke Service Hook', () => {349 it('should call service hook', () => {350 const serviceCallback = sinon.stub();351 const suite = new Suite();352 suite.addServiceHook('name', serviceCallback);353 expect(suite.setServiceHooks).to.have.length(1);354 return suite.invokeServiceHooks()355 .then(() => {356 expect(serviceCallback).to.have.been.calledOnce;357 });358 });359 it('should call parents service hook', () => {360 const serviceCallback = sinon.stub();361 const parentSuite = new Suite('parent');362 parentSuite.addServiceHook('name', serviceCallback);363 expect(parentSuite.setServiceHooks).to.have.length(1);364 const childSuite = new Suite('child', parentSuite);365 expect(childSuite.setServiceHooks).to.be.empty;366 return childSuite.invokeServiceHooks()367 .then(() => {368 expect(serviceCallback).to.have.been.calledOnce;369 });370 });371 it('should call both parent and child\'s service hooks', () => {372 const serviceCallback = sinon.stub();373 const parentSuite = new Suite('parent');374 parentSuite.addServiceHook('name', serviceCallback);375 expect(parentSuite.setServiceHooks).to.have.length(1);376 const serviceCallback2 = sinon.stub();377 const childSuite = new Suite('child', parentSuite);378 childSuite.addServiceHook('name', serviceCallback2);379 expect(childSuite.setServiceHooks).to.have.length(1);380 return childSuite.invokeServiceHooks()381 .then(() => {382 expect(serviceCallback, 'parent hook').to.have.been.calledOnce;383 expect(serviceCallback2, 'child hook').to.have.been.calledOnce;384 });385 });386 it('should not call service hook twice', () => {387 const serviceCallback = sinon.stub();388 const suite = new Suite('me');389 suite.addServiceHook('name', serviceCallback);390 expect(suite.setServiceHooks).to.have.length(1);391 return suite.invokeServiceHooks()392 .then(() => suite.invokeServiceHooks())393 .then(() => {394 expect(serviceCallback).to.have.been.calledOnce;395 });396 });397 });398 describe('Invoke Befores', () => {399 it('should call before hook', () => {400 const beforeCallback = sinon.stub();401 const suite = new Suite();402 suite.addBefore(beforeCallback);403 expect(suite.befores).to.have.length(1);404 return suite.invokeBefores()405 .then(() => {406 expect(beforeCallback).to.have.been.calledOnce;407 });408 });409 it('should call parents before hook', () => {410 const beforeCallback = sinon.stub();411 const parentSuite = new Suite('parent');412 parentSuite.addBefore(beforeCallback);413 expect(parentSuite.befores).to.have.length(1);414 const childSuite = new Suite('child', parentSuite);415 expect(childSuite.befores).to.be.empty;416 return childSuite.invokeBefores()417 .then(() => {418 expect(beforeCallback).to.have.been.calledOnce;419 });420 });421 it('should call both parent and child\'s before hooks', () => {422 const beforeCallback = sinon.stub();423 const parentSuite = new Suite('parent');424 parentSuite.addBefore(beforeCallback);425 expect(parentSuite.befores).to.have.length(1);426 const beforeCallback2 = sinon.stub();427 const childSuite = new Suite('child', parentSuite);428 childSuite.addBefore(beforeCallback2);429 expect(childSuite.befores).to.have.length(1);430 return childSuite.invokeBefores()431 .then(() => {432 expect(beforeCallback, 'parent hook').to.have.been.calledOnce;433 expect(beforeCallback2, 'child hook').to.have.been.calledOnce;434 });435 });436 it('should not call before hook twice', () => {437 const beforeCallback = sinon.stub();438 const suite = new Suite();439 suite.addBefore(beforeCallback);440 expect(suite.befores).to.have.length(1);441 return suite.invokeBefores()442 .then(() => suite.invokeBefores())443 .then(() => {444 expect(beforeCallback).to.have.been.calledOnce;445 });446 });447 });448 describe('Invoke Afters', () => {449 it('should call after hook', () => {450 const afterCallback = sinon.stub();451 const suite = new Suite();452 suite.addAfter(afterCallback);453 expect(suite.afters).to.have.length(1);454 return suite.invokeAfters()455 .then(() => {456 expect(afterCallback).to.have.been.calledOnce;457 });458 });459 it('should not call parents after hook', () => {460 const afterCallback = sinon.stub();461 const parentSuite = new Suite('parent');462 parentSuite.addAfter(afterCallback);463 expect(parentSuite.afters).to.have.length(1);464 const childSuite = new Suite('child', parentSuite);465 expect(childSuite.afters).to.be.empty;466 return childSuite.invokeAfters()467 .then(() => {468 expect(afterCallback).to.have.not.been.called;469 });470 });471 it('should call only the child\'s after hooks', () => {472 const afterCallback = sinon.stub();473 const parentSuite = new Suite('parent');474 parentSuite.addAfter(afterCallback);475 expect(parentSuite.afters).to.have.length(1);476 const afterCallback2 = sinon.stub();477 const childSuite = new Suite('child', parentSuite);478 childSuite.addAfter(afterCallback2);479 expect(childSuite.afters).to.have.length(1);480 return childSuite.invokeAfters()481 .then(() => {482 expect(afterCallback, 'parent hook').to.have.not.been.called;483 expect(afterCallback2, 'child hook').to.have.been.calledOnce;484 });485 });486 it('should not call after hook twice', () => {487 const afterCallback = sinon.stub();488 const suite = new Suite();489 suite.addAfter(afterCallback);490 expect(suite.afters).to.have.length(1);491 return suite.invokeAfters()492 .then(() => suite.invokeAfters())493 .then(() => {494 expect(afterCallback).to.have.been.calledOnce;495 });496 });497 });...

Full Screen

Full Screen

mocha-test-runner.spec.ts

Source:mocha-test-runner.spec.ts Github

copy

Full Screen

1import { expect } from 'chai';2import Mocha from 'mocha';3import { testInjector, factory, assertions, tick } from '@stryker-mutator/test-helpers';4import sinon from 'sinon';5import { KilledMutantRunResult, MutantRunStatus, TestRunnerCapabilities } from '@stryker-mutator/api/test-runner';6import { Task } from '@stryker-mutator/util';7import { MochaTestRunner } from '../../src/mocha-test-runner.js';8import { StrykerMochaReporter } from '../../src/stryker-mocha-reporter.js';9import { MochaAdapter } from '../../src/mocha-adapter.js';10import * as pluginTokens from '../../src/plugin-tokens.js';11import { MochaOptionsLoader } from '../../src/mocha-options-loader.js';12import { createMochaOptions } from '../helpers/factories.js';13describe(MochaTestRunner.name, () => {14 let mocha: sinon.SinonStubbedInstance<Mocha> & { suite: sinon.SinonStubbedInstance<Mocha.Suite>; dispose?: sinon.SinonStub };15 let mochaAdapterMock: sinon.SinonStubbedInstance<MochaAdapter>;16 let mochaOptionsLoaderMock: sinon.SinonStubbedInstance<MochaOptionsLoader>;17 let reporterMock: sinon.SinonStubbedInstance<StrykerMochaReporter>;18 let testFileNames: string[];19 beforeEach(() => {20 reporterMock = sinon.createStubInstance(StrykerMochaReporter);21 reporterMock.tests = [];22 mochaAdapterMock = sinon.createStubInstance(MochaAdapter);23 mochaOptionsLoaderMock = sinon.createStubInstance(MochaOptionsLoader);24 mocha = sinon.createStubInstance(Mocha) as any;25 mocha.suite = sinon.createStubInstance(Mocha.Suite) as any;26 mocha.suite.suites = [];27 mochaAdapterMock.create.returns(mocha as unknown as Mocha);28 testFileNames = [];29 mochaAdapterMock.collectFiles.returns(testFileNames);30 });31 afterEach(() => {32 delete StrykerMochaReporter.log;33 });34 function createSut(): MochaTestRunner {35 return testInjector.injector36 .provideValue(pluginTokens.mochaAdapter, mochaAdapterMock)37 .provideValue(pluginTokens.loader, mochaOptionsLoaderMock)38 .provideValue(pluginTokens.globalNamespace, '__stryker2__' as const)39 .injectClass(MochaTestRunner);40 }41 describe('constructor', () => {42 it('should set the static `log` property on StrykerMochaReporter', () => {43 createSut();44 expect(StrykerMochaReporter.log).eq(testInjector.logger);45 });46 });47 describe('capabilities', () => {48 it('should communicate reloadEnvironment=false', async () => {49 const expectedCapabilities: TestRunnerCapabilities = { reloadEnvironment: false };50 expect(await createSut().capabilities()).deep.eq(expectedCapabilities);51 });52 });53 describe(MochaTestRunner.prototype.init.name, () => {54 let sut: MochaTestRunner;55 beforeEach(() => {56 sut = createSut();57 });58 it('should load mocha options', async () => {59 mochaOptionsLoaderMock.load.returns({});60 await sut.init();61 expect(mochaOptionsLoaderMock.load).calledWithExactly(testInjector.options);62 });63 it('should collect the files', async () => {64 testFileNames.push('foo.js', 'foo.spec.js');65 const mochaOptions = Object.freeze(createMochaOptions());66 mochaOptionsLoaderMock.load.returns(mochaOptions);67 await sut.init();68 expect(mochaAdapterMock.collectFiles).calledWithExactly(mochaOptions);69 testFileNames.forEach((fileName) => {70 expect(mocha.addFile).calledWith(fileName);71 });72 });73 it('should not handle requires when there are no `requires`', async () => {74 mochaOptionsLoaderMock.load.returns({});75 await sut.init();76 expect(mochaAdapterMock.handleRequires).not.called;77 });78 it('should handle requires and collect root hooks', async () => {79 const requires = ['test/setup.js'];80 // eslint-disable-next-line @typescript-eslint/no-empty-function81 const expectedRootHooks = { beforeEach() {} };82 mochaOptionsLoaderMock.load.returns(createMochaOptions({ require: requires }));83 mochaAdapterMock.handleRequires.resolves(expectedRootHooks);84 await sut.init();85 const expectedMochaOptions: Mocha.MochaOptions = { rootHooks: expectedRootHooks };86 expect(mochaAdapterMock.create).calledWith(sinon.match(expectedMochaOptions));87 });88 it('should reject when requires contains "esm" (see #3014)', async () => {89 const requires = ['esm', 'ts-node/require'];90 mochaOptionsLoaderMock.load.returns(createMochaOptions({ require: requires }));91 await expect(sut.init()).rejectedWith(92 'Config option "mochaOptions.require" does not support "esm", please use `"testRunnerNodeArgs": ["--require", "esm"]` instead. See https://github.com/stryker-mutator/stryker-js/issues/3014 for more information.'93 );94 });95 it('should pass along supported options to mocha', async () => {96 // Arrange97 const mochaOptions = Object.freeze(98 createMochaOptions({99 'async-only': true,100 grep: 'grepme',101 opts: 'opts',102 require: [],103 ui: 'exports',104 })105 );106 mochaOptionsLoaderMock.load.returns(mochaOptions);107 // Act108 await sut.init();109 // Assert110 expect(mocha.asyncOnly).called;111 expect(mocha.ui).calledWith('exports');112 expect(mocha.grep).calledWith('grepme');113 });114 it('should force timeout off', async () => {115 mochaOptionsLoaderMock.load.returns({});116 await sut.init();117 expect(mochaAdapterMock.create).calledWithMatch({ timeout: 0 });118 });119 it('should not set asyncOnly if asyncOnly is false', async () => {120 // Arrange121 const mochaOptions = Object.freeze(122 createMochaOptions({123 'async-only': false,124 })125 );126 mochaOptionsLoaderMock.load.returns(mochaOptions);127 // Act128 await sut.init();129 expect(mocha.asyncOnly).not.called;130 });131 });132 describe(MochaTestRunner.prototype.dryRun.name, () => {133 let sut: MochaTestRunner;134 beforeEach(async () => {135 mochaOptionsLoaderMock.load.returns({});136 sut = createSut();137 await sut.init();138 });139 it('should load files the first time', async () => {140 await actDryRun();141 expect(mocha.loadFilesAsync).calledOnceWithExactly();142 expect(mocha.loadFilesAsync).calledBefore(mocha.run);143 });144 it('should not load files again the second time', async () => {145 await actDryRun();146 await actDryRun();147 expect(mocha.loadFilesAsync).calledOnceWithExactly();148 });149 it('should set bail to true when disableBail is false', async () => {150 const childSuite = sinon.createStubInstance(Mocha.Suite);151 mocha.suite.suites.push(childSuite);152 childSuite.suites = [];153 await actDryRun(factory.dryRunOptions({ disableBail: false }));154 expect(mocha.suite.bail).calledWith(true);155 expect(childSuite.bail).calledWith(true);156 });157 it('should set bail to false when disableBail is true', async () => {158 const childSuite = sinon.createStubInstance(Mocha.Suite);159 mocha.suite.suites.push(childSuite);160 childSuite.suites = [];161 await actDryRun(factory.dryRunOptions({ disableBail: true }));162 expect(mocha.suite.bail).calledWith(false);163 expect(childSuite.bail).calledWith(false);164 });165 it('should add a beforeEach hook if coverage analysis is "perTest"', async () => {166 const runPromise = sut.dryRun(factory.dryRunOptions({ coverageAnalysis: 'perTest' }));167 sut.beforeEach!({ currentTest: { fullTitle: () => 'foo should be bar' } } as Mocha.Context);168 mocha.run.callsArg(0);169 await runPromise;170 expect(sut.beforeEach).undefined;171 expect(global.__stryker2__?.currentTestId).eq('foo should be bar');172 });173 it('should not add a beforeEach hook if coverage analysis isn\'t "perTest"', async () => {174 const runPromise = sut.dryRun(factory.dryRunOptions({ coverageAnalysis: 'all' }));175 expect(sut.beforeEach).undefined;176 mocha.run.callsArg(0);177 await runPromise;178 });179 it('should collect mutant coverage', async () => {180 StrykerMochaReporter.currentInstance = reporterMock;181 reporterMock.tests = [];182 global.__stryker2__!.mutantCoverage = factory.mutantCoverage({ static: { 1: 2 } });183 const result = await actDryRun(factory.dryRunOptions({ coverageAnalysis: 'all' }));184 assertions.expectCompleted(result);185 expect(result.mutantCoverage).deep.eq(factory.mutantCoverage({ static: { 1: 2 } }));186 });187 it('should not collect mutant coverage if coverageAnalysis is "off"', async () => {188 StrykerMochaReporter.currentInstance = reporterMock;189 reporterMock.tests = [];190 global.__stryker2__!.mutantCoverage = factory.mutantCoverage({ static: { 1: 2 } });191 const result = await actDryRun(factory.dryRunOptions({ coverageAnalysis: 'off' }));192 assertions.expectCompleted(result);193 expect(result.mutantCoverage).undefined;194 });195 it('should result in the reported tests', async () => {196 const expectedTests = [factory.successTestResult(), factory.failedTestResult()];197 StrykerMochaReporter.currentInstance = reporterMock;198 reporterMock.tests = expectedTests;199 const result = await actDryRun(factory.dryRunOptions({ coverageAnalysis: 'off' }));200 assertions.expectCompleted(result);201 expect(result.tests).eq(expectedTests);202 });203 it("should result an error if the StrykerMochaReporter isn't set correctly", async () => {204 const result = await actDryRun(factory.dryRunOptions({ coverageAnalysis: 'off' }));205 assertions.expectErrored(result);206 expect(result.errorMessage).eq("Mocha didn't instantiate the StrykerMochaReporter correctly. Test result cannot be reported.");207 });208 async function actDryRun(options = factory.dryRunOptions()) {209 mocha.run.callsArg(0);210 return sut.dryRun(options);211 }212 });213 describe(MochaTestRunner.prototype.mutantRun.name, () => {214 let sut: MochaTestRunner;215 beforeEach(async () => {216 mochaOptionsLoaderMock.load.returns({});217 sut = createSut();218 await sut.init();219 StrykerMochaReporter.currentInstance = reporterMock;220 });221 it("should activate the given mutant statically when mutantActivation = 'static'", async () => {222 // Arrange223 const loadFilesAsyncTask = new Task();224 mocha.loadFilesAsync.returns(loadFilesAsyncTask.promise);225 // Act226 const onGoingAct = actMutantRun(227 factory.mutantRunOptions({ activeMutant: factory.mutantTestCoverage({ id: '42' }), mutantActivation: 'static' })228 );229 // Assert230 expect(global.__stryker2__?.activeMutant).eq('42');231 loadFilesAsyncTask.resolve();232 await tick();233 expect(global.__stryker2__?.activeMutant).eq('42');234 expect(mocha.run).called;235 await onGoingAct;236 });237 it("should activate the given mutant at runtime when mutantActivation = 'runtime'", async () => {238 // Arrange239 const loadFilesAsyncTask = new Task();240 mocha.loadFilesAsync.returns(loadFilesAsyncTask.promise);241 // Act242 const onGoingAct = actMutantRun(243 factory.mutantRunOptions({ activeMutant: factory.mutantTestCoverage({ id: '42' }), mutantActivation: 'runtime' })244 );245 // Assert246 expect(global.__stryker2__?.activeMutant).eq(undefined);247 loadFilesAsyncTask.resolve();248 await tick();249 expect(global.__stryker2__?.activeMutant).eq('42');250 expect(mocha.run).called;251 await onGoingAct;252 });253 it('should set bail to true when disableBail is false', async () => {254 const childSuite = sinon.createStubInstance(Mocha.Suite);255 mocha.suite.suites.push(childSuite);256 childSuite.suites = [];257 await actMutantRun(factory.mutantRunOptions({ disableBail: false }));258 expect(mocha.suite.bail).calledWith(true);259 expect(childSuite.bail).calledWith(true);260 });261 it('should set bail to false when disableBail is true', async () => {262 const childSuite = sinon.createStubInstance(Mocha.Suite);263 mocha.suite.suites.push(childSuite);264 childSuite.suites = [];265 await actMutantRun(factory.mutantRunOptions({ disableBail: true }));266 expect(mocha.suite.bail).calledWith(false);267 expect(childSuite.bail).calledWith(false);268 });269 it('should use `grep` to when the test filter is specified', async () => {270 await actMutantRun(factory.mutantRunOptions({ testFilter: ['foo should be bar', 'baz should be qux'] }));271 expect(mocha.grep).calledWith(new RegExp('(foo should be bar)|(baz should be qux)'));272 });273 it('should escape regex characters when filtering', async () => {274 await actMutantRun(factory.mutantRunOptions({ testFilter: ['should escape *.\\, but not /'] }));275 expect(mocha.grep).calledWith(new RegExp('(should escape \\*\\.\\\\, but not /)'));276 });277 it('should be able to report a killed mutant when a test fails', async () => {278 reporterMock.tests = [factory.successTestResult(), factory.failedTestResult({ id: 'foo should be bar', failureMessage: 'foo was baz' })];279 const result = await actMutantRun();280 const expectedResult: KilledMutantRunResult = {281 failureMessage: 'foo was baz',282 killedBy: ['foo should be bar'],283 status: MutantRunStatus.Killed,284 nrOfTests: 2,285 };286 expect(result).deep.eq(expectedResult);287 });288 it('should be able report a survived mutant when all test succeed', async () => {289 reporterMock.tests = [factory.successTestResult(), factory.successTestResult()];290 const result = await actMutantRun();291 assertions.expectSurvived(result);292 });293 it('should report a timeout when the hitLimit was reached', async () => {294 reporterMock.tests = [factory.failedTestResult()];295 const result = await actMutantRun(factory.mutantRunOptions({ hitLimit: 9 }), 10);296 assertions.expectTimeout(result);297 expect(result.reason).contains('Hit limit reached (10/9)');298 });299 it('should reset the hitLimit between runs', async () => {300 reporterMock.tests = [factory.failedTestResult()];301 const firstResult = await actMutantRun(factory.mutantRunOptions({ hitLimit: 9 }), 10);302 reporterMock.tests = [factory.failedTestResult()];303 const secondResult = await actMutantRun(factory.mutantRunOptions({ hitLimit: undefined }), 10);304 assertions.expectTimeout(firstResult);305 assertions.expectKilled(secondResult);306 });307 async function actMutantRun(options = factory.mutantRunOptions(), hitCount?: number) {308 mocha.run.callsArg(0);309 const result = sut.mutantRun(options);310 global.__stryker2__!.hitCount = hitCount;311 return result;312 }313 });314 describe(MochaTestRunner.prototype.dispose.name, () => {315 let sut: MochaTestRunner;316 beforeEach(async () => {317 mochaOptionsLoaderMock.load.returns({});318 sut = createSut();319 await sut.init();320 });321 it('should dispose of mocha', async () => {322 await sut.dispose();323 expect(mocha.dispose).called;324 });325 });...

Full Screen

Full Screen

runner.spec.ts

Source:runner.spec.ts Github

copy

Full Screen

1import { Status } from '../src/result'2import Runnable from '../src/runnable'3import Runner, { normalizeRunOptions, RunOptions } from '../src/runner'4import Suite, { rootSymbol } from '../src/suite'5import Test from '../src/test'6const NOOP = jest.fn()7describe('runner', () => {8 it('should normalize passed options', () => {9 expect(normalizeRunOptions()).toMatchObject({10 bail: false,11 sequential: false,12 timeout: 10000,13 })14 expect(normalizeRunOptions({15 bail: true,16 timeout: 1000,17 })).toMatchObject({18 bail: true,19 sequential: false,20 timeout: 1000,21 })22 })23 // tslint:disable-next-line:max-classes-per-file24 class TimeoutTestRunnable extends Runnable {25 private cb: (options?: RunOptions) => void26 constructor(27 description: string,28 options: any = {},29 parent: Suite | null,30 cb: (options?: RunOptions) => void | null,31 ) {32 super(description, options, parent)33 this.cb = cb || NOOP34 }35 public async run(options?: RunOptions) {36 if (this.options.skip || this.options.todo) {37 return this.doSkip(this.options.todo)38 }39 this.doStart()40 this.result.addMessages('OK')41 this.result.status = Status.Passed42 this.cb(options)43 return this.doPass()44 }45 }46 it('should pass run options to children', async () => {47 const opts = { bail: true, timeout: 1234, sequential: true }48 const rootSuite = new Suite('root', {}, null)49 const childSuite = new Suite('child', {}, null)50 const cb1 = jest.fn()51 childSuite.addChildren(new TimeoutTestRunnable('1', opts, null, cb1))52 const grandchildSuite = new Suite('grandchild', {}, null)53 const cb2 = jest.fn()54 grandchildSuite.addChildren(new TimeoutTestRunnable('2', opts, null, cb2))55 childSuite.addChildren(grandchildSuite)56 rootSuite.addChildren(childSuite)57 rootSuite[rootSymbol] = true58 const runner = new Runner(rootSuite, opts)59 await runner.run()60 expect(cb1).toHaveBeenCalledWith(undefined)61 expect(cb2).toHaveBeenCalledWith(undefined)62 })63 it('should run a suite and children', async () => {64 const rootSuite = new Suite('root', {}, null)65 const childSuite = new Suite('child suite', {}, null)66 const childTest = new Test('child test', NOOP, {}, null)67 const childTestTwo = new Test('child test two', NOOP, {}, null)68 childSuite.addChildren(childTest, childTestTwo)69 rootSuite.addChildren(childSuite)70 rootSuite[rootSymbol] = true71 const runner = new Runner(rootSuite)72 expect(runner.stats.pending).toBe(2)73 expect(await runner.run()).toBe(runner.stats)74 expect(runner.stats.passed).toBe(2)75 })...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var childSuite = require('stryker-parent').childSuite;2childSuite('childSuite', function () {3 it('should pass', function () {4 expect(true).toBe(true);5 });6});7var childSuite = require('stryker-parent').childSuite;8childSuite('childSuite', function () {9 it('should pass', function () {10 expect(true).toBe(true);11 });12});13var childSuite = require('stryker-parent').childSuite;14childSuite('childSuite', function () {15 it('should pass', function () {16 expect(true).toBe(true);17 });18});19var childSuite = require('stryker-parent').childSuite;20childSuite('childSuite', function () {21 it('should pass', function () {22 expect(true).toBe(true);23 });24});25var childSuite = require('stryker-parent').childSuite;26childSuite('childSuite', function () {27 it('should pass', function () {28 expect(true).toBe(true);29 });30});31var childSuite = require('stryker-parent').childSuite;32childSuite('childSuite', function () {33 it('should pass', function () {34 expect(true).toBe(true);35 });36});37var childSuite = require('stryker-parent').childSuite;38childSuite('childSuite', function () {39 it('should pass', function () {40 expect(true).toBe(true);41 });42});43var childSuite = require('stryker-parent').childSuite;44childSuite('childSuite', function () {45 it('should pass', function () {46 expect(true).toBe(true);47 });48});49var childSuite = require('stryker-parent').childSuite;50childSuite('childSuite',

Full Screen

Using AI Code Generation

copy

Full Screen

1var childSuite = require('stryker-parent').childSuite;2childSuite('child suite', function() {3 it('should be tested', function() {4 expect(true).to.be.true;5 });6});7var parentSuite = require('stryker-parent').parentSuite;8parentSuite('parent suite', function() {9 it('should be tested', function() {10 expect(true).to.be.true;11 });12});13var parentSuite = require('stryker-parent').parentSuite;14parentSuite('parent suite', function() {15 it('should be tested', function() {16 expect(true).to.be.true;17 });18});19var parentSuite = require('stryker-parent').parentSuite;20parentSuite('parent suite', function() {21 it('should be tested', function() {22 expect(true).to.be.true;23 });24});25var parentSuite = require('stryker-parent').parentSuite;26parentSuite('parent suite', function() {27 it('should be tested', function() {28 expect(true).to.be.true;29 });30});31var parentSuite = require('stryker-parent').parentSuite;32parentSuite('parent suite', function() {33 it('should be tested', function() {34 expect(true).to.be.true;35 });36});37var parentSuite = require('stryker-parent').parentSuite;38parentSuite('parent suite', function() {39 it('should be tested', function() {40 expect(true).to.be.true;41 });42});43var parentSuite = require('stryker-parent').parentSuite;44parentSuite('parent suite', function() {45 it('should be tested', function() {46 expect(true).to.be.true;47 });48});

Full Screen

Using AI Code Generation

copy

Full Screen

1var parent = require('stryker-parent');2parent.childSuite('childSuite', function() {3 it('should run', function() {4 expect(true).to.be.true;5 });6});7module.exports = function(config) {8 config.set({9 });10};11{12 "dependencies": {13 }14}

Full Screen

Using AI Code Generation

copy

Full Screen

1var childSuite = require('stryker-parent').childSuite;2var child = childSuite('child');3child.addTest('test1', function() {4});5child.addTest('test2', function() {6});7addSuite(child);8addTest('test3', function() {9});10addTest('test4', function() {11});12module.exports = function(config) {13 config.set({14 });15};

Full Screen

Using AI Code Generation

copy

Full Screen

1var childSuite = require('stryker-parent').childSuite;2childSuite('test', function (test) {3 test('test', function (t) {4 t.end();5 });6});

Full Screen

Using AI Code Generation

copy

Full Screen

1var parent = require('stryker-parent');2var childSuite = parent.childSuite;3childSuite('childSuiteName', function() {4 it('childSuiteTest', function() {5 });6});7var parent = require('stryker-parent');8var parentSuite = parent.parentSuite;9parentSuite('parentSuiteName', function() {10 it('parentSuiteTest', function() {11 });12});

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