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

66 lines
8.8 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 process_test_fn_error_1 = __importDefault(require("../errors/process-test-fn-error"));
const phase_1 = __importDefault(require("../test-run/phase"));
const type_assertions_1 = require("../errors/runtime/type-assertions");
class TestRunHookController {
constructor(tests, hook) {
this.beforeFn = hook === null || hook === void 0 ? void 0 : hook.before;
this.afterFn = hook === null || hook === void 0 ? void 0 : hook.after;
this.started = false;
this.runningBeforeHook = false;
this.beforeHookErr = null;
this.pendingTestRunCount = tests.length;
this.testRunCtx = Object.create(null);
this._assertHooks();
}
_assertHooks() {
if (this.beforeFn)
(0, type_assertions_1.assertType)(type_assertions_1.is.function, 'globalBefore', 'The testRun.globalBefore hook', this.beforeFn);
if (this.afterFn)
(0, type_assertions_1.assertType)(type_assertions_1.is.function, 'globalAfter', 'The testRun.globalAfter hook', this.afterFn);
}
isTestBlocked() {
return this.runningBeforeHook;
}
async runTestRunBeforeHookIfNecessary(testRun) {
const shouldRunBeforeHook = !this.started && this.beforeFn;
this.started = true;
if (shouldRunBeforeHook) {
this.runningBeforeHook = true;
try {
await this.beforeFn(this.testRunCtx);
}
catch (err) {
this.beforeHookErr = (0, process_test_fn_error_1.default)(err);
}
this.runningBeforeHook = false;
}
// NOTE: fail all tests if testRun.before hook has error
if (this.beforeHookErr) {
testRun.phase = phase_1.default.inTestRunBeforeHook;
testRun.addError(this.beforeHookErr);
return false;
}
testRun.testRunCtx = this.testRunCtx;
return true;
}
async runTestRunAfterHookIfNecessary(testRun) {
this.pendingTestRunCount--;
if (this.pendingTestRunCount === 0 && this.afterFn) {
testRun.phase = phase_1.default.inTestRunAfterHook;
try {
await this.afterFn(this.testRunCtx);
}
catch (err) {
testRun.addError((0, process_test_fn_error_1.default)(err));
}
}
}
}
exports.default = TestRunHookController;
module.exports = exports.default;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC1ydW4taG9vay1jb250cm9sbGVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3J1bm5lci90ZXN0LXJ1bi1ob29rLWNvbnRyb2xsZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFBQSw0RkFBaUU7QUFFakUsOERBQStDO0FBRS9DLHVFQUFtRTtBQUVuRSxNQUFxQixxQkFBcUI7SUFTdEMsWUFBb0IsS0FBYSxFQUFFLElBQXdCO1FBQ3ZELElBQUksQ0FBQyxRQUFRLEdBQWMsSUFBSSxhQUFKLElBQUksdUJBQUosSUFBSSxDQUFFLE1BQU0sQ0FBQztRQUN4QyxJQUFJLENBQUMsT0FBTyxHQUFlLElBQUksYUFBSixJQUFJLHVCQUFKLElBQUksQ0FBRSxLQUFLLENBQUM7UUFDdkMsSUFBSSxDQUFDLE9BQU8sR0FBZSxLQUFLLENBQUM7UUFDakMsSUFBSSxDQUFDLGlCQUFpQixHQUFLLEtBQUssQ0FBQztRQUNqQyxJQUFJLENBQUMsYUFBYSxHQUFTLElBQUksQ0FBQztRQUNoQyxJQUFJLENBQUMsbUJBQW1CLEdBQUcsS0FBSyxDQUFDLE1BQU0sQ0FBQztRQUN4QyxJQUFJLENBQUMsVUFBVSxHQUFZLE1BQU0sQ0FBQyxNQUFNLENBQUMsSUFBSSxDQUFDLENBQUM7UUFFL0MsSUFBSSxDQUFDLFlBQVksRUFBRSxDQUFDO0lBQ3hCLENBQUM7SUFFTyxZQUFZO1FBQ2hCLElBQUksSUFBSSxDQUFDLFFBQVE7WUFDYixJQUFBLDRCQUFVLEVBQUMsb0JBQUUsQ0FBQyxRQUFRLEVBQUUsY0FBYyxFQUFFLCtCQUErQixFQUFFLElBQUksQ0FBQyxRQUFRLENBQUMsQ0FBQztRQUU1RixJQUFJLElBQUks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