116 lines
19 KiB
JavaScript
116 lines
19 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 base_unit_1 = __importDefault(require("./base-unit"));
|
||
|
const test_page_url_1 = require("../test-page-url");
|
||
|
const handle_tag_args_1 = __importDefault(require("../../utils/handle-tag-args"));
|
||
|
const delegated_api_1 = require("../../utils/delegated-api");
|
||
|
const type_assertions_1 = require("../../errors/runtime/type-assertions");
|
||
|
const flag_list_1 = __importDefault(require("../../utils/flag-list"));
|
||
|
const option_names_1 = __importDefault(require("../../configuration/option-names"));
|
||
|
const path_1 = require("path");
|
||
|
const skip_js_errors_1 = require("../../utils/get-options/skip-js-errors");
|
||
|
const runtime_1 = require("../../errors/runtime");
|
||
|
class TestingUnit extends base_unit_1.default {
|
||
|
constructor(testFile, unitType, pageUrl, baseUrl) {
|
||
|
super(unitType);
|
||
|
this.testFile = testFile;
|
||
|
this.name = null;
|
||
|
this.pageUrl = pageUrl;
|
||
|
this.baseUrl = baseUrl;
|
||
|
this.authCredentials = null;
|
||
|
this.meta = {};
|
||
|
this.only = false;
|
||
|
this.skip = false;
|
||
|
this.requestHooks = [];
|
||
|
this.clientScripts = [];
|
||
|
this.disablePageReloads = void 0;
|
||
|
this.disablePageCaching = false;
|
||
|
this.apiMethodWasCalled = new flag_list_1.default([option_names_1.default.clientScripts, option_names_1.default.requestHooks]);
|
||
|
const unit = this;
|
||
|
this.apiOrigin = function apiOrigin(...args) {
|
||
|
return unit._add(...args);
|
||
|
};
|
||
|
//@ts-ignore
|
||
|
(0, delegated_api_1.delegateAPI)(this.apiOrigin, this.constructor.API_LIST, { handler: this });
|
||
|
}
|
||
|
_only$getter() {
|
||
|
this.only = true;
|
||
|
return this.apiOrigin;
|
||
|
}
|
||
|
_skip$getter() {
|
||
|
this.skip = true;
|
||
|
return this.apiOrigin;
|
||
|
}
|
||
|
_disablePageReloads$getter() {
|
||
|
this.disablePageReloads = true;
|
||
|
return this.apiOrigin;
|
||
|
}
|
||
|
_enablePageReloads$getter() {
|
||
|
this.disablePageReloads = false;
|
||
|
return this.apiOrigin;
|
||
|
}
|
||
|
_page$(url, ...rest) {
|
||
|
this.pageUrl = (0, handle_tag_args_1.default)(url, rest);
|
||
|
this.baseUrl = this.baseUrl || (0, path_1.dirname)(this.testFile.filename);
|
||
|
const base = (0, test_page_url_1.prepareBaseUrl)(this.baseUrl);
|
||
|
(0, type_assertions_1.assertType)(type_assertions_1.is.string, 'page', 'The page URL', this.pageUrl);
|
||
|
(0, test_page_url_1.assertPageUrl)(this.pageUrl, 'page');
|
||
|
this.pageUrl = (0, test_page_url_1.getUrl)(this.pageUrl, base);
|
||
|
return this.apiOrigin;
|
||
|
}
|
||
|
_skipJsErrors$(options = true) {
|
||
|
(0, type_assertions_1.assertType)([type_assertions_1.is.boolean, type_assertions_1.is.nonNullObject, type_assertions_1.is.function], 'skipJsErrors', 'The skipJsErrors options argument', options);
|
||
|
this.skipJsErrorsOptions = options;
|
||
|
(0, skip_js_errors_1.validateSkipJsErrorsOptionValue)(this.skipJsErrorsOptions, runtime_1.SkipJsErrorsArgumentApiError);
|
||
|
return this.apiOrigin;
|
||
|
}
|
||
|
_httpAuth$(credentials) {
|
||
|
(0, type_assertions_1.assertType)(type_assertions_1.is.nonNullObject, 'httpAuth', 'The credentials', credentials);
|
||
|
(0, type_assertions_1.assertType)(type_assertions_1.is.string, 'httpAuth', 'credentials.username', credentials.username);
|
||
|
(0, type_assertions_1.assertType)(type_assertions_1.is.string, 'httpAuth', 'credentials.password', credentials.password);
|
||
|
if (credentials.domain)
|
||
|
(0, type_assertions_1.assertType)(type_assertions_1.is.string, 'httpAuth', 'credentials.domain', credentials.domain);
|
||
|
if (credentials.workstation)
|
||
|
(0, type_assertions_1.assertType)(type_assertions_1.is.string, 'httpAuth', 'credentials.workstation', credentials.workstation);
|
||
|
this.authCredentials = credentials;
|
||
|
return this.apiOrigin;
|
||
|
}
|
||
|
_meta$(key, value) {
|
||
|
(0, type_assertions_1.assertType)([type_assertions_1.is.string, type_assertions_1.is.nonNullObject], 'meta', `${this.unitType}.meta`, key);
|
||
|
const data = typeof key === 'string' ? { [key]: value } : key;
|
||
|
Object.keys(data).forEach(propName => {
|
||
|
this.meta[propName] = data[propName];
|
||
|
});
|
||
|
return this.apiOrigin;
|
||
|
}
|
||
|
_disablePageCaching$getter() {
|
||
|
this.disablePageCaching = true;
|
||
|
return this.apiOrigin;
|
||
|
}
|
||
|
static makeAPIListForChildClass(ChildClass) {
|
||
|
//@ts-ignore
|
||
|
ChildClass.API_LIST = TestingUnit.API_LIST.concat((0, delegated_api_1.getDelegatedAPIList)(ChildClass.prototype));
|
||
|
}
|
||
|
static init(ChildClass, ...initProps) {
|
||
|
const fn = (...args) => {
|
||
|
//@ts-ignore
|
||
|
const apiOrigin = new ChildClass(...initProps);
|
||
|
return apiOrigin(...args);
|
||
|
};
|
||
|
const getHandler = () => {
|
||
|
//@ts-ignore
|
||
|
return new ChildClass(...initProps, false);
|
||
|
};
|
||
|
//@ts-ignore
|
||
|
(0, delegated_api_1.delegateAPI)(fn, ChildClass.API_LIST, { getHandler });
|
||
|
return fn;
|
||
|
}
|
||
|
}
|
||
|
exports.default = TestingUnit;
|
||
|
// @ts-ignore
|
||
|
TestingUnit.API_LIST = (0, delegated_api_1.getDelegatedAPIList)(TestingUnit.prototype);
|
||
|
module.exports = exports.default;
|
||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdGluZy11bml0LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2FwaS9zdHJ1Y3R1cmUvdGVzdGluZy11bml0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7O0FBQUEsNERBQW1DO0FBQ25DLG9EQUkwQjtBQUMx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