Innovenergy_trunk/frontend/node_modules/testcafe/lib/live/test-run-controller.js

98 lines
13 KiB
JavaScript
Raw Permalink Normal View History

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const events_1 = __importDefault(require("events"));
const lodash_1 = require("lodash");
const test_run_1 = require("./test-run");
const test_run_state_1 = __importDefault(require("./test-run-state"));
class LiveModeTestRunController extends events_1.default {
constructor() {
super();
this.testWrappers = [];
this.expectedTestCount = 0;
this._testRunCtor = null;
this.testRuns = {};
this.allTestsCompletePromise = Promise.resolve();
this.completeAllRunningTests = lodash_1.noop;
this.on('all-tests-complete', () => this.completeAllRunningTests());
}
get TestRunCtor() {
if (!this._testRunCtor) {
this._testRunCtor = (0, test_run_1.TestRunCtorFactory)({
created: testRun => this._onTestRunCreated(testRun),
done: (testRun, forced) => this._onTestRunDone(testRun, forced),
readyToNext: testRun => this._onTestRunReadyToNext(testRun),
});
}
return this._testRunCtor;
}
setExpectedTestCount(testCount) {
this.expectedTestCount = testCount;
}
_getTestRuns() {
return [].concat(...Object.values(this.testRuns));
}
run() {
const readyToNextPromises = [];
const testRuns = [].concat(...Object.values(this.testRuns));
testRuns.forEach(testRun => {
if (testRun.finish) {
readyToNextPromises.push(testRun.readyToNextPromise);
testRun.finish();
}
});
this.testRuns = {};
return Promise.all(readyToNextPromises);
}
stop() {
this._getTestRuns().forEach(testRun => {
testRun.stop();
});
}
_getTestWrapper(test) {
return this.testWrappers.find(w => w.test === test);
}
_onTestRunCreated(testRun) {
this.allTestsCompletePromise = new Promise(resolve => {
this.completeAllRunningTests = resolve;
});
const connectionId = testRun.browserConnection.id;
this.testRuns[connectionId] = this.testRuns[connectionId] || [];
this.testRuns[connectionId].push(testRun);
}
_onTestRunDone(testRun) {
testRun.state = test_run_state_1.default.done;
const testWillBeRestarted = !this._isTestFinished(testRun);
const hasRunningTestsInOtherBrowsers = this._getTestRuns().some(t => t.state !== test_run_state_1.default.done);
if (!hasRunningTestsInOtherBrowsers && !testWillBeRestarted)
this.emit('all-tests-complete');
const browserTestRuns = this.testRuns[testRun.browserConnection.id];
const tests = (0, lodash_1.uniq)(browserTestRuns.map(t => t.test));
testRun.readyToNextPromise = new Promise(resolve => {
testRun.setReadyToNext = resolve;
});
const isLastTestRun = tests.length >= this.expectedTestCount;
if (testWillBeRestarted || !isLastTestRun)
return Promise.resolve();
return new Promise(resolve => {
testRun.finish = () => {
testRun.finish = null;
resolve();
};
});
}
_onTestRunReadyToNext(testRun) {
testRun.setReadyToNext();
}
_isTestFinished(testRun) {
const { quarantine, errs } = testRun;
if (!quarantine)
return true;
return quarantine.isFirstAttemptSuccessful(errs) || quarantine.isThresholdReached(errs);
}
}
exports.default = LiveModeTestRunController;
module.exports = exports.default;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC1ydW4tY29udHJvbGxlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9saXZlL3Rlc3QtcnVuLWNvbnRyb2xsZXIuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFBQSxvREFBa0M7QUFDbEMsbUNBQW9DO0FBQ3BDLHlDQUFnRDtBQUNoRCxzRUFBOEM7QUFFOUMsTUFBTSx5QkFBMEIsU0FBUSxnQkFBWTtJQUNoRDtRQUNJLEtBQUssRUFBRSxDQUFDO1FBRVIsSUFBSSxDQUFDLFlBQVksR0FBUSxFQUFFLENBQUM7UUFDNUIsSUFBSSxDQUFDLGlCQUFpQixHQUFHLENBQUMsQ0FBQztRQUMzQixJQUFJLENBQUMsWUFBWSxHQUFRLElBQUksQ0FBQztRQUU5QixJQUFJLENBQUMsUUFBUSxHQUFrQixFQUFFLENBQUM7UUFDbEMsSUFBSSxDQUFDLHVCQUF1QixHQUFHLE9BQU8sQ0FBQyxPQUFPLEVBQUUsQ0FBQztRQUNqR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