Best JavaScript code snippet using stryker-parent
stryker-initializer.spec.ts
Source:stryker-initializer.spec.ts
...57 });58 describe('initialize()', () => {59 beforeEach(() => {60 stubTestRunners('@stryker-mutator/awesome-runner', 'stryker-hyper-runner', 'stryker-ghost-runner');61 stubMutators('@stryker-mutator/typescript', '@stryker-mutator/javascript-mutator');62 stubReporters('stryker-dimension-reporter', '@stryker-mutator/mars-reporter');63 stubPackageClient({64 '@stryker-mutator/awesome-runner': null,65 '@stryker-mutator/javascript-mutator': null,66 '@stryker-mutator/mars-reporter': null,67 '@stryker-mutator/typescript': null,68 '@stryker-mutator/webpack': null,69 'stryker-dimension-reporter': null,70 'stryker-ghost-runner': null,71 'stryker-hyper-runner': {72 files: [],73 someOtherSetting: 'enabled',74 },75 });76 fsWriteFile.resolves();77 presets.push(presetMock);78 });79 it('should prompt for preset, test runner, reporters, package manager and config type', async () => {80 arrangeAnswers({81 packageManager: 'yarn',82 reporters: ['dimension', 'mars'],83 testRunner: 'awesome',84 });85 await sut.initialize();86 expect(inquirerPrompt).callCount(5);87 const [promptPreset, promptTestRunner, promptReporters, promptPackageManagers, promptConfigTypes]: inquirer.ListQuestion[] = [88 inquirerPrompt.getCall(0).args[0],89 inquirerPrompt.getCall(1).args[0],90 inquirerPrompt.getCall(2).args[0],91 inquirerPrompt.getCall(3).args[0],92 inquirerPrompt.getCall(4).args[0],93 ];94 expect(promptPreset.type).to.eq('list');95 expect(promptPreset.name).to.eq('preset');96 expect(promptPreset.choices).to.deep.eq(['awesome-preset', new inquirer.Separator(), 'None/other']);97 expect(promptTestRunner.type).to.eq('list');98 expect(promptTestRunner.name).to.eq('testRunner');99 expect(promptTestRunner.choices).to.deep.eq(['awesome', 'hyper', 'ghost', new inquirer.Separator(), 'command']);100 expect(promptReporters.type).to.eq('checkbox');101 expect(promptReporters.choices).to.deep.eq(['dimension', 'mars', 'html', 'clear-text', 'progress', 'dashboard']);102 expect(promptPackageManagers.type).to.eq('list');103 expect(promptPackageManagers.choices).to.deep.eq(['npm', 'yarn']);104 expect(promptConfigTypes.type).to.eq('list');105 expect(promptConfigTypes.choices).to.deep.eq(['JSON', 'JavaScript']);106 });107 it('should immediately complete when a preset and package manager is chosen', async () => {108 inquirerPrompt.resolves({109 packageManager: 'npm',110 preset: 'awesome-preset',111 configType: 'JSON',112 });113 resolvePresetConfig();114 await sut.initialize();115 expect(inquirerPrompt).callCount(3);116 expect(out).calledWith('Done configuring stryker. Please review "stryker.conf.json", you might need to configure your test runner correctly.');117 expect(out).calledWith("Let's kill some mutants with this command: `stryker run`");118 });119 it('should correctly write and format the stryker js configuration file', async () => {120 const guideUrl = 'https://awesome-preset.org';121 const config = { awesomeConf: 'awesome' };122 childExec.resolves();123 resolvePresetConfig({124 config,125 guideUrl,126 });127 const expectedOutput = `/**128 * @type {import('@stryker-mutator/api/core').StrykerOptions}129 */ 130 module.exports = {131 "_comment": "This config was generated using 'stryker init'. Please see the guide for more information: https://awesome-preset.org",132 "awesomeConf": "${config.awesomeConf}"133 };`;134 inquirerPrompt.resolves({135 packageManager: 'npm',136 preset: 'awesome-preset',137 configType: 'JavaScript',138 });139 await sut.initialize();140 expectStrykerConfWritten(expectedOutput);141 expect(childExec).calledWith('npx prettier --write stryker.conf.js');142 });143 it('should handle errors when formatting fails', async () => {144 // Arrange145 const expectedError = new Error('Formatting fails');146 childExec.rejects(expectedError);147 inquirerPrompt.resolves({148 packageManager: 'npm',149 preset: 'awesome-preset',150 configType: 'JavaScript',151 });152 resolvePresetConfig();153 // Act154 await sut.initialize();155 // Assert156 expect(out).calledWith('Unable to format stryker.conf.js file for you. This is not a big problem, but it might look a bit messy ð.');157 expect(testInjector.logger.debug).calledWith('Prettier exited with error', expectedError);158 });159 it('should correctly load dependencies from the preset', async () => {160 resolvePresetConfig({ dependencies: ['my-awesome-dependency', 'another-awesome-dependency'] });161 inquirerPrompt.resolves({162 packageManager: 'npm',163 preset: 'awesome-preset',164 configType: 'JSON',165 });166 await sut.initialize();167 expect(fsWriteFile).calledOnce;168 expect(childExecSync).calledWith('npm i --save-dev my-awesome-dependency another-awesome-dependency', { stdio: [0, 1, 2] });169 });170 it('should correctly load configuration from a preset', async () => {171 resolvePresetConfig();172 inquirerPrompt.resolves({173 packageManager: 'npm',174 preset: 'awesome-preset',175 configType: 'JSON',176 });177 await sut.initialize();178 expect(inquirerPrompt).callCount(3);179 const [promptPreset, promptConfigType, promptPackageManager]: inquirer.ListQuestion[] = [180 inquirerPrompt.getCall(0).args[0],181 inquirerPrompt.getCall(1).args[0],182 inquirerPrompt.getCall(2).args[0],183 ];184 expect(promptPreset.type).to.eq('list');185 expect(promptPreset.name).to.eq('preset');186 expect(promptPreset.choices).to.deep.eq(['awesome-preset', new inquirer.Separator(), 'None/other']);187 expect(promptConfigType.type).to.eq('list');188 expect(promptConfigType.choices).to.deep.eq(['JSON', 'JavaScript']);189 expect(promptPackageManager.type).to.eq('list');190 expect(promptPackageManager.choices).to.deep.eq(['npm', 'yarn']);191 });192 it('should install any additional dependencies', async () => {193 inquirerPrompt.resolves({194 packageManager: 'npm',195 reporters: ['dimension', 'mars'],196 testRunner: 'awesome',197 configType: 'JSON',198 });199 await sut.initialize();200 expect(out).calledWith('Installing NPM dependencies...');201 expect(childExecSync).calledWith('npm i --save-dev @stryker-mutator/awesome-runner stryker-dimension-reporter @stryker-mutator/mars-reporter', {202 stdio: [0, 1, 2],203 });204 });205 it('should configure testRunner, reporters, and packageManager', async () => {206 inquirerPrompt.resolves({207 packageManager: 'npm',208 reporters: ['dimension', 'mars', 'progress'],209 testRunner: 'awesome',210 configType: 'JSON',211 });212 await sut.initialize();213 expect(fsWriteFile).calledOnce;214 const [fileName, content] = fsWriteFile.getCall(0).args;215 expect(fileName).eq('stryker.conf.json');216 const normalizedContent = normalizeWhitespaces(content as string);217 expect(normalizedContent).contains('"testRunner": "awesome"');218 expect(normalizedContent).contains('"packageManager": "npm"');219 expect(normalizedContent).contains('"coverageAnalysis": "perTest"');220 expect(normalizedContent).contains('"dimension", "mars", "progress"');221 });222 it('should configure the additional settings from the plugins', async () => {223 inquirerPrompt.resolves({224 packageManager: 'npm',225 reporters: [],226 testRunner: 'hyper',227 configType: 'JSON',228 });229 await sut.initialize();230 expect(fs.promises.writeFile).calledWith('stryker.conf.json', sinon.match('"someOtherSetting": "enabled"'));231 expect(fs.promises.writeFile).calledWith('stryker.conf.json', sinon.match('"files": []'));232 });233 it('should set "coverageAnalysis" to "off" when the command test runner is chosen', async () => {234 inquirerPrompt.resolves({235 packageManager: 'npm',236 reporters: [],237 testRunner: 'command',238 configType: 'JSON',239 });240 await sut.initialize();241 expect(fs.promises.writeFile).calledWith('stryker.conf.json', sinon.match('"coverageAnalysis": "off"'));242 });243 it('should reject with that error', () => {244 const expectedError = new Error('something');245 fsWriteFile.rejects(expectedError);246 inquirerPrompt.resolves({247 packageManager: 'npm',248 reporters: [],249 testRunner: 'ghost',250 configType: 'JSON',251 });252 return expect(sut.initialize()).to.eventually.be.rejectedWith(expectedError);253 });254 it('should recover when install fails', async () => {255 childExecSync.throws('error');256 inquirerPrompt.resolves({257 packageManager: 'npm',258 reporters: [],259 testRunner: 'ghost',260 configType: 'JSON',261 });262 await sut.initialize();263 expect(out).calledWith('An error occurred during installation, please try it yourself: "npm i --save-dev stryker-ghost-runner"');264 expect(fs.promises.writeFile).called;265 });266 });267 describe('initialize() when no internet', () => {268 it('should log error and continue when fetching test runners', async () => {269 restClientSearch.get.withArgs('/v2/search?q=keywords:@stryker-mutator/test-runner-plugin').rejects();270 stubMutators('stryker-javascript');271 stubReporters();272 stubPackageClient({ 'stryker-javascript': null, 'stryker-webpack': null });273 inquirerPrompt.resolves({274 packageManager: 'npm',275 reporters: ['clear-text'],276 configType: 'JSON',277 });278 await sut.initialize();279 expect(testInjector.logger.error).calledWith(280 'Unable to reach npms.io (for query /v2/search?q=keywords:@stryker-mutator/test-runner-plugin). Please check your internet connection.'281 );282 expect(fs.promises.writeFile).calledWith('stryker.conf.json', sinon.match('"testRunner": "command"'));283 });284 it('should log error and continue when fetching stryker reporters', async () => {285 stubTestRunners('stryker-awesome-runner');286 stubMutators('stryker-javascript');287 restClientSearch.get.withArgs('/v2/search?q=keywords:@stryker-mutator/reporter-plugin').rejects();288 inquirerPrompt.resolves({289 packageManager: 'npm',290 reporters: ['clear-text'],291 testRunner: 'awesome',292 configType: 'JSON',293 });294 stubPackageClient({ 'stryker-awesome-runner': null, 'stryker-javascript': null, 'stryker-webpack': null });295 await sut.initialize();296 expect(testInjector.logger.error).calledWith(297 'Unable to reach npms.io (for query /v2/search?q=keywords:@stryker-mutator/reporter-plugin). Please check your internet connection.'298 );299 expect(fs.promises.writeFile).called;300 });301 it('should log warning and continue when fetching custom config', async () => {302 stubTestRunners('stryker-awesome-runner');303 stubMutators();304 stubReporters();305 inquirerPrompt.resolves({306 packageManager: 'npm',307 reporters: ['clear-text'],308 testRunner: 'awesome',309 configType: 'JSON',310 });311 restClientPackage.get.rejects();312 await sut.initialize();313 expect(testInjector.logger.warn).calledWith(314 'Could not fetch additional initialization config for dependency stryker-awesome-runner. You might need to configure it manually'315 );316 expect(fs.promises.writeFile).called;317 });...
Using AI Code Generation
1const stubMutators = require('stryker-parent').stubMutators;2stubMutators(['LogicalOperator']);3const stubMutators = require('stryker-parent').stubMutators;4stubMutators(['LogicalOperator']);5const stubMutators = require('stryker-parent').stubMutators;6stubMutators(['LogicalOperator']);7const stubMutators = require('stryker-parent').stubMutators;8stubMutators(['LogicalOperator']);9const stubMutators = require('stryker-parent').stubMutators;10stubMutators(['LogicalOperator']);11const stubMutators = require('stryker-parent').stubMutators;12stubMutators(['LogicalOperator']);13const stubMutators = require('stryker-parent').stubMutators;14stubMutators(['LogicalOperator']);15const stubMutators = require('stryker-parent').stubMutators;16stubMutators(['LogicalOperator']);17const stubMutators = require('stryker-parent').stubMutators;18stubMutators(['LogicalOperator']);19const stubMutators = require('stryker-parent').stubMutators;20stubMutators(['LogicalOperator']);21const stubMutators = require('stryker-parent').stubMutators;22stubMutators(['LogicalOperator']);23const stubMutators = require('stryker-parent').stubMutators;24stubMutators(['LogicalOperator']);25const stubMutators = require('stryker-parent').stubMutators;26stubMutators(['LogicalOperator']);
Using AI Code Generation
1import { strykerParent } from 'stryker-parent';2import { MutatorDescriptor } from 'stryker-api/mutant';3import { expect } from 'chai';4describe('stryker-parent', () => {5 describe('stubMutators', () => {6 it('should return a list of mutators', () => {7 const mutators: MutatorDescriptor[] = strykerParent.stubMutators();8 expect(mutators).lengthOf(2);9 });10 });11});12import { strykerParent } from 'stryker-parent';13import { MutatorDescriptor } from 'stryker-api/mutant';14import { expect } from 'chai';15describe('stryker-parent', () => {16 describe('stubMutators', () => {17 it('should return a list of mutators', () => {18 const mutators: MutatorDescriptor[] = strykerParent.stubMutators();19 expect(mutators).lengthOf(2);20 });21 });22});23import { strykerParent } from 'stryker-parent';24import { MutatorDescriptor } from 'stryker-api/mutant';25import { expect } from 'chai';26describe('stryker-parent', () => {27 describe('stubMutators', () => {28 it('should return a list of mutators', () => {29 const mutators: MutatorDescriptor[] = strykerParent.stubMutators();30 expect(mutators).lengthOf(2);31 });32 });33});34import { strykerParent } from 'stryker-parent';35import { MutatorDescriptor } from 'stryker-api/mutant';36import { expect } from 'chai';37describe('stryker-parent', () => {38 describe('stubMutators', () => {39 it('should return a list of mutators', () => {40 const mutators: MutatorDescriptor[] = strykerParent.stubMutators();41 expect(mutators).lengthOf(2);42 });43 });44});45import { strykerParent }
Using AI Code Generation
1const {stubMutators} = require('stryker-parent');2const mutators = stubMutators();3const {stubMutators} = require('stryker-parent');4const mutators = stubMutators();5const {stubMutators} = require('stryker-parent');6const mutators = stubMutators();7const {stubMutators} = require('stryker-parent');8const mutators = stubMutators();9const {stubMutators} = require('stryker-parent');10const mutators = stubMutators();11const {stubMutators} = require('stryker-parent');12const mutators = stubMutators();13const {stubMutators} = require('stryker-parent');14const mutators = stubMutators();15const {stubMutators} = require('stryker-parent');16const mutators = stubMutators();17const {stubMutators} = require('stryker-parent');18const mutators = stubMutators();19const {stubMutators} = require('stryker-parent');20const mutators = stubMutators();21const {stubMutators} = require('stryker-parent');22const mutators = stubMutators();23const {stubMutators} = require('stryker-parent');24const mutators = stubMutators();25const {stubMutators} = require('stryker-parent');
Using AI Code Generation
1const { stubMutators } = require('stryker-parent');2const mutators = require('stryker-mutator');3const myMutator = require('my-mutator');4stubMutators({5});6const { getMutators } = require('stryker-mutator');7const { myMutator } = require('my-mutator');8describe('getMutators', () => {9 it('should return the list of mutators', () => {10 expect(getMutators()).to.deep.equal([mutators, myMutator]);11 });12});13The stubMutators method will also stub the require method, so that the mutators are not actually loaded. This is important, because the mutators are loaded using the require method, which is synchronous. This means that the mutators will be loaded before the stubMutators method is called
Using AI Code Generation
1const { stubMutators } = require('stryker-parent');2const { expect } = require('chai');3const path = require('path');4const fs = require('fs');5const { execSync } = require('child_process');6const { MutatorFactory } = require('stryker-api/mutant');7const { Config } = require('stryker-api/config');8const { StrykerOptions } = require('stryker-api/core');9function createConfig(config) {10 return new Config().set(config);11}12function createOptions(config) {13 return new StrykerOptions(config);14}15describe('stubMutators', () => {16 it('should stub mutators', () => {17 const config = createConfig({18 });19 const options = createOptions(config);20 const mutator = MutatorFactory.instance().create('javascript', options);21 const mutators = mutator.mutators;22 const mutatorNames = mutators.map((mutator) => mutator.name);23 expect(mutatorNames).to.deep.equal([24 ]);25 stubMutators(mutators);26 execSync('npm run test', {27 cwd: path.resolve(__dirname, '..'),28 });29 mutators.forEach((mutator) => {30 mutator.stub.restore();31 });32 const coverage = JSON.parse(33 fs.readFileSync(path.resolve(__dirname
Using AI Code Generation
1const { stubMutators } = require('stryker-parent');2const { stubMutators } = require('stryker-parent');3const { stubMutators } = require('stryker-parent');4const { stubMutators } = require('stryker-parent');5const { stubMutators } = require('stryker-parent');6const { stubMutators } = require('stryker-parent');7const { stubMutators } = require('stryker-parent');8const { stubMutators } = require('stryker-parent');9const { stubMutators } = require('stryker-parent');10const { stubMutators } = require('stryker-parent');11const { stubMutators } = require('stryker-parent');12const { stubMutators } = require('stryker-parent');
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!!