Innovenergy_trunk/frontend/node_modules/testcafe/lib/runner/fixture-hook-controller.js

107 lines
15 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 phase_1 = __importDefault(require("../test-run/phase"));
const process_test_fn_error_1 = __importDefault(require("../errors/process-test-fn-error"));
const execute_fn_with_timeout_1 = __importDefault(require("../utils/execute-fn-with-timeout"));
class FixtureHookController {
constructor(tests, browserConnectionCount) {
this._fixtureMap = FixtureHookController._createFixtureMap(tests, browserConnectionCount);
}
static _ensureFixtureMapItem(fixtureMap, fixture) {
if (!fixtureMap.has(fixture)) {
const item = {
started: false,
runningFixtureBeforeHook: false,
fixtureBeforeHookErr: null,
pendingTestRunCount: 0,
fixtureCtx: Object.create(null),
};
fixtureMap.set(fixture, item);
}
}
static _createFixtureMap(tests, browserConnectionCount) {
return tests.reduce((fixtureMap, test) => {
const fixture = test.fixture;
if (!test.skip) {
FixtureHookController._ensureFixtureMapItem(fixtureMap, fixture);
const item = fixtureMap.get(fixture);
item.pendingTestRunCount += browserConnectionCount;
}
return fixtureMap;
}, new Map());
}
_getFixtureMapItem(test) {
return test.skip ? null : this._fixtureMap.get(test.fixture);
}
isTestBlocked(test) {
const item = this._getFixtureMapItem(test);
return !!item && item.runningFixtureBeforeHook;
}
async _runFixtureBeforeHook(item, fn, testRun) {
if (!fn)
return true;
item.runningFixtureBeforeHook = true;
try {
await (0, execute_fn_with_timeout_1.default)(fn, testRun.executionTimeout, item.fixtureCtx);
}
catch (err) {
item.fixtureBeforeHookErr = (0, process_test_fn_error_1.default)(err);
}
item.runningFixtureBeforeHook = false;
return !item.fixtureBeforeHookErr;
}
async _runFixtureAfterHook(item, fn, testRun) {
if (!fn)
return;
testRun.phase = phase_1.default.inFixtureAfterHook;
try {
await (0, execute_fn_with_timeout_1.default)(fn, testRun.executionTimeout, item.fixtureCtx);
}
catch (err) {
testRun.addError((0, process_test_fn_error_1.default)(err));
}
}
async runFixtureBeforeHookIfNecessary(testRun) {
const fixture = testRun.test.fixture;
const item = this._getFixtureMapItem(testRun.test);
if (item) {
const shouldRunBeforeHook = !item.started;
item.started = true;
const success = shouldRunBeforeHook
&& await this._runFixtureBeforeHook(item, fixture.globalBeforeFn, testRun)
&& await this._runFixtureBeforeHook(item, fixture.beforeFn, testRun);
// NOTE: fail all tests in fixture if fixture.before hook has error
if (!success && item.fixtureBeforeHookErr) {
testRun.phase = phase_1.default.inFixtureBeforeHook;
testRun.addError(item.fixtureBeforeHookErr);
return false;
}
testRun.fixtureCtx = item.fixtureCtx;
}
return true;
}
async runFixtureAfterHookIfNecessary(testRun) {
var _a;
const fixture = testRun.test.fixture;
const item = this._getFixtureMapItem(testRun.test);
if (!item)
return;
item.pendingTestRunCount--;
if (item.pendingTestRunCount !== 0)
return;
await this._runFixtureAfterHook(item, fixture.afterFn, testRun);
await this._runFixtureAfterHook(item, fixture.globalAfterFn, testRun);
if (item.fixtureCtx) {
await ((_a = testRun.compilerService) === null || _a === void 0 ? void 0 : _a.removeFixtureCtxsFromState({
fixtureIds: [fixture.id],
}));
}
this._fixtureMap.delete(fixture);
}
}
exports.default = FixtureHookController;
module.exports = exports.default;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZml4dHVyZS1ob29rLWNvbnRyb2xsZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvcnVubmVyL2ZpeHR1cmUtaG9vay1jb250cm9sbGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7O0FBQUEsOERBQStDO0FBQy9DLDRGQUFpRTtBQUlqRSwrRkFBb0U7QUFVcEUsTUFBcUIscUJBQXFCO0lBR3RDLFlBQW9CLEtBQWEsRUFBRSxzQkFBOEI7UUFDN0QsSUFBSSxDQUFDLFdBQVcsR0FBRyxxQkFBcUIsQ0FBQyxpQkFBaUI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VhdGVGaXh0dXJlTWFwKHRlc3RzLCBicm93c2VyQ29ubmVjdGlvbkNvdW50KTtcbiAgICB9XG5cbiAgICBwcml2YXRlIHN0YXRpYyBfZW5zdXJlRml4dHVyZU1hcEl0ZW0gKGZpeHR1cmVNYXA6IE1hcDxGaXh0dXJlLCBGaXh0dXJlU3RhdGU+LCBmaXh0dXJlOiBGaXh0dXJlKTogdm9pZCB7XG4gICAgICAgIGlmICghZml4dHVyZU1hcC5oYXMoZml4dHVyZSkpIHtcbiAgICAgICAgICAgIGNvbnN0IGl0ZW0gPSB7XG4gICAgICAgICAgICAgICAgc3RhcnRlZDogICAgICAgICAgICAgICAgICBmYWxzZSxcbiAgICAgICAgICAgICAgICBydW5uaW5nRml4dHVyZUJlZm9yZUhvb2s6IGZhbHNlLFxuICAgICAgICAgICAgICAgIGZpeHR1cmVCZWZvcmVIb29rRXJyOiAgICAgbnVsbCxcbiAgICAgICAgICAgICAgICBwZW5kaW5nVGVzdFJ1bkNvdW50OiAgICAgIDAsXG4gICAgICAgICAgICAgICAgZml4dHVyZUN0eDogICAgICAgICAgICAgICBPYmplY3QuY3JlYXRlKG51bGwpLFxuICAgICAgICAgICAgfTtcblxuICAgICAgICAgICAgZml4dHVyZU1hcC5zZXQoZml4dHVyZSwgaXRlbSk7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBwcml2YXRlIHN0YXRpYyBfY3JlYXRlRml4dHVyZU1hcCAodGVzdHM6IFRlc3RbXSwgYnJvd3NlckNvbm5lY3Rpb25Db3VudDogbnVtYmVyKTogTWFwPEZpeHR1cmUsIEZpeHR1cmVTdGF0ZT4ge1xuICAgICAgICByZXR1cm4gdGVzdHMucmVkdWNlKChmaXh0dXJlTWFwLCB0ZXN0KSA9PiB7XG4gICAgICAgICAgICBjb25zdCBmaXh0dXJlID0gdGVzdC5maXh0dXJlO1xuXG4gICAgICAgICAgICBpZiAoIXRlc3Quc2tpcCkge1xuICAgICAgICAgICAgICAgIEZpeHR1cmVIb29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