UNPKG

flagpole

Version:

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

274 lines 9.83 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 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) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const cli_helper_1 = require("./cli-helper"); const cli_1 = require("./cli"); const prompts = require("prompts"); const typesOfTest = [ { title: "HTML Page", value: "html" }, { title: "REST API (JSON Format)", value: "json", }, { title: "Browser (Puppeteer)", value: "browser", }, ]; const canAdd = ["suite", "scenario", "env", "tag"]; function addSuite() { return __awaiter(this, void 0, void 0, function* () { cli_helper_1.printSubheader("Add New Suite"); if (!cli_1.Cli.config.isValid()) { cli_1.Cli.log("Config file is invalid."); cli_1.Cli.exit(1); } const standardQuestions = yield prompts([ { type: "text", name: "suiteName2", message: "Name of Suite", initial: cli_1.Cli.commandArg2 || "smoke", format: cli_helper_1.trimInput, validate: function (input) { return /^[a-z0-9][a-z0-9/\/_-]{1,62}[a-z0-9]$/i.test(input); }, }, { type: "text", name: "suiteDescription", message: "Description of Suite", initial: "Basic Smoke Test of Site", format: cli_helper_1.trimInput, validate: function (input) { return /^[a-z0-9].{1,63}$/i.test(input); }, }, { type: "text", name: "scenarioDescription", message: "First Scenario", initial: "Homepage Loads", format: cli_helper_1.trimInput, validate: function (input) { return /^[a-z0-9].{1,63}$/i.test(input); }, }, { type: "select", name: "type", message: "What type of test is this scenario?", initial: 0, choices: typesOfTest, }, { type: "text", name: "scenarioPath", message: "Scenario Start Path", initial: "/", format: cli_helper_1.trimInput, validate: function (input) { return /^\/.{0,63}$/i.test(input); }, }, { type: "list", name: "tags", message: "Add Tags (Optional)", initial: "", separator: " ", }, ]); cli_1.Cli.log(""); yield cli_1.Cli.addSuite({ name: standardQuestions.suiteName, description: standardQuestions.suiteDescription, tags: standardQuestions.tags, }, { description: standardQuestions.scenarioDescription, type: standardQuestions.type, path: standardQuestions.scenarioPath, }); cli_1.Cli.log("Created new test suite."); cli_1.Cli.list([ "Suite file created: " + standardQuestions.suiteName, "Scenario added: " + standardQuestions.scenarioDescription, "Config file updated", ]); cli_1.Cli.log(""); cli_1.Cli.exit(0); }); } function addScenario() { return __awaiter(this, void 0, void 0, function* () { cli_helper_1.printSubheader("Add New Scenaio"); const suites = cli_helper_1.stringArrayToPromptChoices(cli_1.Cli.config.getSuiteNames()); if (suites.length == 0) { cli_1.Cli.log(""); cli_1.Cli.log("You have not created any test suites yet. You should do that first."); cli_1.Cli.log(""); cli_1.Cli.log("To add a test suite:"); cli_1.Cli.log("flagpole add suite"); cli_1.Cli.log(""); cli_1.Cli.exit(1); } const responses = yield prompts([ { type: "select", name: "suite", message: "What suite do you want to add it to?", initial: cli_1.Cli.commandArg2 || "", choices: suites, validate: function (input) { return input.length > 0; }, }, { type: "select", name: "type", message: "What type of test is this scenario?", initial: 0, choices: typesOfTest, }, { type: "text", name: "scenarioDescription", message: "Description of Scenario", initial: "Some Other Page Loads", format: cli_helper_1.trimInput, validate: function (input) { return /^[a-z0-9].{1,63}$/i.test(input); }, }, { type: "text", name: "scenarioPath", message: "Scenario Start Path", initial: "/some-other-page", format: cli_helper_1.trimInput, validate: function (input) { return /^\/.{0,63}$/i.test(input); }, }, ]); const suite = cli_1.Cli.config.suites[responses.suite]; if (!suite) { cli_1.Cli.log(`Invalid suite: ${responses.suite}`); cli_1.Cli.log(""); cli_1.Cli.exit(1); } yield cli_1.Cli.addScenario(suite, { description: responses.scenarioDescription, path: responses.scenarioPath, type: responses.type, }); cli_1.Cli.log("Appended new scenario to suite:"); cli_1.Cli.log(suite.getSourcePath()); cli_1.Cli.log(""); cli_1.Cli.log("Scenario added to that suite:"); cli_1.Cli.log(responses.scenarioDescription); cli_1.Cli.log(""); cli_1.Cli.exit(0); }); } function addEnv() { return __awaiter(this, void 0, void 0, function* () { cli_helper_1.printSubheader("Add New Environment"); const responses = yield prompts([ { type: "text", name: "name", message: "What do you want to call the environment?", initial: cli_1.Cli.commandArg2 || "", validate: function (input) { return /^[a-z0-9]{1,12}$/i.test(input); }, }, { type: "text", name: "defaultDomain", message: "Default Domain (optional)", format: cli_helper_1.trimInput, }, ]); cli_1.Cli.config.addEnvironment({ name: responses.name, defaultDomain: responses.defaultDomain, }); yield cli_1.Cli.config.save(); cli_1.Cli.log("Added new environment."); cli_1.Cli.list(["Config file updated"]); cli_1.Cli.log(""); cli_1.Cli.exit(0); }); } function addTag() { return __awaiter(this, void 0, void 0, function* () { const responses = yield prompts([ { type: "text", name: "tag", message: "Tag to Add", validate: (tag) => { return /^[a-z][a-z0-9_-][a-z0-0]+$/i.test(tag) ? true : "Tag should be a single alpha-numeric word"; }, format: cli_helper_1.trimInput, }, { type: "multiselect", name: "suites", min: 1, message: "Suites to apply it to", choices: cli_helper_1.stringArrayToPromptChoices(cli_1.Cli.config.getSuiteNames()), }, ]); responses.suites.forEach((suiteName) => { cli_1.Cli.config.suites[suiteName].addTag(responses.tag); }); cli_1.Cli.config.save(); }); } function add() { return __awaiter(this, void 0, void 0, function* () { cli_1.Cli.hideBanner = true; cli_helper_1.printHeader(); let type = cli_1.Cli.commandArg || ""; if (!canAdd.includes(type)) { type = (yield prompts({ type: "select", name: "thingToAdd", message: "What do you want to add?", choices: [ { value: "suite", title: "Suite" }, { value: "scenario", title: "Scenario" }, { value: "env", title: "Environment" }, { value: "tag", title: "Tag" }, ], })).thingToAdd; } if (type == "scenario") { addScenario(); } else if (type == "env") { addEnv(); } else if (type == "tag") { addTag(); } else { addSuite(); } }); } exports.add = add; //# sourceMappingURL=add.js.map