UNPKG

wdio-performancetotal-service

Version:

WebdriverIO service for analyzing test flow performance

75 lines (74 loc) 3.76 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const path_1 = __importDefault(require("path")); const file_writer_1 = require("./helpers/file-writer"); const id_generator_1 = require("./helpers/id-generator"); const performance_analyzer_1 = require("./performance-analyzer"); const performance_cache_1 = require("./performance-cache"); class PerformanceTotal { constructor(appendToExistingFile = false) { this.logFileName = "performance-log.txt"; this._performanceResultsFileName = "performance-results"; this.performanceCache = new performance_cache_1.PerformanceCache(); this._instanceid = new id_generator_1.IdGenerator().getId("inst"); } 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 if *wdio-performancetotal-service* is enabled. * @param disableAppendToExistingFile If true, existing performance data will be overwritten for each test suite. */ async initialize(disableAppendToExistingFile, performanceResultsDirectory) { let resultsDir = ""; const fileWriter = file_writer_1.FileWriter.getInstance(); if (!global._performanceTotalResultsDir) { resultsDir = await fileWriter.createResultsDirIfNotExist(performanceResultsDirectory); global._performanceTotalResultsDir = resultsDir; } else { resultsDir = global._performanceTotalResultsDir; } const initObj = JSON.stringify({ "startDisplayTime": new Date().toLocaleString(), "instanceID": this._instanceid }); const fileName = path_1.default.join(resultsDir, this.logFileName); if (disableAppendToExistingFile) { await fileWriter.writeToFile(fileName, `${initObj}\n`); } else { await fileWriter.appendLineToFile(fileName, `${initObj}\n`); } } /** * @deprecated Don't use this method if *wdio-performancetotal-service* is enabled. * @param isTestPassed */ async finalizeTest(browser, isTestPassed) { await this.performanceCache.flush(file_writer_1.FileWriter.getInstance().getFilePath(global._performanceTotalResultsDir, this.logFileName), browser, isTestPassed); } /** * @deprecated Don't use this method if *wdio-performancetotal-service* is enabled. * @param performanceResultsFileName The result output file name w/o extension. * @param dropResultsFromFailedTest If true - performance analysis will not includ failed tests. * @param analyzeByBrowser If true - performance analysis by browser would be */ async analyzeResults({ performanceResultsFileName, dropResultsFromFailedTest, analyzeByBrowser, recentDays }) { const analyzer = new performance_analyzer_1.PerformanceAnalyzer(); const fileWriter = file_writer_1.FileWriter.getInstance(); let resultsFileName = this._performanceResultsFileName; const resultsDir = global._performanceTotalResultsDir; if (performanceResultsFileName) { resultsFileName = performanceResultsFileName; } await analyzer.analyze(fileWriter.getFilePath(resultsDir, this.logFileName), fileWriter.getFilePath(resultsDir, resultsFileName), dropResultsFromFailedTest, analyzeByBrowser, recentDays); } } exports.default = new PerformanceTotal();