Best JavaScript code snippet using stryker-parent
config-helper.js
Source:config-helper.js
1import Bluebird from 'bluebird';2import path from 'path';3import fs from 'fs';4import url from 'url';5import _ from 'lodash';6import helpers from './index';7import getYArgs from '../core/yargs';8const args = getYArgs().argv;9const api = {10 config: undefined,11 rawConfig: undefined,12 error: undefined,13 init () {14 return Bluebird.resolve()15 .then(() => {16 let config;17 if (args.url) {18 config = api.parseDbUrl(args.url);19 } else {20 try {21 config = require(api.getConfigFile());22 } catch (e) {23 api.error = e;24 }25 }26 return config;27 })28 .then(config => {29 if (typeof config === 'object' || config === undefined) {30 return config;31 } else if (config.length === 1) {32 return Bluebird.promisify(config)();33 } else {34 return config();35 }36 })37 .then(config => {38 api.rawConfig = config;39 })40 .then(() => {41 // Always return the full config api42 return api;43 });44 },45 getConfigFile () {46 if (args.config) {47 return path.resolve(process.cwd(), args.config);48 }49 const defaultPath = path.resolve(process.cwd(), 'config', 'config.json');50 const alternativePath = defaultPath.replace('.json', '.js');51 return helpers.path.existsSync(alternativePath) ? alternativePath : defaultPath;52 },53 getModelsIndexFile () {54 return helpers.path.getModelPath('index');55 },56 relativeConfigFile () {57 return path.relative(process.cwd(), api.getConfigFile());58 },59 configFileExists () {60 return helpers.path.existsSync(api.getConfigFile());61 },62 getDefaultConfig () {63 return (64 JSON.stringify(65 {66 development: {67 database: {68 url: 'mongodb://localhost/mongoose_dev',69 options: {70 useNewUrlParser: true,71 },72 },73 },74 test: {75 database: {76 url: 'mongodb://localhost/mongoose_test',77 options: {78 useNewUrlParser: true,79 },80 },81 },82 production: {83 database: {84 protocol: 'mongodb',85 username: 'root',86 password: 'password',87 name: 'database_production',88 host: 'localhost',89 port: '',90 options: {91 useNewUrlParser: true,92 //dbName: "" // uncomment this line if you use something like mongo atlas93 },94 },95 },96 },97 undefined,98 2,99 ) + '\n'100 );101 },102 writeDefaultConfig () {103 const configPath = path.dirname(api.getConfigFile());104 if (!helpers.path.existsSync(configPath)) {105 helpers.asset.mkdirp(configPath);106 }107 fs.writeFileSync(api.getConfigFile(), api.getDefaultConfig());108 },109 readConfig () {110 if (!api.config) {111 const env = helpers.generic.getEnvironment();112 if (api.rawConfig === undefined) {113 throw new Error('Error reading "' + api.relativeConfigFile() + '". Error: ' + api.error);114 }115 if (typeof api.rawConfig !== 'object') {116 throw new Error('Config must be an object or a promise for an object: ' + api.relativeConfigFile());117 }118 if (args.url) {119 helpers.view.log('Parsed url ' + api.filteredUrl(args.url, api.rawConfig));120 } else {121 helpers.view.log('Loaded configuration file "' + api.relativeConfigFile() + '".');122 }123 if (api.rawConfig[env]) {124 helpers.view.log('Using environment "' + env + '".');125 api.rawConfig = api.rawConfig[env];126 }127 // The Sequelize library needs a function passed in to its logging option128 if (api.rawConfig.database.logging && !_.isFunction(api.rawConfig.database.logging)) {129 api.rawConfig.database.logging = console.log;130 }131 // in case url is present - we overwrite the configuration132 if (api.rawConfig.database.url) {133 api.rawConfig.database = _.merge(api.rawConfig.database, api.parseDbUrl(api.rawConfig.database.url));134 }135 api.config = api.rawConfig;136 }137 return api.config;138 },139 readConf () {140 try {141 api.config = require(api.getConfigFile());142 api.rawConfig = api.config;143 } catch (e) {144 throw new Error(145 'Error occured when looking for "' +146 api.relativeConfigFile() +147 '". Kindly bootstrap the project using "mongoose init" comand.',148 );149 }150 const env = helpers.generic.getEnvironment();151 if (api.rawConfig === undefined) {152 throw new Error('Error reading "' + api.relativeConfigFile() + '". Error: ' + api.error);153 }154 if (typeof api.rawConfig !== 'object') {155 throw new Error('Config must be an object: ' + api.relativeConfigFile());156 }157 helpers.view.log('Loaded configuration file "' + api.relativeConfigFile() + '".');158 if (api.rawConfig[env]) {159 helpers.view.log('Using environment "' + env + '".');160 api.rawConfig = api.rawConfig[env];161 }162 if (api.rawConfig.database.logging && !_.isFunction(api.rawConfig.database.logging)) {163 api.rawConfig.database.logging = console.log;164 }165 // in case url is present - we overwrite the configuration166 if (api.rawConfig.database.url) {167 api.rawConfig.database = _.merge(api.rawConfig.database, api.parseDbUrl(api.rawConfig.database.url));168 }169 return api.rawConfig;170 },171 filteredUrl (uri, config) {172 const regExp = new RegExp(':?' + (config.password || '') + '@');173 return uri.replace(regExp, ':*****@');174 },175 urlStringToConfigHash (urlString) {176 try {177 const urlParts = url.parse(urlString);178 let result = {179 name: urlParts.pathname.replace(/^\//, ''),180 host: urlParts.hostname,181 port: urlParts.port ? urlParts.port : '27017',182 protocol: urlParts.protocol.replace(/:$/, ''),183 ssl: urlParts.query ? urlParts.query.indexOf('ssl=true') >= 0 : false,184 };185 if (urlParts.auth) {186 result = _.assign(result, {187 username: urlParts.auth.split(':')[0],188 password: urlParts.auth.split(':')[1],189 });190 }191 return result;192 } catch (e) {193 throw new Error('Error parsing url: ' + urlString);194 }195 },196 parseDbUrl (urlString) {197 return api.urlStringToConfigHash(urlString);198 },199};...
Configuration.ts
Source:Configuration.ts
1import { Action } from 'redux-actions'2import * as ActionTypes from './ActionTypes'3import {4 BranchId,5 Configuration,6 DagHistory,7 RawConfiguration,8 StateId,9} from './interfaces'10export const CLEAR = 'DAG_HISTORY_CLEAR'11export const UNDO = 'DAG_HISTORY_UNDO'12export const REDO = 'DAG_HISTORY_REDO'13export const JUMP_TO_STATE = 'DAG_HISTORY_JUMP_TO_STATE'14export const JUMP_TO_BRANCH = 'DAG_HISTORY_JUMP_TO_BRANCH'15export const CREATE_BRANCH = 'DAG_HISTORY_CREATE_BRANCH'16export const SQUASH = 'DAG_HISTORY_SQUASH'17const DEFAULT_ACTION_FILTER = () => true18function identityEquality<T>(s1: T, s2: T): boolean {19 return s1 === s220}21export default class ConfigurationImpl<T> implements Configuration<T> {22 constructor(protected rawConfig: RawConfiguration<T> = {}) {}23 public get stateEqualityPredicate() {24 return this.rawConfig.stateEqualityPredicate || identityEquality25 }26 public get stateKeyGenerator() {27 return this.rawConfig.stateKeyGenerator28 }29 public actionName(state: T, id: StateId) {30 if (this.rawConfig.actionName) {31 return this.rawConfig.actionName(state, id)32 } else {33 return `State ${id}`34 }35 }36 public branchName(37 oldBranch: BranchId,38 newBranch: BranchId,39 actionName: string,40 ) {41 if (this.rawConfig.branchName) {42 return this.rawConfig.branchName(oldBranch, newBranch, actionName)43 }44 return `${newBranch}: ${actionName}`45 }46 public canHandleAction(action: Action<any>): boolean {47 return !!(48 this.rawConfig.canHandleAction && this.rawConfig.canHandleAction(action)49 )50 }51 public handleAction(52 action: Action<any>,53 history: DagHistory<T>,54 ): DagHistory<T> {55 if (this.rawConfig.handleAction) {56 return this.rawConfig.handleAction(action, history)57 } else {58 throw new Error('config.handleAction function must be defined')59 }60 }61 public get debug() {62 return this.rawConfig.debug || false63 }64 public get actionFilter() {65 return this.rawConfig.actionFilter || DEFAULT_ACTION_FILTER66 }67 public get loadActionType() {68 return this.rawConfig.loadActionType || ActionTypes.LOAD69 }70 public get clearActionType() {71 return this.rawConfig.clearActionType || ActionTypes.CLEAR72 }73 public get undoActionType() {74 return this.rawConfig.undoActionType || ActionTypes.UNDO75 }76 public get redoActionType() {77 return this.rawConfig.redoActionType || ActionTypes.REDO78 }79 public get jumpToStateActionType() {80 return this.rawConfig.jumpToStateActionType || ActionTypes.JUMP_TO_STATE81 }82 public get jumpToBranchActionType() {83 return this.rawConfig.jumpToBranchActionType || ActionTypes.JUMP_TO_BRANCH84 }85 public get jumpToLatestOnBranchActionType() {86 return (87 this.rawConfig.jumpToLatestOnBranchActionType ||88 ActionTypes.JUMP_TO_LATEST_ON_BRANCH89 )90 }91 public get createBranchActionType() {92 return this.rawConfig.createBranchActionType || ActionTypes.CREATE_BRANCH93 }94 public get renameBranchActionType() {95 return this.rawConfig.renameBranchActionType || ActionTypes.RENAME_BRANCH96 }97 public get squashActionType() {98 return this.rawConfig.squashActionType || ActionTypes.SQUASH99 }100 public get renameStateActionType() {101 return this.rawConfig.renameStateActionType || ActionTypes.RENAME_STATE102 }103 public get skipToStartActionType() {104 return this.rawConfig.skipToStartActionType || ActionTypes.SKIP_TO_START105 }106 public get skipToEndActionType() {107 return this.rawConfig.skipToEndActionType || ActionTypes.SKIP_TO_END108 }109 public get initialBranchName() {110 return this.rawConfig.initialBranchName || 'Branch 1'111 }112 public get initialStateName() {113 return this.rawConfig.initialStateName || 'Initial'114 }...
read-raw-config-file.js
Source:read-raw-config-file.js
1'use strict';2/**3 * External dependencies4 */5const fs = require( 'fs' ).promises;6/**7 * Internal dependencies8 */9const { ValidationError } = require( './validate-config' );10/**11 * Reads the config JSON from the filesystem and returns it as a JS object12 * compatible with the env package.13 *14 * @param {string} name The name of the file for error messages.15 * @param {string} configPath The path to the JSON file to read.16 *17 * @return {Object} the raw config data.18 */19module.exports = async function readRawConfigFile( name, configPath ) {20 try {21 return withBackCompat(22 JSON.parse( await fs.readFile( configPath, 'utf8' ) )23 );24 } catch ( error ) {25 if ( error.code === 'ENOENT' ) {26 return null;27 } else if ( error instanceof SyntaxError ) {28 throw new ValidationError(29 `Invalid ${ name }: ${ error.message }`30 );31 } else {32 throw new ValidationError(33 `Could not read ${ name }: ${ error.message }`34 );35 }36 }37};38/**39 * Used to maintain back compatibility with older versions of the .wp-env.json40 * file. Returns an object in the shape of the currently expected .wp-env.json41 * version.42 *43 * @param {Object} rawConfig config right after being read from a file.44 * @return {Object} Same config with any old-format values converted into the45 * shape of the currently expected format.46 */47function withBackCompat( rawConfig ) {48 // Convert testsPort into new env.tests format.49 if ( rawConfig.testsPort !== undefined ) {50 rawConfig.env = {51 ...( rawConfig.env || {} ),52 tests: {53 port: rawConfig.testsPort,54 ...( rawConfig.env && rawConfig.env.tests55 ? rawConfig.env.tests56 : {} ),57 },58 };59 }60 delete rawConfig.testsPort;61 return rawConfig;...
Using AI Code Generation
1var rawConfig = require('stryker-parent').rawConfig;2var config = rawConfig('stryker.conf.js');3module.exports = function(config) {4 config.set({5 });6};7config.set(options)
Using AI Code Generation
1const { rawConfig } = require('stryker-parent');2const config = rawConfig({3 jest: {4 config: require('./jest.config.js'),5 },6});7module.exports = config;8module.exports = {9 transform: {10 '^.+\\.(ts|tsx)$': 'ts-jest',11 },12 testMatch: ['**/__tests__/**/*.+(ts|tsx|js)', '**/?(*.)+(spec|test).+(ts|tsx|js)'],13};14{15 "scripts": {16 },17 "devDependencies": {18 }19}20{21 "compilerOptions": {
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!!