106 lines
18 KiB
JavaScript
106 lines
18 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 lodash_1 = require("lodash");
|
||
|
const testing_unit_1 = __importDefault(require("./testing-unit"));
|
||
|
const unit_type_1 = __importDefault(require("./unit-type"));
|
||
|
const type_assertions_1 = require("../../errors/runtime/type-assertions");
|
||
|
const wrap_test_function_1 = __importDefault(require("../wrap-test-function"));
|
||
|
const assert_type_1 = __importDefault(require("../request-hooks/assert-type"));
|
||
|
const assert_type_2 = __importDefault(require("../../custom-client-scripts/assert-type"));
|
||
|
const types_1 = require("../../errors/types");
|
||
|
const runtime_1 = require("../../errors/runtime");
|
||
|
const option_names_1 = __importDefault(require("../../configuration/option-names"));
|
||
|
const testcafe_hammerhead_1 = require("testcafe-hammerhead");
|
||
|
const test_timeout_1 = __importDefault(require("./test-timeout"));
|
||
|
const esm_runtime_holder_name_1 = __importDefault(require("../../services/compiler/esm-runtime-holder-name"));
|
||
|
class Test extends testing_unit_1.default {
|
||
|
constructor(testFile, isCompilerServiceMode = false, baseUrl, returnApiOrigin = true) {
|
||
|
// NOTE: 'fixture' directive can be missing
|
||
|
const fixture = testFile.currentFixture;
|
||
|
const pageUrl = (fixture === null || fixture === void 0 ? void 0 : fixture.pageUrl) || testcafe_hammerhead_1.SPECIAL_BLANK_PAGE;
|
||
|
super(testFile, unit_type_1.default.test, pageUrl, baseUrl);
|
||
|
this.fixture = null;
|
||
|
this.fn = null;
|
||
|
this.beforeFn = null;
|
||
|
this.afterFn = null;
|
||
|
this.globalBeforeFn = null;
|
||
|
this.globalAfterFn = null;
|
||
|
this.timeouts = null;
|
||
|
this._isCompilerService = isCompilerServiceMode;
|
||
|
this._initFixture(testFile);
|
||
|
// NOTE: This is internal data of 'esm' module
|
||
|
// @ts-ignore
|
||
|
this.esmRuntime = global[esm_runtime_holder_name_1.default] || null;
|
||
|
if (returnApiOrigin)
|
||
|
return this.apiOrigin;
|
||
|
}
|
||
|
static init({ testFile, baseUrl, isCompilerServiceMode }) {
|
||
|
return testing_unit_1.default.init(Test, testFile, isCompilerServiceMode, baseUrl);
|
||
|
}
|
||
|
_initFixture(testFile) {
|
||
|
this.fixture = testFile.currentFixture;
|
||
|
if (!this.fixture)
|
||
|
return;
|
||
|
this.pageUrl = this.fixture.pageUrl || testcafe_hammerhead_1.SPECIAL_BLANK_PAGE;
|
||
|
this.requestHooks = this.fixture.requestHooks.slice();
|
||
|
this.clientScripts = this.fixture.clientScripts.slice();
|
||
|
this.skipJsErrorsOptions = this.fixture.skipJsErrorsOptions;
|
||
|
}
|
||
|
_add(name, fn) {
|
||
|
if (this._isCompilerService && !this.fixture)
|
||
|
this._initFixture(this.testFile);
|
||
|
(0, type_assertions_1.assertType)(type_assertions_1.is.string, 'apiOrigin', 'The test name', name);
|
||
|
(0, type_assertions_1.assertType)(type_assertions_1.is.function, 'apiOrigin', 'The test body', fn);
|
||
|
(0, type_assertions_1.assertType)(type_assertions_1.is.nonNullObject, 'apiOrigin', `The fixture of '${name}' test`, this.fixture);
|
||
|
this.name = name;
|
||
|
this.fn = (0, wrap_test_function_1.default)(fn);
|
||
|
if (!this.testFile.collectedTests.includes(this))
|
||
|
this.testFile.collectedTests.push(this);
|
||
|
return this.apiOrigin;
|
||
|
}
|
||
|
_before$(fn) {
|
||
|
(0, type_assertions_1.assertType)(type_assertions_1.is.function, 'before', 'The test.before hook', fn);
|
||
|
this.beforeFn = (0, wrap_test_function_1.default)(fn);
|
||
|
return this.apiOrigin;
|
||
|
}
|
||
|
_after$(fn) {
|
||
|
(0, type_assertions_1.assertType)(type_assertions_1.is.function, 'after', 'The test.after hook', fn);
|
||
|
this.afterFn = (0, wrap_test_function_1.default)(fn);
|
||
|
return this.apiOrigin;
|
||
|
}
|
||
|
_requestHooks$(...hooks) {
|
||
|
if (this.apiMethodWasCalled.requestHooks)
|
||
|
throw new runtime_1.APIError(option_names_1.default.requestHooks, types_1.RUNTIME_ERRORS.multipleAPIMethodCallForbidden, option_names_1.default.requestHooks);
|
||
|
hooks = (0, lodash_1.flattenDeep)(hooks);
|
||
|
(0, assert_type_1.default)(hooks);
|
||
|
this.requestHooks = (0, lodash_1.union)(this.requestHooks, hooks);
|
||
|
this.apiMethodWasCalled.requestHooks = true;
|
||
|
return this.apiOrigin;
|
||
|
}
|
||
|
_clientScripts$(...scripts) {
|
||
|
if (this.apiMethodWasCalled.clientScripts)
|
||
|
throw new runtime_1.APIError(option_names_1.default.clientScripts, types_1.RUNTIME_ERRORS.multipleAPIMethodCallForbidden, option_names_1.default.clientScripts);
|
||
|
scripts = (0, lodash_1.flattenDeep)(scripts);
|
||
|
(0, assert_type_2.default)(scripts);
|
||
|
this.clientScripts = (0, lodash_1.union)(this.clientScripts, scripts);
|
||
|
this.apiMethodWasCalled.clientScripts = true;
|
||
|
return this.apiOrigin;
|
||
|
}
|
||
|
_timeouts$(timeouts) {
|
||
|
(0, type_assertions_1.assertType)(type_assertions_1.is.testTimeouts, 'timeouts', 'test.timeouts', timeouts);
|
||
|
Object.keys(test_timeout_1.default)
|
||
|
.filter(timeout => timeout in timeouts)
|
||
|
.forEach(timeout => {
|
||
|
(0, type_assertions_1.assertType)(type_assertions_1.is.nonNegativeNumber, 'timeouts', `test.timeouts.${timeout}`, timeouts[timeout]);
|
||
|
});
|
||
|
this.timeouts = timeouts;
|
||
|
return this.apiOrigin;
|
||
|
}
|
||
|
}
|
||
|
exports.default = Test;
|
||
|
testing_unit_1.default.makeAPIListForChildClass(Test);
|
||
|
module.exports = exports.default;
|
||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9hcGkvc3RydWN0dXJlL3Rlc3QudHMiXSwibmFtZXMiOltdL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