Best JavaScript code snippet using best
bootstrap.js
Source:bootstrap.js
...95 'to run https server',96 '',97 // commands are borrowed from node.js docs98 'To quickly create self-signed certificate, use:',99 ' $ openssl genrsa -out ' + resolveConfigPath('verdaccio-key.pem') + ' 2048',100 ' $ openssl req -new -sha256 -key ' + resolveConfigPath('verdaccio-key.pem') + ' -out ' + resolveConfigPath('verdaccio-csr.pem'),101 ' $ openssl x509 -req -in ' + resolveConfigPath('verdaccio-csr.pem') +102 ' -signkey ' + resolveConfigPath('verdaccio-key.pem') + ' -out ' + resolveConfigPath('verdaccio-cert.pem'),103 '',104 'And then add to config file (' + storageLocation + '):',105 ' https:',106 ` key: ${resolveConfigPath('verdaccio-key.pem')}`,107 ` cert: ${resolveConfigPath('verdaccio-cert.pem')}`,108 ` ca: ${resolveConfigPath('verdaccio-csr.pem')}`,109 ].join('\n'));110 process.exit(2);111}112function handleHTTPS(app, configPath, config) {113 try {114 let httpsOptions = {115 secureProtocol: 'SSLv23_method', // disable insecure SSLv2 and SSLv3116 secureOptions: constants.SSL_OP_NO_SSLv2 | constants.SSL_OP_NO_SSLv3,117 };118 if (config.https.pfx) {119 httpsOptions = assign(httpsOptions, {120 pfx: fs.readFileSync(config.https.pfx),121 passphrase: config.https.passphrase || '',122 });...
index.js
Source:index.js
...47 .then(config => callback(null, config))48 .catch(callback);49};50parse.promise = options => {51 let filepath = parse.resolveConfigPath(options);52 let read = util.promisify(fs.readFile);53 let stat = util.promisify(fs.stat);54 if (!filepath) return Promise.resolve(null);55 return stat(filepath)56 .then(() => read(filepath, 'utf8'))57 .then(str => {58 if (options && options.include === true) {59 str = injectInclude(str, path.resolve(path.dirname(filepath)));60 }61 return parseIni(str, options);62 });63};64/**65 * Synchronously parse a `.git/config` file. If no arguments are passed,66 * the `.git/config` file relative to `process.cwd()` is used.67 *68 * ```js69 * console.log(parse.sync());70 * console.log(parse.sync({ cwd: 'foo' }));71 * console.log(parse.sync({ cwd: 'foo', path: 'some/.git/config' }));72 * ```73 * @name .sync74 * @param {Object|String} `options` Options with `cwd` or `path`, or the cwd to use.75 * @return {Object}76 * @api public77 */78parse.sync = options => {79 let filepath = parse.resolveConfigPath(options);80 if (filepath && fs.existsSync(filepath)) {81 let input = fs.readFileSync(filepath, 'utf8');82 if (options && options.include === true) {83 let cwd = path.resolve(path.dirname(filepath));84 input = injectInclude(input, cwd);85 }86 return parseIni(input, options);87 }88 return {};89};90/**91 * Resolve the git config path92 */93parse.resolveConfigPath = options => {94 if (typeof options === 'string') options = { type: options };95 const opts = Object.assign({ cwd: process.cwd() }, options);96 const fp = opts.path ? expand(opts.path) : configPath(opts.type);97 return fp ? path.resolve(opts.cwd, fp) : null;98};99/**100 * Deprecated: use `.resolveConfigPath` instead101 */102parse.resolve = options => parse.resolveConfigPath(options);103/**104 * Returns an object with only the properties that had ini-style keys105 * converted to objects.106 *107 * ```js108 * const config = parse.sync({ path: '/path/to/.gitconfig' });109 * const obj = parse.expandKeys(config);110 * ```111 * @name .expandKeys112 * @param {Object} `config` The parsed git config object.113 * @return {Object}114 * @api public115 */116parse.expandKeys = config => {...
index.ts
Source:index.ts
...70 }71}72const getConfigPath = () => {73 if (argv[0] === undefined)74 return resolveConfigPath('tmax.config.js') || resolveConfigPath('tmax.config.json')75 const fpath = resolveConfigPath(argv[0])76 if (fpath === null) {77 console.error(`Config file does not exist: ${argv[0]}`)78 process.exit(1)79 }80 return fpath81}82const configFilePath = getConfigPath()83if (!configFilePath) {84 console.error('No tmax.config.js or tmax.config.json file')85 process.exit(1)86}87const config = require(configFilePath)88const cwd = path.dirname(configFilePath)89let defaultTitle = 'tmax'...
resolve_config_path.test.js
Source:resolve_config_path.test.js
...22 const relativeConfigPath = 'a/b/c/my_config.js';23 const absoluteConfigPath = path.resolve(DIR, relativeConfigPath);24 writeFiles(DIR, {[relativeConfigPath]: ''});25 // absolute26 expect(resolveConfigPath(absoluteConfigPath, DIR)).toBe(absoluteConfigPath);27 expect(() => resolveConfigPath('/does_not_exist', DIR)).toThrowError(28 NO_ROOT_DIR_ERROR_PATTERN,29 );30 // relative31 expect(resolveConfigPath(relativeConfigPath, DIR)).toBe(absoluteConfigPath);32 expect(() => resolveConfigPath('does_not_exist', DIR)).toThrowError(33 NO_ROOT_DIR_ERROR_PATTERN,34 );35});36test('directory path', () => {37 const relativePackageJsonPath = 'a/b/c/package.json';38 const absolutePackageJsonPath = path.resolve(DIR, relativePackageJsonPath);39 const relativeJestConfigPath = 'a/b/c/jest.config.js';40 const absoluteJestConfigPath = path.resolve(DIR, relativeJestConfigPath);41 writeFiles(DIR, {'a/b/c/some_random_file.js': ''});42 // no configs yet. should throw43 expect(() =>44 // absolute45 resolveConfigPath(path.dirname(absoluteJestConfigPath), DIR),46 ).toThrowError(ERROR_PATTERN);47 expect(() =>48 // relative49 resolveConfigPath(path.dirname(relativeJestConfigPath), DIR),50 ).toThrowError(ERROR_PATTERN);51 writeFiles(DIR, {[relativePackageJsonPath]: ''});52 // absolute53 expect(resolveConfigPath(path.dirname(absolutePackageJsonPath), DIR)).toBe(54 absolutePackageJsonPath,55 );56 // relative57 expect(resolveConfigPath(path.dirname(relativePackageJsonPath), DIR)).toBe(58 absolutePackageJsonPath,59 );60 writeFiles(DIR, {[relativeJestConfigPath]: ''});61 // jest.config.js takes presedence62 // absolute63 expect(resolveConfigPath(path.dirname(absolutePackageJsonPath), DIR)).toBe(64 absoluteJestConfigPath,65 );66 // relative67 expect(resolveConfigPath(path.dirname(relativePackageJsonPath), DIR)).toBe(68 absoluteJestConfigPath,69 );70 expect(() => {71 resolveConfigPath(72 path.join(path.dirname(relativePackageJsonPath), 'j/x/b/m/'),73 DIR,74 );75 }).toThrowError(NO_ROOT_DIR_ERROR_PATTERN);...
resolveConfigPath.test.js
Source:resolveConfigPath.test.js
...19 const relativeConfigPath = 'a/b/c/my_config.js';20 const absoluteConfigPath = path.resolve(DIR, relativeConfigPath);21 writeFiles(DIR, {[relativeConfigPath]: ''});22 // absolute23 expect(resolveConfigPath(absoluteConfigPath, DIR)).toBe(absoluteConfigPath);24 expect(() => resolveConfigPath('/does_not_exist', DIR)).toThrowError(25 NO_ROOT_DIR_ERROR_PATTERN,26 );27 // relative28 expect(resolveConfigPath(relativeConfigPath, DIR)).toBe(absoluteConfigPath);29 expect(() => resolveConfigPath('does_not_exist', DIR)).toThrowError(30 NO_ROOT_DIR_ERROR_PATTERN,31 );32});33test('directory path', () => {34 const relativePackageJsonPath = 'a/b/c/package.json';35 const absolutePackageJsonPath = path.resolve(DIR, relativePackageJsonPath);36 const relativeJestConfigPath = 'a/b/c/jest.config.js';37 const absoluteJestConfigPath = path.resolve(DIR, relativeJestConfigPath);38 writeFiles(DIR, {'a/b/c/some_random_file.js': ''});39 // no configs yet. should throw40 expect(() =>41 // absolute42 resolveConfigPath(path.dirname(absoluteJestConfigPath), DIR),43 ).toThrowError(ERROR_PATTERN);44 expect(() =>45 // relative46 resolveConfigPath(path.dirname(relativeJestConfigPath), DIR),47 ).toThrowError(ERROR_PATTERN);48 writeFiles(DIR, {[relativePackageJsonPath]: ''});49 // absolute50 expect(resolveConfigPath(path.dirname(absolutePackageJsonPath), DIR)).toBe(51 absolutePackageJsonPath,52 );53 // relative54 expect(resolveConfigPath(path.dirname(relativePackageJsonPath), DIR)).toBe(55 absolutePackageJsonPath,56 );57 writeFiles(DIR, {[relativeJestConfigPath]: ''});58 // jest.config.js takes presedence59 // absolute60 expect(resolveConfigPath(path.dirname(absolutePackageJsonPath), DIR)).toBe(61 absoluteJestConfigPath,62 );63 // relative64 expect(resolveConfigPath(path.dirname(relativePackageJsonPath), DIR)).toBe(65 absoluteJestConfigPath,66 );67 expect(() => {68 resolveConfigPath(69 path.join(path.dirname(relativePackageJsonPath), 'j/x/b/m/'),70 DIR,71 );72 }).toThrowError(NO_ROOT_DIR_ERROR_PATTERN);...
config.js
Source:config.js
...21 }22 return configPath;23};24const readConfig = async () => {25 const configPath = await resolveConfigPath();26 if (!configPath) {27 return {};28 }29 try {30 const configFile = fs.readFileSync(configPath, { encoding: 'utf-8' });31 const config = JSON.parse(configFile);32 return config;33 }34 catch (error) {35 return {};36 }37};38const writeValue = async ({ key, value }) => {39 const configPath = await resolveConfigPath(true);40 const config = await fs.readJson(configPath);41 const newConfig = { ...config, [key]: value };42 await fs.writeJson(configPath, newConfig, { spaces: 2 });43 return newConfig;44};45const writeValues = async (values = {}) => {46 const configPath = await resolveConfigPath(true);47 const config = await fs.readJson(configPath);48 const newConfig = { ...config, ...values };49 await fs.writeJson(configPath, newConfig, { spaces: 2 });50 return newConfig;51};52module.exports = {53 readConfig,54 resolveConfigPath,55 configFolder,56 writeValue,57 writeValues...
test_parse-git-config.js
Source:test_parse-git-config.js
...37 const keys = parse.expandKeys(config);38 keys.foo.bar.doStuff === true;39 keys.foo.baz.doStuff === true;40}41parse.resolveConfigPath('foo'); // $ExpectType string | null42parse.resolveConfigPath({ cwd: 'foo' }); // $ExpectType string | null43parse.resolveConfigPath({ path: '.git/config' }); // $ExpectType string | null44parse.resolveConfigPath({ type: 'global' }); // $ExpectType string | null45parse.resolveConfigPath({ type: 'foo' }); // $ExpectError...
args-from
Source:args-from
...8 return path.join(dir, filename)9 }10 }11 if (dir !== '/') {12 return resolveConfigPath(path.resolve(dir, '..'), og || dir)13 } else {14 throw new Error('Could not resolve package.json from ' + og)15 }16}17const configPath = resolveConfigPath(process.cwd())18const config = JSON.parse(fs.readFileSync(configPath))19const name = process.argv[2]20if (config[name]) {21 let sect = config[name]22 let input = []23 for (let key in sect) {24 if (key[0] === '_') {25 if (Array.isArray(sect[key])) {26 input = input.concat(sect[key])27 } else {28 input.push(sect[key])29 }30 delete sect[key]31 }...
Using AI Code Generation
1var BestPracticeConfig = require('./BestPracticeConfig.js');2var bestPracticeConfig = new BestPracticeConfig();3var path = bestPracticeConfig.resolveConfigPath('test1.json');4console.log(path);5var path = require('path');6var BestPracticeConfig = function () {7 this.resolveConfigPath = function (configName) {8 var configPath = path.resolve(__dirname, configName);9 return configPath;10 };11};12module.exports = BestPracticeConfig;
Using AI Code Generation
1var BestPracticeConfigLoader = require('./BestPracticeConfigLoader.js');2var configLoader = new BestPracticeConfigLoader();3var configPath = configLoader.resolveConfigPath('test4.js');4console.log('configPath: ' + configPath);5var BestPracticeConfigLoader = require('./BestPracticeConfigLoader.js');6var configLoader = new BestPracticeConfigLoader();7var configPath = configLoader.resolveConfigPath('test5.js');8console.log('configPath: ' + configPath);9var BestPracticeConfigLoader = require('./BestPracticeConfigLoader.js');10var configLoader = new BestPracticeConfigLoader();11var configPath = configLoader.resolveConfigPath('test6.js');12console.log('configPath: ' + configPath);13var BestPracticeConfigLoader = require('./BestPracticeConfigLoader.js');14var configLoader = new BestPracticeConfigLoader();15var configPath = configLoader.resolveConfigPath('test7.js');16console.log('configPath: ' + configPath);17var BestPracticeConfigLoader = require('./BestPracticeConfigLoader.js');18var configLoader = new BestPracticeConfigLoader();19var configPath = configLoader.resolveConfigPath('test8.js');20console.log('configPath: ' + configPath);21var BestPracticeConfigLoader = require('./BestPracticeConfigLoader.js');22var configLoader = new BestPracticeConfigLoader();23var configPath = configLoader.resolveConfigPath('test9.js');24console.log('configPath: ' + configPath);25var BestPracticeConfigLoader = require('./BestPracticeConfigLoader.js');26var configLoader = new BestPracticeConfigLoader();27var configPath = configLoader.resolveConfigPath('test10.js');28console.log('configPath: ' + configPath);
Using AI Code Generation
1var bpc = require('best-practice-checker');2var path = require('path');3var configPath = bpc.resolveConfigPath(path.join(__dirname, 'test4.js'));4console.log('configPath: ' + configPath);5var bpc = require('best-practice-checker');6var path = require('path');7var configPath = bpc.resolveConfigPath(path.join(__dirname, 'test5.js'));8console.log('configPath: ' + configPath);9var bpc = require('best-practice-checker');10var path = require('path');11var configPath = bpc.resolveConfigPath(path.join(__dirname, 'test6.js'));12console.log('configPath: ' + configPath);13var bpc = require('best-practice-checker');14var path = require('path');15var configPath = bpc.resolveConfigPath(path.join(__dirname, 'test7.js'));16console.log('configPath: ' + configPath);17var bpc = require('best-practice-checker');18var path = require('path');19var configPath = bpc.resolveConfigPath(path.join(__dirname, 'test8.js'));20console.log('configPath: ' + configPath);21var bpc = require('best-practice-checker');22var path = require('path');23var configPath = bpc.resolveConfigPath(path.join(__dirname, 'test9.js'));24console.log('configPath: ' +
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!!