Best JavaScript code snippet using best
normalize.ts
Source:normalize.ts
...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':...
Using AI Code Generation
1var BestPracticeChecker = require('jsinspect').BestPracticeChecker;2var checker = new BestPracticeChecker();3var patterns = ['test1.js', 'test2.js', 'test3.js'];4var normalizedPaths = checker.normalizeModulePathPatterns(patterns);5console.log(normalizedPaths);6var BestPracticeChecker = require('jsinspect').BestPracticeChecker;7var checker = new BestPracticeChecker();8var patterns = ['test1.js', 'test2.js', 'test3.js', 'test4.js'];9var normalizedPaths = checker.normalizeModulePathPatterns(patterns);10console.log(normalizedPaths);11var BestPracticeChecker = require('jsinspect').BestPracticeChecker;12var checker = new BestPracticeChecker();13var patterns = ['test1.js', 'test2.js', 'test3.js', 'test4.js', 'test5.js'];14var normalizedPaths = checker.normalizeModulePathPatterns(patterns);15console.log(normalizedPaths);16var BestPracticeChecker = require('jsinspect').BestPracticeChecker;17var checker = new BestPracticeChecker();18var patterns = ['test1.js', 'test2.js', 'test3.js', 'test4.js', 'test5.js', 'test6.js'];19var normalizedPaths = checker.normalizeModulePathPatterns(patterns);20console.log(normalizedPaths);21var BestPracticeChecker = require('jsinspect').BestPracticeChecker;22var checker = new BestPracticeChecker();
Using AI Code Generation
1var BestPracticeChecker = require('sfdc-lwc-jest').BestPracticeChecker;2var bestPracticeChecker = new BestPracticeChecker();3var normalizeModulePathPatterns = bestPracticeChecker.normalizeModulePathPatterns;4var normalizedModulePathPatterns = normalizeModulePathPatterns('c/**/test/**/test.js');5console.log(normalizedModulePathPatterns);6var BestPracticeChecker = require('sfdc-lwc-jest').BestPracticeChecker;7var bestPracticeChecker = new BestPracticeChecker();8var normalizeModulePathPatterns = bestPracticeChecker.normalizeModulePathPatterns;9var normalizedModulePathPatterns = normalizeModulePathPatterns('c/**/test/**/test.js', 'c/**/test/**/test2.js');10console.log(normalizedModulePathPatterns);11var BestPracticeChecker = require('sfdc-lwc-jest').BestPracticeChecker;12var bestPracticeChecker = new BestPracticeChecker();13var normalizeModulePathPatterns = bestPracticeChecker.normalizeModulePathPatterns;14var normalizedModulePathPatterns = normalizeModulePathPatterns(['c/**/test/**/test.js', 'c/**/test/**/test2.js']);15console.log(normalizedModulePathPatterns);16var BestPracticeChecker = require('sfdc-lwc-jest').BestPracticeChecker;17var bestPracticeChecker = new BestPracticeChecker();18var normalizeModulePathPatterns = bestPracticeChecker.normalizeModulePathPatterns;19var normalizedModulePathPatterns = normalizeModulePathPatterns(['c/**/test/**/test.js', 'c/**/test/**/test2.js'], 'c/**/test/**/test3.js');20console.log(normalizedModulePathPatterns);
Using AI Code Generation
1var BestPracticeChecker = require('jsinspect').BestPracticeChecker;2var checker = new BestPracticeChecker();3var patterns = checker.normalizeModulePathPatterns(['./lib', './lib2']);4console.log(patterns);5console.log(patterns[0].indexOf('./lib') > -1);6console.log(patterns[1].indexOf('./lib2') > -1);7var BestPracticeChecker = require('jsinspect').BestPracticeChecker;8var checker = new BestPracticeChecker();9var patterns = checker.normalizeModulePathPatterns(['./lib', './lib2']);10console.log(patterns);11console.log(patterns[0].indexOf('./lib') > -1);12console.log(patterns[1].indexOf('./lib2') > -1);13var BestPracticeChecker = require('jsinspect').BestPracticeChecker;14var checker = new BestPracticeChecker();15var patterns = checker.normalizeModulePathPatterns(['./lib', './lib2']);16console.log(patterns);17console.log(patterns[0].indexOf('./lib') > -1);18console.log(patterns[1].indexOf('./lib2') > -1);19var BestPracticeChecker = require('jsinspect').BestPracticeChecker;20var checker = new BestPracticeChecker();21var patterns = checker.normalizeModulePathPatterns(['./lib', './lib2']);22console.log(patterns);23console.log(patterns[0].indexOf('./lib') > -1);24console.log(patterns[1].indexOf('./lib2') > -1);
Using AI Code Generation
1var BestPracticeChecker = require('./lib/best-practice-checker.js');2var bestPracticeChecker = new BestPracticeChecker();3bestPracticeChecker.normalizeModulePathPatterns(['test1.js', 'test2.js']);4var BestPracticeChecker = require('./lib/best-practice-checker.js');5var bestPracticeChecker = new BestPracticeChecker();6var results = bestPracticeChecker.check([7 {8 },9 {10 },11 {12 },13 {14 },15 {16 }17]);
Using AI Code Generation
1var BestPracticeAnalyzer = require('./BestPracticeAnalyzer.js');2var bpa = new BestPracticeAnalyzer();3var pathPatterns = ['lib/**', 'test/**', 'node_modules/**'];4var normalizedPathPatterns = bpa.normalizeModulePathPatterns(pathPatterns);5console.log(normalizedPathPatterns);6var BestPracticeAnalyzer = require('./BestPracticeAnalyzer.js');7var bpa = new BestPracticeAnalyzer();8var pathPatterns = ['lib/**', 'test/**', 'node_modules/**'];9var normalizedPathPatterns = bpa.normalizeModulePathPatterns(pathPatterns);10var allowed = bpa.isModulePathAllowed('lib/index.js', normalizedPathPatterns);11console.log(allowed);12var BestPracticeAnalyzer = require('./BestPracticeAnalyzer.js');13var bpa = new BestPracticeAnalyzer();14var pathPatterns = ['lib/**', 'test/**', 'node_modules/**'];15var normalizedPathPatterns = bpa.normalizeModulePathPatterns(pathPatterns);16var allowed = bpa.isModulePathAllowed('lib/index.js', normalizedPathPatterns);17console.log(allowed);18var BestPracticeAnalyzer = require('./BestPracticeAnalyzer.js');19var bpa = new BestPracticeAnalyzer();20var pathPatterns = ['lib/**', 'test/**', 'node_modules/**'];21var normalizedPathPatterns = bpa.normalizeModulePathPatterns(pathPatterns);22var allowed = bpa.isModulePathAllowed('lib/index.js', normalizedPathPatterns);23console.log(allowed);24var BestPracticeAnalyzer = require('./BestPracticeAnalyzer.js');25var bpa = new BestPracticeAnalyzer();26var pathPatterns = ['lib/**', 'test/**', 'node_modules/**'];27var normalizedPathPatterns = bpa.normalizeModulePathPatterns(pathPatterns);28var allowed = bpa.isModulePathAllowed('lib/index.js', normalizedPathPatterns);29console.log(allowed);30var BestPracticeAnalyzer = require('./BestPracticeAnalyzer.js');31var bpa = new BestPracticeAnalyzer();
Using AI Code Generation
1var BestPracticePlugin = require('webida-lib/plugins/workbench/plugin/best-practice-plugin');2];3];4console.log('testPath');5console.log(testPath);6console.log('testPatterns');7console.log(testPatterns);8console.log('normalizeModulePathPatterns');9console.log(BestPracticePlugin.normalizeModulePathPatterns(testPath, testPatterns));10var BestPracticePlugin = require('webida-lib/plugins/workbench/plugin/best-practice-plugin');11];12];13console.log('testPath');14console.log(testPath);15console.log('testPatterns');16console.log(testPatterns);17console.log('normalizeModulePathPatterns');18console.log(BestPracticePlugin.normalizeModulePathPatterns(testPath, testPatterns));19var BestPracticePlugin = require('webida
Using AI Code Generation
1var BestMatchPattern = require('./BestMatchPattern');2var path = require('path');3var bestMatchPattern = new BestMatchPattern();4var patterns = ['/home/xyz/abc/xyz', '/home/xyz/abc/xyz/abc', '/home/xyz/abc/xyz/abc/xyz', '/home/xyz/abc/xyz/abc/xyz/abc'];5var normalizedPatterns = bestMatchPattern.normalizeModulePathPatterns(patterns);6console.log(normalizedPatterns);7var BestMatchPattern = require('./BestMatchPattern');8var path = require('path');9var bestMatchPattern = new BestMatchPattern();10var patterns = ['/home/xyz/abc/xyz', '/home/xyz/abc/xyz/abc', '/home/xyz/abc/xyz/abc/xyz', '/home/xyz/abc/xyz/abc/xyz/abc'];
Using AI Code Generation
1var BestPracticeChecker = require('best-practice-checker');2var checker = new BestPracticeChecker();3var patterns = ['*/*/*', '*/**/*', '**/*', '**/*/*', '**/test/*'];4var normalizedPatterns = checker.normalizeModulePathPatterns(patterns);5console.log(normalizedPatterns);6var BestPracticeChecker = require('best-practice-checker');7var checker = new BestPracticeChecker();
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!!