本文整理匯總了TypeScript中@kbn/dev-utils.ToolingLog類的典型用法代碼示例。如果您正苦於以下問題:TypeScript ToolingLog類的具體用法?TypeScript ToolingLog怎麽用?TypeScript ToolingLog使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了ToolingLog類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: onFailure
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: lintFiles
export async function lintFiles(log: ToolingLog, files: File[]) {
for (const [project, filesInProject] of groupFilesByProject(files)) {
const exitCode = await run(
{
exclude: [],
files: filesInProject.map(f => f.getAbsolutePath()),
fix: false,
format: 'stylish',
project: project.tsConfigPath,
},
{
log(m: string) {
log.write(m);
},
error(m: string) {
log.error(m);
},
}
);
if (exitCode > 0) {
throw createFailError(`[tslint] failure`, 1);
} else {
log.success(
'[tslint/%s] %d files linted successfully',
project.name,
filesInProject.length
);
}
}
}
示例3: 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 };
}
示例4: 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;
}
示例5: 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);
}
示例6: startTestServers
export async function startTestServers({
adjustTimeout,
settings = {},
}: {
adjustTimeout: (timeout: number) => void;
settings: Record<string, any>;
}) {
if (!adjustTimeout) {
throw new Error('adjustTimeout is required in order to avoid flaky tests');
}
const log = new ToolingLog({
level: 'debug',
writeTo: process.stdout,
});
log.indent(6);
log.info('starting elasticsearch');
log.indent(4);
const es = createEsTestCluster({ log });
log.indent(-4);
adjustTimeout(es.getStartTimeout());
await es.start();
const root = createRootWithCorePlugins(settings);
await root.start();
const kbnServer = getKbnServer(root);
await kbnServer.server.plugins.elasticsearch.waitUntilReady();
return {
kbnServer,
root,
es,
async stop() {
await root.shutdown();
await es.cleanup();
},
};
}
示例7: function
return function(this: any, ...args: any[]) {
log.verbose(`${name}.${prop}(${printArgs(args)})`);
log.indent(2);
let result;
try {
result = {
returned: value.apply(this, args),
};
} catch (error) {
result = {
returned: undefined,
thrown: error,
};
}
if (result.hasOwnProperty('thrown')) {
log.indent(-2);
throw result.thrown;
}
const { returned } = result;
if (returned && typeof returned.then === 'function') {
return returned.finally(() => {
log.indent(-2);
});
}
log.indent(-2);
return returned;
};
示例8: if
messageCallback: (message: ExtractorMessage) => {
if (message.messageId === 'console-api-report-not-copied') {
// ConsoleMessageId.ApiReportNotCopied
log.warning(`You have changed the signature of the ${folder} Core API`);
log.warning(
'To accept these changes run `node scripts/check_core_api_changes.js --accept` and then:\n' +
"\t 1. Commit the updated documentation and API review file '" +
config.reportFilePath +
"' \n" +
"\t 2. Describe the change in your PR including whether it's a major, minor or patch"
);
message.handled = true;
} else if (message.messageId === 'console-api-report-copied') {
// ConsoleMessageId.ApiReportCopied
log.warning(`You have changed the signature of the ${folder} Core API`);
log.warning(
"Please commit the updated API documentation and the review file in '" +
config.reportFilePath
);
message.handled = true;
} else if (message.messageId === 'console-api-report-unchanged') {
// ConsoleMessageId.ApiReportUnchanged
log.info(`Core ${folder} API: no changes detected â`);
message.handled = true;
}
},
示例9: setInterval
this.loggingInterval = setInterval(() => {
if (this.complete === undefined) {
return;
}
if (this.total === undefined) {
log.info('progress: %d', this.getComplete());
return;
}
log.info('progress: %d/%d (%d%)', this.getComplete(), this.getTotal(), this.getPercent());
}, 10 * SECOND);
示例10:
list.run().catch((error: any) => {
process.exitCode = 1;
if (!error.errors) {
log.error('Unhandled exception!');
log.error(error);
process.exit();
}
for (const e of error.errors) {
if (e instanceof ProjectFailure) {
log.write('');
log.error(`${e.project.name} failed\n${e.error.stdout}`);
} else {
log.error(e);
}
}
});