UNPKG

protractor-smartrunner

Version:

Protractor utility for keeping track of passed/failed tests between runs. Works together with protractor-retry.

51 lines (50 loc) â€ĸ 2.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SmartRunnerResults = void 0; const path_1 = require("path"); const fs = require('fs-extra'); const filenamify = require('filenamify'); class SmartRunnerResults { constructor(outputDirectory, repoHash, logger) { this.logger = logger; this.affectedSuites = {}; if (!(repoHash === null || repoHash === void 0 ? void 0 : repoHash.length)) { this.logger.error('🛑 ERROR: repoHash is not defined, terminating...'); process.exit(1); } this.smartRunDir = path_1.resolve(outputDirectory, repoHash); fs.ensureDirSync(this.smartRunDir); } load() { this.results = fs.readdirSync(this.smartRunDir) .map((jsonFile) => fs.readJsonSync(path_1.resolve(this.smartRunDir, `./${jsonFile}`))) .reduce((accumulator, currentValue) => (Object.assign(Object.assign({}, accumulator), currentValue)), {}); } set(suiteName, testName, passed, duration) { var _a, _b, _c; if (!this.results[suiteName]) { this.results[suiteName] = {}; } this.results[suiteName][testName] = { retries: ((_c = (_b = (_a = this.results) === null || _a === void 0 ? void 0 : _a[suiteName]) === null || _b === void 0 ? void 0 : _b[testName]) === null || _c === void 0 ? void 0 : _c.retries) + 1 || 0, passed, duration }; this.affectedSuites[suiteName] = true; } get(suiteName, testName) { return this.results[suiteName] && this.results[suiteName][testName] || {}; } save() { const updatedSuiteNames = Object.keys(this.affectedSuites); const suites = Object.keys(this.results); for (const suite of suites) { if (updatedSuiteNames.indexOf(suite) !== -1) { this.logger.info(`â„šī¸ Suite (${suite}) was affected by this thread, writing to filesystem.`); const fileName = path_1.resolve(this.smartRunDir, filenamify(`./${suite}.json`)); fs.outputJsonSync(fileName, { [suite]: this.results[suite] }, { spaces: 4 }); } } } } exports.SmartRunnerResults = SmartRunnerResults;