UNPKG

html-reporter

Version:

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

103 lines 5.76 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; 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 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 { getStatus } = await Promise.resolve().then(() => __importStar(require('../../test-result/testplane'))); const { finalizeSnapshotsForTest } = await Promise.resolve().then(() => __importStar(require('../../event-handling/testplane/snapshots'))); const status = getStatus(eventName, testplane.events, data); const formattedResultWithoutAttempt = (0, server_utils_1.formatTestResult)(data, status, constants_2.UNKNOWN_ATTEMPT, testplane.config.saveHistoryMode); const attachments = formattedResultWithoutAttempt.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 finalizeSnapshotsForTest({ testResult: formattedResultWithoutAttempt, attempt, reportPath: testplane.htmlReporter.config.path, events: testplane.events, eventName, timeTravelConfig: testplane.config.browsers[formattedResultWithoutAttempt.browserId].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) => { // eslint-disable-next-line @typescript-eslint/no-var-requires const { handleDomSnapshotsEvent } = require('../../event-handling/testplane/snapshots'); handleDomSnapshotsEvent(client, context, data); }); }; exports.handleTestResults = handleTestResults; //# sourceMappingURL=test-results-handler.js.map