本文整理汇总了TypeScript中@kbn/dev-utils.ToolingLog.debug方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ToolingLog.debug方法的具体用法?TypeScript ToolingLog.debug怎么用?TypeScript ToolingLog.debug使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@kbn/dev-utils.ToolingLog
的用法示例。
在下文中一共展示了ToolingLog.debug方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: defaultOnFailure
export async function retryForSuccess<T>(log: ToolingLog, options: Options<T>) {
const { timeout, methodName, block, accept = returnTrue } = options;
const { onFailure = defaultOnFailure(methodName) } = options;
const start = Date.now();
const retryDelay = 502;
let lastError;
while (true) {
if (lastError && Date.now() - start > timeout) {
await onFailure(lastError);
throw new Error('expected onFailure() option to throw an error');
}
const attempt = await runAttempt(block);
if ('result' in attempt && accept(attempt.result)) {
return attempt.result;
}
if ('error' in attempt) {
if (lastError && lastError.message === attempt.error.message) {
log.debug(`--- ${methodName} failed again with the same message...`);
} else {
log.debug(`--- ${methodName} error: ${attempt.error.message}`);
}
lastError = attempt.error;
}
await delay(retryDelay);
}
}
示例2: attemptToCreateCommand
async function attemptToCreateCommand(log: ToolingLog, browserType: 'chrome' | 'firefox') {
const attemptId = ++attemptCounter;
log.debug('[webdriver] Creating session');
const buildDriverInstance = async () => {
switch (browserType) {
case 'chrome':
const chromeOptions = new chrome.Options();
const loggingPref = new logging.Preferences();
loggingPref.setLevel(logging.Type.BROWSER, logging.Level.ALL);
chromeOptions.setLoggingPrefs(loggingPref);
if (process.env.TEST_BROWSER_HEADLESS) {
// Use --disable-gpu to avoid an error from a missing Mesa library, as per
// See: https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md
chromeOptions.addArguments('headless', 'disable-gpu');
}
return new Builder()
.forBrowser(browserType)
.setChromeOptions(chromeOptions)
.setChromeService(new chrome.ServiceBuilder(chromeDriver.path).enableVerboseLogging())
.build();
case 'firefox':
const firefoxOptions = new firefox.Options();
if (process.env.TEST_BROWSER_HEADLESS) {
// See: https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Headless_mode
firefoxOptions.addArguments('-headless');
}
return new Builder()
.forBrowser(browserType)
.setFirefoxOptions(firefoxOptions)
.setFirefoxService(new firefox.ServiceBuilder(geckoDriver.path).enableVerboseLogging())
.build();
default:
throw new Error(`${browserType} is not supported yet`);
}
};
const session = await buildDriverInstance();
if (throttleOption === 'true' && browserType === 'chrome') {
// Only chrome supports this option.
log.debug('NETWORK THROTTLED: 768k down, 256k up, 100ms latency.');
(session as any).setNetworkConditions({
offline: false,
latency: 100, // Additional latency (ms).
download_throughput: 768 * 1024, // These speeds are in bites per second, not kilobytes.
upload_throughput: 256 * 1024,
});
}
if (attemptId !== attemptCounter) {
return;
} // abort
return { driver: session, By, Key, until, LegacyActionSequence };
}
示例3: comparePngs
export async function comparePngs(
sessionPath: string,
baselinePath: string,
diffPath: string,
sessionDirectory: string,
log: ToolingLog
) {
log.debug(`comparePngs: ${sessionPath} vs ${baselinePath}`);
const session = (await Jimp.read(sessionPath)).clone();
const baseline = (await Jimp.read(baselinePath)).clone();
if (
session.bitmap.width !== baseline.bitmap.width ||
session.bitmap.height !== baseline.bitmap.height
) {
// eslint-disable-next-line no-console
console.log(
'expected height ' + baseline.bitmap.height + ' and width ' + baseline.bitmap.width
);
// eslint-disable-next-line no-console
console.log('actual height ' + session.bitmap.height + ' and width ' + session.bitmap.width);
const width = Math.min(session.bitmap.width, baseline.bitmap.width);
const height = Math.min(session.bitmap.height, baseline.bitmap.height);
session.resize(width, height); // , Jimp.HORIZONTAL_ALIGN_LEFT | Jimp.VERTICAL_ALIGN_TOP);
baseline.resize(width, height); // , Jimp.HORIZONTAL_ALIGN_LEFT | Jimp.VERTICAL_ALIGN_TOP);
}
session.quality(60);
baseline.quality(60);
log.debug(`calculating diff pixels...`);
// Note that this threshold value only affects color comparison from pixel to pixel. It won't have
// any affect when comparing neighboring pixels - so slight shifts, font variations, or "blurry-ness"
// will still show up as diffs, but upping this will not help that. Instead we keep the threshold low, and expect
// some the diffCount to be lower than our own threshold value.
const THRESHOLD = 0.1;
const { image, percent } = Jimp.diff(session, baseline, THRESHOLD);
log.debug(`percent different: ${percent}`);
if (percent > 0) {
image.write(diffPath);
// For debugging purposes it'll help to see the resized images and how they compare.
session.write(join(sessionDirectory, `${parse(sessionPath).name}-session-resized.png`));
baseline.write(join(sessionDirectory, `${parse(baselinePath).name}-baseline-resized.png`));
}
return percent;
}
示例4: getSettingsFromFile
async function getSettingsFromFile(log: ToolingLog, path: string, settingOverrides: any) {
const configModule = require(path); // eslint-disable-line @typescript-eslint/no-var-requires
const configProvider = configModule.__esModule ? configModule.default : configModule;
if (!cache.has(configProvider)) {
log.debug('Loading config file from %j', path);
cache.set(
configProvider,
configProvider({
log,
async readConfigFile(p: string, o: any) {
return new Config({
settings: await getSettingsFromFile(log, p, o),
primary: false,
path: p,
});
},
})
);
}
const settingsWithDefaults = defaultsDeep({}, settingOverrides, await cache.get(configProvider)!);
const logDeprecation = (error: string | Error) => log.error(error);
return transformDeprecations(settingsWithDefaults, logDeprecation);
}
示例5: retryForTruthy
export async function retryForTruthy(
log: ToolingLog,
{ timeout, methodName, description, block }: Options
) {
log.debug(`Waiting up to ${timeout}ms for ${description}...`);
await retryForSuccess(log, {
timeout,
methodName,
block,
onFailure: lastError => {
let msg = `timed out waiting for ${description}`;
if (lastError) {
msg = `${msg} -- last error: ${lastError.stack || lastError.message}`;
}
throw new Error(msg);
},
accept: result => Boolean(result),
});
}
示例6:
const debug = (msg: string, ...args: any[]) => log.debug(`[${name}] ${msg}`, ...args);