html-reporter
Version:
Html-reporter and GUI for viewing and managing results of a tests run. Currently supports Testplane and Hermione.
162 lines • 8.21 kB
JavaScript
;
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 });
const os_1 = __importDefault(require("os"));
const path_1 = __importDefault(require("path"));
const lodash_1 = __importDefault(require("lodash"));
const p_queue_1 = __importDefault(require("p-queue"));
const commands_1 = require("./lib/cli/commands");
const config_1 = require("./lib/config");
const constants_1 = require("./lib/constants");
const server_utils_1 = require("./lib/server-utils");
const create_workers_1 = require("./lib/workers/create-workers");
const cache_1 = require("./lib/cache");
const utils_1 = require("./lib/adapters/test-result/utils");
exports.default = (testplane, opts) => {
if (testplane.isWorker()) {
return;
}
const config = (0, config_1.parseConfig)(opts);
Object.assign(opts, config);
if (!config.enabled) {
return;
}
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { TestplaneToolAdapter } = require('./lib/adapters/tool/testplane');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { StaticReportBuilder } = require('./lib/report-builder/static');
const toolAdapter = TestplaneToolAdapter.create({ toolName: constants_1.ToolName.Testplane, tool: testplane, reporterConfig: config });
const { htmlReporter } = toolAdapter;
let isCliCommandLaunched = false;
let handlingTestResults;
let staticReportBuilder;
const withMiddleware = (fn) => {
return (...args) => {
// If any CLI command was launched, e.g. merge-reports, we need to interrupt regular flow
if (isCliCommandLaunched) {
return;
}
return fn.call(undefined, ...args);
};
};
testplane.on(testplane.events.CLI, (commander) => {
lodash_1.default.values(commands_1.cliCommands).forEach((command) => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
require(path_1.default.resolve(__dirname, 'lib/cli/commands', command))(commander, toolAdapter);
commander.prependListener(`command:${command}`, () => {
isCliCommandLaunched = true;
});
});
});
testplane.on(testplane.events.INIT, withMiddleware(async () => {
const [{ SqliteClient }, { SqliteImageStore }, { ImagesInfoSaver }] = await Promise.all([
Promise.resolve().then(() => __importStar(require('./lib/sqlite-client'))),
Promise.resolve().then(() => __importStar(require('./lib/image-store'))),
Promise.resolve().then(() => __importStar(require('./lib/images-info-saver')))
]);
const dbClient = await SqliteClient.create({ htmlReporter, reportPath: config.path });
const imageStore = new SqliteImageStore(dbClient);
const expectedPathsCache = new cache_1.Cache(server_utils_1.getExpectedCacheKey);
const imagesInfoSaver = new ImagesInfoSaver({
imageFileSaver: htmlReporter.imagesSaver,
expectedPathsCache,
imageStore,
reportPath: htmlReporter.config.path
});
staticReportBuilder = StaticReportBuilder.create({
htmlReporter: toolAdapter.htmlReporter,
reporterConfig: config,
dbClient,
imagesInfoSaver
});
handlingTestResults = Promise.all([
staticReportBuilder.saveStaticFiles(),
handleTestResults(testplane, staticReportBuilder)
]).then(async () => {
await staticReportBuilder.finalize();
}).then(async () => {
await htmlReporter.emitAsync(htmlReporter.events.REPORT_SAVED, { reportPath: config.path });
});
htmlReporter.emit(htmlReporter.events.DATABASE_CREATED, dbClient.getRawConnection());
}));
testplane.on(testplane.events.RUNNER_START, withMiddleware((runner) => {
staticReportBuilder.registerWorkers((0, create_workers_1.createWorkers)(runner));
}));
testplane.on(testplane.events.RUNNER_END, withMiddleware(async () => {
try {
await handlingTestResults;
(0, server_utils_1.logPathToHtmlReport)(config);
}
catch (e) {
(0, server_utils_1.logError)(e);
}
}));
};
async function handleTestResults(testplane, reportBuilder) {
return new Promise((resolve, reject) => {
const queue = new p_queue_1.default({ concurrency: os_1.default.cpus().length });
const promises = [];
[
{ eventName: testplane.events.TEST_PASS },
{ eventName: testplane.events.RETRY },
{ eventName: testplane.events.TEST_FAIL },
{ eventName: testplane.events.TEST_PENDING }
].forEach(({ eventName }) => {
testplane.on(eventName, (testResult) => {
promises.push(queue.add(async () => {
const { getStatus } = await Promise.resolve().then(() => __importStar(require('./lib/adapters/test-result/testplane')));
const { finalizeSnapshotsForTest } = await Promise.resolve().then(() => __importStar(require('./lib/adapters/event-handling/testplane/snapshots')));
const formattedResult = (0, server_utils_1.formatTestResult)(testResult, getStatus(eventName, testplane.events, testResult), constants_1.UNKNOWN_ATTEMPT, testplane.config.saveHistoryMode);
const attachments = formattedResult.attachments;
const attempt = reportBuilder.registerAttempt({ fullName: formattedResult.fullName, browserId: formattedResult.browserId }, formattedResult.status);
const snapshotAttachments = await finalizeSnapshotsForTest({
testResult: formattedResult,
attempt,
reportPath: testplane.htmlReporter.config.path,
timeTravelConfig: testplane.config.browsers[formattedResult.browserId].timeTravel,
events: testplane.events,
eventName,
snapshotsSaver: testplane.htmlReporter.snapshotsSaver
});
attachments.push(...snapshotAttachments);
const formattedResultWithAttachments = (0, utils_1.copyAndUpdate)(formattedResult, { attachments, attempt });
await reportBuilder.addTestResult(formattedResultWithAttachments);
}).catch(reject));
});
});
testplane.on(testplane.events.RUNNER_END, () => {
return Promise.all(promises).then(() => resolve(), reject);
});
testplane.on(testplane.events.DOM_SNAPSHOTS, (context, data) => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { handleDomSnapshotsEvent } = require('./lib/adapters/event-handling/testplane/snapshots');
handleDomSnapshotsEvent(null, context, data);
});
});
}
//# sourceMappingURL=testplane.js.map