Best JavaScript code snippet using playwright-internal
path-util.js
Source:path-util.js
...7const RuleUtil = require('../db/rule-util');8const ruleUtil = new RuleUtil();9class PathUtil {10 static getAccountBalancePath(address) {11 return CommonUtil.formatPath([PredefinedDbPaths.ACCOUNTS, address, PredefinedDbPaths.BALANCE]);12 }13 static getAccountNoncePath(address) {14 return CommonUtil.formatPath([PredefinedDbPaths.ACCOUNTS, address, PredefinedDbPaths.ACCOUNTS_NONCE]);15 }16 static getAccountTimestampPath(address) {17 return CommonUtil.formatPath([PredefinedDbPaths.ACCOUNTS, address, PredefinedDbPaths.ACCOUNTS_TIMESTAMP]);18 }19 static getServiceAccountPath(serviceType, serviceName, accountKey) {20 return CommonUtil.formatPath([PredefinedDbPaths.SERVICE_ACCOUNTS, serviceType, serviceName, accountKey]);21 }22 static getServiceAccountBalancePath(serviceType, serviceName, accountKey) {23 return `${PathUtil.getServiceAccountPath(serviceType, serviceName, accountKey)}/${PredefinedDbPaths.BALANCE}`;24 }25 static getServiceAccountPathFromAccountName(accountName) {26 const parsed = CommonUtil.parseServAcntName(accountName);27 return CommonUtil.formatPath([PredefinedDbPaths.SERVICE_ACCOUNTS, parsed[0], parsed[1], parsed[2]]);28 }29 static getServiceAccountBalancePathFromAccountName(accountName) {30 return `${PathUtil.getServiceAccountPathFromAccountName(accountName)}/${PredefinedDbPaths.BALANCE}`;31 }32 static getTokenBridgeConfigPath(networkName, chainId, tokenId) {33 return CommonUtil.formatPath([34 PredefinedDbPaths.TOKEN, PredefinedDbPaths.TOKEN_BRIDGE, networkName, chainId, tokenId]);35 }36 static getTokenBridgeTokenPoolPath(networkName, chainId, tokenId) {37 return CommonUtil.formatPath([38 PredefinedDbPaths.TOKEN, PredefinedDbPaths.TOKEN_BRIDGE, networkName, chainId, tokenId,39 PredefinedDbPaths.TOKEN_BRIDGE_TOKEN_POOL40 ]);41 }42 static getTransferPath(from, to, key) {43 return CommonUtil.formatPath([PredefinedDbPaths.TRANSFER, from, to, key]);44 }45 static getTransferValuePath(from, to, key) {46 return CommonUtil.appendPath(PathUtil.getTransferPath(from, to, key), PredefinedDbPaths.TRANSFER_VALUE);47 }48 static getTransferResultPath(from, to, key) {49 return CommonUtil.appendPath(PathUtil.getTransferPath(from, to, key), PredefinedDbPaths.TRANSFER_RESULT);50 }51 static getCreateAppRecordPath(appName, recordId) {52 return CommonUtil.formatPath([53 PredefinedDbPaths.MANAGE_APP, appName, PredefinedDbPaths.MANAGE_APP_CREATE, recordId]);54 }55 static getCreateAppResultPath(appName, recordId) {56 return `${PathUtil.getCreateAppRecordPath(appName, recordId)}/${PredefinedDbPaths.MANAGE_APP_RESULT}`;57 }58 static getManageAppConfigPath(appName) {59 return CommonUtil.formatPath([PredefinedDbPaths.MANAGE_APP, appName, PredefinedDbPaths.MANAGE_APP_CONFIG]);60 }61 static getManageAppConfigAdminPath(appName) {62 return `${PathUtil.getManageAppConfigPath(appName)}/${PredefinedDbPaths.MANAGE_APP_CONFIG_ADMIN}`;63 }64 static getManageAppBillingUsersPath(appName, billingId) {65 return `${PathUtil.getManageAppConfigPath(appName)}/${PredefinedDbPaths.MANAGE_APP_CONFIG_BILLING}/` +66 `${billingId}/${PredefinedDbPaths.MANAGE_APP_CONFIG_BILLING_USERS}`;67 }68 static getAppPath(appName) {69 return CommonUtil.formatPath([PredefinedDbPaths.APPS, appName]);70 }71 static getAppAdminPathFromServiceAccountName(accountName) {72 return ruleUtil.getAppAdminPath(accountName);73 }74 static getStakingLockupDurationPath(serviceName) {75 return CommonUtil.formatPath([PredefinedDbPaths.MANAGE_APP, serviceName,76 PredefinedDbPaths.MANAGE_APP_CONFIG, PredefinedDbPaths.MANAGE_APP_CONFIG_SERVICE,77 PredefinedDbPaths.STAKING, PredefinedDbPaths.STAKING_LOCKUP_DURATION]);78 }79 static getStakingServicePath(serviceName) {80 return CommonUtil.formatPath([PredefinedDbPaths.STAKING, serviceName]);81 }82 static getStakingExpirationPath(serviceName, user, stakingKey) {83 return CommonUtil.formatPath([PredefinedDbPaths.STAKING, serviceName, user, stakingKey,84 PredefinedDbPaths.STAKING_EXPIRE_AT]);85 }86 static getStakingStakeRecordPath(serviceName, user, stakingKey, recordId) {87 return CommonUtil.formatPath([PredefinedDbPaths.STAKING, serviceName, user, stakingKey,88 PredefinedDbPaths.STAKING_STAKE, recordId]);89 }90 static getStakingUnstakeRecordPath(serviceName, user, stakingKey, recordId) {91 return CommonUtil.formatPath([PredefinedDbPaths.STAKING, serviceName, user, stakingKey,92 PredefinedDbPaths.STAKING_UNSTAKE, recordId]);93 }94 static getStakingStakeRecordValuePath(serviceName, user, stakingKey, recordId) {95 return `${PathUtil.getStakingStakeRecordPath(serviceName, user, stakingKey, recordId)}/` +96 `${PredefinedDbPaths.STAKING_VALUE}`;97 }98 static getStakingStakeResultPath(serviceName, user, stakingKey, recordId) {99 return `${PathUtil.getStakingStakeRecordPath(serviceName, user, stakingKey, recordId)}/` +100 `${PredefinedDbPaths.STAKING_RESULT}`;101 }102 static getStakingUnstakeResultPath(serviceName, user, stakingKey, recordId) {103 return `${PathUtil.getStakingUnstakeRecordPath(serviceName, user, stakingKey, recordId)}/` +104 `${PredefinedDbPaths.STAKING_RESULT}`;105 }106 static getStakingBalanceTotalPath(serviceName) {107 return CommonUtil.formatPath([PredefinedDbPaths.STAKING, serviceName, PredefinedDbPaths.STAKING_BALANCE_TOTAL]);108 }109 static getPaymentServiceAdminPath(serviceName) {110 return CommonUtil.formatPath([PredefinedDbPaths.PAYMENTS, serviceName, PredefinedDbPaths.PAYMENTS_CONFIG,111 PredefinedDbPaths.PAYMENTS_ADMIN]);112 }113 static getPaymentPayRecordPath(serviceName, user, paymentKey, recordId) {114 return CommonUtil.formatPath([PredefinedDbPaths.PAYMENTS, serviceName, user, paymentKey,115 PredefinedDbPaths.PAYMENTS_PAY, recordId]);116 }117 static getPaymentClaimRecordPath(serviceName, user, paymentKey, recordId) {118 return CommonUtil.formatPath([PredefinedDbPaths.PAYMENTS, serviceName, user, paymentKey,119 PredefinedDbPaths.PAYMENTS_CLAIM, recordId]);120 }121 static getPaymentPayRecordResultPath(serviceName, user, paymentKey, recordId) {122 return `${PathUtil.getPaymentPayRecordPath(serviceName, user, paymentKey, recordId)}/` +123 `${PredefinedDbPaths.PAYMENTS_RESULT}`;124 }125 static getPaymentClaimRecordResultPath(serviceName, user, paymentKey, recordId) {126 return `${PathUtil.getPaymentClaimRecordPath(serviceName, user, paymentKey, recordId)}/` +127 `${PredefinedDbPaths.PAYMENTS_RESULT}`;128 }129 static getEscrowHoldRecordPath(source, target, escrowKey, recordId) {130 return CommonUtil.formatPath([PredefinedDbPaths.ESCROW, source, target, escrowKey,131 PredefinedDbPaths.ESCROW_HOLD, recordId]);132 }133 static getEscrowHoldRecordResultPath(source, target, escrowKey, recordId) {134 return `${PathUtil.getEscrowHoldRecordPath(source, target, escrowKey, recordId)}/` +135 `${PredefinedDbPaths.ESCROW_RESULT}`;136 }137 static getEscrowReleaseRecordResultPath(source, target, escrowKey, recordId) {138 return CommonUtil.formatPath([PredefinedDbPaths.ESCROW, source, target, escrowKey,139 PredefinedDbPaths.ESCROW_RELEASE, recordId, PredefinedDbPaths.ESCROW_RESULT]);140 }141 static getLatestShardReportPath(branchPath) {142 return CommonUtil.appendPath(branchPath, ShardingProperties.LATEST);143 }144 static getLatestShardReportPathFromValuePath(valuePath) {145 const branchPath = CommonUtil.formatPath(valuePath.slice(0, -2));146 return PathUtil.getLatestShardReportPath(branchPath);147 }148 static getCheckinRequestPath(networkName, chainId, tokenId, address, checkinId) {149 return CommonUtil.formatPath([150 PredefinedDbPaths.CHECKIN, PredefinedDbPaths.CHECKIN_REQUESTS, networkName, chainId,151 tokenId, address, checkinId]);152 }153 static getCheckinHistoryPath(networkName, chainId, tokenId, address, checkinId) {154 return CommonUtil.formatPath([155 PredefinedDbPaths.CHECKIN, PredefinedDbPaths.CHECKIN_HISTORY, networkName, chainId,156 tokenId, address, checkinId]);157 }158 static getCheckinPendingAmountPerTokenPoolPath(tokenPoolAddr) {159 return CommonUtil.formatPath([160 PredefinedDbPaths.CHECKIN, PredefinedDbPaths.CHECKIN_STATS,161 PredefinedDbPaths.CHECKIN_STATS_PENDING, PredefinedDbPaths.CHECKIN_TOKEN_POOL, tokenPoolAddr]);162 }163 static getCheckinPendingAmountPerSenderPath(networkName, chainId, tokenId, sender) {164 return CommonUtil.formatPath([165 PredefinedDbPaths.CHECKIN, PredefinedDbPaths.CHECKIN_STATS,166 PredefinedDbPaths.CHECKIN_STATS_PENDING, networkName, chainId, tokenId, sender]);167 }168 static getCheckinCompleteAmountTotalPath() {169 return CommonUtil.formatPath([170 PredefinedDbPaths.CHECKIN, PredefinedDbPaths.CHECKIN_STATS,171 PredefinedDbPaths.CHECKIN_STATS_COMPLETE, PredefinedDbPaths.CHECKIN_STATS_TOTAL]);172 }173 static getCheckinCompleteAmountPerAddrPath(address) {174 return CommonUtil.formatPath([175 PredefinedDbPaths.CHECKIN, PredefinedDbPaths.CHECKIN_STATS,176 PredefinedDbPaths.CHECKIN_STATS_COMPLETE, address]);177 }178 static getCheckoutRequestPath(networkName, chainId, tokenId, address, checkoutId) {179 return CommonUtil.formatPath([180 PredefinedDbPaths.CHECKOUT, PredefinedDbPaths.CHECKOUT_REQUESTS, networkName, chainId,181 tokenId, address, checkoutId]);182 }183 static getCheckoutHistoryPath(networkName, chainId, tokenId, address, checkoutId) {184 return CommonUtil.formatPath([185 PredefinedDbPaths.CHECKOUT, PredefinedDbPaths.CHECKOUT_HISTORY, networkName, chainId,186 tokenId, address, checkoutId]);187 }188 static getCheckoutHistoryRefundPath(networkName, chainId, tokenId, address, checkoutId) {189 return CommonUtil.appendPath(190 PathUtil.getCheckoutHistoryPath(networkName, chainId, tokenId, address, checkoutId),191 PredefinedDbPaths.CHECKOUT_HISTORY_REFUND);192 }193 static getCheckoutPendingAmountTotalPath() {194 return CommonUtil.formatPath([195 PredefinedDbPaths.CHECKOUT, PredefinedDbPaths.CHECKOUT_STATS,196 PredefinedDbPaths.CHECKOUT_STATS_PENDING, PredefinedDbPaths.CHECKOUT_STATS_TOTAL]);197 }198 static getCheckoutPendingAmountPerAddrPath(address) {199 return CommonUtil.formatPath([200 PredefinedDbPaths.CHECKOUT, PredefinedDbPaths.CHECKOUT_STATS,201 PredefinedDbPaths.CHECKOUT_STATS_PENDING, address]);202 }203 static getCheckoutCompleteAmountTotalPath() {204 return CommonUtil.formatPath([205 PredefinedDbPaths.CHECKOUT, PredefinedDbPaths.CHECKOUT_STATS,206 PredefinedDbPaths.CHECKOUT_STATS_COMPLETE, PredefinedDbPaths.CHECKOUT_STATS_TOTAL]);207 }208 static getCheckoutCompleteAmountDailyPath(dayTimestamp) {209 return CommonUtil.formatPath([210 PredefinedDbPaths.CHECKOUT, PredefinedDbPaths.CHECKOUT_STATS,211 PredefinedDbPaths.CHECKOUT_STATS_COMPLETE, dayTimestamp]);212 }213 static getConsensusOffenseRecordsPath() {214 return CommonUtil.formatPath([PredefinedDbPaths.CONSENSUS, PredefinedDbPaths.CONSENSUS_OFFENSE_RECORDS]);215 }216 static getConsensusOffenseRecordsAddrPath(address) {217 return CommonUtil.formatPath([PredefinedDbPaths.CONSENSUS, PredefinedDbPaths.CONSENSUS_OFFENSE_RECORDS, address]);218 }219 static getConsensusWhitelistPath() {220 return CommonUtil.formatPath([PredefinedDbPaths.CONSENSUS, PredefinedDbPaths.CONSENSUS_WHITELIST]);221 }222 static getConsensusWhitelistAddrPath(address) {223 return CommonUtil.formatPath([PredefinedDbPaths.CONSENSUS, PredefinedDbPaths.CONSENSUS_WHITELIST, address]);224 }225 static getConsensusStakingAccountPath(address) {226 return PathUtil.getServiceAccountPath(PredefinedDbPaths.STAKING, PredefinedDbPaths.CONSENSUS, `${address}|0`);227 }228 static getConsensusStakingAccountBalancePath(address) {229 const accountPath = PathUtil.getServiceAccountPath(PredefinedDbPaths.STAKING, PredefinedDbPaths.CONSENSUS, `${address}|0`);230 return CommonUtil.appendPath(accountPath, PredefinedDbPaths.BALANCE)231 }232 static getConsensusRewardsPath(address) {233 return CommonUtil.formatPath([PredefinedDbPaths.CONSENSUS, PredefinedDbPaths.CONSENSUS_REWARDS, address]);234 }235 static getConsensusRewardsUnclaimedPath(address) {236 return CommonUtil.formatPath([PredefinedDbPaths.CONSENSUS, PredefinedDbPaths.CONSENSUS_REWARDS, address, PredefinedDbPaths.CONSENSUS_REWARDS_UNCLAIMED]);237 }238 static getConsensusRewardsCumulativePath(address) {239 return CommonUtil.formatPath([PredefinedDbPaths.CONSENSUS, PredefinedDbPaths.CONSENSUS_REWARDS, address, PredefinedDbPaths.CONSENSUS_REWARDS_CUMULATIVE]);240 }241 static getConsensusNumberPath(blockNumber) {242 return CommonUtil.formatPath([PredefinedDbPaths.CONSENSUS, PredefinedDbPaths.CONSENSUS_NUMBER, blockNumber]);243 }244 static getConsensusProposePath(blockNumber) {245 return CommonUtil.formatPath([246 PredefinedDbPaths.CONSENSUS, PredefinedDbPaths.CONSENSUS_NUMBER, blockNumber, PredefinedDbPaths.CONSENSUS_PROPOSE]);247 }248 static getConsensusVotePath(blockNumber, blockHash, address) {249 return CommonUtil.formatPath([250 PredefinedDbPaths.CONSENSUS, PredefinedDbPaths.CONSENSUS_NUMBER, blockNumber, blockHash,251 PredefinedDbPaths.CONSENSUS_VOTE, address]);252 }253 static getGasFeeClaimPath(userAddr, recordId) {254 return CommonUtil.formatPath([255 PredefinedDbPaths.GAS_FEE, PredefinedDbPaths.GAS_FEE_CLAIM, userAddr, recordId]);256 }257 static getGasFeeCollectPath(blockNumber, userAddr, txHash) {258 return CommonUtil.formatPath([259 PredefinedDbPaths.GAS_FEE, PredefinedDbPaths.GAS_FEE_COLLECT, blockNumber, userAddr, txHash]);260 }261 static getReceiptPath(txHash) {262 return CommonUtil.formatPath([PredefinedDbPaths.RECEIPTS, txHash]);263 }264}...
bundler.js
Source:bundler.js
1/* global describe, it, before */2/*eslint no-underscore-dangle: 0*/3'use strict';4var bundalo = require("../index");5var engine = "none";6var path = require('path');7var assert = require('assert');8var formatPath = require('kraken-format-path');9var dust = require('dustjs-linkedin');10var dustFormatter = function (bundle) {11 bundle.formatDust = function (pattern, model, renderCb) {12 if (!this.cache[pattern]) {13 this.cache[pattern] = dust.loadSource(dust.compile(this.get(pattern)));14 }15 dust.render(this.cache[pattern], model, renderCb);16 };17 return bundle;18};19describe("bundalo none bundler @none@", function () {20 it("should maintain one cache per instance", function (done) {21 var contentPath = path.resolve(__dirname, 'fixture', 'nolocale');22 var fallback = "";23 var bundloo = bundalo({contentPath: contentPath, fallback: fallback, formatPath: formatPath});24 var bundlee = bundalo({contentPath: contentPath, fallback: fallback, formatPath: formatPath});25 bundloo.get({26 'bundle': 'nest/nonea',27 'locality': ''28 }, function bundaloReturn(err, bundle) {29 if (err) {30 return done(err);31 }32 try {33 assert(bundle.get('greeting'));34 assert(bundloo.__cache()[path.resolve(contentPath, 'nest/nonea.properties')]);35 assert(!bundlee.__cache()[path.resolve(contentPath, 'nest/nonea.properties')]);36 done();37 } catch (e) {38 done(e);39 }40 });41 });42});43describe("bundalo none bundler @none@disableCache@", function () {44 it("should not maintain cache", function (done) {45 var contentPath = path.resolve(__dirname, 'fixture', 'nolocale');46 var fallback = "";47 var bundloo = bundalo({48 contentPath: contentPath,49 engine: engine,50 fallback: fallback,51 cache: false,52 formatPath: formatPath53 });54 bundloo.get({55 'bundle': 'nest/nonea',56 'locality': ''57 }, function bundaloReturn(err, bundle) {58 if (err) {59 return done(err);60 }61 try {62 assert(bundle.get('greeting'));63 assert(!bundloo.__cache()[path.resolve(contentPath, 'nest/nonea.properties')]);64 done();65 } catch (e) {66 done(e);67 }68 });69 });70});71describe("bundalo none bundler, no locale @none@nofallback@", function () {72 var contentPath = path.resolve(__dirname, 'fixture', 'nolocale');73 var fallback = "";74 var _bundalo;75 before(function () {76 _bundalo = bundalo({contentPath: contentPath, engine: engine, fallback: fallback, formatPath: formatPath});77 return;78 });79 it("should give back single bundle", function (done) {80 _bundalo.get({81 'bundle': 'nest/nonea',82 'locality': ''83 }, function bundaloReturn(err, bundle) {84 if (err) {85 return done(err);86 }87 try {88 assert(bundle.get('greeting'));89 assert(_bundalo.__cache()[path.resolve(contentPath, 'nest/nonea.properties')]);90 done();91 } catch (e) {92 done(e);93 }94 });95 });96 it("should give back multiple bundles", function (done) {97 _bundalo.get({98 'bundle': ['nest/nonea', 'nest/noneb'],99 'locality': ''100 }, function bundaloReturn(err, bundle) {101 if (err) {102 return done(err);103 }104 try {105 assert(bundle['nest/nonea'].get('greeting'));106 assert(bundle['nest/noneb'].get('signoff'));107 done();108 } catch (e) {109 done(e);110 }111 });112 });113 it("should give back multiple bundles with alias", function (done) {114 _bundalo.get({115 'bundle': {116 'nonea': 'nest/nonea',117 'noneb': 'nest/noneb'118 },119 'locality': ''120 }, function bundaloReturn(err, bundle) {121 if (err) {122 return done(err);123 }124 try {125 assert(bundle.nonea.get('greeting'));126 assert(bundle.noneb.get('signoff'));127 done();128 } catch (e) {129 done(e);130 }131 });132 });133});134//135//136describe("bundalo none bundler, existing locale @none@nofallback@", function () {137 var contentPath = path.resolve(__dirname, "fixture", "locales");138 var fallback = "en-US";139 var _bundalo;140 before(function () {141 _bundalo = bundalo({contentPath: contentPath, engine: engine, fallback: fallback, formatPath: formatPath});142 return;143 });144 it("should give back single bundle", function (done) {145 _bundalo.get({146 'bundle': 'nest/nonea',147 'locality': 'es-ES'148 }, function bundaloReturn(err, bundle) {149 if (err) {150 return done(err);151 }152 try {153 assert(bundle.get('greeting'));154 done();155 } catch (e) {156 done(e);157 }158 });159 });160 it("should give back multiple bundles", function (done) {161 _bundalo.get({162 'bundle': ['nest/nonea', 'nest/noneb'],163 'locality': 'es-ES'164 }, function bundaloReturn(err, bundle) {165 if (err) {166 return done(err);167 }168 try {169 assert(bundle['nest/nonea'].get('greeting'));170 assert(bundle['nest/noneb'].get('signoff'));171 assert(_bundalo.__cache()[path.resolve(contentPath, 'ES/es/nest/noneb.properties')]);172 done();173 } catch (e) {174 done(e);175 }176 });177 });178 it("should give back multiple bundles with alias", function (done) {179 _bundalo.get({180 'bundle': {181 'nonea': 'nest/nonea',182 'noneb': 'nest/noneb'183 },184 'locality': 'es-ES'185 }, function bundaloReturn(err, bundle) {186 if (err) {187 return done(err);188 }189 try {190 assert(bundle.nonea.get('greeting'));191 assert(bundle.noneb.get('signoff'));192 done();193 } catch (e) {194 done(e);195 }196 });197 });198});199describe("bundalo none bundler, fallback locale @none@fallback@", function () {200 var contentPath = path.resolve(__dirname, "fixture", "locales");201 var fallback = "en-US";202 var locality = "fr-FR";203 var _bundalo;204 before(function () {205 _bundalo = bundalo({206 contentPath: contentPath,207 locality: locality,208 fallback: fallback,209 formatPath: formatPath210 });211 return;212 });213 it("should give back single bundle", function (done) {214 _bundalo.get({215 'bundle': 'nest/nonea'216 }, function bundaloReturn(err, bundle) {217 if (err) {218 return done(err);219 }220 try {221 assert(bundle.get('greeting'));222 done();223 } catch (e) {224 done(e);225 }226 });227 });228 it("should give back multiple bundles", function (done) {229 _bundalo.get({230 'bundle': ['nest/nonea', 'nest/noneb']231 }, function bundaloReturn(err, bundle) {232 if (err) {233 return done(err);234 }235 try {236 assert(bundle['nest/nonea'].get('greeting'));237 assert(bundle['nest/noneb'].get('signoff'));238 done();239 } catch (e) {240 done(e);241 }242 });243 });244 it("should give back multiple bundles with alias", function (done) {245 _bundalo.get({246 'bundle': {247 'nonea': 'nest/nonea',248 'noneb': 'nest/noneb'249 }250 }, function bundaloReturn(err, bundle) {251 if (err) {252 return done(err);253 }254 try {255 assert(bundle.nonea.get('greeting'));256 assert(bundle.noneb.get('signoff'));257 done();258 } catch (e) {259 done(e);260 }261 });262 });263});264describe("bundalo with dust", function () {265 it("should format messages given a model", function (done) {266 var contentPath = path.resolve(__dirname, 'fixture', 'nolocale');267 var bundloo = bundalo({contentPath: contentPath, formatPath: formatPath});268 bundloo.get({269 'bundle': 'nest/dusta',270 'locality': ''271 }, function bundaloReturn(err, bundle) {272 if (err) {273 return done(err);274 }275 bundle = dustFormatter(bundle);276 bundle.formatDust('greeting', {name: 'World'}, function (innererr, rendered) {277 if (innererr) {278 return done(innererr);279 }280 try {281 assert.equal(rendered, "Hello, World");282 done();283 } catch (e) {284 done(e);285 }286 });287 });288 });289 it("should accept jsonpath", function (done) {290 var contentPath = path.resolve(__dirname, 'fixture', 'nolocale');291 var bundloo = bundalo({contentPath: contentPath, formatPath: formatPath});292 bundloo.get({293 'bundle': 'nest/nonea',294 'locality': ''295 }, function bundaloReturn(err, bundle) {296 if (err) {297 return done(err);298 }299 try {300 assert.equal(bundle.get('deep.greeting'), "So nice to meet you");301 done();302 } catch (e) {303 done(e);304 }305 });306 });...
Imfs.js
Source:Imfs.js
1/*2* Imfs.js3* Copyright (C) 2017 sabertazimi <sabertazimi@gmail.com>4*5* Distributed under terms of the MIT license.6*/7'use strict';8const path = require('path'); // utils for resolve path9class Imfs {10 constructor(data) {11 this.data = data || {};12 this.cwd = '/';13 }14 /**15 * judge whether current node is directory or not16 *17 * @method isDir18 * @param {object} node current node19 * @return {Boolean} true stand for is directory20 */21 isDir(node) {22 if (typeof node !== 'object') {23 return false;24 } else {25 return node[''] === true;26 }27 }28 /**29 * judge whether current node is file or not30 *31 * @method isFile32 * @param {object} node current node33 * @return {Boolean} true stand for is file34 */35 isFile(node) {36 if (typeof node !== 'object') {37 return false;38 } else {39 return node[''] === false;40 }41 }42 /**43 * change path string to path array44 *45 * @method resolvePath46 * @param {string} _path path string for target47 * @return {string} normalized absolute path48 */49 resolvePath(_path) {50 let formatPath = _path;51 // combine path to absolute path52 if (!path.isAbsolute(formatPath)) {53 formatPath = path.join(this.cwd, formatPath);54 }55 formatPath = path.normalize(formatPath);56 return formatPath;57 }58 /**59 * change normalized absolute path to array60 *61 * @param {string} formatPath normalized absolute path62 * @return {array} path array63 */64 path2arr(formatPath) {65 let patharr = formatPath.substr(1).split('/');66 // remove tail '/' when from relative path67 if (!patharr[patharr.length - 1]) {68 patharr.pop();69 }70 return patharr;71 }72 /**73 * change current working directory74 *75 * @method chdir76 * @param {string} _path path string for target77 * @return {object} reference to imfs (this)78 */79 chdir(_path) {80 const formatPath = this.resolvePath(_path);81 if (this.isExist(formatPath)) {82 this.cwd = formatPath;83 } else {84 throw new Error(`Error: directory '${formatPath}' not exists.`);85 }86 }87 /**88 * judge a dir/file whether exists or not89 *90 * @method isExist91 * @param {string} _path path string for target92 * @return {Boolean} true stand for existance93 */94 isExist(_path) {95 const formatPath = this.resolvePath(_path);96 const patharr = this.path2arr(formatPath);97 // root directory98 if (patharr.length === 0) {99 return true;100 }101 let cache = this.data;102 let i = 0;103 for (; i < patharr.length - 1; i++) {104 if (!this.isDir(cache[patharr[i]])) {105 return false;106 }107 cache = cache[patharr[i]];108 }109 return !!cache[patharr[i]];110 }111 /**112 * read content of directory113 *114 * @method readdir115 * @param {string} _path path string for target116 * @return {array} string array of file/subdir name117 */118 readdir(_path) {119 const formatPath = this.resolvePath(_path);120 const patharr = this.path2arr(formatPath);121 // root directory122 if (patharr.length === 0) {123 return Object.keys(this.data).filter(Boolean);124 }125 let cache = this.data;126 let i = 0;127 for (; i < patharr.length - 1; i++) {128 if (!this.isDir(cache[patharr[i]])) {129 throw new Error(`Error: directory '${formatPath}' not exists.`);130 }131 cache = cache[patharr[i]];132 }133 if (!this.isDir(cache[patharr[i]])) {134 throw new Error(`Error: directory '${formatPath}' not exists.`);135 }136 return Object.keys(cache[patharr[i]]).filter(Boolean);137 }138 /**139 * make new directory/file140 *141 * @method mkNode142 * @param {string} _path path string for target143 * @param {Boolean} type 0 for directory, 1 for file144 * @return {object} reference to imfs (this)145 */146 mkNode(_path, type) {147 const formatPath = this.resolvePath(_path);148 const patharr = this.path2arr(formatPath);149 // root directory150 if (patharr.length === 0) {151 return this;152 }153 let cache = this.data;154 let i = 0;155 for (; i < patharr.length - 1; i++) {156 if (this.isFile(cache[patharr[i]])) {157 throw new Error(`Error: homonymous file '${patharr[i]}' exists.`);158 } else if (!this.isDir(cache[patharr[i]])) {159 // create new directory when non-exist160 cache[patharr[i]] = {'': true};161 }162 cache = cache[patharr[i]];163 }164 if (this.isDir(cache[patharr[i]])) {165 throw new Error(`Error: directory '${patharr[i]}' exists.`);166 }167 if (type) {168 cache[patharr[i]] = {'': false, 'content': ''};169 console.log(`Success: create file '${formatPath}'.`);170 } else {171 cache[patharr[i]] = {'': true};172 console.log(`Success: create directory '${formatPath}'.`);173 }174 return this;175 }176 /**177 * delete directory/file178 *179 * @method rmNode180 * @param {string} _path path string for target181 * @return {object} reference to imfs (this)182 */183 rmNode(_path) {184 const formatPath = this.resolvePath(_path);185 const patharr = this.path2arr(formatPath);186 if (patharr.length === 0) {187 throw new Error(`Error: can't remove '/' directory`);188 }189 let cache = this.data;190 let i = 0;191 for (; i < patharr.length - 1; i++) {192 if (!this.isDir(cache[patharr[i]])) {193 throw new Error(`Error: directory '${patharr[i]}' not exists.`);194 }195 cache = cache[patharr[i]];196 }197 delete cache[patharr[i]];198 return this;199 }200 /**201 * read content of file202 *203 * @method readFile204 * @param {string} _path path string for target205 * @return {string} content of file206 */207 readFile(_path) {208 const formatPath = this.resolvePath(_path);209 const patharr = this.path2arr(formatPath);210 let cache = this.data;211 let i = 0212 for (; i < patharr.length - 1; i++) {213 if (!this.isDir(cache[patharr[i]])) {214 throw new Error(`Error: directory '${patharr[i]}' not exists.`);215 }216 cache = cache[patharr[i]];217 }218 if (!this.isFile(cache[patharr[i]])) {219 throw new Error(`Error: file '${patharr[i]}' not exists.`);220 }221 return cache[patharr[i]]['content'].toString();222 }223 /**224 * write content to file225 *226 * @method writeFile227 * @param {string} _path path string for target228 * @param {string} content content to write229 * @return {object} reference to imfs (this)230 */231 writeFile(_path, content) {232 if (!content) {233 throw new Error(`Error: no content.`);234 }235 const formatPath = this.resolvePath(_path);236 const patharr = this.path2arr(formatPath);237 if (patharr.length === 0) {238 throw new Error(`Error: file '${formatPath}' not exists.`);239 }240 let cache = this.data;241 let i = 0242 for (; i < patharr.length - 1; i++) {243 if (!this.isDir(cache[patharr[i]])) {244 throw new Error(`Error: directory '${patharr[i]}' not exists.`);245 }246 cache = cache[patharr[i]];247 }248 if (this.isDir(cache[patharr[i]])) {249 throw new Error(`Error: file '${formatPath}' not exists.`);250 }251 cache[patharr[i]]['content'] = content;252 return this;253 }254}...
scssInitialize.js
Source:scssInitialize.js
...62 let watcher = chokidar.watch("public/stylesheets/scss/**", { ignoreInitial: true });63 watcher64 .on('add', function (path) {65 // new file is added66 let formatPath = fileHelper.formatPath(path);67 jsonSetUp.addNewFileToJSON(formatPath, true);68 if (!fileHelper.checkFileEmpty(formatPath)) {69 fileHelper.createFileAsync([formatPath], [translateToCSS(formatPath, isProduction)], fileNameReplaceCondition)70 .catch(function (e) {71 console.log(e);72 });73 }74 console.log(`setSCSSFileListener: File ${path} is added.`);75 console.log("-------------------------------------------------------");76 })77 .on('unlink', function (path) {78 // new file is removed79 let formatPath = fileHelper.formatPath(path);80 jsonSetUp.removeFileFromJSON(formatPath);81 fileHelper.removeFileAsync(fileHelper.replacePath(formatPath, fileNameReplaceCondition));82 console.log(`setSCSSFileListener: File ${path} is removed.`);83 console.log("-------------------------------------------------------");84 })85 .on('addDir', function (path) {86 // new directory is added87 let formatPath = fileHelper.formatPath(path);88 fileHelper.createDirectoryAsync([formatPath], directoryNameReplaceCondition);89 console.log(`setSCSSFileListener: Directory ${path} is added.`);90 console.log("-------------------------------------------------------");91 })92 .on('unlinkDir', function (path) {93 // new directory is removed94 // NOTICE: for Windows user, it will trigger EPERM error if you want to delete an empty directory95 let formatPath = fileHelper.replacePath(path.replace(/\\/g, "/"), directoryNameReplaceCondition);96 console.log("path: " + formatPath);97 fileHelper.removeDirectoryAsync(formatPath);98 console.log(`setSCSSFileListener: Directory ${path} is removed.`);99 console.log("-------------------------------------------------------");100 })101 .on('change', function (path) {102 //file is changed103 let formatPath = fileHelper.formatPath(path);104 let updatePath = [];105 let cssContent = [];106 updatePath.push(formatPath);107 cssContent.push(translateToCSS(formatPath, isProduction));108 let linkSCSS = jsonSetUp.getLinkSCSS(formatPath);109 if (linkSCSS.length !== 0) {110 linkSCSS.forEach(function (link) {111 updatePath.push(link);112 cssContent.push(translateToCSS(link, isProduction));113 });114 }115 fileHelper.createFileAsync(updatePath, cssContent, fileNameReplaceCondition)116 .then(function () {117 updatePath.forEach(function (link) {...
router.js
Source:router.js
1'use strict';2const querystring = require('querystring')3/**4 * @name è·¯ç±è§£æä¸éå®å5 */6module.exports = options => {7 /**8 * @name è·¯ç±è§£æä¸éå®å9 */10 return async function(ctx, next) {11 const isDev = ctx.app.config.env !== 'prod'12 const {controller: CTRLS} = ctx.app.router.format13 const {camelCase, primaryKeyAdaptor} = ctx.app.config.router14 let module, controller, action;15 const origin = ctx.originalUrl.split('?')16 const originPath = camelCase ? Array.from(origin[0].split('/'), str => ctx._.camelCase(str)).join('/') : origin[0]17 const originaPath = originPath.replace(/(^\/*)|(\/*$)/g, "").split('/') // 注æéè¦å»é¤å¤´å°¾çææ 18 /**19 * è·å主é®ï¼èªå¨å¤æ主é®æ¯å¦åè§ï¼20 * é»è®¤ä½¿ç¨ int è¿è¡å¤æï¼ä¹å¯ä»¥ä¼ å
¥æå® primaryKeyAdaptor è¿è¡å¤æ21 * @param {string} sample éè¦å¤æçæ ·æ¬å符22 * @return {number|boolean} è¥å¤å®æåè¿åæ£ç¡®ç主é®å¼23 */24 const getPrimary = sample => {25 if (sample) {26 if (typeof primaryKeyAdaptor === 'function') {27 const primary = primaryKeyAdaptor(sample)28 if (primary) {29 return primary === true ? sample : primary30 }31 } else {32 const primary = Number(sample)33 if (primary == sample) {34 return primary35 }36 }37 }38 return false39 }40 // 强å¶æ¨¡ååï¼è¥æªå®ä¹ååé»è®¤å¼41 if (!originaPath[0] || originaPath[0] === '') {42 originaPath[0] = options['defaultModule']43 }44 // ä»åå§è·¯å¾ä¸æ·è´ä¸ä¸ªè·¯å¾è¿è¡è®¡ç®45 const formatPath = Array(...originaPath)46 module = formatPath.shift() // åºå®ç¬¬ä¸ä¸ªä¸ºæ¨¡åå47 // ååºå¹¶å° params ä¸ query è¿è¡å并48 const params = {}49 const query = querystring.decode(origin[1])50 for (const key in query) {51 if (key !== '' && query[key] !== '' && query[key] !== 'undefined') {52 params[key] = query[key]53 }54 }55 // æå formatPath ç params ä¼ åï¼æ³¨æä¸è½æå第ä¸ä¸ªä¸æåä¸ä¸ª56 // ä¾: /user/5/address/6 解æ为 /user/address?user=5&address=657 formatPath.forEach((item, index) => {58 const primary = getPrimary(item)59 if (primary && index) {60 if (formatPath[index - 1] && formatPath.length - 1 !== index) {61 params[formatPath[index - 1]] = primary62 formatPath.splice(index - 1, 2)63 }64 }65 })66 // æ ¹æ® formatPath å°¾é¨å¤æï¼å¦æ为 ä¸»é® æ index, é£ä¹å¯ä»¥æ¨æ action 为 index, å¦åéè¦ä¸ä¸æ¥å»æ¨å¯¼67 const tail = formatPath[formatPath.length - 1]68 const possiblePrimary = getPrimary(tail)69 if (possiblePrimary || tail === 'index') {70 action = 'index'71 if (possiblePrimary) {72 params[options['primaryKey']] = possiblePrimary // æç»ä»¶æååºæ¥73 }74 formatPath.pop()75 }76 // å½å formatPath 被åé¤æäºæ¨¡ååä¸åæ°ï¼å¦æ为空åå¡«å
¥ä¸ä¸ªé»è®¤å¼77 if (!formatPath[0] || formatPath[0] === '') {78 formatPath[0] = options['defaultController']79 }80 controller = formatPath.join('/') // å¦æä¹åè·åå°äº action é£ä¹å©ä¸çè·¯å¾å³æ¯èµæºå81 if (CTRLS[`/${module}/${controller}`]) {82 action = options['defaultAction'] // å¦æåå¨æ§å¶å¨ï¼ååæ§å¶å¨ï¼å¹¶æ å°é»è®¤æ¹æ³83 } else {84 // å¦æä¸åå¨æ§å¶å¨ï¼åæå¯è½æåä¸è·¯å¾ä¸ºå¨ä½å85 action = formatPath.pop()86 controller = formatPath.join('/') || options['defaultController']87 }88 // è¥è·¯ç±ä¸åå¨å¯ä»¥ç´æ¥æ¥é89 const controllerPath = `/${module}${controller === 'index' ? '' : '/' + controller}`90 const fullPath = `${controllerPath}${action === 'index' ? '' : '/' + action}`91 if (!CTRLS[controllerPath] || action != 'index' && !CTRLS[controllerPath][action]) {92 return ctx.err(404, isDev ? 'resource is undefined.' : null )93 }94 // è¿åç»æ95 ctx.api = {96 module, controller, action,97 originaPath, controllerPath, fullPath,98 params99 }100 ctx.request.url = `${fullPath}?${querystring.encode(params)}`101 return next()102 }...
url.test.js
Source:url.test.js
2import * as all from '$shared/utils/url'3describe('url utils', () => {4 describe('formatPath', () => {5 it('must format the path', () => {6 assert.equal(all.formatPath('part1', 'part2', '/part3/', '/part4'), '/part1/part2/part3/part4')7 })8 it('must format the path and queryString correctly', () => {9 assert.equal(all.formatPath('part1', 'part2', '/part3', {10 query1: 'test',11 query2: 'aapeli',12 }), '/part1/part2/part3?query1=test&query2=aapeli')13 assert.equal(all.formatPath('part1', {14 query1: 'value1',15 }, 'part2', {16 query2: 'value2',17 }), '/part1/part2?query1=value1&query2=value2')18 assert.equal(all.formatPath('part1', {19 query: 'value1',20 }, 'part2', {21 query: 'value2',22 }), '/part1/part2?query=value2')23 })24 it('must work with a slash in a part', () => {25 assert.equal(all.formatPath('part1', 'part2', '/part3/part4'), '/part1/part2/part3/part4')26 })27 it('must work with a slash only urls', () => {28 assert.equal(all.formatPath('/'), '/')29 assert.equal(all.formatPath('/', '/'), '/')30 assert.equal(all.formatPath('////', '//'), '/')31 })32 it('ignores skipLocale and locale query params', () => {33 assert.equal(all.formatPath('part1', {34 skipLocale: true,35 locale: 'whatever',36 }, 'part2'), '/part1/part2')37 })38 it('converts locale into lang param properly', () => {39 assert.equal(all.formatPath('part1', {40 skipLocale: false,41 locale: 'pl',42 }, 'part2'), '/part1/part2?lang=pl')43 assert.equal(all.formatPath('part1', {44 locale: 'pl',45 }, 'part2'), '/part1/part2?lang=pl')46 })47 it('does not convert "en" locale into lang param', () => {48 assert.equal(all.formatPath('part1', {49 locale: 'en',50 }, 'part2'), '/part1/part2')51 })52 it('does not convert (untranslated/unsupported) "id" locale into lang param', () => {53 assert.equal(all.formatPath('part1', {54 locale: 'id',55 }, 'part2'), '/part1/part2')56 })57 })58 describe('formatApiUrl', () => {59 let oldStreamrApiUrl60 beforeEach(() => {61 oldStreamrApiUrl = process.env.STREAMR_API_URL62 process.env.STREAMR_API_URL = 'http://marketplace.test'63 })64 afterEach(() => {65 process.env.STREAMR_API_URL = oldStreamrApiUrl66 })67 it('must format the path', () => {...
request.js
Source:request.js
...9 },10 path: '/api/TestApiPath/:id'11 };12 const expected = '/api/TestApiPath/1';13 const received = formatPath(payload.path, payload.query, null, methods.GET, null);14 expect(received).toMatch(expected);15 });16});17describe('formatPath', () => {18 it('formatPath should return correct path when using query params', () => {19 const payload = {20 query: {21 id: 122 },23 path: '/api/TestApiPath'24 };25 const expected = '/api/TestApiPath?id=1';26 const received = formatPath(payload.path, payload.query, null, methods.GET, null);27 expect(received).toMatch(expected);28 });29});30describe('formatPath', () => {31 it('formatPath should return correct path when using param and query params', () => {32 const payload = {33 query: {34 id: 1,35 value: 'test'36 },37 path: '/api/TestApiPath/:id'38 };39 const expected = '/api/TestApiPath/1?value=test';40 const received = formatPath(payload.path, payload.query, null, methods.GET, null);41 expect(received).toMatch(expected);42 });43});44describe('formatPath', () => {45 it('formatPath should return correct path when using multiple query params', () => {46 const payload = {47 query: {48 id: 1,49 value: 'test'50 },51 path: '/api/TestApiPath'52 };53 const expected = '/api/TestApiPath?id=1&value=test';54 const received = formatPath(payload.path, payload.query, null, methods.GET, null);55 expect(received).toMatch(expected);56 });57});58describe('formatPath', () => {59 it('formatPath should return correct path when using multiple path params', () => {60 const payload = {61 query: {62 id: 1,63 value: 'test'64 },65 path: '/api/TestApiPath/:id/:value'66 };67 const expected = '/api/TestApiPath/1/test';68 const received = formatPath(payload.path, payload.query, null, methods.GET, null);69 expect(received).toMatch(expected);70 });71});72describe('formatPath', () => {73 it('path should be falsy if nullableParams is false and path params are null', () => {74 const payload = {75 query: {76 id: null77 },78 path: '/api/TestApiPath/:id'79 };80 const received = formatPath(payload.path, payload.query, null, methods.GET, null);81 expect(received).toBeFalsy();82 });83});84describe('formatPath', () => {85 it('path should be falsy if nullableParams is false and query params are null', () => {86 const payload = {87 query: {88 id: null89 },90 path: '/api/TestApiPath'91 };92 const received = formatPath(payload.path, payload.query, null, methods.GET, null);93 expect(received).toBeFalsy();94 });95});96describe('formatPath', () => {97 it('path should be falsy if nullableParams is false and some params are null', () => {98 const payload = {99 query: {100 id: 1,101 value: null102 },103 path: '/api/TestApiPath'104 };105 const received = formatPath(payload.path, payload.query, null, methods.GET, null);106 expect(received).toBeFalsy();107 });108});109describe('formatPath', () => {110 it('path should not include params if only payloadBody is initialized', () => {111 const payload = {112 body: {113 id: 1,114 value: 'test'115 },116 path: '/api/TestApiPath'117 };118 const received = formatPath(payload.path, null, payload.body, methods.POST, false);119 const expected = '/api/TestApiPath';120 expect(received).toMatch(expected);121 });...
utils.js
Source:utils.js
1function Utils () {}2/**3 * å¨æ解æè·¯å¾4 * @param formatPath å¾
解æè·¯å¾5 * @param fileName æ件å6 * @param timestamp æ¶é´æ³7 * @return {string|*} å¤çåçæ件å8 */9Utils.getSavePath = (formatPath, fileName, { timestamp = false } = {}) => {10 if (!/{.*?}/.test(formatPath)) {11 // å¨æ²¡æé
ç½®å¨æè·¯å¾æ¶12 if (timestamp) {13 return window.path.join(formatPath, Date.now().toString() + fileName)14 }15 return window.path.join(formatPath, fileName)16 }17 /**18 * å
è®¸æ ¼å¼åçå
³é®è¯19 * @type {string[]} Y-å¹´ M-æ D-æ¥ H-æ¶ m-å s-ç§ rand-10ä½ éæºå符串 since_millisecond 毫ç§æ¶é´æ³ since_second ç§æ¶é´æ³20 */21 const enableKeywords = ['Y', 'M', 'D', 'H', 'm', 's', 'rand', 'ms', 'since_millisecond', 'since_second']22 const date = new Date()23 const option = {24 Y: date.getFullYear().toString(),25 M: (date.getMonth() + 1).toString(),26 D: date.getDate().toString(),27 H: date.getHours().toString().padStart(2, '0'),28 m: date.getMinutes().toString().padStart(2, '0'),29 s: date.getSeconds().toString().padStart(2, '0'),30 ms: date.getMilliseconds().toString(),31 rand: Math.random().toString(36).slice(-10),32 since_millisecond: Date.now(),33 since_second: Math.round(Date.now() / 1000),34 }35 const noFilename = formatPath.includes('{no_filename}')36 const rewrite = formatPath.includes('filename') || noFilename37 if (noFilename) {38 formatPath = formatPath.replace('{no_filename}', '')39 }40 for (const key of enableKeywords) {41 if (option[key]) {42 formatPath = formatPath.replace(new RegExp('\\{' + key + '\\}', 'g'), option[key])43 }44 }45 if (rewrite) {46 return formatPath47 }48 return formatPath49}...
Using AI Code Generation
1const { formatPath } = require('@playwright/test');2const path = require('path');3const test = require('@playwright/test');4test('test', async ({page}) => {5 await page.screenshot({ path: formatPath(path.join(__dirname, 'assets', 'screenshots', 'google-homepage.png')) });6});
Using AI Code Generation
1const { formatPath } = require('@playwright/test/lib/utils/pathUtils');2const path = require('path');3const { test } = require('@playwright/test');4test('use formatPath method of Playwright Internal API', async ({ page }) => {5 const filePath = path.join(__dirname, 'assets', 'test.png');6 const formattedFilePath = formatPath(filePath);7 await page.goto(`file:${formattedFilePath}`);8});
Using AI Code Generation
1const { formatPath } = require('playwright/lib/utils/utils');2const path = formatPath('/home/username/test.js');3console.log(path);4const { formatPath } = require('playwright/lib/utils/utils');5const path = formatPath('test.js');6console.log(path);7const { formatPath } = require('playwright/lib/utils/utils');8const path = formatPath('C:\\Users\\username\\test.js');9console.log(path);10const { formatPath } = require('playwright/lib/utils/utils');11const path = formatPath('C:\\Users\\username\\test.js');12console.log(path);13const { formatPath } = require('playwright/lib/utils/utils');14const path = formatPath('C:\\Users\\username\\test.js');15console.log(path);16const { formatPath } = require('playwright/lib/utils/utils');17const path = formatPath('C:\\Users\\username\\test.js');18console.log(path);19const { formatPath } = require('playwright/lib/utils/utils');20const path = formatPath('C:\\Users\\username\\test.js');21console.log(path);
Using AI Code Generation
1const { formatPath } = require('@playwright/test/lib/utils/pathUtils');2const path = require('path');3const filePath = path.join(__dirname, 'test.spec.js');4console.log(formatPath(filePath));5console.log(formatPath(filePath, { line: 1, column: 1 }));6console.log(formatPath(filePath, { line: 1, column: 1, name: 'test.spec' }));7### formatPath(path, [options])8[Apache-2.0](../LICENSE)
Using AI Code Generation
1const path = require('path');2const { formatPath } = require('playwright-core/lib/utils/utils');3const filePath = path.join(__dirname, 'test.pdf');4const formattedPath = formatPath(filePath);5console.log(formattedPath);6const input = await page.$('input[type="file"]');7await input.uploadFile('C:\\Users\\user\\Documents\\test.pdf');8const input = await page.$('input[type="file"]');9await input.uploadFile('C:\\Users\\user\\Documents\\test.pdf');10const input = await page.$('input[type="file"]');11await input.uploadFile('C:\\Users\\user\\Documents\\test.pdf');12const input = await page.$('input[type="file"]');13await input.uploadFile('C:\\Users\\user\\Documents\\test.pdf');
Using AI Code Generation
1const { formatPath } = require('playwright/lib/utils/utils');2const path = formatPath('test.js');3console.log(path);4- **Syntax:** `fileURLToPath(url)`5const { fileURLToPath } = require('playwright/lib/utils/utils');6console.log(path);7- **Syntax:** `isUnderTest()`8const { isUnderTest } = require('playwright/lib/utils/utils');9const test = isUnderTest();10console.log(test);11- **Syntax:** `makeAbsolute(path)`12const { makeAbsolute } = require('playwright/lib/utils/utils');13const path = makeAbsolute('test.js');14console.log(path);15- **Syntax:** `parseQuery(query)`16const { parseQuery } = require('playwright/lib/utils/utils');17const query = parseQuery('query');18console.log(query);
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!