Best JavaScript code snippet using stryker-parent
options-validator.ts
Source:options-validator.ts
1import os from 'os';2import { hasMagic } from 'glob';3import Ajv, { ValidateFunction } from 'ajv';4import { StrykerOptions, strykerCoreSchema } from '@stryker-mutator/api/core';5import { tokens, commonTokens } from '@stryker-mutator/api/plugin';6import { noopLogger, propertyPath, deepFreeze } from '@stryker-mutator/util';7import { Logger } from '@stryker-mutator/api/logging';8import type { JSONSchema7 } from 'json-schema';9import { coreTokens } from '../di';10import { ConfigError } from '../errors';11import { CommandTestRunner } from '../test-runner/command-test-runner';12import { IGNORE_PATTERN_CHARACTER, MUTATION_RANGE_REGEX } from '../input';13import { describeErrors } from './validation-errors';14const ajv = new Ajv({ useDefaults: true, allErrors: true, jsPropertySyntax: true, verbose: true, logger: false, strict: false });15export class OptionsValidator {16 private readonly validateFn: ValidateFunction;17 public static readonly inject = tokens(coreTokens.validationSchema, commonTokens.logger);18 constructor(schema: JSONSchema7, private readonly log: Logger) {19 this.validateFn = ajv.compile(schema);20 }21 public validate(options: Record<string, unknown>): asserts options is StrykerOptions {22 this.removeDeprecatedOptions(options);23 this.schemaValidate(options);24 this.additionalValidation(options);25 }26 private removeDeprecatedOptions(rawOptions: Record<string, unknown>) {27 if (typeof rawOptions.mutator === 'string') {28 this.log.warn(29 'DEPRECATED. Use of "mutator" as string is no longer needed. You can remove it from your configuration. Stryker now supports mutating of JavaScript and friend files out of the box.'30 );31 delete rawOptions.mutator;32 }33 // @ts-expect-error mutator.name34 if (typeof rawOptions.mutator === 'object' && rawOptions.mutator.name) {35 this.log.warn(36 'DEPRECATED. Use of "mutator.name" is no longer needed. You can remove "mutator.name" from your configuration. Stryker now supports mutating of JavaScript and friend files out of the box.'37 );38 // @ts-expect-error mutator.name39 delete rawOptions.mutator.name;40 }41 if (Object.keys(rawOptions).includes('testFramework')) {42 this.log.warn(43 'DEPRECATED. Use of "testFramework" is no longer needed. You can remove it from your configuration. Your test runner plugin now handles its own test framework integration.'44 );45 delete rawOptions.testFramework;46 }47 if (Array.isArray(rawOptions.transpilers)) {48 const example = rawOptions.transpilers.includes('babel')49 ? 'babel src --out-dir lib'50 : rawOptions.transpilers.includes('typescript')51 ? 'tsc -b'52 : rawOptions.transpilers.includes('webpack')53 ? 'webpack --config webpack.config.js'54 : 'npm run build';55 this.log.warn(56 `DEPRECATED. Support for "transpilers" is removed. You can now configure your own "${propertyPath<StrykerOptions>(57 'buildCommand'58 )}". For example, ${example}.`59 );60 delete rawOptions.transpilers;61 }62 if (Array.isArray(rawOptions.files)) {63 const ignorePatternsName = propertyPath<StrykerOptions>('ignorePatterns');64 const isString = (uncertain: unknown): uncertain is string => typeof uncertain === 'string';65 const files = rawOptions.files.filter(isString);66 const newIgnorePatterns: string[] = [67 '**',68 ...files.map((filePattern) =>69 filePattern.startsWith(IGNORE_PATTERN_CHARACTER) ? filePattern.substr(1) : `${IGNORE_PATTERN_CHARACTER}${filePattern}`70 ),71 ];72 delete rawOptions.files;73 this.log.warn(74 `DEPRECATED. Use of "files" is deprecated, please use "${ignorePatternsName}" instead (or remove "files" altogether will probably work as well). For now, rewriting them as ${JSON.stringify(75 newIgnorePatterns76 )}. See https://stryker-mutator.io/docs/stryker-js/configuration/#ignorepatterns-string`77 );78 const existingIgnorePatterns = Array.isArray(rawOptions[ignorePatternsName]) ? (rawOptions[ignorePatternsName] as unknown[]) : [];79 rawOptions[ignorePatternsName] = [...newIgnorePatterns, ...existingIgnorePatterns];80 }81 // @ts-expect-error jest.enableBail82 if (rawOptions.jest?.enableBail !== undefined) {83 this.log.warn(84 'DEPRECATED. Use of "jest.enableBail" inside deprecated, please use "disableBail" instead. See https://stryker-mutator.io/docs/stryker-js/configuration#disablebail-boolean'85 );86 // @ts-expect-error jest.enableBail87 rawOptions.disableBail = !rawOptions.jest?.enableBail;88 // @ts-expect-error jest.enableBail89 delete rawOptions.jest.enableBail;90 }91 }92 private additionalValidation(options: StrykerOptions) {93 const additionalErrors: string[] = [];94 if (options.thresholds.high < options.thresholds.low) {95 additionalErrors.push('Config option "thresholds.high" should be higher than "thresholds.low".');96 }97 if (options.maxConcurrentTestRunners !== Number.MAX_SAFE_INTEGER) {98 this.log.warn('DEPRECATED. Use of "maxConcurrentTestRunners" is deprecated. Please use "concurrency" instead.');99 if (!options.concurrency && options.maxConcurrentTestRunners < os.cpus().length - 1) {100 options.concurrency = options.maxConcurrentTestRunners;101 }102 }103 if (CommandTestRunner.is(options.testRunner)) {104 if (options.testRunnerNodeArgs.length) {105 this.log.warn(106 'Using "testRunnerNodeArgs" together with the "command" test runner is not supported, these arguments will be ignored. You can add your custom arguments by setting the "commandRunner.command" option.'107 );108 }109 }110 options.mutate.forEach((mutateString, index) => {111 const match = MUTATION_RANGE_REGEX.exec(mutateString);112 if (match) {113 if (hasMagic(mutateString)) {114 additionalErrors.push(115 `Config option "mutate[${index}]" is invalid. Cannot combine a glob expression with a mutation range in "${mutateString}".`116 );117 } else {118 const [_, _fileName, mutationRange, startLine, _startColumn, endLine, _endColumn] = match;119 const start = parseInt(startLine, 10);120 const end = parseInt(endLine, 10);121 if (start < 1) {122 additionalErrors.push(123 `Config option "mutate[${index}]" is invalid. Mutation range "${mutationRange}" is invalid, line ${start} does not exist (lines start at 1).`124 );125 }126 if (start > end) {127 additionalErrors.push(128 `Config option "mutate[${index}]" is invalid. Mutation range "${mutationRange}" is invalid. The "from" line number (${start}) should be less then the "to" line number (${end}).`129 );130 }131 }132 }133 });134 additionalErrors.forEach((error) => this.log.error(error));135 this.throwErrorIfNeeded(additionalErrors);136 }137 private schemaValidate(options: unknown): asserts options is StrykerOptions {138 if (!this.validateFn(options)) {139 const describedErrors = describeErrors(this.validateFn.errors!);140 describedErrors.forEach((error) => this.log.error(error));141 this.throwErrorIfNeeded(describedErrors);142 }143 }144 private throwErrorIfNeeded(errors: string[]) {145 if (errors.length > 0) {146 throw new ConfigError(147 errors.length === 1 ? 'Please correct this configuration error and try again.' : 'Please correct these configuration errors and try again.'148 );149 }150 }151}152export function defaultOptions(): StrykerOptions {153 const options: Record<string, unknown> = {};154 const validator: OptionsValidator = new OptionsValidator(strykerCoreSchema, noopLogger);155 validator.validate(options);156 return options;157}158validateOptions.inject = tokens(commonTokens.options, coreTokens.optionsValidator);159export function validateOptions(options: Record<string, unknown>, optionsValidator: OptionsValidator): StrykerOptions {160 optionsValidator.validate(options);161 return deepFreeze(options) as StrykerOptions;...
is-help-available.ts
Source:is-help-available.ts
1import includes from 'lodash-es/includes';2const describedErrors = [3 'InvalidPaymentTool',4 'AccountLimitsExceeded',5 'InsufficientFunds',6 'PreauthorizationFailed',7 'RejectedByIssuer',8 'PaymentRejected'9];...
Using AI Code Generation
1const { describeErrors } = require('stryker-parent');2describeErrors();3const { describeErrors } = require('stryker-parent');4describeErrors();5const { describeErrors } = require('stryker-parent');6describeErrors();7const { describeErrors } = require('stryker-parent');8describeErrors();9const { describeErrors } = require('stryker-parent');10describeErrors();11const { describeErrors } = require('stryker-parent');12describeErrors();13const { describeErrors } = require('stryker-parent');14describeErrors();15const { describeErrors } = require('stryker-parent');16describeErrors();17const { describeErrors } = require('stryker-parent');18describeErrors();19const { describeErrors } = require('stryker-parent');20describeErrors();21const { describeErrors } = require('stryker-parent');22describeErrors();23const { describeErrors } = require('stryker-parent');24describeErrors();25const { describeErrors } = require('stryker-parent');26describeErrors();27const { describeErrors } = require('stryker-parent');28describeErrors();29const { describeErrors } = require('stry
Using AI Code Generation
1const { describeErrors } = require('stryker-parent');2describeErrors();3const { describeErrors } = require('stryker-parent');4describeErrors();5const { describeErrors } = require('stryker-parent');6describeErrors();7const { describeErrors } = require('stryker-parent');8describeErrors();9const { describeErrors } = require('stryker-parent');10describeErrors();11const { describeErrors } = require('stryker-parent');12describeErrors();13const { describeErrors } = require('stryker-parent');14describeErrors();15const { describeErrors } = require('stryker-parent');16describeErrors();17const { describeErrors } = require('stryker-parent');18describeErrors();19const { describeErrors } = require('stryker-parent');20describeErrors();21const { describeErrors } = require('stryker-parent');22describeErrors();23const { describeErrors } = require('stryker-parent');24describeErrors();25const { describeErrors } = require('stryker-parent');26describeErrors();27const { describeErrors } = require('stryker-parent');28describeErrors();29const { describeErrors } = require('stryker-parent');30describeErrors();31const { describeErrors } = require('stryker-parent');32describeErrors();33const { describe
Using AI Code Generation
1const {describedErrors} = require('stryker-parent');2const strykerParent = require('stryker-parent');3const {describedErrors: {StrykerError}} = require('stryker-parent');4const {describedErrors} = require('stryker-parent');5const strykerParent = require('stryker-parent');6const {describedErrors: {StrykerError}} = require('stryker-parent');7const {describedErrors} = require('stryker-parent');8const strykerParent = require('stryker-parent');9const {describedErrors: {StrykerError}} = require('stryker-parent');10const {describedErrors} = require('stryker-parent');11const strykerParent = require('stryker-parent');12const {describedErrors: {StrykerError}} = require('stryker-parent');13const {describedErrors} = require('stryker-parent');14const strykerParent = require('stryker-parent');15const {describedErrors: {StrykerError}} = require('stryker-parent');16const {describedErrors} = require('stryker-parent');17const strykerParent = require('stryker-parent');18const {des
Using AI Code Generation
1const { describedErrors } = require('stryker-parent');2function* generator() {3 yield 1;4}5try {6 generator().next();7} catch (error) {8 console.log(describedErrors(error));9}10const { describeError } = require('stryker-parent');11function* generator() {12 yield 1;13}14try {15 generator().next();16} catch (error) {17 console.log(describeError(error));18}19const { describedErrors } = require('stryker-parent');20function* generator() {
Using AI Code Generation
1const { strykerParent } = require('stryker-parent');2const { describeErrors } = strykerParent;3describeErrors([4 { name: 'testError', message: 'This is a test error' }5]);6const { strykerParent } = require('stryker-parent');7const { describeErrors } = strykerParent;8describeErrors([9 { name: 'testError', message: 'This is a test error' }10]);11import { strykerParent } from 'stryker-parent';12const { describeErrors } = strykerParent;13describeErrors([14 { name: 'testError', message: 'This is a test error' }15]);16import { strykerParent } from 'stryker-parent';17const { describeErrors } = strykerParent;18describeErrors([19 { name: 'testError', message: 'This is a test error' }20]);21import { strykerParent } from 'stryker-parent';22const { describeErrors } = strykerParent;23describeErrors([24 { name: 'testError', message: 'This is a test error' }25]);26Read our [contributing guide](
Using AI Code Generation
1var stryker = require('stryker');2var myError = stryker.describedErrors('myError', 'My Error');3var error = new myError('My Error Message');4var stryker = require('stryker');5var myError = stryker.describedErrors('myError', 'My Error', Error);6var error = new myError('My Error Message');
Using AI Code Generation
1const {describeErrors} = require('stryker-parent');2const {MyError} = require('./my-error');3describeErrors(MyError, (error) => {4 error('MyError', (err) => {5 err('message', 'message');6 err('code', 'code');7 });8});9const {describeErrors} = require('stryker-parent');10const {MySubError} = require('./my-sub-error');11describeErrors(MyError, (error) => {12 error('MyError', (err) => {13 err('message', 'message');14 err('code', 'code');15 });16 error('MySubError', MySubError, (err) => {17 err('message', 'message');18 err('code', 'code');19 });20});21const {describeErrors} = require('stryker-parent');22const {MySubSubError} = require('./my-sub-sub-error');23describeErrors(MyError, (error) => {24 error('MyError', (err) => {25 err('message', 'message');26 err('code', 'code');27 });28 error('MySubError', MySubError, (err) => {29 err('message', 'message');30 err('code', 'code');31 });32 error('MySubSubError', MySubSubError, (err) => {33 err('message', 'message');34 err('code', 'code');35 });36});37const {describeErrors} = require('stryker-parent');38describeErrors(MyError, (error) => {39 error('MyError', (err) => {40 err('message', 'message');41 err('code', 'code');42 });43 error('MySubError', MySubError, (err) => {44 err('message', 'message');45 err('code', 'code');46 });47 error('MySubSubError', MySubSubError, (err) => {48 err('message', 'message');49 err('code', 'code');50 });51});
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!!