Best JavaScript code snippet using stryker-parent
mocha-options-loader.ts
Source:mocha-options-loader.ts
1import fs from 'fs';2import path from 'path';3import { Logger } from '@stryker-mutator/api/logging';4import { commonTokens, tokens } from '@stryker-mutator/api/plugin';5import { PropertyPathBuilder } from '@stryker-mutator/util';6import { MochaOptions, MochaRunnerOptions } from '../src-generated/mocha-runner-options';7import { LibWrapper } from './lib-wrapper';8import { filterConfig, serializeMochaLoadOptionsArguments } from './utils';9import { MochaRunnerWithStrykerOptions } from './mocha-runner-with-stryker-options';10/**11 * Subset of defaults for mocha options12 * @see https://github.com/mochajs/mocha/blob/master/lib/mocharc.json13 */14export const DEFAULT_MOCHA_OPTIONS: Readonly<MochaOptions> = Object.freeze({15 extension: ['js'],16 require: [],17 file: [],18 ignore: [],19 opts: './test/mocha.opts',20 spec: ['test'],21 ui: 'bdd',22 'no-package': false,23 'no-opts': false,24 'no-config': false,25 'async-only': false,26});27export class MochaOptionsLoader {28 public static inject = tokens(commonTokens.logger);29 constructor(private readonly log: Logger) {}30 public load(strykerOptions: MochaRunnerWithStrykerOptions): MochaOptions {31 const mochaOptions = { ...strykerOptions.mochaOptions } as MochaOptions;32 const options = { ...DEFAULT_MOCHA_OPTIONS, ...this.loadMochaOptions(mochaOptions), ...mochaOptions };33 if (this.log.isDebugEnabled()) {34 this.log.debug(`Loaded options: ${JSON.stringify(options, null, 2)}`);35 }36 return options;37 }38 private loadMochaOptions(overrides: MochaOptions) {39 if (LibWrapper.loadOptions) {40 this.log.debug("Mocha >= 6 detected. Using mocha's `%s` to load mocha options", LibWrapper.loadOptions.name);41 return this.loadMocha6Options(overrides);42 } else {43 this.log.warn('DEPRECATED: Mocha < 6 detected. Please upgrade to at least Mocha version 6. Stryker will drop support for Mocha < 6 in V5.');44 this.log.debug('Mocha < 6 detected. Using custom logic to parse mocha options');45 return this.loadLegacyMochaOptsFile(overrides);46 }47 }48 private loadMocha6Options(overrides: MochaOptions) {49 const args = serializeMochaLoadOptionsArguments(overrides);50 const rawConfig = LibWrapper.loadOptions!(args) ?? {};51 if (this.log.isTraceEnabled()) {52 this.log.trace(`Mocha: ${LibWrapper.loadOptions!.name}([${args.map((arg) => `'${arg}'`).join(',')}]) => ${JSON.stringify(rawConfig)}`);53 }54 const options = filterConfig(rawConfig);55 return options;56 }57 private loadLegacyMochaOptsFile(options: MochaOptions): Partial<MochaOptions> {58 if (options['no-opts']) {59 this.log.debug('Not reading additional mochaOpts from a file');60 return options;61 }62 switch (typeof options.opts) {63 case 'undefined':64 const defaultMochaOptsFileName = path.resolve(DEFAULT_MOCHA_OPTIONS.opts!);65 if (fs.existsSync(defaultMochaOptsFileName)) {66 return this.readMochaOptsFile(defaultMochaOptsFileName);67 } else {68 this.log.debug(69 'No mocha opts file found, not loading additional mocha options (%s was not defined).',70 PropertyPathBuilder.create<MochaRunnerOptions>().prop('mochaOptions').prop('opts').build()71 );72 return {};73 }74 case 'string':75 const optsFileName = path.resolve(options.opts);76 if (fs.existsSync(optsFileName)) {77 return this.readMochaOptsFile(optsFileName);78 } else {79 this.log.error(`Could not load opts from "${optsFileName}". Please make sure opts file exists.`);80 return {};81 }82 default:83 return {};84 }85 }86 private readMochaOptsFile(optsFileName: string) {87 this.log.info(`Loading mochaOpts from "${optsFileName}"`);88 return this.parseOptsFile(fs.readFileSync(optsFileName, 'utf8'));89 }90 private parseOptsFile(optsFileContent: string): MochaOptions {91 const options = optsFileContent.split('\n').map((val) => val.trim());92 const mochaRunnerOptions: MochaOptions = Object.create(null);93 options.forEach((option) => {94 const args = option.split(' ').filter(Boolean);95 if (args[0]) {96 switch (args[0]) {97 case '--require':98 case '-r':99 args.shift();100 if (!mochaRunnerOptions.require) {101 mochaRunnerOptions.require = [];102 }103 mochaRunnerOptions.require.push(...args);104 break;105 case '--async-only':106 case '-A':107 mochaRunnerOptions['async-only'] = true;108 break;109 case '--ui':110 case '-u':111 mochaRunnerOptions.ui = (this.parseNextString(args) as 'bdd' | 'exports' | 'qunit' | 'tdd') ?? DEFAULT_MOCHA_OPTIONS.ui!;112 break;113 case '--grep':114 case '-g':115 let arg = `${this.parseNextString(args)}`;116 if (arg.startsWith('/') && arg.endsWith('/')) {117 arg = arg.substring(1, arg.length - 1);118 }119 mochaRunnerOptions.grep = arg;120 break;121 default:122 this.log.debug(`Ignoring option "${args[0]}" as it is not supported.`);123 break;124 }125 }126 });127 return mochaRunnerOptions;128 }129 private parseNextString(args: string[]): string | undefined {130 if (args.length > 1) {131 return args[1];132 } else {133 return undefined;134 }135 }...
Using AI Code Generation
1const { defaultMochaOptsFileName } = require('stryker-parent');2const { defaultMochaOptsFileName } = require('stryker-mocha-runner');3const { defaultMochaOptsFileName } = require('stryker-jest-runner');4const { defaultMochaOptsFileName } = require('stryker-karma-runner');5const { defaultMochaOptsFileName } = require('stryker-jasmine-runner');6const { defaultMochaOptsFileName } = require('stryker-cucumber-runner');7const { defaultMochaOptsFileName } = require('stryker-typescript');8const { defaultMochaOptsFileName } = require('stryker-mutator');9const { defaultMochaOptsFileName } = require('stryker');10const { defaultMochaOptsFileName } = require('stryker-html-reporter');11const { defaultMochaOptsFileName } = require('stryker-babel-transpiler');12const { defaultMochaOptsFileName } = require('stryker-mocha-framework');13const { defaultMochaOptsFileName } = require('stryker-jasmine-framework');14const { defaultMochaOptsFileName } = require('stryker-jest-runner');15const { defaultMochaOptsFileName } = require('stryker-karma-runner');
Using AI Code Generation
1const defaultMochaOptsFileName = require('stryker-parent').defaultMochaOptsFileName;2console.log(defaultMochaOptsFileName);3const defaultMochaOptsFileName = require('stryker').defaultMochaOptsFileName;4console.log(defaultMochaOptsFileName);5const defaultMochaOptsFileName = require('stryker-mocha-runner').defaultMochaOptsFileName;6console.log(defaultMochaOptsFileName);7const defaultMochaOptsFileName = require('stryker-mocha-framework').defaultMochaOptsFileName;8console.log(defaultMochaOptsFileName);9const defaultMochaOptsFileName = require('stryker-mocha').defaultMochaOptsFileName;10console.log(defaultMochaOptsFileName);11const defaultMochaOptsFileName = require('stryker-mocha-runner').defaultMochaOptsFileName;12console.log(defaultMochaOptsFileName);13const defaultMochaOptsFileName = require('stryker-mocha-framework').defaultMochaOptsFileName;14console.log(defaultMochaOptsFileName);15const defaultMochaOptsFileName = require('stryker-mocha').defaultMochaOptsFileName;16console.log(defaultMochaOptsFileName);17const defaultMochaOptsFileName = require('stryker-mocha-runner').defaultMochaOptsFileName;18console.log(defaultMochaOptsFileName);19const defaultMochaOptsFileName = require('stryker-mocha-framework').defaultMochaOptsFileName;20console.log(defaultMochaOptsFileName);21const defaultMochaOptsFileName = require('stryker-mocha').defaultMochaOptsFileName;22console.log(defaultMochaOptsFileName);
Using AI Code Generation
1const defaultMochaOptsFileName = require('stryker-parent').defaultMochaOptsFileName;2console.log(defaultMochaOptsFileName);3const defaultMochaOptsFileName = require('stryker-parent').defaultMochaOptsFileName;4console.log(defaultMochaOptsFileName);5const defaultMochaOptsFileName = require('stryker-parent').defaultMochaOptsFileName;6console.log(defaultMochaOptsFileName);7const defaultMochaOptsFileName = require('stryker-parent').defaultMochaOptsFileName;8console.log(defaultMochaOptsFileName);9const defaultMochaOptsFileName = require('stryker-parent').defaultMochaOptsFileName;10console.log(defaultMochaOptsFileName);11const defaultMochaOptsFileName = require('stryker-parent').defaultMochaOptsFileName;12console.log(defaultMochaOptsFileName);13const defaultMochaOptsFileName = require('stryker-parent').defaultMochaOptsFileName;14console.log(defaultMochaOptsFileName);15const defaultMochaOptsFileName = require('stryker-parent').defaultMochaOptsFileName;16console.log(defaultMochaOptsFileName);17const defaultMochaOptsFileName = require('stryker-parent').defaultMochaOptsFileName;18console.log(defaultMochaOptsFileName);19const defaultMochaOptsFileName = require('stryker-parent').defaultMochaOptsFileName;20console.log(defaultMochaOptsFileName);21const defaultMochaOptsFileName = require('
Using AI Code Generation
1import {defaultMochaOptsFileName} from 'stryker-parent';2import {defaultMochaOptsFileName} from 'stryker-mocha-runner';3import {defaultMochaOptsFileName} from 'stryker-parent';4import {defaultMochaOptsFileName} from 'stryker-mocha-runner';5import {defaultMochaOptsFileName} from 'stryker-parent';6import {defaultMochaOptsFileName} from 'stryker-mocha-runner';7import {defaultMochaOptsFileName} from 'stryker-parent';8import {defaultMochaOptsFileName} from 'stryker-mocha-runner';9import {defaultMochaOptsFileName} from 'stryker-parent';10import {defaultMochaOptsFileName} from 'stryker-mocha-runner';11import {defaultMochaOptsFileName} from 'stryker-parent';12import {defaultMochaOptsFileName} from 'stryker-mocha-runner';13import {defaultMochaOptsFileName} from 'stryker-parent';14import {defaultMochaOptsFileName} from 'stryker-mocha-runner';15import {defaultMochaOptsFileName} from
Using AI Code Generation
1const { defaultMochaOptsFileName } = require('stryker-parent');2const { defaultMochaOptsFileName } = require('stryker-parent');3const { defaultMochaOptsFileName } = require('stryker-parent');4const { defaultMochaOptsFileName } = require('stryker-parent');5const { defaultMochaOptsFileName } = require('stryker-parent');6const { defaultMochaOptsFileName } = require('stryker-parent');7const { defaultMochaOptsFileName } = require('stryker-parent');8const { defaultMochaOptsFileName } = require('stryker-parent');9const { defaultMochaOptsFileName } = require('stryker-parent');10const { defaultMochaOptsFileName } = require('stryker-parent');11const { defaultMochaOptsFileName } = require('stryker-parent');12const { defaultMochaOptsFileName } = require('stryker-parent');13const { defaultMochaOptsFileName } = require('stryker-parent');14const { defaultMochaOptsFileName } = require('stryker-parent');15const { defaultMochaOptsFileName } = require('stryker-parent');
Using AI Code Generation
1const { defaultMochaOptsFileName } = require('stryker-parent');2console.log(defaultMochaOptsFileName);3const strykerParent = require('stryker-parent');4console.log(strykerParent.defaultMochaOptsFileName);5const { defaultMochaOptsFileName } = require('stryker-parent');6console.log(defaultMochaOptsFileName);7const strykerParent = require('stryker-parent');8console.log(strykerParent.defaultMochaOptsFileName);9const { defaultMochaOptsFileName } = require('stryker-parent');10console.log(defaultMochaOptsFileName);11const strykerParent = require('stryker-parent');12console.log(strykerParent.defaultMochaOptsFileName);13const { defaultMochaOptsFileName } = require('stryker-parent');14console.log(defaultMochaOptsFileName);15const strykerParent = require('stryker-parent');16console.log(strykerParent.defaultMochaOptsFileName);17const { defaultMochaOptsFileName } = require('stryker-parent');18console.log(defaultMochaOptsFileName);19const strykerParent = require('stryker-parent');20console.log(strykerParent.defaultMochaOptsFileName);21const { defaultMochaOptsFileName } = require('stryker-parent');22console.log(defaultMochaOptsFileName);
Using AI Code Generation
1var defaultMochaOptsFileName = require('stryker-parent').defaultMochaOptsFileName;2var mochaOptsFileName = defaultMochaOptsFileName();3var defaultMochaOptsFileName = require('stryker-mocha-runner').defaultMochaOptsFileName;4var mochaOptsFileName = defaultMochaOptsFileName();5var defaultMochaOptsFileName = require('stryker-mocha-runner').defaultMochaOptsFileName;6var mochaOptsFileName = defaultMochaOptsFileName();7var defaultMochaOptsFileName = require('stryker-mocha-runner').defaultMochaOptsFileName;8var mochaOptsFileName = defaultMochaOptsFileName();9var defaultMochaOptsFileName = require('stryker-mocha-runner').defaultMochaOptsFileName;10var mochaOptsFileName = defaultMochaOptsFileName();11var defaultMochaOptsFileName = require('stryker-mocha-runner').defaultMochaOptsFileName;12var mochaOptsFileName = defaultMochaOptsFileName();13var defaultMochaOptsFileName = require('stryker-mocha-runner').defaultMochaOptsFileName;14var mochaOptsFileName = defaultMochaOptsFileName();
Using AI Code Generation
1const defaultMochaOptsFileName = require('stryker-parent').defaultMochaOptsFileName;2const mochaOptsFile = defaultMochaOptsFileName();3const defaultMochaOptsFileName = require('stryker-parent').defaultMochaOptsFileName;4const mochaOptsFile = defaultMochaOptsFileName();5const defaultMochaOptsFileName = require('stryker-parent').defaultMochaOptsFileName;6const mochaOptsFile = defaultMochaOptsFileName();7const defaultMochaOptsFileName = require('stryker-parent').defaultMochaOptsFileName;8const mochaOptsFile = defaultMochaOptsFileName();9const defaultMochaOptsFileName = require('stryker-parent').defaultMochaOptsFileName;10const mochaOptsFile = defaultMochaOptsFileName();11const defaultMochaOptsFileName = require('stryker-parent').defaultMochaOptsFileName;12const mochaOptsFile = defaultMochaOptsFileName();13const defaultMochaOptsFileName = require('stryker-parent').defaultMochaOptsFileName;14const mochaOptsFile = defaultMochaOptsFileName();15const defaultMochaOptsFileName = require('stryker-parent').defaultMocha
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!!