How to use excessPropertyNames method in stryker-parent

Best JavaScript code snippet using stryker-parent

options-validator.ts

Source:options-validator.ts Github

copy

Full Screen

1import os from 'os';2import path from 'path';3import glob from 'glob';4import Ajv, { ValidateFunction } from 'ajv';5import { StrykerOptions, strykerCoreSchema } from '@stryker-mutator/api/core';6import { tokens, commonTokens } from '@stryker-mutator/api/plugin';7import { noopLogger, findUnserializables, Immutable, deepFreeze } from '@stryker-mutator/util';8import { Logger } from '@stryker-mutator/api/logging';9import type { JSONSchema7 } from 'json-schema';10import { coreTokens } from '../di/index.js';11import { ConfigError } from '../errors.js';12import { objectUtils, optionsPath } from '../utils/index.js';13import { CommandTestRunner } from '../test-runner/command-test-runner.js';14import { IGNORE_PATTERN_CHARACTER, MUTATION_RANGE_REGEX } from '../fs/index.js';15import { describeErrors } from './validation-errors.js';16const ajv = new Ajv({ useDefaults: true, allErrors: true, jsPropertySyntax: true, verbose: true, logger: false, strict: false });17export class OptionsValidator {18 private readonly validateFn: ValidateFunction;19 public static readonly inject = tokens(coreTokens.validationSchema, commonTokens.logger);20 constructor(private readonly schema: JSONSchema7, private readonly log: Logger) {21 this.validateFn = ajv.compile(schema);22 }23 /**24 * Validates the provided options, throwing an error if something is wrong.25 * Optionally also warns about excess or unserializable options.26 * @param options The stryker options to validate27 * @param mark Wether or not to log warnings on unknown properties or unserializable properties28 */29 public validate(options: Record<string, unknown>, mark = false): asserts options is StrykerOptions {30 this.removeDeprecatedOptions(options);31 this.schemaValidate(options);32 this.customValidation(options);33 if (mark) {34 this.markOptions(options);35 }36 }37 private removeDeprecatedOptions(rawOptions: Record<string, unknown>) {38 if (typeof rawOptions.mutator === 'string') {39 this.log.warn(40 '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.'41 );42 delete rawOptions.mutator;43 }44 // @ts-expect-error mutator.name45 if (typeof rawOptions.mutator === 'object' && rawOptions.mutator.name) {46 this.log.warn(47 '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.'48 );49 // @ts-expect-error mutator.name50 delete rawOptions.mutator.name;51 }52 if (Object.keys(rawOptions).includes('testFramework')) {53 this.log.warn(54 '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.'55 );56 delete rawOptions.testFramework;57 }58 if (Array.isArray(rawOptions.transpilers)) {59 const example = rawOptions.transpilers.includes('babel')60 ? 'babel src --out-dir lib'61 : rawOptions.transpilers.includes('typescript')62 ? 'tsc -b'63 : rawOptions.transpilers.includes('webpack')64 ? 'webpack --config webpack.config.js'65 : 'npm run build';66 this.log.warn(67 `DEPRECATED. Support for "transpilers" is removed. You can now configure your own "${optionsPath('buildCommand')}". For example, ${example}.`68 );69 delete rawOptions.transpilers;70 }71 if (Array.isArray(rawOptions.files)) {72 const ignorePatternsName = optionsPath('ignorePatterns');73 const isString = (uncertain: unknown): uncertain is string => typeof uncertain === 'string';74 const files = rawOptions.files.filter(isString);75 const newIgnorePatterns: string[] = [76 '**',77 ...files.map((filePattern) =>78 filePattern.startsWith(IGNORE_PATTERN_CHARACTER) ? filePattern.substr(1) : `${IGNORE_PATTERN_CHARACTER}${filePattern}`79 ),80 ];81 delete rawOptions.files;82 this.log.warn(83 `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(84 newIgnorePatterns85 )}. See https://stryker-mutator.io/docs/stryker-js/configuration/#ignorepatterns-string`86 );87 const existingIgnorePatterns = Array.isArray(rawOptions[ignorePatternsName]) ? (rawOptions[ignorePatternsName] as unknown[]) : [];88 rawOptions[ignorePatternsName] = [...newIgnorePatterns, ...existingIgnorePatterns];89 }90 // @ts-expect-error jest.enableBail91 if (rawOptions.jest?.enableBail !== undefined) {92 this.log.warn(93 'DEPRECATED. Use of "jest.enableBail" is deprecated, please use "disableBail" instead. See https://stryker-mutator.io/docs/stryker-js/configuration#disablebail-boolean'94 );95 // @ts-expect-error jest.enableBail96 rawOptions.disableBail = !rawOptions.jest?.enableBail;97 // @ts-expect-error jest.enableBail98 delete rawOptions.jest.enableBail;99 }100 // @ts-expect-error htmlReporter.baseDir101 if (rawOptions.htmlReporter?.baseDir) {102 this.log.warn(103 `DEPRECATED. Use of "htmlReporter.baseDir" is deprecated, please use "${optionsPath(104 'htmlReporter',105 'fileName'106 )}" instead. See https://stryker-mutator.io/docs/stryker-js/configuration/#reporters-string`107 );108 // @ts-expect-error htmlReporter.baseDir109 if (!rawOptions.htmlReporter.fileName) {110 // @ts-expect-error htmlReporter.baseDir111 rawOptions.htmlReporter.fileName = path.join(String(rawOptions.htmlReporter.baseDir), 'index.html');112 }113 // @ts-expect-error htmlReporter.baseDir114 delete rawOptions.htmlReporter.baseDir;115 }116 }117 private customValidation(options: StrykerOptions) {118 const additionalErrors: string[] = [];119 if (options.thresholds.high < options.thresholds.low) {120 additionalErrors.push('Config option "thresholds.high" should be higher than "thresholds.low".');121 }122 if (options.maxConcurrentTestRunners !== Number.MAX_SAFE_INTEGER) {123 this.log.warn('DEPRECATED. Use of "maxConcurrentTestRunners" is deprecated. Please use "concurrency" instead.');124 if (!options.concurrency && options.maxConcurrentTestRunners < os.cpus().length - 1) {125 options.concurrency = options.maxConcurrentTestRunners;126 }127 }128 if (CommandTestRunner.is(options.testRunner)) {129 if (options.testRunnerNodeArgs.length) {130 this.log.warn(131 '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.'132 );133 }134 }135 if (options.ignoreStatic && options.coverageAnalysis !== 'perTest') {136 additionalErrors.push(137 `Config option "${optionsPath('ignoreStatic')}" is not supported with coverage analysis "${138 options.coverageAnalysis139 }". Either turn off "${optionsPath('ignoreStatic')}", or configure "${optionsPath('coverageAnalysis')}" to be "perTest".`140 );141 }142 options.mutate.forEach((mutateString, index) => {143 const match = MUTATION_RANGE_REGEX.exec(mutateString);144 if (match) {145 if (glob.hasMagic(mutateString)) {146 additionalErrors.push(147 `Config option "mutate[${index}]" is invalid. Cannot combine a glob expression with a mutation range in "${mutateString}".`148 );149 } else {150 const [_, _fileName, mutationRange, startLine, _startColumn, endLine, _endColumn] = match;151 const start = parseInt(startLine, 10);152 const end = parseInt(endLine, 10);153 if (start < 1) {154 additionalErrors.push(155 `Config option "mutate[${index}]" is invalid. Mutation range "${mutationRange}" is invalid, line ${start} does not exist (lines start at 1).`156 );157 }158 if (start > end) {159 additionalErrors.push(160 `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}).`161 );162 }163 }164 }165 });166 additionalErrors.forEach((error) => this.log.error(error));167 this.throwErrorIfNeeded(additionalErrors);168 }169 private schemaValidate(options: unknown): asserts options is StrykerOptions {170 if (!this.validateFn(options)) {171 const describedErrors = describeErrors(this.validateFn.errors!);172 describedErrors.forEach((error) => this.log.error(error));173 this.throwErrorIfNeeded(describedErrors);174 }175 }176 private throwErrorIfNeeded(errors: string[]) {177 if (errors.length > 0) {178 throw new ConfigError(179 errors.length === 1 ? 'Please correct this configuration error and try again.' : 'Please correct these configuration errors and try again.'180 );181 }182 }183 private markOptions(options: StrykerOptions): void {184 this.markExcessOptions(options);185 this.markUnserializableOptions(options);186 }187 private markExcessOptions(options: StrykerOptions) {188 const OPTIONS_ADDED_BY_STRYKER = ['set', 'configFile', '$schema'];189 if (objectUtils.isWarningEnabled('unknownOptions', options.warnings)) {190 const schemaKeys = Object.keys(this.schema.properties!);191 const excessPropertyNames = Object.keys(options)192 .filter((key) => !key.endsWith('_comment'))193 .filter((key) => !OPTIONS_ADDED_BY_STRYKER.includes(key))194 .filter((key) => !schemaKeys.includes(key));195 if (excessPropertyNames.length) {196 excessPropertyNames.forEach((excessPropertyName) => {197 this.log.warn(`Unknown stryker config option "${excessPropertyName}".`);198 });199 this.log.warn(`Possible causes:200 * Is it a typo on your end?201 * Did you only write this property as a comment? If so, please postfix it with "_comment".202 * You might be missing a plugin that is supposed to use it. Stryker loaded plugins from: ${JSON.stringify(options.plugins)}203 * The plugin that is using it did not contribute explicit validation. 204 (disable "${optionsPath('warnings', 'unknownOptions')}" to ignore this warning)`);205 }206 }207 }208 private markUnserializableOptions(options: StrykerOptions) {209 if (objectUtils.isWarningEnabled('unserializableOptions', options.warnings)) {210 const unserializables = findUnserializables(options);211 if (unserializables) {212 unserializables.forEach((unserializable) =>213 this.log.warn(214 `Config option "${unserializable.path.join('.')}" is not (fully) serializable. ${215 unserializable.reason216 }. Any test runner or checker worker processes might not receive this value as intended.`217 )218 );219 this.log.warn(`(disable ${optionsPath('warnings', 'unserializableOptions')} to ignore this warning)`);220 }221 }222 }223}224export function createDefaultOptions(): StrykerOptions {225 const options: Record<string, unknown> = {};226 const validator: OptionsValidator = new OptionsValidator(strykerCoreSchema, noopLogger);227 validator.validate(options);228 return options;229}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1module.exports = {2}3export function excessPropertyNames(): string[];4{5}6{7 "compilerOptions": {8 }9}10{11}12{13 "scripts": {14 }15}16{17 "scripts": {18 },19 "devDependencies": {20 }21}22{23 "scripts": {24 },25 "devDependencies": {26 },27 "publishConfig": {28 }29}30{

Full Screen

Using AI Code Generation

copy

Full Screen

1const strykerParent = require('stryker-parent');2const strykerParentConfig = strykerParent.config;3const excessPropertyNames = strykerParent.excessPropertyNames;4const strykerParent = require('stryker-parent');5const strykerParentConfig = strykerParent.config;6const excessPropertyNames = strykerParent.excessPropertyNames;7const strykerParent = require('stryker-parent');8const strykerParentConfig = strykerParent.config;9const excessPropertyNames = strykerParent.excessPropertyNames;10const strykerParent = require('stryker-parent');11const strykerParentConfig = strykerParent.config;12const excessPropertyNames = strykerParent.excessPropertyNames;13const strykerParent = require('stryker-parent');14const strykerParentConfig = strykerParent.config;15const excessPropertyNames = strykerParent.excessPropertyNames;16const strykerParent = require('stryker-parent');17const strykerParentConfig = strykerParent.config;18const excessPropertyNames = strykerParent.excessPropertyNames;19const strykerParent = require('stryker-parent');20const strykerParentConfig = strykerParent.config;21const excessPropertyNames = strykerParent.excessPropertyNames;22const strykerParent = require('stryker-parent');23const strykerParentConfig = strykerParent.config;24const excessPropertyNames = strykerParent.excessPropertyNames;25const strykerParent = require('stryker-parent');26const strykerParentConfig = strykerParent.config;27const excessPropertyNames = strykerParent.excessPropertyNames;28const strykerParent = require('stryker-parent');

Full Screen

Using AI Code Generation

copy

Full Screen

1const stryker = require('stryker-parent');2const strykerConfig = stryker.configReader.readConfig();3const excessProperties = stryker.configReader.excessPropertyNames(strykerConfig);4console.log(excessProperties);5const stryker = require('stryker');6const strykerConfig = stryker.configReader.readConfig();7const excessProperties = stryker.configReader.excessPropertyNames(strykerConfig);8console.log(excessProperties);9const stryker = require('stryker-api');10const strykerConfig = stryker.configReader.readConfig();11const excessProperties = stryker.configReader.excessPropertyNames(strykerConfig);12console.log(excessProperties);13const stryker = require('stryker-cli');14const strykerConfig = stryker.configReader.readConfig();15const excessProperties = stryker.configReader.excessPropertyNames(strykerConfig);16console.log(excessProperties);17const stryker = require('stryker-html-reporter');18const strykerConfig = stryker.configReader.readConfig();19const excessProperties = stryker.configReader.excessPropertyNames(strykerConfig);20console.log(excessProperties);21const stryker = require('stryker-jasmine');22const strykerConfig = stryker.configReader.readConfig();23const excessProperties = stryker.configReader.excessPropertyNames(strykerConfig);24console.log(excessProperties);25const stryker = require('stryker-jest-runner');26const strykerConfig = stryker.configReader.readConfig();27const excessProperties = stryker.configReader.excessPropertyNames(strykerConfig);28console.log(excessProperties);29const stryker = require('stryker-mocha-framework');30const strykerConfig = stryker.configReader.readConfig();31const excessProperties = stryker.configReader.excessPropertyNames(strykerConfig);32console.log(ex

Full Screen

Using AI Code Generation

copy

Full Screen

1var strykerParent = require('stryker-parent');2var excessPropertyNames = strykerParent.excessPropertyNames;3var strykerConfig = {4 karma: {5 config: {6 files: [{7 }, {8 }, {9 }],10 }11 }12};13var validConfig = {14 karma: {15 }16};17console.log(excessPropertyNames(strykerConfig, validConfig));18var strykerConfig = {19 karma: {20 config: {21 files: [{22 }, {23 }, {24 }],25 }26 }27};28var validConfig = {29 karma: {30 }31};32console.log(excessPropertyNames(str

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run stryker-parent automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful