How to use argsCLI method in Best

Best JavaScript code snippet using best

normalize.ts

Source:normalize.ts Github

copy

Full Screen

1/*2 * Copyright (c) 2019, salesforce.com, inc.3 * All rights reserved.4 * SPDX-License-Identifier: MIT5 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT6*/7import path from 'path';8import chalk from 'chalk';9import DEFAULT_CONFIG from './defaults';10import { replacePathSepForRegex } from '@best/regex-util';11import { CliConfig, UserConfig, NormalizedConfig, RunnerConfig, BrowserSpec } from '@best/types';12const TARGET_COMMIT = process.env.TARGET_COMMIT;13const BASE_COMMIT = process.env.BASE_COMMIT;14function normalizeModulePathPatterns(options: any, key: string) {15 return options[key].map((pattern: any) => replacePathSepForRegex(normalizeRootDirPattern(pattern, options.rootDir)));16}17function normalizeRunner(runner: string, runners: RunnerConfig[]) {18 const defaultRunners = runners.filter((c) => c.alias === undefined || c.alias === 'default');19 if (defaultRunners.length > 1) {20 throw new Error('Wrong configuration: More than one default configuration declared');21 }22 if (runner === "default") {23 if (defaultRunners.length) {24 return defaultRunners[0].runner;25 }26 } else {27 const selectedRunner = runners.find((c) => c.alias === runner || c.runner === runner);28 if (selectedRunner) {29 return selectedRunner.runner;30 }31 }32 return 'unknown';33}34function normalizeRunnerConfig(runner: string, runners: RunnerConfig[], specs?: BrowserSpec) {35 if (!runners) {36 return {};37 }38 let selectedRunner;39 if (runner === "default") {40 const defaultRunners = runners.filter((c: RunnerConfig) => c.alias === undefined || c.alias === 'default');41 if (defaultRunners.length > 0) {42 selectedRunner = defaultRunners[0];43 }44 } else {45 const selectedAliasRunner = runners.find((c: RunnerConfig) => c.alias === runner);46 selectedRunner = selectedAliasRunner || runners.find((c: RunnerConfig) => c.runner === runner);47 }48 if (selectedRunner) {49 const selectedRunnerConfig = selectedRunner.config || {};50 return { ...selectedRunnerConfig, specs: selectedRunner.specs || specs };51 }52}53function setCliOptionOverrides(initialOptions: UserConfig, argsCLI: CliConfig): UserConfig {54 const argvToOptions = Object.keys(argsCLI)55 .reduce((options: any, key: string) => {56 switch (key) {57 case '_':58 options.nonFlagArgs = argsCLI[key] || [];59 break;60 case 'disableInteractive':61 options.isInteractive = argsCLI[key] !== undefined ? false : undefined;62 break;63 case 'iterations':64 if (argsCLI[key] !== undefined) {65 options.benchmarkIterations = argsCLI[key];66 }67 break;68 case 'runInBatch':69 options.runInBatch = !!argsCLI[key];70 break;71 case 'runInBand':72 options.runInBand = !!argsCLI[key];73 break;74 case 'projects':75 if (argsCLI.projects && argsCLI.projects.length) {76 options.projects = argsCLI.projects;77 }78 break;79 case 'compareStats':80 options.compareStats = argsCLI.compareStats && argsCLI.compareStats.filter(Boolean);81 break;82 case 'gitIntegration':83 options.gitIntegration = Boolean(argsCLI[key]);84 break;85 case 'generateHTML':86 options.generateHTML = Boolean(argsCLI[key]);87 break;88 case 'dbAdapter':89 if (argsCLI[key] !== undefined) {90 options.apiDatabase = { 91 adapter: argsCLI[key], 92 uri: argsCLI['dbURI'],93 token: argsCLI['dbToken']94 }95 }96 break;97 case 'dbURI':98 case 'dbToken':99 break100 default:101 options[key] = argsCLI[key];102 break;103 }104 return options;105 }, {});106 return { ...initialOptions, ...argvToOptions };107}108function normalizeObjectPathPatterns(options: { [key: string]: any }, rootDir: string) {109 return Object.keys(options).reduce((m: any, key) => {110 const value = options[key];111 if (typeof value === 'string') {112 m[key] = normalizeRootDirPattern(value, rootDir);113 } else {114 m[key] = value;115 }116 return m;117 }, {});118}119function normalizePlugins(plugins: any, { rootDir }: UserConfig) {120 return plugins.map((plugin: any) => {121 if (typeof plugin === 'string') {122 return normalizeRootDirPattern(plugin, rootDir);123 } else if (Array.isArray(plugin)) {124 return [normalizeRootDirPattern(plugin[0], rootDir), normalizeObjectPathPatterns(plugin[1], rootDir)];125 }126 return plugin;127 });128}129function normalizeRootDir(options: UserConfig): UserConfig {130 // Assert that there *is* a rootDir131 if (!options.hasOwnProperty('rootDir')) {132 throw new Error(` Configuration option ${chalk.bold('rootDir')} must be specified.`);133 }134 options.rootDir = path.normalize(options.rootDir);135 return options;136}137function normalizeCommits(commits?: string[]): string[] | undefined {138 if (!commits) {139 return undefined;140 }141 let [base, target] = commits;142 base = (base || BASE_COMMIT || '');143 target = (target || TARGET_COMMIT || '');144 return [base.slice(0, 7), target.slice(0, 7)];145}146export function normalizeRootDirPattern(str: string, rootDir: string) {147 return str.replace(/<rootDir>/g, rootDir);148}149export function normalizeRegexPattern(names: string | string[] | RegExp) {150 if (typeof names === 'string') {151 names = names.split(',');152 }153 if (Array.isArray(names)) {154 names = names.map(name => name.replace(/\*/g, '.*'));155 names = new RegExp(`^(${names.join('|')})$`);156 }157 if (!(names instanceof RegExp)) {158 throw new Error(` Names must be provided as a string, array or regular expression.`);159 }160 return typeof names === 'string' ? new RegExp(names) : names;161}162export function normalizeConfig(userConfig: UserConfig, cliOptions: CliConfig): NormalizedConfig {163 const userCliMergedConfig = normalizeRootDir(setCliOptionOverrides(userConfig, cliOptions));164 const normalizedConfig: NormalizedConfig = { ...DEFAULT_CONFIG, ...userCliMergedConfig };165 const aliasRunner = normalizedConfig.runner;166 Object.keys(normalizedConfig).reduce((mergeConfig: NormalizedConfig, key: string) => {167 switch (key) {168 case 'projects':169 mergeConfig[key] = normalizeModulePathPatterns(normalizedConfig, key);170 break;171 case 'plugins':172 mergeConfig[key] = normalizePlugins(normalizedConfig[key], normalizedConfig);173 break;174 case 'runnerConfig':175 mergeConfig['runnerConfig'] = normalizeRunnerConfig(aliasRunner, mergeConfig.runners, mergeConfig.specs);176 break;177 case 'runner':178 mergeConfig[key] = normalizeRunner(normalizedConfig[key], mergeConfig.runners);179 break;180 case 'compareStats':181 mergeConfig[key] = normalizeCommits(normalizedConfig[key]);182 break;183 case 'specs':184 mergeConfig[key] = normalizedConfig['runnerConfig'].specs || mergeConfig[key];185 break;186 case 'apiDatabase': {187 const apiDatabaseConfig = normalizedConfig[key];188 mergeConfig[key] = apiDatabaseConfig ? normalizeObjectPathPatterns(apiDatabaseConfig, normalizedConfig.rootDir) : apiDatabaseConfig;189 break;190 }191 default:192 break;193 }194 return mergeConfig;195 }, normalizedConfig);196 return normalizedConfig;...

Full Screen

Full Screen

index.ts

Source:index.ts Github

copy

Full Screen

1/*2 * Copyright (c) 2019, salesforce.com, inc.3 * All rights reserved.4 * SPDX-License-Identifier: MIT5 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT6*/7import { normalize, usage, options, docs, check } from './args';8import Output from './output';9import yargs from 'yargs';10import rimraf from 'rimraf';11import { OutputStream } from '@best/console-stream';12import { logError } from "@best/utils";13import { runBest } from '../run_best';14import { runCompare } from '../run_compare';15import { getConfigs } from "@best/config";16import { ProjectConfigs, FrozenProjectConfig, CliConfig } from '@best/types';17export function buildArgs(maybeArgv?: string[]): CliConfig {18 const parsedArgs = yargs(maybeArgv || process.argv.slice(2))19 .usage(usage)20 .alias('help', 'h')21 .options(options)22 .epilogue(docs)23 .check(check)24 .version(false).argv;25 return normalize(parsedArgs);26}27function getProjectListFromCLIArgs(argsCLI: CliConfig, project?: string): string[] {28 const projects = argsCLI.projects.slice();29 if (project) {30 projects.push(project);31 }32 if (!projects.length) {33 projects.push(process.cwd());34 }35 return projects;36}37export async function run(maybeArgv?: string[], project?: string) {38 try {39 const argsCLI = buildArgs(maybeArgv);40 const projects = getProjectListFromCLIArgs(argsCLI, project);41 await runCLI(argsCLI, projects);42 } catch (error) {43 const errParts: string[] = error.stack ? error.stack.split('\n') : ['unknown', 'unknown'];44 const errTitle = errParts.shift();45 if (errTitle) {46 logError(errTitle);47 }48 console.warn(errParts.join('\n'));49 process.exit(1);50 }51}52export async function runCLI(argsCLI: CliConfig, projects: string[]) {53 const outputStream = new OutputStream(process.stdout);54 let projectConfigs: ProjectConfigs;55 try {56 outputStream.write('Looking for Best configurations...');57 projectConfigs = await getConfigs(projects, argsCLI);58 } finally {59 outputStream.clearLine();60 }61 const { globalConfig, configs } = projectConfigs;62 if (argsCLI.showConfigs) {63 outputStream.writeln(JSON.stringify({ globalConfig, configs }, null, ' '));64 return process.exit(0);65 }66 if (argsCLI.clearCache) {67 configs.forEach((config : FrozenProjectConfig) => {68 rimraf.sync(config.cacheDirectory);69 outputStream.writeln(`Cleared ${config.cacheDirectory}`);70 });71 return process.exit(0);72 }73 const output = new Output({}, outputStream);74 if (argsCLI.compareStats) {75 const results = await runCompare(globalConfig, configs, process.stdout);76 if (results) {77 output.compare(results);78 }79 } else {80 if (argsCLI.clearResults) {81 outputStream.writeln('Clearing previous benchmark results...');82 configs.forEach((config: FrozenProjectConfig) => {83 rimraf.sync(config.benchmarkOutput);84 outputStream.writeln(`- Cleared: ${config.benchmarkOutput}`);85 });86 }87 const results = await runBest(globalConfig, configs, process.stdout);88 if (!results) {89 throw new Error('AggregatedResult must be present after test run is complete');90 }91 output.report(results);92 if (argsCLI.generateHTML) {93 try {94 const { buildStaticFrontend } = await import('@best/frontend');95 const projectConfig = configs[0];96 await buildStaticFrontend(results, globalConfig, projectConfig, process.stdout);97 } catch (err) {98 throw new Error('You passed the `--generateHTML` flag, but `@best/frontend` is not a dependency. Make sure you include it as a dependency.');99 }100 }101 }102 return true;103}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestGlobals = require('bestglobals');2var bg = new BestGlobals();3var args = bg.argsCLI();4console.log('argsCLI: ' + JSON.stringify(args));5var BestGlobals = require('bestglobals');6var bg = new BestGlobals();7var args = bg.argsCLI();8console.log('argsCLI: ' + JSON.stringify(args));9var BestGlobals = require('bestglobals');10var bg = new BestGlobals();11var args = bg.argsCLI();12console.log('argsCLI: ' + JSON.stringify(args));13var BestGlobals = require('bestglobals');14var bg = new BestGlobals();15var args = bg.argsCLI();16console.log('argsCLI: ' + JSON.stringify(args));17var BestGlobals = require('bestglobals');18var bg = new BestGlobals();19var args = bg.argsCLI();20console.log('argsCLI: ' + JSON.stringify(args));21var BestGlobals = require('bestglobals');22var bg = new BestGlobals();23var args = bg.argsCLI();24console.log('argsCLI: ' + JSON.stringify(args));25var BestGlobals = require('bestglobals');26var bg = new BestGlobals();27var args = bg.argsCLI();28console.log('argsCLI: ' + JSON.stringify(args));29var BestGlobals = require('bestglobals');30var bg = new BestGlobals();31var args = bg.argsCLI();32console.log('argsCLI: ' + JSON.stringify(args));33var BestGlobals = require('bestglobals');34var bg = new BestGlobals();35var args = bg.argsCLI();36console.log('argsCLI: ' + JSON.stringify(args));

Full Screen

Using AI Code Generation

copy

Full Screen

1var bg = require('bestGlobals');2var args = bg.argsCLI();3console.log('argsCLI',args);4var bg = require('bestGlobals');5var args = bg.argsCLI();6console.log('argsCLI',args);7var bg = require('bestGlobals');8var args = bg.argsCLI();9console.log('argsCLI',args);10var bg = require('bestGlobals');11var args = bg.argsCLI();12console.log('argsCLI',args);13var bg = require('bestGlobals');14var args = bg.argsCLI();15console.log('argsCLI',args);16var bg = require('bestGlobals');17var args = bg.argsCLI();18console.log('argsCLI',args);19var bg = require('bestGlobals');20var args = bg.argsCLI();21console.log('argsCLI',args);22var bg = require('bestGlobals');

Full Screen

Using AI Code Generation

copy

Full Screen

1const BestGlobals = require('bestglobals');2const args = BestGlobals.argsCLI();3console.log(args);4### argsCLI() - parse command line arguments5const BestGlobals = require('bestglobals');6const args = BestGlobals.argsCLI();7console.log(args);8### argsCLI() - parse command line arguments9const BestGlobals = require('bestglobals');10const args = BestGlobals.argsCLI();11console.log(args);12### argsCLI() - parse command line arguments13const BestGlobals = require('bestglobals');14const args = BestGlobals.argsCLI();15console.log(args);16### argsCLI() - parse command line arguments17const BestGlobals = require('bestglobals');18const args = BestGlobals.argsCLI();19console.log(args);20### argsCLI() - parse command line arguments21const BestGlobals = require('bestglobals');22const args = BestGlobals.argsCLI();23console.log(args);

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestGlobals = require('bestglobals');2var bg = new BestGlobals();3var args = bg.argsCLI();4var argsArr = args.argsCLI;5var argsStr = args.argsCLIStr;6var nonArgVals = args.nonArgVals;7console.log('args: ', args);8console.log('argsArr: ', argsArr);9console.log('argsStr: ', argsStr);10console.log('nonArgVals: ', nonArgVals);

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 Best 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