Best JavaScript code snippet using stryker-parent
websiteBenchConfig.js
Source:websiteBenchConfig.js
1"use strict";2Object.defineProperty(exports, "__esModule", { value: true });3const fs_1 = require("fs");4const process_1 = require("process");5class WebsiteBenchConfig {6 constructor(confFiles, logObj) {7 this._configObj = {};8 this._versionNum = '2.0.6';9 this._allowCaching = false;10 this._ignoreSslErrors = false;11 this._logResourceErrors = false;12 this._maxConcurrentJobs = 5;13 this._minCheckInterval = 30;14 this._influxVersion = 1.7;15 this._influxDefaultAuth = 'userpass';16 this.logObj = null;17 this.logObj = logObj;18 let confFileData = this.readConfig(confFiles.configFile);19 let secretFileData = this.readConfig(confFiles.secretsFile);20 this._configObj = Object.assign({21 allowCaching: this._allowCaching,22 maxConcurrentJobs: this._maxConcurrentJobs,23 logResErrors: this._logResourceErrors,24 ignoreSslErrors: this._ignoreSslErrors,25 versionNum: this._versionNum26 }, confFileData);27 this._configObj.influxDb = {28 ...{ version: this._influxVersion, authmethod: this._influxDefaultAuth },29 ...this._configObj.influxDb,30 ...secretFileData.influxDb31 };32 try {33 this.checkMandatory();34 }35 catch (missingProp) {36 let missingPropsArray = missingProp.message.split(';');37 this.logObj.error(`Unable to start websiteBench.`);38 missingPropsArray.forEach(propName => {39 this.logObj.error(`Config file misses mandatory property: ${propName}`);40 });41 process_1.exit(1);42 }43 try {44 this.checkConfig();45 }46 catch (configError) {47 this.logObj.error(`Unable to start websiteBench.`);48 this.logObj.error(`Error in property "${configError.errorProperty}": ${configError.errorMessage}`);49 process_1.exit(1);50 }51 this.logObj.setSettings({ minLevel: this._configObj.logLevel });52 }53 configObj() {54 return this._configObj;55 }56 checkMandatory() {57 const mandatoryProps = ['maxConcurrentJobs', 'allowCaching', 'websiteList', 'influxDb', 'instanceName'];58 const mandatoryInflux = ['hostname', 'database', 'authmethod', 'version'];59 let missingProps = null;60 for (const objProp of mandatoryProps) {61 if (!(objProp in this._configObj)) {62 missingProps = (missingProps === null) ? objProp : `${missingProps};${objProp}`;63 }64 }65 for (const objProp of mandatoryInflux) {66 if (!(objProp in this._configObj.influxDb)) {67 missingProps = (missingProps === null) ? `influxDb.${objProp}` : `${missingProps};influxDb.${objProp}`;68 }69 }70 if (missingProps !== null) {71 throw new Error(missingProps);72 }73 return;74 }75 checkConfig() {76 const configError = Object.assign({ hasError: false });77 if (this._configObj.userAgent == '') {78 configError.hasError = true;79 configError.errorProperty = 'userAgent';80 configError.errorMessage = 'Setting cannot be empty';81 }82 if (typeof this._configObj.allowCaching !== 'boolean' || this._configObj.allowCaching === null) {83 configError.hasError = true;84 configError.errorProperty = 'allowCaching';85 configError.errorMessage = 'Needs to be a boolean value';86 }87 if (!('version' in this._configObj.influxDb) || typeof this._configObj.influxDb.version !== 'number') {88 configError.hasError = true;89 configError.errorProperty = 'influxDb => version';90 configError.errorMessage = 'InluxDb configuration setting "version" is not a number.';91 }92 if (!('authmethod' in this._configObj.influxDb) || typeof this._configObj.influxDb.authmethod !== 'string') {93 configError.hasError = true;94 configError.errorProperty = 'influxDb => authmethod';95 configError.errorMessage = 'InluxDb configuration setting "authmethod" is not a string.';96 }97 if ('authmethod' in this._configObj.influxDb && (this._configObj.influxDb.authmethod.toLowerCase() !== 'token' && this._configObj.influxDb.authmethod.toLowerCase() !== 'userpass')) {98 configError.hasError = true;99 configError.errorProperty = 'influxDb => authmethod';100 configError.errorMessage = `InluxDb configuration setting "authmethod" needs to be either "userpass" or "token": ${this._configObj.influxDb.authmethod}`;101 }102 if ('authmethod' in this._configObj.influxDb && this._configObj.influxDb.authmethod.toLowerCase() === 'token') {103 if (!('token' in this._configObj.influxDb) || this._configObj.influxDb.token === '' || this._configObj.influxDb.token === null) {104 configError.hasError = true;105 configError.errorProperty = 'influxDb => token';106 configError.errorMessage = `InluxDb configuration setting "token" value cannot be empty in token-auth mode`;107 }108 if (!('organization' in this._configObj.influxDb) || this._configObj.influxDb.organization === '' || this._configObj.influxDb.organization === null) {109 configError.hasError = true;110 configError.errorProperty = 'influxDb => organization';111 configError.errorMessage = `InluxDb configuration setting "organization" value cannot be empty in token-auth mode`;112 }113 }114 else {115 if (!('username' in this._configObj.influxDb) || this._configObj.influxDb.username === '' || this._configObj.influxDb.username === null) {116 configError.hasError = true;117 configError.errorProperty = 'influxDb => username';118 configError.errorMessage = `InluxDb configuration setting "username" value cannot be empty in userpass-auth mode`;119 }120 if (!('password' in this._configObj.influxDb) || this._configObj.influxDb.password === '' || this._configObj.influxDb.password === null) {121 configError.hasError = true;122 configError.errorProperty = 'influxDb => password';123 configError.errorMessage = `InluxDb configuration setting "password" value cannot be empty in userpass-auth mode`;124 }125 }126 if ('authmethod' in this._configObj.influxDb && this._configObj.influxDb.authmethod === 'token' && this._configObj.influxDb.version < 2) {127 configError.hasError = true;128 configError.errorProperty = 'influxDb => authmethod/version';129 configError.errorMessage = `InluxDb version below 2.0 does not support token authentication. Please switch to userpass-auth mode`;130 }131 this._configObj.websiteList.forEach(websiteEntry => {132 if (!('siteName' in websiteEntry) || typeof websiteEntry.siteName !== 'string') {133 configError.hasError = true;134 configError.errorProperty = 'websiteList => siteName';135 configError.errorMessage = 'Not all website list entries have a "siteName" property or the value is not a string';136 }137 if (!('siteUrl' in websiteEntry) || typeof websiteEntry.siteUrl !== 'string') {138 configError.hasError = true;139 configError.errorProperty = 'websiteList => siteUrl';140 configError.errorMessage = 'Not all website list entries have a "siteUrl" property or the value is not a string';141 }142 if ('checkType' in websiteEntry && typeof websiteEntry.checkType !== 'string') {143 configError.hasError = true;144 configError.errorProperty = 'websiteList => checkType';145 configError.errorMessage = 'Value of "checkType" is not a string';146 }147 if ('isDisabled' in websiteEntry && typeof websiteEntry.isDisabled !== 'boolean') {148 configError.hasError = true;149 configError.errorProperty = 'websiteList => isDisabled';150 configError.errorMessage = 'Value of "isDisabled" is not a boolean';151 }152 if (!('checkInterval' in websiteEntry) || typeof websiteEntry.checkInterval !== 'number') {153 configError.hasError = true;154 configError.errorProperty = 'websiteList => checkInterval';155 configError.errorMessage = 'Not all website list entries have a "checkInterval" property or the value is not a number';156 }157 if (websiteEntry.checkInterval < this._minCheckInterval) {158 configError.hasError = true;159 configError.errorProperty = 'checkInterval';160 configError.errorMessage = `"checkInterval" of website entry "${websiteEntry.siteName}" is too low. Minimum checkInterval is 60 seconds`;161 }162 if (websiteEntry.siteName === '' || websiteEntry.siteName === null) {163 configError.hasError = true;164 configError.errorProperty = 'siteName';165 configError.errorMessage = `"siteName" of website entry "${websiteEntry.siteName}" cannot be empty`;166 }167 if (websiteEntry.siteUrl === '' || websiteEntry.siteUrl === null) {168 configError.hasError = true;169 configError.errorProperty = 'siteUrl';170 configError.errorMessage = `"siteUrl" of website entry "${websiteEntry.siteName}" cannot be empty`;171 }172 if ('checkType' in websiteEntry && (websiteEntry.checkType.toLowerCase() !== 'browser' && websiteEntry.checkType.toLowerCase() !== 'curl')) {173 configError.hasError = true;174 configError.errorProperty = 'checkType';175 configError.errorMessage = `"checkType" of website entry "${websiteEntry.siteName}" has to be either "browser" or "curl"`;176 }177 try {178 new URL(websiteEntry.siteUrl);179 }180 catch (errorObj) {181 configError.hasError = true;182 configError.errorProperty = 'siteUrl';183 configError.errorMessage = `"siteUrl" of website entry "${websiteEntry.siteName}" is not a valid URL: ${errorObj.code}`;184 }185 });186 if (configError.hasError === true) {187 throw configError;188 }189 }190 readConfig(configFile) {191 if (configFile === null) {192 throw new Error('No config file path given.');193 }194 let configRaw, configJson;195 try {196 configRaw = fs_1.readFileSync(configFile, { encoding: 'utf-8' });197 }198 catch (errObj) {199 console.error(`Unable to read config file: ${errObj.message}`);200 process_1.exit(1);201 }202 try {203 configJson = JSON.parse(configRaw);204 }205 catch (errObj) {206 console.error(`Unable to parse config file: ${errObj.message}`);207 process_1.exit(1);208 }209 return configJson;210 }211 isBrowserNeeded() {212 let browserCount = 0;213 this._configObj.websiteList.forEach(siteEntry => {214 if (typeof siteEntry.checkType === 'undefined' || siteEntry.checkType === null) {215 browserCount++;216 }217 else if ('checkType' in siteEntry && siteEntry.checkType.toLowerCase() === 'browser') {218 browserCount++;219 }220 });221 return browserCount > 0;222 }223}...
ShellScript.test.ts
Source:ShellScript.test.ts
1import { ShellScript } from '../ShellScript';2import { ConfigError } from '../../errors';3describe('ShellScript', () => {4 describe('constructor', () => {5 test('should be instantiable with minimum config', () => {6 expect(7 () =>8 new ShellScript({9 type: 'shell',10 command: 'command'11 })12 ).not.toThrow();13 });14 test('should throw ConfigError if scriptFile is missing', () => {15 expect(16 () =>17 new ShellScript({18 type: 'shell'19 } as any)20 ).toThrowError(ConfigError);21 });22 test('should throw ConfigError if workingDirectory is empty or not a string', () => {23 expect(24 () =>25 new ShellScript({26 type: 'shell',27 command: 'command',28 workingDirectory: 12 as any29 })30 ).toThrowError(ConfigError);31 expect(32 () =>33 new ShellScript({34 type: 'shell',35 command: 'command',36 workingDirectory: ''37 })38 ).toThrowError(ConfigError);39 });40 test('should throw ConfigError if command is empty or not a string', () => {41 expect(42 () =>43 new ShellScript({44 type: 'shell',45 command: ''46 })47 ).toThrowError(ConfigError);48 expect(49 () =>50 new ShellScript({51 type: 'shell',52 command: 12 as any53 })54 ).toThrowError(ConfigError);55 expect(56 () =>57 new ShellScript({58 type: 'shell',59 command: (() => {}) as any60 })61 ).toThrowError(ConfigError);62 });63 it('should throw ConfigError if args is not strings', () => {64 expect(65 () =>66 new ShellScript({67 type: 'shell',68 command: 'command',69 args: [12] as any70 })71 ).toThrowError(ConfigError);72 expect(73 () =>74 new ShellScript({75 type: 'shell',76 command: 'command',77 args: [() => {}] as any78 })79 ).toThrowError(ConfigError);80 expect(81 () =>82 new ShellScript({83 type: 'shell',84 command: 'command',85 args: ['']86 })87 ).toThrowError(ConfigError);88 expect(89 () =>90 new ShellScript({91 type: 'shell',92 command: 'command',93 args: [null] as any94 })95 ).toThrowError(ConfigError);96 });97 });...
ConfigError.spec.ts
Source:ConfigError.spec.ts
1import { ConfigError } from '../../../../../src/core/configuration';2describe('ConfigError', () => {3 describe(`Create "Variable not set error" `, () => {4 it(`When variable is HOST, expect ConfigError says that HOST variable is not set`, () => {5 const expectedErrorMessage: string = 'HOST not set.';6 const error: ConfigError = ConfigError.createVariableNotSetError('HOST');7 expect(error).toBeInstanceOf(ConfigError);8 expect(error.message).toBe(expectedErrorMessage);9 });10 });11 describe(`Create "Variable parsing error"`, () => {12 it(`When variable is HOST, expect ConfigError says there is an error when parsing a HOST variable`, () => {13 const expectedErrorMessage: string = 'HOST parsing error.';14 const error: ConfigError = ConfigError.createVariableParsingError('HOST');15 expect(error).toBeInstanceOf(ConfigError);16 expect(error.message).toBe(expectedErrorMessage);17 });18 });...
Using AI Code Generation
1const { ConfigError } = require('stryker');2throw new ConfigError('This is a config error');3module.exports = function(config) {4 config.set({5 commandRunner: {6 }7 });8};
Using AI Code Generation
1var stryker = require('stryker-parent');2stryker.ConfigError('test');3module.exports = {4 ConfigError: function (message) {5 console.log(message);6 }7}8var stryker = require('stryker-parent');9stryker.ConfigError('test');10module.exports = {11 ConfigError: function (message) {12 console.log(message);13 }14}15var stryker = require('stryker-parent');16stryker.ConfigError('test');17module.exports = {18 ConfigError: function (message) {19 console.log(message);20 }21}22var stryker = require('stryker-parent');23stryker.ConfigError('test');24module.exports = {25 ConfigError: function (message) {26 console.log(message);27 }28}29var stryker = require('stryker-parent');30stryker.ConfigError('test');31module.exports = {32 ConfigError: function (message) {33 console.log(message);34 }35}36var stryker = require('stryker-parent');37stryker.ConfigError('test');
Using AI Code Generation
1var stryker = require('stryker-parent');2stryker.ConfigError('test error');3function ConfigError(message) {4 this.message = message;5 this.name = 'ConfigError';6}7exports.ConfigError = ConfigError;8var Stryker = require('./Stryker');9var stryker = new Stryker();10exports.ConfigError = stryker.ConfigError;11{12}13{14 "dependencies": {15 }16}
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!!