171 lines
29 KiB
JavaScript
171 lines
29 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 async_event_emitter_1 = __importDefault(require("../utils/async-event-emitter"));
|
|
//@ts-ignore
|
|
const testcafe_legacy_api_1 = require("testcafe-legacy-api");
|
|
const test_run_1 = __importDefault(require("../test-run"));
|
|
const session_controller_1 = __importDefault(require("../test-run/session-controller"));
|
|
const quarantine_1 = require("../utils/get-options/quarantine");
|
|
const DISCONNECT_THRESHOLD = 3;
|
|
class TestRunController extends async_event_emitter_1.default {
|
|
constructor({ test, index, proxy, screenshots, warningLog, fixtureHookController, opts, testRunHook, compilerService, messageBus, }) {
|
|
super();
|
|
this.test = test;
|
|
this.index = index;
|
|
this._opts = opts;
|
|
this._proxy = proxy;
|
|
this._screenshots = screenshots;
|
|
this._warningLog = warningLog;
|
|
this._fixtureHookController = fixtureHookController;
|
|
this._testRunHook = testRunHook;
|
|
this._testRunCtor = TestRunController._getTestRunCtor(test, opts);
|
|
this.testRun = null;
|
|
this.done = false;
|
|
this._quarantine = this._opts.quarantineMode ? new quarantine_1.Quarantine() : null;
|
|
this._disconnectionCount = 0;
|
|
this.compilerService = compilerService;
|
|
this._messageBus = messageBus;
|
|
}
|
|
static _getTestRunCtor(test, opts) {
|
|
if (opts.TestRunCtor)
|
|
return opts.TestRunCtor;
|
|
return test.isLegacy ? testcafe_legacy_api_1.TestRun : test_run_1.default;
|
|
}
|
|
async _createTestRun(connection, startRunExecutionTime) {
|
|
const screenshotCapturer = this._screenshots.createCapturerFor(this.test, this.index, this._quarantine, connection, this._warningLog);
|
|
const TestRunCtor = this._testRunCtor;
|
|
this.testRun = new TestRunCtor({
|
|
test: this.test,
|
|
browserConnection: connection,
|
|
globalWarningLog: this._warningLog,
|
|
opts: this._opts,
|
|
compilerService: this.compilerService,
|
|
messageBus: this._messageBus,
|
|
screenshotCapturer,
|
|
startRunExecutionTime,
|
|
});
|
|
await this.testRun.initialize();
|
|
this._screenshots.addTestRun(this.test, this.testRun);
|
|
if (this.testRun.addQuarantineInfo)
|
|
this.testRun.addQuarantineInfo(this._quarantine);
|
|
if (this._quarantine) {
|
|
const { successThreshold, attemptLimit } = this._opts.quarantineMode;
|
|
this._quarantine.setCustomParameters(attemptLimit, successThreshold);
|
|
}
|
|
if (!this._quarantine || this._isFirstQuarantineAttempt()) {
|
|
await this.emit('test-run-create', {
|
|
testRun: this.testRun,
|
|
legacy: TestRunCtor === testcafe_legacy_api_1.TestRun,
|
|
test: this.test,
|
|
index: this.index,
|
|
quarantine: this._quarantine,
|
|
});
|
|
}
|
|
return this.testRun;
|
|
}
|
|
async _endQuarantine() {
|
|
if (this._quarantine.attempts.length > 1)
|
|
this.testRun.unstable = this._quarantine.getPassedAttempts().length > 0;
|
|
await this._emitTestRunDone();
|
|
}
|
|
_shouldKeepInQuarantine() {
|
|
const errors = this.testRun.errs;
|
|
const hasErrors = !!errors.length;
|
|
const attempts = this._quarantine.attempts;
|
|
const isFirstAttempt = this._isFirstQuarantineAttempt();
|
|
attempts.push({ testRunId: this.testRun.id, errors });
|
|
return isFirstAttempt ? hasErrors : !this._quarantine.isThresholdReached();
|
|
}
|
|
_isFirstQuarantineAttempt() {
|
|
return !!this._quarantine && !this._quarantine.attempts.length;
|
|
}
|
|
async _keepInQuarantine() {
|
|
await this._restartTest();
|
|
}
|
|
async _restartTest() {
|
|
await this.emit('test-run-restart');
|
|
}
|
|
async _testRunDoneInQuarantineMode() {
|
|
if (this._shouldKeepInQuarantine())
|
|
await this._keepInQuarantine();
|
|
else
|
|
await this._endQuarantine();
|
|
}
|
|
async _testRunDone() {
|
|
if (this._quarantine)
|
|
await this._testRunDoneInQuarantineMode();
|
|
else
|
|
await this._emitTestRunDone();
|
|
}
|
|
async _emitActionStart(args) {
|
|
await this._messageBus.emit('test-action-start', args);
|
|
}
|
|
async _emitActionDone(args) {
|
|
await this.emit('test-action-done', args);
|
|
}
|
|
async _emitTestRunDone() {
|
|
// NOTE: we should report test run completion in order they were completed in browser.
|
|
// To keep a sequence after fixture hook execution we use completion queue.
|
|
await this._fixtureHookController.runFixtureAfterHookIfNecessary(this.testRun);
|
|
await this._testRunHook.runTestRunAfterHookIfNecessary(this.testRun);
|
|
this.done = true;
|
|
await this.emit('test-run-done');
|
|
}
|
|
async _emitTestRunStart() {
|
|
await this._messageBus.emit('test-run-start', this.testRun);
|
|
}
|
|
async _testRunBeforeDone() {
|
|
let raiseEvent = !this._quarantine;
|
|
if (!raiseEvent) {
|
|
const isSuccessfulQuarantineFirstAttempt = this._isFirstQuarantineAttempt() && !this.testRun.errs.length;
|
|
const isAttemptsThresholdReached = this._quarantine.isThresholdReached(this.testRun.errs);
|
|
raiseEvent = isSuccessfulQuarantineFirstAttempt || isAttemptsThresholdReached;
|
|
}
|
|
if (raiseEvent)
|
|
await this.emit('test-run-before-done');
|
|
}
|
|
_testRunDisconnected(connection) {
|
|
this._disconnectionCount++;
|
|
const disconnectionThresholdExceedeed = this._disconnectionCount >= DISCONNECT_THRESHOLD;
|
|
return connection
|
|
.processDisconnection(disconnectionThresholdExceedeed)
|
|
.then(() => {
|
|
return this._restartTest();
|
|
});
|
|
}
|
|
_assignTestRunEvents(testRun, connection) {
|
|
testRun.on('action-start', async (args) => this._emitActionStart(Object.assign(args, { testRun })));
|
|
testRun.on('action-done', async (args) => this._emitActionDone(Object.assign(args, { testRun })));
|
|
testRun.once('start', async () => this._emitTestRunStart());
|
|
testRun.once('ready', async () => {
|
|
if (!this._quarantine || this._isFirstQuarantineAttempt())
|
|
await this.emit('test-run-ready');
|
|
});
|
|
testRun.once('before-done', () => this._testRunBeforeDone());
|
|
testRun.once('done', () => this._testRunDone());
|
|
testRun.once('disconnected', () => this._testRunDisconnected(connection));
|
|
}
|
|
get blocked() {
|
|
return this._fixtureHookController.isTestBlocked(this.test);
|
|
}
|
|
async start(connection, startRunExecutionTime) {
|
|
const testRun = await this._createTestRun(connection, startRunExecutionTime);
|
|
const hookOk = await this._testRunHook.runTestRunBeforeHookIfNecessary(testRun)
|
|
&& await this._fixtureHookController.runFixtureBeforeHookIfNecessary(testRun);
|
|
if (this.test.skip || !hookOk) {
|
|
await this._emitTestRunStart();
|
|
await this.emit('test-run-before-done');
|
|
await this._emitTestRunDone();
|
|
return null;
|
|
}
|
|
this._assignTestRunEvents(testRun, connection);
|
|
testRun.start();
|
|
return session_controller_1.default.getSessionUrl(testRun, this._proxy);
|
|
}
|
|
}
|
|
exports.default = TestRunController;
|
|
module.exports = exports.default;
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC1ydW4tY29udHJvbGxlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydW5uZXIvdGVzdC1ydW4tY29udHJvbGxlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBLHVGQUE2RDtBQUM3RCxZQUFZO0FBQ1osNkRBQStEO0FBQy9ELDJEQUFrQztBQUNsQyx3RkFBK0Q7QUFVL0QsZ0VBQTZEO0FBSTdELE1BQU0sb0JBQW9CLEdBQUcsQ0FBQyxDQUFDO0FBRy9CLE1BQXFCLGlCQUFrQixTQUFRLDZCQUFpQjtJQWlCNUQsWUFBb0IsRUFDaEIsSUFBSSxFQUNKLEtBQUssRUFDTCxLQUFLLEVBQ0wsV0FBVyxFQUNYLFVBQVUsRUFDVixxQkFBcUIsRUFDckIsSUFBSSxFQUNKLFdBQVcsRUFDWCxlQUFlLEVBQ2YsVUFBVSxHQUNVO1FBQ3BCLEtBQUssRUFBRSxDQUFDO1FBRVIsSUFBSSxDQUFDLElBQUksR0FBSSxJQUFJLENBQUM7UUFDbEIsSUFBSSxDQUFDLEtBQUssR0FBRyxLQUFLLENBQUM7UUFDbkIsSUFBSSxDQUFDLEtBQUssR0FBRyxJQUF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GVzdFJ1bkhvb2ssXG4gICAgICAgIGNvbXBpbGVyU2VydmljZSxcbiAgICAgICAgbWVzc2FnZUJ1cyxcbiAgICB9OiBUZXN0UnVuQ29udHJvbGxlckluaXQpIHtcbiAgICAgICAgc3VwZXIoKTtcblxuICAgICAgICB0aGlzLnRlc3QgID0gdGVzdDtcbiAgICAgICAgdGhpcy5pbmRleCA9IGluZGV4O1xuICAgICAgICB0aGlzLl9vcHRzID0gb3B0cztcblxuICAgICAgICB0aGlzLl9wcm94eSAgICAgICAgICAgICAgICAgPSBwcm94eTtcbiAgICAgICAgdGhpcy5fc2NyZWVuc2hvdHMgICAgICAgICAgID0gc2NyZWVuc2hvdHM7XG4gICAgICAgIHRoaXMuX3dhcm5pbmdMb2cgICAgICAgICAgICA9IHdhcm5pbmdMb2c7XG4gICAgICAgIHRoaXMuX2ZpeHR1cmVIb29rQ29udHJvbGxlciA9IGZpeHR1cmVIb29rQ29udHJvbGxlcjtcbiAgICAgICAgdGhpcy5fdGVzdFJ1bkhvb2sgICAgICAgICAgID0gdGVzdFJ1bkhvb2s7XG5cbiAgICAgICAgdGhpcy5fdGVzdFJ1bkN0b3IgPSBUZXN0UnVuQ29udHJvbGxlci5fZ2V0VGVzdFJ1bkN0b3IodGVzdCwgb3B0cyk7XG5cbiAgICAgICAgdGhpcy50ZXN0UnVuICAgICAgICAgICAgID0gbnVsbDtcbiAgICAgICAgdGhpcy5kb25lICAgICAgICAgICAgICAgID0gZmFsc2U7XG4gICAgICAgIHRoaXMuX3F1YXJhbnRpbmUgICAgICAgICA9IHRoaXMuX29wdHMucXVhcmFudGluZU1vZGUgPyBuZXcgUXVhcmFudGluZSgpIDogbnVsbDtcbiAgICAgICAgdGhpcy5fZGlzY29ubmVjdGlvbkNvdW50ID0gMDtcbiAgICAgICAgdGhpcy5jb21waWxlclNlcnZpY2UgICAgID0gY29tcGlsZXJTZXJ2aWNlO1xuICAgICAgICB0aGlzLl9tZXNzYWdlQnVzICAgICAgICAgPSBtZ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