Best JavaScript code snippet using stryker-parent
mocha-adapter.spec.ts
Source:mocha-adapter.spec.ts
1import path from 'path';2import fs from 'fs';3import sinon from 'sinon';4import { expect } from 'chai';5import { testInjector } from '@stryker-mutator/test-helpers';6import { MochaAdapter } from '../../src/mocha-adapter.js';7import { LibWrapper } from '../../src/lib-wrapper.js';8describe(MochaAdapter.name, () => {9 let requireStub: sinon.SinonStub;10 let collectFilesStub: sinon.SinonStub;11 let handleRequiresStub: sinon.SinonStub;12 let sut: MochaAdapter;13 let mochaConstructorStub: sinon.SinonStub;14 let existsSyncStub: sinon.SinonStub;15 beforeEach(() => {16 requireStub = sinon.stub(LibWrapper, 'require');17 mochaConstructorStub = sinon.stub(LibWrapper, 'Mocha');18 collectFilesStub = sinon.stub(LibWrapper, 'collectFiles');19 handleRequiresStub = sinon.stub(LibWrapper, 'handleRequires');20 existsSyncStub = sinon.stub(fs, 'existsSync');21 sut = testInjector.injector.injectClass(MochaAdapter);22 });23 describe(MochaAdapter.prototype.create.name, () => {24 it('should create a new mocha instance with provided options', () => {25 const mochaInstance = { isMochaInstance: true };26 const mochaOptions: Mocha.MochaOptions = { timeout: 2356 };27 mochaConstructorStub.returns(mochaInstance);28 const actual = sut.create(mochaOptions);29 expect(actual).eq(mochaInstance);30 expect(mochaConstructorStub).calledWithNew;31 expect(mochaConstructorStub).calledWithExactly(mochaOptions);32 });33 });34 describe(MochaAdapter.prototype.collectFiles.name, () => {35 let discoveredFiles: string[];36 beforeEach(() => {37 discoveredFiles = [];38 collectFilesStub.returns(discoveredFiles);39 });40 it('should mock away the `process.exit` method when calling the mocha function (unfortunate side effect)', async () => {41 const originalProcessExit = process.exit;42 let stubbedProcessExit = process.exit;43 collectFilesStub.callsFake(() => (stubbedProcessExit = process.exit));44 sut.collectFiles({});45 expect(originalProcessExit, "Process.exit doesn't seem to be stubbed away").not.eq(stubbedProcessExit);46 expect(originalProcessExit, "Process.exit doesn't seem to be reset").eq(process.exit);47 });48 });49 describe(MochaAdapter.prototype.handleRequires.name, () => {50 describe('when mocha version < 7.2', () => {51 beforeEach(() => {52 handleRequiresStub.value(undefined);53 });54 it('should pass require additional options when constructed', async () => {55 await sut.handleRequires(['ts-node', 'babel-register']);56 expect(requireStub).calledTwice;57 expect(requireStub).calledWith('ts-node');58 expect(requireStub).calledWith('babel-register');59 });60 it('should resolve local files', async () => {61 const setupFileName = path.resolve('test/setup.js');62 existsSyncStub.returns(false).withArgs(setupFileName).returns(true);63 await sut.handleRequires(['ts-node', 'test/setup.js']);64 expect(requireStub).calledWith('ts-node');65 expect(requireStub).calledWith(setupFileName);66 });67 });68 describe('when mocha version >= 7.2, < 8.2', () => {69 const originalLoadRootHooks = LibWrapper.loadRootHooks;70 afterEach(() => {71 LibWrapper.loadRootHooks = originalLoadRootHooks;72 });73 it("should use mocha's `handleRequires`", async () => {74 await sut.handleRequires(['ts-node']);75 expect(handleRequiresStub).calledWithExactly(['ts-node']);76 });77 it('should also load the root hooks', async () => {78 const loadRootHooksStub = sinon.stub();79 LibWrapper.loadRootHooks = loadRootHooksStub;80 handleRequiresStub.resolves('raw root hooks');81 loadRootHooksStub.resolves('root hooks');82 const result = await sut.handleRequires(['./test/setup.js']);83 expect(loadRootHooksStub).calledWith('raw root hooks');84 expect(result).eq('root hooks');85 });86 });87 describe('when mocha version >= 8.2', () => {88 const originalLoadRootHooks = LibWrapper.loadRootHooks;89 afterEach(() => {90 LibWrapper.loadRootHooks = originalLoadRootHooks;91 });92 it('should also load the root hooks', async () => {93 delete LibWrapper.loadRootHooks; // this does not exist anymore94 handleRequiresStub.resolves({ rootHooks: 'root hooks' });95 const result = await sut.handleRequires(['./test/setup.js']);96 expect(result).eq('root hooks');97 });98 });99 });...
Using AI Code Generation
1var stryker = require('stryker-parent');2stryker.loadRootHooksStub();3var stryker = require('stryker');4stryker.loadRootHooksStub();5var stryker = require('stryker-api');6stryker.loadRootHooksStub();7var stryker = require('stryker-api/core');8stryker.loadRootHooksStub();9var stryker = require('stryker-api/test');10stryker.loadRootHooksStub();11var stryker = require('stryker-api/test_helpers');12stryker.loadRootHooksStub();13var stryker = require('stryker-api/src');14stryker.loadRootHooksStub();15var stryker = require('stryker-api/src/core');16stryker.loadRootHooksStub();17var stryker = require('stryker-api/src/test');18stryker.loadRootHooksStub();19var stryker = require('stryker-api/src/test_helpers');20stryker.loadRootHooksStub();21var stryker = require('stryker/src');22stryker.loadRootHooksStub();23var stryker = require('stryker/src/core');24stryker.loadRootHooksStub();25var stryker = require('stryker/src/test');26stryker.loadRootHooksStub();27var stryker = require('stryker/src/test_helpers');28stryker.loadRootHooksStub();
Using AI Code Generation
1const loadRootHooksStub = require('stryker-parent').loadRootHooksStub;2loadRootHooksStub('test');3module.exports = function(config) {4 config.set({5 });6};7loadRootHooksStub('jest');8loadRootHooksStub('jest');9loadRootHooksStub('jest');10loadRootHooksStub('jest');
Using AI Code Generation
1const { loadRootHooksStub } = require("stryker-parent");2module.exports = loadRootHooksStub(__dirname);3module.exports = function(config) {4 config.set({5 rootHooks: require("./test.js")6 });7};8const { loadRootHooksStub } = require("stryker-parent");9loadRootHooksStub(__dirname);10require("stryker-parent/rootHooks");
Using AI Code Generation
1require('stryker-parent').loadRootHooksStub(__dirname);2require('stryker-parent').loadStrykerPlugins(__dirname);3require('stryker-parent').loadStrykerConfig(__dirname);4require('stryker-parent').loadStrykerConfig(__dirname, 'stryker.conf.js');5require('stryker-parent').loadStrykerConfig(__dirname, 'stryker.conf.js', 'config');6require('stryker-parent').loadStrykerConfig(__dirname, 'stryker.conf.js', 'config', 'configObject');7require('stryker-parent').loadHooks(__dirname);8require('stryker-parent').loadPlugins(__dirname);9require('stryker-parent').loadConfig(__dirname);10require('stryker-parent').loadConfig(__dirname, 'stryker.conf.js');11require('stryker-parent').loadConfig(__dirname, 'stryker.conf.js', 'config');12require('stryker-parent').loadConfig(__dirname, 'stryker.conf.js', 'config
Using AI Code Generation
1function loadRootHooksStub() {2 return {test: 'test'};3}4module.exports = {5}6const { loadRootHooksStub } = require('./index');7const { loadRootHooksStub } = require('./index');8module.exports = function(config) {9 config.set({10 hooks: loadRootHooksStub()11 });12};
Using AI Code Generation
1require('stryker-parent').loadRootHooksStub('./hooks.js');2require('stryker-parent').loadHooksStub('./hooks.js');3require('stryker-parent').loadRootHooksStub('./hooks.js');4require('stryker-parent').loadHooksStub('./hooks.js');5require('stryker-parent').loadRootHooksStub('./hooks.js');6require('stryker-parent').loadHooksStub('./hooks.js');7require('stryker-parent').loadRootHooksStub('./hooks.js');8require('stryker-parent').loadHooksStub('./hooks.js');9require('stryker-parent').loadRootHooksStub('./hooks.js');10require('stryker-parent').loadHooksStub('./hooks.js');11require('stryker
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!!