Best JavaScript code snippet using best
normalize.ts
Source:normalize.ts
...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;...
index.ts
Source:index.ts
...50 benchmarkMaxDuration: options.benchmarkMaxDuration,51 benchmarkMinIterations: options.benchmarkMinIterations,52 benchmarkIterations: options.benchmarkIterations,53 benchmarkOnClient: options.benchmarkOnClient,54 benchmarkOutput: normalizeRootDirPattern(options.benchmarkOutput, options.rootDir),55 benchmarkCustomAssets: normalizeRootDirPattern(options.benchmarkCustomAssets, options.rootDir),56 testMatch: options.testMatch,57 testPathIgnorePatterns: options.testPathIgnorePatterns,58 samplesQuantileThreshold: options.samplesQuantileThreshold59 });60 return { globalConfig, projectConfig };61}62export async function readConfig(cliOptions: CliConfig, packageRoot: string, parentConfigPath?: string): Promise<{ configPath: string, globalConfig?: FrozenGlobalConfig, projectConfig: FrozenProjectConfig }> {63 const configPath = resolveConfigPath(packageRoot, process.cwd());64 const userConfig = readConfigAndSetRootDir(configPath);65 const options = normalizeConfig(userConfig, cliOptions);66 let gitConfig;67 // If we have a parent Config path, we are in a nested/project best config68 if (!parentConfigPath) {69 try {...
Using AI Code Generation
1var BestMatchFinder = require('./lib/BestMatchFinder');2var bestMatchFinder = new BestMatchFinder();3var pattern = bestMatchFinder.normalizeRootDirPattern('**/test');4console.log(pattern);5var BestMatchFinder = require('./lib/BestMatchFinder');6var bestMatchFinder = new BestMatchFinder();7var bestMatch = bestMatchFinder.findBestMatch('test', ['test', 'test2']);8console.log(bestMatch);9var BestMatchFinder = require('./lib/BestMatchFinder');10var bestMatchFinder = new BestMatchFinder();11var bestMatch = bestMatchFinder.findBestMatch('test', ['test', 'test2', 'test3']);12console.log(bestMatch);13var BestMatchFinder = require('./lib/BestMatchFinder');14var bestMatchFinder = new BestMatchFinder();15var bestMatch = bestMatchFinder.findBestMatch('test', ['test', 'test2', 'test3', 'test4']);16console.log(bestMatch);17var BestMatchFinder = require('./lib/BestMatchFinder');18var bestMatchFinder = new BestMatchFinder();19var bestMatch = bestMatchFinder.findBestMatch('test', ['test', 'test2', 'test3', 'test4', 'test5']);20console.log(bestMatch);21var BestMatchFinder = require('./lib/BestMatchFinder');22var bestMatchFinder = new BestMatchFinder();23var bestMatch = bestMatchFinder.findBestMatch('test', ['test', 'test2', 'test3', 'test4', 'test5', 'test6']);24console.log(bestMatch);25var BestMatchFinder = require('./lib/BestMatchFinder');26var bestMatchFinder = new BestMatchFinder();27var bestMatch = bestMatchFinder.findBestMatch('test', ['test', 'test2', 'test3', 'test4', 'test5
Using AI Code Generation
1var BestMatchFinder = require('./BestMatchFinder');2var finder = new BestMatchFinder();3var result = finder.normalizeRootDirPattern('**/test');4console.log(result);5var BestMatchFinder = require('./BestMatchFinder');6var finder = new BestMatchFinder();7var result = finder.getBestMatch('test1.js', ['test1.js', 'test2.js', 'test3.js']);8console.log(result);9var BestMatchFinder = require('./BestMatchFinder');10var finder = new BestMatchFinder();11var result = finder.getBestMatch('test1.js', ['test1.js', 'test2.js', 'test3.js']);12console.log(result);13var BestMatchFinder = require('./BestMatchFinder');14var finder = new BestMatchFinder();15var result = finder.getBestMatch('test1.js', ['test1.js', 'test2.js', 'test3.js']);16console.log(result);17var BestMatchFinder = require('./BestMatchFinder');18var finder = new BestMatchFinder();19var result = finder.getBestMatch('test1.js', ['test1.js', 'test2.js', 'test3.js']);20console.log(result);21var BestMatchFinder = require('./BestMatchFinder');22var finder = new BestMatchFinder();23var result = finder.getBestMatch('test1.js', ['test1.js', 'test2.js', 'test3.js']);24console.log(result);25var BestMatchFinder = require('./BestMatchFinder');26var finder = new BestMatchFinder();27var result = finder.getBestMatch('test1.js', ['test1.js', 'test2.js', 'test3.js']);
Using AI Code Generation
1var BestMatchFinder = require('./BestMatchFinder.js');2var finder = new BestMatchFinder();3var pattern = '/a/b/c/*.js';4pattern = '/a/b/c/**/*.js';5pattern = '/a/b/c/**/d/*.js';6var BestMatchFinder = require('./BestMatchFinder.js');7var finder = new BestMatchFinder();8var pattern = '/a/b/c/*.js';9var files = ['a.js', 'b.js', 'c.js', 'd.js', 'a/b.js', 'a/b/c.js', 'a/b/c/d.js', 'a/b/c/d/e.js'];10var BestMatchFinder = require('./BestMatchFinder.js');11var finder = new BestMatchFinder();12var pattern = '/a/b/c/**/*.js';13var files = ['a.js', 'b.js', 'c.js', 'd.js', 'a/b.js', 'a/b/c.js', 'a/b/c/d.js', 'a/b/c/d/e.js'];14var BestMatchFinder = require('./BestMatchFinder.js');15var finder = new BestMatchFinder();16var pattern = '/a/b/c/**/d/*.js';17var files = ['a.js', 'b.js', 'c.js', 'd.js', 'a/b.js', 'a/b/c.js', 'a/b/c/d.js', 'a/b/c/d/e.js'];18var BestMatchFinder = require('./BestMatchFinder.js');19var finder = new BestMatchFinder();
Using AI Code Generation
1var BestMatchFinder = require('BestMatchFinder');2var path = require('path');3var finder = new BestMatchFinder();4var root = path.join(__dirname, 'test');5var pattern = path.join(root, 'test1.js');6var normalPattern = finder.normalizeRootDirPattern(pattern, root);7console.log("Normal Pattern: " + normalPattern);8var BestMatchFinder = require('BestMatchFinder');9var path = require('path');10var finder = new BestMatchFinder();11var root = path.join(__dirname, 'test');12var pattern = path.join(root, 'test1.js');13var normalPattern = finder.normalizeRootDirPattern(pattern, root);14var bestMatch = finder.findBestMatch(normalPattern, root);15console.log("Best Match: " + bestMatch);16var BestMatchFinder = require('BestMatchFinder');17var path = require('path');18var finder = new BestMatchFinder();19var root = path.join(__dirname, 'test');20var pattern = path.join(root, 'test1.js');21var normalPattern = finder.normalizeRootDirPattern(pattern, root);22var bestMatch = finder.findBestMatch(normalPattern, root);23console.log("Best Match: " + bestMatch);24var BestMatchFinder = require('BestMatchFinder');25var path = require('path');26var finder = new BestMatchFinder();27var root = path.join(__dirname, 'test');28var pattern = path.join(root, 'test1.js');29var normalPattern = finder.normalizeRootDirPattern(pattern, root);30var bestMatch = finder.findBestMatch(normalPattern, root);31console.log("Best Match: " + bestMatch);32var BestMatchFinder = require('BestMatchFinder');33var path = require('path');34var finder = new BestMatchFinder();35var root = path.join(__dirname, 'test');36var pattern = path.join(root, '
Using AI Code Generation
1var BestMatchFinder = require("BestMatchFinder");2var finder = new BestMatchFinder();3var pattern = finder.normalizeRootDirPattern("C:\\Users\\test\\");4console.log(pattern);5var BestMatchFinder = require("BestMatchFinder");6var finder = new BestMatchFinder();7var match = finder.getBestMatch("C:\\Users\\test\\", ["C:\\Users\\test\\", "C:\\Users\\test\\test\\"]);8console.log(match);9var BestMatchFinder = require("BestMatchFinder");10var finder = new BestMatchFinder();11var match = finder.getBestMatch("C:\\Users\\test\\", ["C:\\Users\\test\\test\\", "C:\\Users\\test\\"]);12console.log(match);13var BestMatchFinder = require("BestMatchFinder");14var finder = new BestMatchFinder();15var match = finder.getBestMatch("C:\\Users\\test\\", ["C:\\Users\\test\\test\\", "C:\\Users\\test\\test1\\"]);16console.log(match);17var BestMatchFinder = require("BestMatchFinder");18var finder = new BestMatchFinder();19var match = finder.getBestMatch("C:\\Users\\test\\", ["C:\\Users\\test\\test\\", "C:\\Users\\test\\test1\\", "C:\\Users\\test\\test2\\"]);20console.log(match);21var BestMatchFinder = require("BestMatchFinder");22var finder = new BestMatchFinder();23var match = finder.getBestMatch("C:\\Users\\test\\", ["C:\\Users\\test\\test\\", "C:\\Users\\test\\test1\\", "C:\\Users\\test\\
Using AI Code Generation
1var BestMatchFinder = require("./BestMatchFinder");2var bestMatchFinder = new BestMatchFinder();3var input = "C:/Users/abc/def/ghi";4var pattern = "C:/Users/abc";5var result = bestMatchFinder.normalizeRootDirPattern(input, pattern);6console.log(result);7function BestMatchFinder() {8 this.normalizeRootDirPattern = function (input, pattern) {9 var normalizedPattern = pattern;10 var index = input.indexOf(pattern);11 if (index === 0) {12 normalizedPattern = input.substr(0, pattern.length);13 }14 return normalizedPattern;15 }16}17module.exports = BestMatchFinder;
Using AI Code Generation
1var BestMatchFinder = require('../best-match-finder');2var bestMatchFinder = new BestMatchFinder();3var rootDir = 'D:/Projects/best-match-finder/test';4var pattern = '**/test1.js';5var normalizedRootDirPattern = bestMatchFinder.normalizeRootDirPattern(rootDir, pattern);6console.log(normalizedRootDirPattern);7var BestMatchFinder = require('../best-match-finder');8var bestMatchFinder = new BestMatchFinder();9var rootDir = 'D:/Projects/best-match-finder/test';10var pattern = '**/test1.js';11var bestMatch = bestMatchFinder.findBestMatch(rootDir, pattern);12console.log(bestMatch);13var BestMatchFinder = require('../best-match-finder');14var bestMatchFinder = new BestMatchFinder();15var rootDir = 'D:/Projects/best-match-finder/test';16var pattern = '**/test1.js';17var options = { caseSensitive: true };18var bestMatch = bestMatchFinder.findBestMatch(rootDir, pattern, options);19console.log(bestMatch);20var BestMatchFinder = require('../best-match-finder');21var bestMatchFinder = new BestMatchFinder();22var rootDir = 'D:/Projects/best-match-finder/test';23var pattern = '**/test1.js';24var options = { caseSensitive: true, returnAllMatches: true };25var bestMatch = bestMatchFinder.findBestMatch(rootDir, pattern, options);26console.log(bestMatch);
Using AI Code Generation
1var BestMatchFinder = require('glob').BestMatchFinder;2var finder = new BestMatchFinder();3var rootDirPattern = finder.normalizeRootDirPattern('/home/abc/def/**');4console.log(rootDirPattern);5var BestMatchFinder = require('glob').BestMatchFinder;6var finder = new BestMatchFinder();7var bestMatch = finder.findBestMatch('/home/abc/def/ghi/jkl.txt', ['/home/abc/def/**', '/home/abc/def/ghi/**']);8console.log(bestMatch);9var BestMatchFinder = require('glob').BestMatchFinder;10var finder = new BestMatchFinder();11var bestMatchIndex = finder.findBestMatchIndex('/home/abc/def/ghi/jkl.txt', ['/home/abc/def/**', '/home/abc/def/ghi/**']);12console.log(bestMatchIndex);
Using AI Code Generation
1var BestMatchFinder = require('appium-ios-device').BestMatchFinder;2var bestMatchFinder = new BestMatchFinder();3var path = '/var/containers/Bundle/Application/6E5A6A5E-9A1C-4F73-8E7E-3F3A3F8B3C2A/MyApp.app/MyApp';4var rootDirPattern = '/var/containers/Bundle/Application';5console.log(bestMatchFinder.normalizeRootDirPattern(path, rootDirPattern));6var BestMatchFinder = require('appium-ios-device').BestMatchFinder;7var bestMatchFinder = new BestMatchFinder();8var path = '/var/containers/Bundle/Application/6E5A6A5E-9A1C-4F73-8E7E-3F3A3F8B3C2A/MyApp.app/MyApp';9var rootDirPattern = '/var/containers/Bundle/Application/6E5A6A5E-9A1C-4F73-8E7E-3F3A3F8B3C2A';10console.log(bestMatchFinder.normalizeRootDirPattern(path, rootDirPattern));11var BestMatchFinder = require('appium-ios-device').BestMatchFinder;12var bestMatchFinder = new BestMatchFinder();13var path = '/var/containers/Bundle/Application/6E5A6A5E-9A1C-4F73-8E7E-3F3A3F8B3C2A/MyApp.app/MyApp';
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!!