playwright-performance
Version:
Playwright plugin for analyzing test flow performance
73 lines (72 loc) • 3.03 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PerformanceMain = void 0;
const path_1 = __importDefault(require("path"));
const file_writer_1 = require("./helpers/file-writer");
const id_generator_1 = require("./helpers/id-generator");
const options_1 = require("./entities/options");
const performance_analyzer_1 = require("./performance-analyzer");
const performance_cache_1 = require("./performance-cache");
const variables_1 = require("./constants/variables");
class PerformanceMain {
constructor(options) {
this.logFileName = variables_1.variables.logFileName;
this._instanceid = new id_generator_1.IdGenerator().getId("inst");
this.performanceCache = new performance_cache_1.PerformanceCache();
if (options) {
(0, options_1.setOptions)(options);
this._options = (0, options_1.getOptions)();
}
else {
this._options = (0, options_1.getOptions)();
}
}
sampleStart(stepName) {
this.performanceCache.sampleStart(stepName, this._instanceid);
}
sampleEnd(stepName) {
this.performanceCache.sampleEnd(stepName, this._instanceid);
}
getSampleTime(stepName) {
return this.performanceCache.getSampleTime(stepName);
}
/**
* @deprecated Don't use this method directly.
*/
async initialize() {
let resultsDir = "";
const fileWriter = file_writer_1.FileWriter.getInstance();
if (!global._playwrightPerformanceResultsDir) {
resultsDir = await fileWriter.createResultsDirIfNotExist(this._options.performanceResultsDirectoryName);
global._playwrightPerformanceResultsDir = resultsDir;
}
else {
resultsDir = global._playwrightPerformanceResultsDir;
}
const initObj = JSON.stringify({ "startDisplayTime": new Date().toLocaleString(), "instanceID": this._instanceid });
const fileName = path_1.default.join(resultsDir, this.logFileName);
if (this._options.disableAppendToExistingFile) {
await fileWriter.writeToFile(fileName, `${initObj}\n`);
}
else {
await fileWriter.appendLineToFile(fileName, `${initObj}\n`);
}
}
/**
* @deprecated Don't use this method directly.
*/
async finalizeTest(browser, workerInfo) {
await this.performanceCache.flush(file_writer_1.FileWriter.getInstance().getFilePath(global._playwrightPerformanceResultsDir, variables_1.variables.logFileName), browser, workerInfo.status == 'passed');
}
/**
* @deprecated Don't use this method directly.
*/
async analyzeResults(workerIndex) {
const analyzer = new performance_analyzer_1.PerformanceAnalyzer();
await analyzer.analyze(this._options, workerIndex);
}
}
exports.PerformanceMain = PerformanceMain;