flagpole
Version:
Simple and fast DOM integration, headless or headful browser, and REST API testing framework.
196 lines • 6.01 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const scenario_1 = require("./scenario");
const url_1 = require("url");
const flagpolereport_1 = require("./logging/flagpolereport");
const util_1 = require("./util");
const flagpoleexecution_1 = require("./flagpoleexecution");
const suitetaskmanager_1 = require("./suitetaskmanager");
class Suite {
constructor(title) {
this._baseUrl = null;
this._waitToExecute = false;
this._verifySslCert = true;
this.verifyCert = this.verifySslCert;
this._title = title;
if (flagpoleexecution_1.FlagpoleExecution.global.baseDomain) {
this._baseUrl = new url_1.URL(flagpoleexecution_1.FlagpoleExecution.global.baseDomain);
}
this._taskManager = new suitetaskmanager_1.SuiteTaskManager(this);
this._taskManager.finally(() => {
if (flagpoleexecution_1.FlagpoleExecution.global.automaticallyPrintToConsole) {
this.print(flagpoleexecution_1.FlagpoleExecution.global.exitOnDone);
}
else {
flagpoleexecution_1.FlagpoleExecution.global.exitOnDone && util_1.exitProcess(this.hasPassed);
}
});
}
get baseUrl() {
return this._baseUrl;
}
get failCount() {
return this._taskManager.scenariosFailed.length;
}
get waitingToExecuteCount() {
return this._taskManager.scenariosWaitingToExecute.length;
}
get executingCount() {
return this._taskManager.scenariosCurrentlyExcuting.length;
}
get hasPassed() {
return this._taskManager.haveAllPassed;
}
get hasFailed() {
return this._taskManager.haveAnyFailed;
}
get hasExecuted() {
return this._taskManager.hasExecutionBegan;
}
get hasFinished() {
return this._taskManager.hasFinished;
}
get totalDuration() {
return this.totalDuration;
}
get executionDuration() {
return this._taskManager.executionDuration;
}
get title() {
return this._title;
}
get finished() {
return this._taskManager.finished;
}
get executionOptions() {
return flagpoleexecution_1.FlagpoleExecution.global;
}
get scenarios() {
return this._taskManager.scenarios;
}
subscribe(callback) {
this._taskManager.subscribe(callback);
return this;
}
verifySslCert(verify) {
this._verifySslCert = verify;
return this;
}
wait(bool = true) {
this._waitToExecute = bool;
return this;
}
setConcurrencyLimit(maxExecutions) {
this._taskManager.concurrencyLimit = maxExecutions;
return this;
}
print(exitAfterPrint = true) {
const report = new flagpolereport_1.FlagpoleReport(this);
report.print().then(() => {
exitAfterPrint && util_1.exitProcess(this.hasPassed);
});
}
scenario(title, type = "html", opts) {
const scenario = scenario_1.Scenario.create(this, title, type, opts);
scenario.verifyCert(this._verifySslCert);
this._waitToExecute && scenario.wait();
this._taskManager.registerScenario(scenario);
return scenario;
}
json(title) {
return this.scenario(title, "json");
}
image(title) {
return this.scenario(title, "image");
}
video(title) {
return this.scenario(title, "video");
}
html(title) {
return this.scenario(title, "html");
}
stylesheet(title) {
return this.scenario(title, "stylesheet");
}
script(title) {
return this.scenario(title, "script");
}
resource(title) {
return this.scenario(title, "resource");
}
browser(title, opts = {}) {
return this.scenario(title, "browser", opts);
}
extjs(title, opts = {}) {
return this.scenario(title, "extjs", opts);
}
base(url) {
var _a;
let baseUrl = "";
if (typeof url == "string") {
baseUrl = url;
}
else if (typeof url == "function") {
baseUrl = url(this);
}
else if (Object.keys(url).length > 0) {
const env = ((_a = flagpoleexecution_1.FlagpoleExecution.global.environment) === null || _a === void 0 ? void 0 : _a.name) || "";
baseUrl = url[env];
if (!baseUrl) {
baseUrl = url[Object.keys(url)[0]];
}
}
if (baseUrl.length > 0) {
this._baseUrl = new url_1.URL(baseUrl);
}
else {
throw Error("Invalid base url.");
}
return this;
}
execute() {
if (this.hasExecuted) {
throw new Error(`Suite already executed.`);
}
this.scenarios.forEach((scenario) => {
scenario.wait(false);
});
return this;
}
beforeAll(callback, prepend = false) {
this._taskManager.beforeAll(callback, prepend);
return this;
}
beforeEach(callback, prepend = false) {
this._taskManager.beforeEach(callback, prepend);
return this;
}
afterEach(callback, prepend = false) {
this._taskManager.afterEach(callback, prepend);
return this;
}
afterAll(callback, prepend = false) {
this._taskManager.afterAll(callback, prepend);
return this;
}
success(callback, prepend = false) {
this._taskManager.success(callback, prepend);
return this;
}
failure(callback, prepend = false) {
this._taskManager.failure(callback, prepend);
return this;
}
finally(callback, prepend = false) {
this._taskManager.finally(callback, prepend);
return this;
}
promise() {
return new Promise((resolve, reject) => {
this.success(resolve);
this.failure(reject);
});
}
}
exports.Suite = Suite;
//# sourceMappingURL=suite.js.map