Best JavaScript code snippet using stryker-parent
jest-test-runner.it.spec.ts
Source:jest-test-runner.it.spec.ts
1import path from 'path';2import { expect } from 'chai';3import { commonTokens } from '@stryker-mutator/api/plugin';4import { factory, testInjector, assertions } from '@stryker-mutator/test-helpers';5import { CompleteDryRunResult, TestStatus } from '@stryker-mutator/api/test-runner';6import { JestTestRunner, jestTestRunnerFactory } from '../../src/jest-test-runner';7import { JestRunnerOptionsWithStrykerOptions } from '../../src/jest-runner-options-with-stryker-options';8import { JestOptions } from '../../src-generated/jest-runner-options';9import { createJestOptions } from '../helpers/producers';10import { resolveTestResource } from '../helpers/resolve-test-resource';11import { expectTestResults } from '../helpers/assertions';12// Needed for Jest in order to run tests13process.env.BABEL_ENV = 'test';14describe(`${JestTestRunner.name} integration test`, () => {15 // Names of the tests in the example projects16 const testNames = Object.freeze([17 'Add should be able to add two numbers',18 'Add should be able to add one to a number',19 'Add should be able negate a number',20 'Add should be able to recognize a negative number',21 'Circle should have a circumference of 2PI when the radius is 1',22 ]);23 function createSut(overrides?: Partial<JestOptions>) {24 const options: JestRunnerOptionsWithStrykerOptions = factory.strykerWithPluginOptions({25 jest: createJestOptions(overrides),26 });27 return testInjector.injector.provideValue(commonTokens.options, options).injectFunction(jestTestRunnerFactory);28 }29 const expectToHaveSuccessfulTests = (result: CompleteDryRunResult, n: number) => {30 expect(result.tests.filter((t) => t.status === TestStatus.Success)).to.have.length(n);31 };32 describe('dryRun', () => {33 it('should set the test name and timeSpentMs', async function () {34 process.chdir(resolveTestResource('jasmine2-node'));35 const jestTestRunner = createSut();36 const runResult = await jestTestRunner.dryRun(factory.dryRunOptions({ coverageAnalysis: 'off' }));37 assertions.expectCompleted(runResult);38 const result = runResult.tests.find((test) => test.id === 'Add should be able to add two numbers');39 expect(result).to.not.be.null;40 expect(result!.name).to.equal('Add should be able to add two numbers');41 expect(result!.timeSpentMs).to.be.above(-1);42 });43 it('should run tests on the example custom project using package.json', async () => {44 process.chdir(resolveTestResource('jasmine2-node'));45 const jestTestRunner = createSut();46 const runResult = await jestTestRunner.dryRun(factory.dryRunOptions({ coverageAnalysis: 'off' }));47 assertions.expectCompleted(runResult);48 expectToHaveSuccessfulTests(runResult, testNames.length);49 });50 it('should run tests on the example custom project using jest.config.js', async () => {51 process.chdir(resolveTestResource('exampleProjectWithExplicitJestConfig'));52 const jestTestRunner = createSut();53 const runResult = await jestTestRunner.dryRun(factory.dryRunOptions({ coverageAnalysis: 'off' }));54 assertions.expectCompleted(runResult);55 expectToHaveSuccessfulTests(runResult, testNames.length);56 });57 it('should report the test positions and file names', async () => {58 process.chdir(resolveTestResource('exampleProjectWithExplicitJestConfig'));59 const addSpecFileName = resolveTestResource('exampleProjectWithExplicitJestConfig', 'src', '__tests__', 'AddSpec.js');60 const circleSpecFileName = resolveTestResource('exampleProjectWithExplicitJestConfig', 'src', '__tests__', 'CircleSpec.js');61 const jestTestRunner = createSut();62 const runResult = await jestTestRunner.dryRun(factory.dryRunOptions({ coverageAnalysis: 'perTest' }));63 assertions.expectCompleted(runResult);64 expectTestResults(runResult, [65 {66 id: 'Add should be able to add two numbers',67 fileName: addSpecFileName,68 startPosition: { column: 2, line: 6 },69 },70 {71 id: 'Add should be able to add one to a number',72 fileName: addSpecFileName,73 startPosition: { column: 2, line: 16 },74 },75 {76 id: 'Add should be able negate a number',77 fileName: addSpecFileName,78 startPosition: { column: 2, line: 25 },79 },80 {81 id: 'Add should be able to recognize a negative number',82 fileName: addSpecFileName,83 startPosition: { column: 2, line: 34 },84 },85 {86 id: 'Circle should have a circumference of 2PI when the radius is 1',87 fileName: circleSpecFileName,88 startPosition: { column: 2, line: 3 },89 },90 ]);91 });92 });93 describe('mutantRun', () => {94 it('should kill mutant 1', async () => {95 const exampleProjectRoot = resolveTestResource('jasmine2-node-instrumented');96 process.chdir(exampleProjectRoot);97 const jestTestRunner = createSut();98 const mutantRunOptions = factory.mutantRunOptions({99 activeMutant: factory.mutant({ id: '1' }),100 sandboxFileName: require.resolve(path.resolve(exampleProjectRoot, 'src', 'Add.js')),101 });102 mutantRunOptions.activeMutant.id = '1';103 const runResult = await jestTestRunner.mutantRun(mutantRunOptions);104 assertions.expectKilled(runResult);105 expect(runResult.killedBy).eq('Add should be able to add two numbers');106 expect(runResult.failureMessage).contains('Expected: 7').contains('Received: -3');107 });108 it('should let mutant 11 survive', async () => {109 const exampleProjectRoot = resolveTestResource('jasmine2-node-instrumented');110 process.chdir(resolveTestResource('jasmine2-node-instrumented'));111 const jestTestRunner = createSut();112 const mutantRunOptions = factory.mutantRunOptions({113 sandboxFileName: require.resolve(path.resolve(exampleProjectRoot, 'src', 'Circle.js')),114 });115 mutantRunOptions.activeMutant.id = '11';116 const runResult = await jestTestRunner.mutantRun(mutantRunOptions);117 assertions.expectSurvived(runResult);118 });119 it('should be able to let a mutant survive after killing mutant 1', async () => {120 // Arrange121 const exampleProjectRoot = resolveTestResource('jasmine2-node-instrumented');122 process.chdir(exampleProjectRoot);123 const jestTestRunner = createSut();124 const mutantRunOptions = factory.mutantRunOptions({125 sandboxFileName: require.resolve(path.resolve(exampleProjectRoot, 'src', 'Add.js')),126 });127 mutantRunOptions.activeMutant.id = '1';128 // Act129 const firstResult = await jestTestRunner.mutantRun(mutantRunOptions);130 mutantRunOptions.activeMutant.id = '10';131 const secondResult = await jestTestRunner.mutantRun(mutantRunOptions);132 // Assert133 assertions.expectKilled(firstResult);134 assertions.expectSurvived(secondResult);135 });136 it('should only report the first failing test in `killedBy` when disableBail = false', async () => {137 // Arrange138 const exampleProjectRoot = resolveTestResource('jasmine2-node-instrumented');139 process.chdir(exampleProjectRoot);140 const jestTestRunner = createSut();141 const mutantRunOptions = factory.mutantRunOptions({142 sandboxFileName: require.resolve(path.resolve(exampleProjectRoot, 'src', 'Add.js')),143 activeMutant: factory.mutant({ id: '0' }),144 });145 // Act146 const result = await jestTestRunner.mutantRun(mutantRunOptions);147 // Assert148 assertions.expectKilled(result);149 expect(result.killedBy).eq('Add should be able to add two numbers');150 });151 it('should be able to collect all tests that kill a mutant when disableBail = true', async () => {152 // Arrange153 const exampleProjectRoot = resolveTestResource('jasmine2-node-instrumented');154 process.chdir(exampleProjectRoot);155 const jestTestRunner = createSut();156 const mutantRunOptions = factory.mutantRunOptions({157 sandboxFileName: require.resolve(path.resolve(exampleProjectRoot, 'src', 'Add.js')),158 activeMutant: factory.mutant({ id: '0' }),159 disableBail: true,160 });161 // Act162 const result = await jestTestRunner.mutantRun(mutantRunOptions);163 // Assert164 assertions.expectKilled(result);165 expect(result.killedBy).to.have.length(2);166 });167 });...
Using AI Code Generation
1function addSpecFileName() {2}3module.exports = {4}5const strykerParent = require('./stryker-parent');6function childMethod() {7 strykerParent.addSpecFileName();8}9module.exports = {10}11const strykerChild = require('./stryker-child');
Using AI Code Generation
1const strykerParent = require('stryker-parent');2strykerParent.addSpecFileName('test.js');3const strykerParent = require('stryker-parent');4strykerParent.addSpecFileName('test.js');5const strykerParent = require('stryker-parent');6strykerParent.addSpecFileName('test.js');7const strykerParent = require('stryker-parent');8strykerParent.addSpecFileName('test.js');9const strykerParent = require('stryker-parent');10strykerParent.addSpecFileName('test.js');11const strykerParent = require('stryker-parent');12strykerParent.addSpecFileName('test.js');13const strykerParent = require('stryker-parent');14strykerParent.addSpecFileName('test.js');15const strykerParent = require('stryker-parent');16strykerParent.addSpecFileName('test.js');17const strykerParent = require('stryker-parent');18strykerParent.addSpecFileName('test.js');19const strykerParent = require('stryker-parent');20strykerParent.addSpecFileName('test.js');21const strykerParent = require('stryker-parent');22strykerParent.addSpecFileName('test.js');23const strykerParent = require('stryker-parent');24strykerParent.addSpecFileName('test.js');
Using AI Code Generation
1addSpecFileName(__filename);2addSpecFileName(__filename);3addSpecFileName(__filename);4addSpecFileName(__filename);5addSpecFileName(__filename);6addSpecFileName(__filename);
Using AI Code Generation
1var stryker = require('stryker-parent');2stryker.addSpecFileName('test.js');3var stryker = require('stryker-parent');4stryker.addSpecFileName('test.js');5var stryker = require('stryker-parent');6stryker.addSpecFileName('test.js');7var stryker = require('stryker-parent');8stryker.addSpecFileName('test.js');9var stryker = require('stryker-parent');10stryker.addSpecFileName('test.js');11var stryker = require('stryker-parent');12stryker.addSpecFileName('test.js');13var stryker = require('stryker-parent');14stryker.addSpecFileName('test.js');15var stryker = require('stryker-parent');16stryker.addSpecFileName('test.js');17var stryker = require('stryker-parent');18stryker.addSpecFileName('test.js');19var stryker = require('stryker-parent');20stryker.addSpecFileName('test.js');21var stryker = require('stryker-parent');22stryker.addSpecFileName('test.js');23var stryker = require('stryker-parent');24stryker.addSpecFileName('test.js');25var stryker = require('stryker-parent');26stryker.addSpecFileName('test.js
Using AI Code Generation
1const stryker = require('stryker-parent');2stryker.addSpecFileName('test.js');3const stryker = require('stryker-parent');4stryker.addSpecFileName('test.js');5const stryker = require('stryker-parent');6stryker.addSpecFileName('test.js');
Using AI Code Generation
1const { addSpecFileName } = require('stryker-parent');2addSpecFileName('test.js');3const { addSpecFileName } = require('stryker-parent');4addSpecFileName('test.js');5const { addSpecFileName } = require('stryker-parent');6addSpecFileName('test.js');7const { addSpecFileName } = require('stryker-parent');8addSpecFileName('test.js');9const { addSpecFileName } = require('stryker-parent');10addSpecFileName('test.js');11const { addSpecFileName } = require('stryker-parent');12addSpecFileName('test.js');13const { addSpecFileName } = require('stryker-parent');14addSpecFileName('test.js');15const { addSpecFileName } = require('stryker-parent');16addSpecFileName('test.js');17const { addSpecFileName } = require('stryker-parent');18addSpecFileName('test.js');19const { addSpecFileName } = require('stryker-parent');20addSpecFileName('test.js');
Using AI Code Generation
1function addSpecFileName(fileName) {2 const specFiles = readSpecFiles();3 specFiles.push(fileName);4 writeSpecFiles(specFiles);5}6function readSpecFiles() {7 return specFiles;8}9function writeSpecFiles(specFiles) {10}
Using AI Code Generation
1const strykerParent = require('stryker-parent');2const myCustomReporter = require('stryker-custom-reporter');3strykerParent.addSpecFileName('myCustomReporter', myCustomReporter);4const strykerParent = require('stryker-parent');5const myCustomReporter = require('stryker-custom-reporter');6strykerParent.addSpecFileName('myCustomReporter', myCustomReporter);7const strykerParent = require('stryker-parent');8const myCustomReporter = require('stryker-custom-reporter');9strykerParent.addSpecFileName('myCustomReporter', myCustomReporter);10const strykerParent = require('stryker-parent');11const myCustomReporter = require('stryker-custom-reporter');12strykerParent.addSpecFileName('myCustomReporter', myCustomReporter);13const strykerParent = require('stryker-parent');14const myCustomReporter = require('stryker-custom-reporter');15strykerParent.addSpecFileName('myCustomReporter', myCustomReporter);16const strykerParent = require('stryker-parent');17const myCustomReporter = require('stryker-custom-reporter');18strykerParent.addSpecFileName('myCustomReporter', myCustomReporter);19const strykerParent = require('stryker-parent');20const myCustomReporter = require('stryker-custom-reporter');21strykerParent.addSpecFileName('myCustomReporter', myCustomReporter);22const strykerParent = require('stryker-parent');23const myCustomReporter = require('stryker-custom-reporter');24strykerParent.addSpecFileName('myCustomReporter', myCustomReporter);25const strykerParent = require('stryker-parent');26const myCustomReporter = require('stryker-custom-reporter');27strykerParent.addSpecFileName('myCustomReporter', myCustomReporter);28const strykerParent = require('stryker-parent');
Using AI Code Generation
1import { addSpecFileName } from 'stryker-parent';2addSpecFileName('test.js');3export function addSpecFileName(specFileName) {4 console.log('Spec file name added: ' + specFileName);5}6import { addSpecFileName } from 'stryker-parent';7addSpecFileName('test.js');8import { addSpecFileName } from '../../../stryker-stryker-parent/src/index.js';9addSpecFileName('test.js');10import { addSpecFileName } from '../src/index.js';11addSpecFileName('test.js');12import { addSpecFileName } from '../src/index.ts';13addSpecFileName('test.js');14import { addSpecFileName } from '../src/index.tsx';15addSpecFileName('test.js');16import { addSpecFileName } from '../src/index.jsx';17addSpecFileName('test.js');18import { addSpecFileName } from '../src/index';19addSpecFileName('test.js');20import { addSpecFileName } from '../src/index.ts';21addSpecFileName('test.js');
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!!