148 lines
21 KiB
JavaScript
148 lines
21 KiB
JavaScript
|
"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 });
|
||
|
const lodash_1 = require("lodash");
|
||
|
const moment_1 = __importDefault(require("moment"));
|
||
|
const async_event_emitter_1 = __importDefault(require("../../utils/async-event-emitter"));
|
||
|
const browser_job_1 = __importDefault(require("../browser-job"));
|
||
|
const screenshots_1 = __importDefault(require("../../screenshots"));
|
||
|
const warning_log_1 = __importDefault(require("../../notifications/warning-log"));
|
||
|
const fixture_hook_controller_1 = __importDefault(require("../fixture-hook-controller"));
|
||
|
const clientScriptsRouting = __importStar(require("../../custom-client-scripts/routing"));
|
||
|
const videos_1 = __importDefault(require("../../video-recorder/videos"));
|
||
|
const phase_1 = __importDefault(require("./phase"));
|
||
|
class Task extends async_event_emitter_1.default {
|
||
|
constructor({ tests, browserConnectionGroups, proxy, opts, runnerWarningLog, compilerService, messageBus, }) {
|
||
|
super({ captureRejections: true });
|
||
|
this._timeStamp = (0, moment_1.default)();
|
||
|
this._phase = phase_1.default.initialized;
|
||
|
this.browserConnectionGroups = browserConnectionGroups;
|
||
|
this.tests = tests;
|
||
|
this.opts = opts;
|
||
|
this._proxy = proxy;
|
||
|
this.warningLog = new warning_log_1.default(null, warning_log_1.default.createAddWarningCallback(messageBus));
|
||
|
this._compilerService = compilerService;
|
||
|
this._messageBus = messageBus;
|
||
|
this.warningLog.copyFrom(runnerWarningLog);
|
||
|
const { path, pathPattern, fullPage, thumbnails, autoTakeOnFails } = this.opts.screenshots;
|
||
|
this.screenshots = new screenshots_1.default({
|
||
|
enabled: !this.opts.disableScreenshots,
|
||
|
path,
|
||
|
pathPattern,
|
||
|
fullPage,
|
||
|
thumbnails,
|
||
|
messageBus,
|
||
|
autoTakeOnFails,
|
||
|
});
|
||
|
this.fixtureHookController = new fixture_hook_controller_1.default(tests, browserConnectionGroups.length);
|
||
|
this._pendingBrowserJobs = this._createBrowserJobs(proxy, this.opts);
|
||
|
this._clientScriptRoutes = clientScriptsRouting.register(proxy, tests, !!this.opts.experimentalProxyless);
|
||
|
this.testStructure = this._prepareTestStructure(tests);
|
||
|
if (this.opts.videoPath) {
|
||
|
const { videoPath, videoOptions, videoEncodingOptions } = this.opts;
|
||
|
this.videos = new videos_1.default(this._pendingBrowserJobs, { videoPath, videoOptions, videoEncodingOptions }, this.warningLog, this._timeStamp);
|
||
|
}
|
||
|
}
|
||
|
_assignBrowserJobEventHandlers(job) {
|
||
|
job.on('test-run-done', async (testRun) => {
|
||
|
await this._messageBus.emit('test-run-done', testRun);
|
||
|
if (this.opts.stopOnFirstFail && testRun.errs.length) {
|
||
|
this.abort();
|
||
|
await this._messageBus.emit('done');
|
||
|
}
|
||
|
});
|
||
|
job.once('start', async (startTime) => {
|
||
|
if (this._phase !== phase_1.default.started) {
|
||
|
this._phase = phase_1.default.started;
|
||
|
this.startTime = startTime;
|
||
|
await this._messageBus.emit('start', this);
|
||
|
}
|
||
|
});
|
||
|
job.once('done', async () => {
|
||
|
await this.emit('browser-job-done', job);
|
||
|
(0, lodash_1.pull)(this._pendingBrowserJobs, job);
|
||
|
if (!this._pendingBrowserJobs.length) {
|
||
|
this._phase = phase_1.default.done;
|
||
|
await this._messageBus.emit('done');
|
||
|
}
|
||
|
});
|
||
|
job.on('test-action-done', async (args) => {
|
||
|
if (this._phase === phase_1.default.done)
|
||
|
return;
|
||
|
await this._messageBus.emit('test-action-done', args);
|
||
|
});
|
||
|
}
|
||
|
_prepareTestStructure(tests) {
|
||
|
const groups = (0, lodash_1.groupBy)(tests, 'fixture.id');
|
||
|
return Object.keys(groups).map(fixtureId => {
|
||
|
const testsByGroup = groups[fixtureId];
|
||
|
const fixture = testsByGroup[0].fixture;
|
||
|
return {
|
||
|
fixture: {
|
||
|
id: fixture.id,
|
||
|
name: fixture.name,
|
||
|
tests: testsByGroup.map(test => {
|
||
|
return {
|
||
|
id: test.id,
|
||
|
name: test.name,
|
||
|
skip: test.skip,
|
||
|
};
|
||
|
}),
|
||
|
},
|
||
|
};
|
||
|
});
|
||
|
}
|
||
|
_createBrowserJobs(proxy, opts) {
|
||
|
return this.browserConnectionGroups.map(browserConnectionGroup => {
|
||
|
const job = new browser_job_1.default({
|
||
|
tests: this.tests,
|
||
|
browserConnections: browserConnectionGroup,
|
||
|
screenshots: this.screenshots,
|
||
|
warningLog: this.warningLog,
|
||
|
fixtureHookController: this.fixtureHookController,
|
||
|
compilerService: this._compilerService,
|
||
|
messageBus: this._messageBus,
|
||
|
proxy,
|
||
|
opts,
|
||
|
});
|
||
|
this._assignBrowserJobEventHandlers(job);
|
||
|
browserConnectionGroup.map(bc => bc.addJob(job));
|
||
|
return job;
|
||
|
});
|
||
|
}
|
||
|
unRegisterClientScriptRouting() {
|
||
|
clientScriptsRouting.unRegister(this._proxy, this._clientScriptRoutes);
|
||
|
}
|
||
|
// API
|
||
|
abort() {
|
||
|
this._pendingBrowserJobs.forEach(job => job.abort());
|
||
|
}
|
||
|
}
|
||
|
exports.default = Task;
|
||
|
module.exports = exports.default;
|
||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvcnVubmVyL3Rhc2svaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OztBQUFBLG1DQUFpRDtBQUNqRCxvREFBNEI7QUFDNUIsMEZBQWdFO0FBQ2hFLGlFQUF3QztBQUN4QyxvRUFBNEM7QUFDNUMsa0ZBQXlEO0FBQ3pELHlGQUErRDtBQUMvRCwwRkFBNEU7QUFDNUUseUVBQWlEO0FBYWpELG9EQUFnQztBQUtoQyxNQUFxQixJQUFLLFNBQVEsNkJBQWlCO0lBa0IvQyxZQUFvQixFQUNoQixLQUFLLEVBQ0wsdUJBQXVCLEVBQ3ZCLEtBQUssRUFDTCxJQUFJLEVBQ0osZ0JBQWdCLEVBQ2hCLGVBQWUsRUFDZixVQUFVLEdBQ0g7UUFDUCxLQUFLLENBQUMsRUFBRSxpQkFBaUIsRUFBRSxJQUFJLEVBQUUsQ0FBQyxDQUFDO1FBRW5DLElBQUksQ0FBQyxVQUFVLEdBQWdCLElBQUEsZ0JBQU0sR0FBRSxDQUFDO1FBQ3hDLElBQUksQ0FBQyxNQUFNLEdBQW9CLGVBQVMsQ0FBQyxXQUFXLENBQUM7UUFDckQsSUFBSSxDQUFDLHVCQUF1QixHQUFHLHVCQUF1QixDQUFDO1FBQ3ZELElBQUksQ0FBQyxLQUFLLEdBQXFCLEtBQUssQ0FBQztRQUNyQyxJQUFJLENBQUMsSUFBSSxHQU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