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

66 lines
8.8 KiB
JavaScript
Raw 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 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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC1ydW4taG9vay1jb250cm9sbGVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3J1bm5lci90ZXN0LXJ1bi1ob29rLWNvbnRyb2xsZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFBQSw0RkFBaUU7QUFFakUsOERBQStDO0FBRS9DLHVFQUFtRTtBQUVuRSxNQUFxQixxQkFBcUI7SUFTdEMsWUFBb0IsS0FBYSxFQUFFLElBQXdCO1FBQ3ZELElBQUksQ0FBQyxRQUFRLEdBQWMsSUFBSSxhQUFKLElBQUksdUJBQUosSUFBSSxDQUFFLE1BQU0sQ0FBQztRQUN4QyxJQUFJLENBQUMsT0FBTyxHQUFlLElBQUksYUFBSixJQUFJLHVCQUFKLElBQUksQ0FBRSxLQUFLLENBQUM7UUFDdkMsSUFBSSxDQUFDLE9BQU8sR0FBZSxLQUFLLENBQUM7UUFDakMsSUFBSSxDQUFDLGlCQUFpQixHQUFLLEtBQUssQ0FBQztRQUNqQyxJQUFJLENBQUMsYUFBYSxHQUFTLElBQUksQ0FBQztRQUNoQyxJQUFJLENBQUMsbUJBQW1CLEdBQUcsS0FBSyxDQUFDLE1BQU0sQ0FBQztRQUN4QyxJQUFJLENBQUMsVUFBVSxHQUFZLE1BQU0sQ0FBQyxNQUFNLENBQUMsSUFBSSxDQUFDLENBQUM7UUFFL0MsSUFBSSxDQUFDLFlBQVksRUFBRSxDQUFDO0lBQ3hCLENBQUM7SUFFTyxZQUFZO1FBQ2hCLElBQUksSUFBSSxDQUFDLFFBQVE7WUFDYixJQUFBLDRCQUFVLEVBQUMsb0JBQUUsQ0FBQyxRQUFRLEVBQUUsY0FBYyxFQUFFLCtCQUErQixFQUFFLElBQUksQ0FBQyxRQUFRLENBQUMsQ0FBQztRQUU1RixJQ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