UNPKG

flagpole

Version:

Simple and fast DOM integration, headless or headful browser, and REST API testing framework.

145 lines 5.83 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const browser_1 = require("./browser"); exports.Browser = browser_1.Browser; const browserresponse_1 = require("./browserresponse"); exports.BrowserResponse = browserresponse_1.BrowserResponse; const cssresponse_1 = require("./cssresponse"); exports.CssResponse = cssresponse_1.CssResponse; const domelement_1 = require("./domelement"); exports.DOMElement = domelement_1.DOMElement; const extjsresponse_1 = require("./extjsresponse"); exports.ExtJSResponse = extjsresponse_1.ExtJSResponse; const htmlresponse_1 = require("./htmlresponse"); exports.HtmlResponse = htmlresponse_1.HtmlResponse; const imageresponse_1 = require("./imageresponse"); exports.ImageResponse = imageresponse_1.ImageResponse; const jpath_1 = require("./jpath"); exports.jPath = jpath_1.jPath; const jsonresponse_1 = require("./jsonresponse"); exports.JsonResponse = jsonresponse_1.JsonResponse; const resourceresponse_1 = require("./resourceresponse"); exports.ResourceResponse = resourceresponse_1.ResourceResponse; const response_1 = require("./response"); exports.ResponseType = response_1.ResponseType; exports.GenericResponse = response_1.GenericResponse; exports.NormalizedResponse = response_1.NormalizedResponse; const scenario_1 = require("./scenario"); exports.Scenario = scenario_1.Scenario; const scriptresponse_1 = require("./scriptresponse"); exports.ScriptResponse = scriptresponse_1.ScriptResponse; const suite_1 = require("./suite"); exports.Suite = suite_1.Suite; const value_1 = require("./value"); exports.Value = value_1.Value; const videoresponse_1 = require("./videoresponse"); exports.VideoResponse = videoresponse_1.VideoResponse; const cheerio = require('cheerio'); var FlagpoleOutput; (function (FlagpoleOutput) { FlagpoleOutput[FlagpoleOutput["console"] = 1] = "console"; FlagpoleOutput[FlagpoleOutput["text"] = 2] = "text"; FlagpoleOutput[FlagpoleOutput["json"] = 3] = "json"; FlagpoleOutput[FlagpoleOutput["html"] = 4] = "html"; FlagpoleOutput[FlagpoleOutput["csv"] = 5] = "csv"; FlagpoleOutput[FlagpoleOutput["tsv"] = 6] = "tsv"; FlagpoleOutput[FlagpoleOutput["psv"] = 7] = "psv"; FlagpoleOutput[FlagpoleOutput["browser"] = 8] = "browser"; })(FlagpoleOutput = exports.FlagpoleOutput || (exports.FlagpoleOutput = {})); class Flagpole { static get output() { return this._output; } static setEnvironment(env) { Flagpole.environment = env; } static getEnvironment() { return Flagpole.environment; } static setOutput(output) { if (typeof output == 'string') { if (Object.keys(FlagpoleOutput).includes(output)) { if (parseInt(output) > 0) { Flagpole._output = parseInt(output); } else { Flagpole._output = FlagpoleOutput[output]; } } } } static exit(passed) { process.exit(passed ? 0 : 1); } static Suite(title) { let suite = new suite_1.Suite(title); return suite; } static isNullOrUndefined(obj) { return (typeof obj === "undefined" || obj === null); } static toType(obj) { if (typeof obj === 'undefined') { return 'undefined'; } else if (obj === null) { return 'null'; } else if (obj === NaN) { return 'nan'; } else if (obj instanceof cheerio) { return 'cheerio'; } else if (!!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function' && typeof obj.catch === 'function') { return 'promise'; } else if (obj && obj.constructor && obj.constructor.name) { return String(obj.constructor.name).toLocaleLowerCase(); } else if (obj && obj.constructor && obj.constructor.toString) { let arr = obj.constructor.toString().match(/function\s*(\w+)/); if (arr && arr.length == 2) { return String(arr[1]).toLocaleLowerCase(); } } const match = ({}).toString.call(obj).match(/\s([a-zA-Z]+)/); return match !== null ? String(match[1]).toLocaleLowerCase() : ''; } static uniqueId() { return '_' + Math.random().toString(36).substr(2, 9); } static openInBrowser(content) { return __awaiter(this, void 0, void 0, function* () { const open = require('open'); const fs = require('fs'); const tmp = require('tmp'); const tmpObj = tmp.fileSync({ postfix: '.html' }); const filePath = tmpObj.name; console.log(filePath); fs.writeFileSync(filePath, content); yield open(filePath); return filePath; }); } } Flagpole.automaticallyPrintToConsole = false; Flagpole.quietMode = false; Flagpole.logOutput = false; Flagpole._output = FlagpoleOutput.console; Flagpole.environment = 'dev'; Flagpole.exitOnDone = false; Flagpole.suite = Flagpole.Suite; exports.Flagpole = Flagpole; //# sourceMappingURL=flagpole.js.map