UNPKG

html-reporter

Version:

Html-reporter and GUI for viewing and managing results of a tests run. Currently supports Testplane and Hermione.

76 lines 4.29 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.handleTestResults = void 0; const os_1 = __importDefault(require("os")); const p_queue_1 = __importDefault(require("p-queue")); const constants_1 = require("../../../gui/constants"); const plugin_utils_1 = require("../../../plugin-utils"); const create_workers_1 = require("../../../workers/create-workers"); const server_utils_1 = require("../../../server-utils"); const constants_2 = require("../../../constants"); const testplane_1 = require("../../test-result/testplane"); const snapshots_1 = require("../../event-handling/testplane/snapshots"); const utils_1 = require("../../test-result/utils"); const handleTestResults = (testplane, reportBuilder, client) => { const queue = new p_queue_1.default({ concurrency: os_1.default.cpus().length }); testplane.on(testplane.events.RUNNER_START, (runner) => { reportBuilder.registerWorkers((0, create_workers_1.createWorkers)(runner)); }); testplane.on(testplane.events.SUITE_BEGIN, (suite) => { if (suite.pending) { return; } client.emit(constants_1.ClientEvents.BEGIN_SUITE, { suiteId: (0, plugin_utils_1.getSuitePath)(suite).join(' '), status: constants_2.TestStatus.RUNNING }); }); [ { eventName: testplane.events.TEST_BEGIN, clientEventName: constants_1.ClientEvents.BEGIN_STATE }, { eventName: testplane.events.TEST_PASS, clientEventName: constants_1.ClientEvents.TEST_RESULT }, { eventName: testplane.events.RETRY, clientEventName: constants_1.ClientEvents.TEST_RESULT }, { eventName: testplane.events.TEST_FAIL, clientEventName: constants_1.ClientEvents.TEST_RESULT }, { eventName: testplane.events.TEST_PENDING, clientEventName: constants_1.ClientEvents.TEST_RESULT } ].forEach(({ eventName, clientEventName }) => { testplane.on(eventName, (data) => { queue.add(async () => { const status = (0, testplane_1.getStatus)(eventName, testplane.events, data); const formattedResultWithoutAttempt = (0, server_utils_1.formatTestResult)(data, status); const attachments = []; if (eventName !== testplane.events.TEST_BEGIN) { // By this time an attempt had already been created for "running" test result, so here we have current attempt number const attempt = reportBuilder.getLatestAttempt({ fullName: formattedResultWithoutAttempt.fullName, browserId: formattedResultWithoutAttempt.browserId }); const snapshotAttachments = await (0, snapshots_1.finalizeSnapshotsForTest)({ testResult: formattedResultWithoutAttempt, attempt, reportPath: testplane.htmlReporter.config.path, events: testplane.events, eventName, timeTravelConfig: testplane.config.timeTravel, snapshotsSaver: testplane.htmlReporter.snapshotsSaver }); attachments.push(...snapshotAttachments); } const formattedResultWithAttachments = (0, utils_1.copyAndUpdate)(formattedResultWithoutAttempt, { attachments }); const formattedResult = await reportBuilder.addTestResult(formattedResultWithAttachments); const testBranch = reportBuilder.getTestBranch(formattedResult.id); return client.emit(clientEventName, testBranch); }).catch(server_utils_1.logError); }); }); testplane.on(testplane.events.RUNNER_END, async () => { try { await queue.onIdle(); client.emit(constants_1.ClientEvents.END); } catch (err) { (0, server_utils_1.logError)(err); } }); testplane.on(testplane.events.DOM_SNAPSHOTS, (context, data) => (0, snapshots_1.handleDomSnapshotsEvent)(client, context, data)); }; exports.handleTestResults = handleTestResults; //# sourceMappingURL=test-results-handler.js.map