Best JavaScript code snippet using stryker-parent
4-mutation-test-executor.spec.ts
Source:4-mutation-test-executor.spec.ts
...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 });247});
test-preset.js
Source:test-preset.js
1import Scenario from "../Scenario";2describe("scenario preset", () => {3 it("should arrange in preset if arrange option is present", async () => {4 const callback = jest.fn();5 const arrangeScenario = new Scenario({6 name: "Arrange Scenario"7 }).act(callback);8 const PresetScenario = Scenario.preset({ arrange: arrangeScenario });9 await new PresetScenario({ name: "Test Scenario" }).play();10 expect(callback).toBeCalledTimes(1);11 });12 it("should include arrange scenario in preset if arrange option is instance of Scenario", async () => {13 const callback = jest.fn();14 const arrangeScenario = new Scenario({15 name: "Arrange Scenario"16 }).act(callback);17 const PresetScenario = Scenario.preset({ arrange: arrangeScenario });18 await new PresetScenario({ name: "Test Scenario" }).play();19 expect(callback).toBeCalledTimes(1);20 });...
Using AI Code Generation
1const { arrangeScenario } = require('stryker-parent');2const { arrangeScenario } = require('stryker-child');3const { arrangeScenario } = require('stryker-parent');4const { arrangeScenario } = require('stryker-child');5const { arrangeScenario } = require('stryker-parent');6const { arrangeScenario } = require('stryker-child');7const { arrangeScenario } = require('stryker-parent');8const { arrangeScenario } = require('stryker-child');9const { arrangeScenario } = require('stryker-parent');10const { arrangeScenario } = require('stryker-child');11const { arrangeScenario } = require('stryker-parent');12const { arrangeScenario } = require('stryker-child');13const { arrangeScenario } = require('stryker-parent');14const { arrangeScenario } = require('stryker-child');15const { arrangeScenario } = require('stryker-parent');16const { arrangeScenario } = require('stryker-child');17const { arrangeScenario } = require('stryker-parent');18const { arrangeScenario } = require('stryker-child');
Using AI Code Generation
1var arrangeScenario = require('stryker-parent').arrangeScenario;2var arrangeScenario = require('stryker-child').arrangeScenario;3var arrangeScenario = require('stryker-parent').arrangeScenario;4var arrangeScenario = require('stryker-child').arrangeScenario;5var arrangeScenario = require('stryker-parent').arrangeScenario;6var arrangeScenario = require('stryker-child').arrangeScenario;7var arrangeScenario = require('stryker-parent').arrangeScenario;8var arrangeScenario = require('stryker-child').arrangeScenario;9var arrangeScenario = require('stryker-parent').arrangeScenario;10var arrangeScenario = require('stryker-child').arrangeScenario;11var arrangeScenario = require('stryker-parent').arrangeScenario;12var arrangeScenario = require('stryker-child').arrangeScenario;13var arrangeScenario = require('stryker-parent').arrangeScenario;14var arrangeScenario = require('stryker-child').arrangeScenario;15var arrangeScenario = require('stryker-parent').arrangeScenario;16var arrangeScenario = require('stryker-child').arrangeScenario;17var arrangeScenario = require('stryker-parent').arrangeScenario;
Using AI Code Generation
1const { arrangeScenario } = require('stryker-parent');2describe('a test', () => {3 arrangeScenario('scenario 1', () => {4 });5 arrangeScenario('scenario 2', () => {6 });7});8module.exports = function(config) {9 config.set({10 jest: {11 config: require('./jest.config.js'),12 },13 });14};15module.exports = {16};17const { StrykerJestTestRunner } = require('@stryker-mutator/jest-runner');18const { TestRunnerDecorator } = require('@stryker-mutator/api/test_runner');19const scenarioMap = new Map();20class ArrangeScenarioTestRunner extends TestRunnerDecorator {21 constructor(options) {22 super(new StrykerJestTestRunner(options));23 }24 async init() {25 await super.init();26 this.scenario = scenarioMap.get(this.options.scenarioName);27 }28 async run(options) {29 await this.scenario();30 return super.run(options);31 }32}33function arrangeScenario(scenarioName, scenario) {34 scenarioMap.set(scenarioName, scenario);35}36module.exports = { arrangeScenario, ArrangeScenarioTestRunner };37module.exports = function(config) {38 config.set({39 customTestRunner: { project: './stryker-parent', name: 'ArrangeScenarioTestRunner' },40 jest: {41 config: require('./jest.config.js'),42 },43 });44};45module.exports = {
Using AI Code Generation
1function arrangeScenario(scenario) {2}3function arrangeScenario(scenario) {4}5module.exports = {6}7module.exports = {8}9var strykerParent = require('stryker-parent');10var strykerChild = require('stryker-child');11function arrangeScenario(scenario) {12}13function arrangeScenario(scenario) {14}15module.exports = {16}17module.exports = {18}19var strykerParent = require('stryker-parent');20var strykerChild = require('stryker-child');21function arrangeScenario(scenario) {22}23function arrangeScenario(scenario) {24}25module.exports = {26}27module.exports = {28}29var strykerParent = require('stryker-parent');30var strykerChild = require('stryker-child');31function arrangeScenario(scenario) {32}
Using AI Code Generation
1var arrangeScenario = require('stryker-parent').arrangeScenario;2describe('My first test', function () {3 it('should pass', function () {4 arrangeScenario('test.js', 'should pass');5 expect(true).toBe(true);6 });7 it('should fail', function () {8 arrangeScenario('test.js', 'should fail');9 expect(true).toBe(false);10 });11});12module.exports = function (config) {13 config.set({14 });15};16[2018-03-16 10:14:27.876] [INFO] SandboxPool - Creating 4 test runners (based on CPU count)17[2018-03-16 10:14:28.287] [INFO] Sandbox - Starting sandbox [0] (outOf: 4, configured: 4)18[2018-03-16 10:14:28.288] [INFO] Sandbox - Starting sandbox [1] (outOf: 4, configured: 4)
Using AI Code Generation
1const { arrangeScenario } = require('stryker-parent');2describe('My test suite', () => {3 it('should do something', () => {4 arrangeScenario('scenario1');5 });6});
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!