UNPKG

perfrunner-core

Version:

Automated UI performance test tool to measure performance changes for the web apps and sites

71 lines (70 loc) 3.59 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.profile = void 0; const validation_1 = require("./validation/validation"); const profiler_1 = require("./profiler/profiler"); const db_1 = require("./db"); const processor_1 = require("./processor/processor"); const logger_1 = require("./logger"); /** * Profile given URL and returns performance data * @param {PerfRunnerOptions} options Profiling parameters * @returns {Promise<IPerformanceResult>} performance result */ function profile(options, storage) { return __awaiter(this, void 0, void 0, function* () { (0, validation_1.validateArguments)(options); const url = new URL(options.url); const connectionString = (0, db_1.getConnectionString)(options.output, url, options.testName); const db = storage !== null && storage !== void 0 ? storage : new db_1.Db(connectionString); if (!options.reportOnly) { const conditions = `network: ${options.network.name != undefined ? options.network.name : 'custom'}; throttling: ${options.throttlingRate}x, ${options.useCache ? `with cache` : `no cache`}`; (0, logger_1.log)(`starting profile session for ${url.href}`); (0, logger_1.log)(conditions); const { executablePath, timeout, network, throttlingRate, waitFor, afterPageLoaded } = options; const rawPerformanceResult = yield (0, profiler_1.runProfilingSession)({ args: options.chromeArgs, executablePath: executablePath, headless: !!options.headless, ignoreDefaultArgs: !!options.ignoreDefaultArgs, product: 'chrome', timeout: timeout, }, { network: network, throttlingRate: throttlingRate, url: url, useCache: !!options.useCache, waitFor: waitFor, afterPageLoaded, }, options.runs, options.output); (0, logger_1.log)('processing data...'); const { pageMetrics, performanceEntries } = (0, processor_1.processPerfData)(rawPerformanceResult); const performanceResult = { timeStamp: Date.now(), pageMetrics, performanceEntries, runParams: { useCache: options.useCache, network: options.network, throttlingRate: options.throttlingRate, url: options.url, }, comment: options.comment, }; (0, logger_1.log)('saving data...'); yield db.write(performanceResult, options.purge); } const result = yield db.read(); return result; }); } exports.profile = profile;