UNPKG

flagpole

Version:

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

185 lines 7.85 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 command_1 = require("../command"); const flagpole_execution_1 = require("../../flagpole-execution"); const prompts = require("prompts"); const cli_helper_1 = require("../cli-helper"); const cli_1 = require("../cli"); const typesOfTest = [ { title: "REST API/JSON", value: "json", }, { title: "HTML Page/DOM", value: "html", }, { title: "Browser (Puppeteer)", value: "browser", }, { title: "XML", value: "xml", }, { title: "RSS Feed", value: "rss", }, { title: "Atom Feed", value: "atom", }, { title: "ExtJS", value: "extjs", }, { title: "HLS Video Stream", value: "hls", }, ]; const choicesOfType = [ { value: "suite", title: "Suite" }, { value: "scenario", title: "Scenario" }, { value: "env", title: "Environment" }, { value: "tag", title: "Tag" }, ]; class Add extends command_1.Command { constructor() { super(...arguments); this.commandString = "add [type]"; this.description = "add a new suite, scenario, environment or tag"; this.options = [ new command_1.CliCommandOption({ flags: "-l, --label <name>", description: "label to add", }), new command_1.CliCommandOption({ flags: "-u, --url <url>", description: "url to add", }), ]; } action(type, args) { return __awaiter(this, void 0, void 0, function* () { if (!type || !choicesOfType.map((choice) => choice.value).includes(type)) { type = yield askForType(); } if (type == "tag") { promptToAddTag(args); } else if (type == "env") { return args.label && args.url ? addEnv(args.label, args.url) : promptToAddEnv(args); } else if (type == "scenario") { promptToAddScenario(args); } else { promptToAddSuite(args); } }); } } exports.default = Add; const askForType = () => __awaiter(void 0, void 0, void 0, function* () { return (yield prompts(cli_helper_1.promptSelect("thingToAdd", "What do you want to add?", choicesOfType, 0))).thingToAdd; }); function addEnv(name, url) { flagpole_execution_1.FlagpoleExecution.global.config.addEnvironment({ name: name, defaultDomain: url, }); return flagpole_execution_1.FlagpoleExecution.global.config.save(); } function promptToAddEnv(args) { return __awaiter(this, void 0, void 0, function* () { const responses = yield prompts([ cli_helper_1.promptTextName("name", "What do you want to call the environment?", args.label), cli_helper_1.promptUrl("url", "Default Domain (optional)", args.url), ]); return addEnv(responses.name, responses.url); }); } function promptToAddTag(args) { return __awaiter(this, void 0, void 0, function* () { const responses = yield prompts([ cli_helper_1.promptTextName("tag", "Tag to Add", args.label), cli_helper_1.promptMultiSelect("suites", "Suites to apply it to", cli_helper_1.stringArrayToPromptChoices(flagpole_execution_1.FlagpoleExecution.global.config.getSuiteNames().sort())), ]); flagpole_execution_1.FlagpoleExecution.global.config.addTagToSuite(responses.suites, responses.tag); yield flagpole_execution_1.FlagpoleExecution.global.config.save(); }); } function promptToAddScenario(args) { return __awaiter(this, void 0, void 0, function* () { const suites = cli_helper_1.stringArrayToPromptChoices(flagpole_execution_1.FlagpoleExecution.global.config.getSuiteNames().sort()); if ((suites === null || suites === void 0 ? void 0 : suites.length) == 0) { cli_1.Cli.log("", "You have not created any test suites yet. You should do that first.", "", "To add a test suite:", "flagpole add suite", ""); cli_1.Cli.exit(1); } const responses = yield prompts([ cli_helper_1.promptSelect("suite", "What suite do you want to add it to?", suites), cli_helper_1.promptSelect("type", "What type of test is this scenario?", typesOfTest, 0), cli_helper_1.promptTextDescription("scenarioDescription", "Description of Scenario", "Some Other Page Loads"), cli_helper_1.promptTextPath("scenarioPath", "Scenario Start Path", args.url || "/some-other-page"), ]); const suite = flagpole_execution_1.FlagpoleExecution.global.config.getSuite(responses.suite); if (!suite) { return cli_1.Cli.log(`Invalid suite: ${responses.suite}`, "").exit(1); } yield cli_1.addScenario(suite, { description: responses.scenarioDescription, path: responses.scenarioPath, type: responses.type, }); cli_1.Cli.log("Appended new scenario to suite:", suite.getSourcePath(), "", "Scenario added to that suite:", responses.scenarioDescription, ""); }); } function promptToAddSuite(args) { return __awaiter(this, void 0, void 0, function* () { cli_1.Cli.subheader("Add New Suite"); const standardQuestions = yield prompts([ cli_helper_1.promptTextName("suiteName", "Name of Suite", args.label || "smoke"), cli_helper_1.promptTextDescription("suiteDescription", "Description of Suite", "Basic Smoke Test of Site"), cli_helper_1.promptTextDescription("scenarioDescription", "First Scenario", "Homepage Loads"), cli_helper_1.promptSelect("type", "What type of test is this scenario?", typesOfTest, 0), cli_helper_1.promptTextPath("scenarioPath", "Scenario Start Path", args.url || "/"), cli_helper_1.promptList("tags", "Add Tags (Optional, Space Delimited)"), ]); if (standardQuestions.suiteName && standardQuestions.suiteDescription && standardQuestions.scenarioDescription && standardQuestions.type && standardQuestions.scenarioPath) { yield cli_1.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.") .list("Suite file created: " + standardQuestions.suiteName, "Scenario added: " + standardQuestions.scenarioDescription, "Config file updated") .log("") .exit(0); } else { cli_1.Cli.log("", "No suite created.", "").exit(0); } }); } //# sourceMappingURL=add.js.map