Best JavaScript code snippet using stryker-parent
stryker-initializer.spec.ts
Source:stryker-initializer.spec.ts
...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 });318 });...
Using AI Code Generation
1const { stubReporters } = require('stryker-parent');2const { expect } = require('chai');3describe('test', () => {4 it('should use stubReporters', () => {5 stubReporters();6 expect(true).to.be.true;7 });8});9const { StrykerOptions } = require('stryker-parent');10module.exports = function(config) {11 config.set({12 });13};14{15 "scripts": {16 },17 "dependencies": {18 }19}20[2018-03-06 12:41:35.719] [INFO] Stryker - Loaded config: {
Using AI Code Generation
1const { stubReporters } = require('stryker-parent');2const { expect } = require('chai');3describe('test', () => {4 it('should work', () => {5 const reporters = stubReporters();6 reporters.forEach((reporter) => {7 expect(reporter).to.be.ok;8 });9 });10});11const { stubReporters } = require('stryker-parent');12const { expect } = require('chai');13describe('test2', () => {14 it('should work', () => {15 const reporters = stubReporters();16 reporters.forEach((reporter) => {17 expect(reporter).to.be.ok;18 });19 });20});21module.exports = function(config) {22 config.set({23 mochaOptions: {24 }25 });26};27module.exports = function(config) {28 config.set({29 mochaOptions: {30 }31 });32};
Using AI Code Generation
1const stubReporters = require('stryker-parent').stubReporters;2const Stryker = require('stryker');3stubReporters(['progress', 'clear-text', 'html']);4const stryker = new Stryker({5});6stryker.runMutationTest();7const stubReporters = require('stryker-parent').stubReporters;8const Stryker = require('stryker');9stubReporters(['progress', 'clear-text', 'html']);10const stryker = new Stryker({11});12stryker.runMutationTest();13const stubReporters = require('stryker-parent').stubReporters;14const Stryker = require('stryker');15stubReporters(['progress', 'clear-text', 'html']);16const stryker = new Stryker({17});18stryker.runMutationTest();19const stubReporters = require('stryker-parent').stubReporters;20const Stryker = require('stryker');21stubReporters(['progress', 'clear-text', 'html']);22const stryker = new Stryker({23});24stryker.runMutationTest();25const stubReporters = require('stryker-parent').stubReporters;26const Stryker = require('stryker');27stubReporters(['progress', 'clear-text', 'html']);
Using AI Code Generation
1const { stubReporters } = require('stryker-parent');2const { expect } = require('chai');3const { Reporter } = require('stryker-api/report');4describe('MyReporter', () => {5 it('should be a reporter', () => {6 expect(new MyReporter()).to.be.instanceOf(Reporter);7 });8 it('should report "foo"', () => {9 const reporter = stubReporters(new MyReporter());10 reporter.onMutationTestReportReady({ foo: 'bar' });11 expect(reporter.log).calledWith('foo');12 });13});14Mocha is designed for BDD (Behavior Driven Development) style tests. Mocha has a rich API that allows you to write tests in a way that is easy to read and understand. Mocha also has a rich plugin system. This allows you to extend Mocha with your own plugins. Mocha has a plugin system that allows you to extend Mocha with your own plugins. This allows you to extend Mocha with your own plugins. Mocha has a plugin system that
Using AI Code Generation
1var reporter = require('stryker-parent');2var stubReporter = reporter.stubReporters;3var reporters = stubReporter(['progress', 'clear-text', 'dots']);4var reporter = require('stryker-parent');5var stubReporter = reporter.stubReporters;6var reporters = stubReporter(['progress', 'clear-text', 'dots']);
Using AI Code Generation
1const test = require('test');2const stubReporters = require('stryker-parent').stubReporters;3describe('test', () => {4 it('should pass', () => {5 stubReporters();6 test();7 });8});9const stubReporters = require('./lib/stubReporters');10module.exports = {11};12module.exports = function stubReporters() {13};14const test = require('test');15const stubReporters = require('stryker-parent').stubReporters;16describe('test', () => {17 it('should pass', () => {18 stubReporters();19 test();20 });21});22const test = require('test');23const stubReporters = require('stryker-parent').stubReporters;24describe('test', () => {25 it('should pass', () => {26 stubReporters();27 test();28 });29});30const test = require('test');31const stubReporters = require('stryker-parent').stubReporters;32describe('test', () => {33 it('should pass', () => {34 stubReporters();35 test();36 });37});38const test = require('test');39const stubReporters = require('stryker-parent').stubReporters;40describe('test', () => {41 it('should pass', () => {42 stubReporters();43 test();44 });45});46const test = require('test');
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!!