Innovenergy_trunk/frontend/node_modules/testcafe/lib/runner/browser-job.js

175 lines
31 KiB
JavaScript

"use strict";
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 async_event_emitter_1 = __importDefault(require("../utils/async-event-emitter"));
const test_run_controller_1 = __importDefault(require("./test-run-controller"));
const session_controller_1 = __importDefault(require("../test-run/session-controller"));
const browser_job_result_1 = __importDefault(require("./browser-job-result"));
const test_run_hook_controller_1 = __importDefault(require("./test-run-hook-controller"));
var BrowserJobStatus;
(function (BrowserJobStatus) {
BrowserJobStatus[BrowserJobStatus["initialized"] = 0] = "initialized";
BrowserJobStatus[BrowserJobStatus["starting"] = 1] = "starting";
BrowserJobStatus[BrowserJobStatus["started"] = 2] = "started";
})(BrowserJobStatus || (BrowserJobStatus = {}));
class BrowserJob extends async_event_emitter_1.default {
constructor({ tests, browserConnections, proxy, screenshots, warningLog, fixtureHookController, opts, compilerService, messageBus, }) {
var _a;
super();
this._status = BrowserJobStatus.initialized;
this._startTime = new Date();
this._total = 0;
this._passed = 0;
this._opts = opts;
this._proxy = proxy;
this.browserConnections = browserConnections;
this._screenshots = screenshots;
this.warningLog = warningLog;
this.fixtureHookController = fixtureHookController;
this._result = null;
this._messageBus = messageBus;
this._testRunHook = new test_run_hook_controller_1.default(tests, (_a = opts.hooks) === null || _a === void 0 ? void 0 : _a.testRun);
this._testRunControllerQueue = tests.map((test, index) => this._createTestRunController(test, index, compilerService));
this._completionQueue = [];
this._reportsPending = [];
this._connectionErrorListener = (error) => this._setResult(browser_job_result_1.default.errored, error);
this._resolveWaitingLastTestInFixture = null;
this.browserConnections.map(bc => bc.once('error', this._connectionErrorListener));
}
_createTestRunController(test, index, compilerService) {
const testRunController = new test_run_controller_1.default({
test,
index: index + 1,
proxy: this._proxy,
screenshots: this._screenshots,
warningLog: this.warningLog,
fixtureHookController: this.fixtureHookController,
opts: this._opts,
messageBus: this._messageBus,
compilerService,
testRunHook: this._testRunHook,
});
testRunController.on('test-run-create', async (testRunInfo) => {
await this.emit('test-run-create', testRunInfo);
});
testRunController.on('test-run-ready', async () => {
await this.emit('test-run-ready', testRunController);
});
testRunController.on('test-run-restart', async () => this._onTestRunRestart(testRunController));
testRunController.on('test-run-before-done', async () => {
await this.emit('test-run-before-done', testRunController);
});
testRunController.on('test-run-done', async () => this._onTestRunDone(testRunController));
testRunController.on('test-action-done', async (args) => {
await this.emit('test-action-done', args);
});
return testRunController;
}
async _setResult(status, data) {
if (this._result)
return;
this._result = { status, data };
this.browserConnections.forEach(bc => bc.removeListener('error', this._connectionErrorListener));
await Promise.all(this.browserConnections.map(bc => bc.reportJobResult(this._result.status, this._result.data)));
}
_addToCompletionQueue(testRunInfo) {
this._completionQueue.push(testRunInfo);
}
_removeFromCompletionQueue(testRunInfo) {
(0, lodash_1.pull)(this._completionQueue, testRunInfo);
}
async _onTestRunRestart(testRunController) {
this._removeFromCompletionQueue(testRunController);
this._testRunControllerQueue.unshift(testRunController);
await this.emit('test-run-restart', testRunController);
}
async _onTestRunDone(testRunController) {
this._total++;
if (!testRunController.testRun.errs.length)
this._passed++;
while (this._completionQueue.length && this._completionQueue[0].done) {
testRunController = this._completionQueue.shift();
await this.emit('test-run-done', testRunController.testRun);
(0, lodash_1.pull)(this._reportsPending, testRunController);
if (!this._reportsPending.length && this._resolveWaitingLastTestInFixture) {
this._resolveWaitingLastTestInFixture();
this._resolveWaitingLastTestInFixture = null;
}
}
if (!this._completionQueue.length && !this.hasQueuedTestRuns) {
if (!this._opts.live)
session_controller_1.default.closeSession(testRunController.testRun);
this
._setResult(browser_job_result_1.default.done, { total: this._total, passed: this._passed })
.then(() => this.emit('done'));
}
}
async _isNextTestRunAvailable(testRunController) {
// NOTE: event task start is currently executing,
// so test run is temporary blocked
if (this._status === BrowserJobStatus.starting)
return false;
// NOTE: before hook for test run fixture is currently
// executing, so test run is temporary blocked
const isBlocked = testRunController.blocked;
const isConcurrency = this._opts.concurrency > 1;
const hasIncompleteTestRuns = this._completionQueue.some(controller => !controller.done);
const needWaitLastTestInFixture = this._reportsPending.some(controller => controller.test.fixture !== testRunController.test.fixture);
if (isBlocked || (hasIncompleteTestRuns || needWaitLastTestInFixture) && !isConcurrency) {
const disablePageReloads = testRunController.test.disablePageReloads ||
this._opts.disablePageReloads && testRunController.test.disablePageReloads !== false;
if (!needWaitLastTestInFixture || !disablePageReloads)
return false;
// NOTE: if we have `disablePageReloads` enabled and the next test is from next
// fixture, then we need to wait until all reporters finished to prevent
// redirecting to the `idle` page
await new Promise(resolve => {
this._resolveWaitingLastTestInFixture = resolve;
});
}
return true;
}
// API
get hasQueuedTestRuns() {
return !!this._testRunControllerQueue.length;
}
get currentTestRun() {
return this._completionQueue.length ? this._completionQueue[0].testRun : null;
}
async popNextTestRunInfo(connection) {
while (this._testRunControllerQueue.length) {
const testRunController = this._testRunControllerQueue[0];
const isNextTestRunAvailable = await this._isNextTestRunAvailable(testRunController);
if (!isNextTestRunAvailable)
break;
this._reportsPending.push(testRunController);
this._testRunControllerQueue.shift();
this._addToCompletionQueue(testRunController);
if (this._status === BrowserJobStatus.initialized) {
this._status = BrowserJobStatus.starting;
this._startTime = new Date();
await this.emit('start', this._startTime);
this._status = BrowserJobStatus.started;
}
const testRunUrl = await testRunController.start(connection, this._startTime);
if (testRunUrl) {
return {
testRunId: testRunController.testRun.id,
url: testRunUrl,
};
}
}
return null;
}
abort() {
this.clearListeners();
this._setResult(browser_job_result_1.default.aborted);
this.browserConnections.map(bc => bc.removeJob(this));
}
}
exports.default = BrowserJob;
module.exports = exports.default;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYnJvd3Nlci1qb2IuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvcnVubmVyL2Jyb3dzZXItam9iLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Oz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biAgICBwcml2YXRlIF9yZXNvbHZlV2FpdGluZ0xhc3RUZXN0SW5GaXh0dXJlOiBGdW5jdGlvbiB8IG51bGw7XG4gICAgcHJpdmF0ZSByZWFkb25seSBfbWVzc2FnZUJ1czogTWVzc2FnZUJ1cztcbiAgICBwcml2YXRlIHJlYWRvbmx5IF90ZXN0UnVuSG9vazogVGVzdFJ1bkhvb2tDb250cm9sbGVyO1xuXG4gICAgcHVibGljIGNvbnN0cnVjdG9yICh7XG4gICAgICAgIHRlc3RzLFxuICAgICAgICBicm93c2VyQ29ubmVjdGlvbnMsXG4gICAgICAgIHByb3h5LFxuICAgICAgICBzY3JlZW5zaG90cyxcbiAgICAgICAgd2FybmluZ0xvZyxcbiAgICAgICAgZml4dHVyZUhvb2tDb250cm9sbGVyLFxuICAgICAgICBvcHRzLFxuICAgICAgICBjb21waWxlclNlcnZpY2UsXG4gICAgICAgIG1lc3NhZ2VCdXMsXG4gICAgfTogQnJvd3NlckpvYkluaXQpIHtcbiAgICAgICAgc3VwZXIoKTtcblxuICAgICAgICB0aGlzLl9zdGF0dXMgPSBCcm93c2VySm9iU3RhdHVzLmluaXRpYWxpemVkO1xuICAgICAgICB0aGlzLl9zdGFydFRpbWUgPSBuZXcgRGF0ZSgpO1xuXG4gICAgICAgIHRoaXMuX3RvdGFsICAgICAgICAgICAgICAgID0gMDtcbiAgICAgICAgdGhpcy5fcGFzc2VkICAgICAgICAgICAgICAgPSAwO1xuICAgICAgICB0aGlzLl9vcHRzICAgICAgICAgICAgICAgICA9IG9wdHM7XG4gICAgICAgIHRoaXMuX3Byb3h5ICAgICAgICAgICAgICAgID0gcHJveHk7XG4gICAgICAgIHRoaXMuYnJvd3NlckNvbm5lY3Rpb25zICAgID0gYnJvd3NlckNvbm5lY3Rpb25zO1xuICAgICAgICB0aGlzLl9zY3JlZW5zaG90cyAgICAgICAgICA9IHNjcmVlbnNob3RzO1xuICAgICAgICB0aGlzLndhcm5pbmdMb2cgICAgICAgICAgICA9IHd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W1iZXIsIGNvbXBpbGVyU2VydmljZT86IENvbXBpbGVyU2VydmljZSk6IFRlc3RSdW5Db250cm9sbGVyIHtcbiAgICAgICAgY29uc3QgdGVzdFJ1bkNvbnRyb2xsZXIgPSBuZXcgVGVzdFJ1bkNvbnRyb2xsZXIoe1xuICAgICAgICAgICAgdGVzdCxcbiAgICAgICAgICAgIGluZGV4OiAgICAgICAgICAgICAgICAgaW5kZXggKyAxLFxuICAgICAgICAgICAgcHJveHk6ICAgICAgICAgICAgICAgICB0aGlzLl9wcm94eSxcbiAgICAgICAgICAgIHNjcmVlbnNob3RzOiAgICAgICAgICAgdGhpcy5fc2NyZWVuc2hvdHMsXG4gICAgICAgICAgICB3YXJuaW5nTG9nOiAgICAgICAgICAgIHRoaXMud2FybmluZ0xvZyxcbiAgICAgICAgICAgIGZpeHR1cmVIb29rQ29udHJvbGxlcjogdGhpcy5maXh0dXJlSG9va0NvbnRyb2xsZXIsXG4gICAgICAgICAgICBvcHRzOiAgICAgICAgICAgICAgICAgIHRoaXMuX29wdHMsXG4gICAgICAgICAgICBtZXNzYWdlQnVzOiAgICAgICAgICAgIHRoaXMuX21lc3NhZ2VCdXMsXG4gICAgICAgICAgICBjb21waWxlclNlcnZpY2UsXG4gICAgICAgICAgICB0ZXN0UnVuSG9vazogICAgICAgICAgIHRoaXMuX3Rlc3RSdW5Ib29rLFxuICAgICAgICB9KTtcblxuICAgICAgICB0ZXN0UnVuQ29udHJvbGxlci5vbigndGVzdC1ydW4tY3JlYXRlJywgYXN5bmMgdGVzdFJ1bkluZm8gPT4ge1xuICAgICAgICAgICAgYXdhaXQgdGhpcy5lbWl0KCd0ZXN0LXJ1bi1jcmVhdGUnLCB0ZXN0UnVuSW5mbyk7XG4gICAgICAgIH0pO1xuICAgICAgICB0ZXN0UnVuQ29udHJvbGxlci5vbigndGVzdC1ydW4tcmVhZHknLCBhc3luYyAoKSA9PiB7XG4gICAgICAgICAgICBhd2FpdCB0aGlzLmVtaXQoJ3Rlc3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