UNPKG

@hkvstore/taco-cli

Version:

taco-cli is a command-line interface for rapid Apache Cordova development (forked from Microsoft taco-cli)

341 lines (339 loc) 16.9 kB
// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for details. /// <reference path="../../typings/mocha.d.ts"/> /// <reference path="../../typings/should.d.ts"/> /// <reference path="../../typings/tacoUtils.d.ts"/> /// <reference path="../../typings/tacoTestsUtils.d.ts"/> "use strict"; /* tslint:disable:no-var-requires */ // var require needed for should module to work correctly // Note not import: We don't want to refer to shouldModule, but we need the require to occur since it modifies the prototype of Object. var shouldModule = require("should"); /* tslint:enable:no-var-requires */ /* tslint:disable:no-var-requires */ // Special case to allow using color package with index signature for style rules var colors = require("colors/safe"); var tacoTestsUtils = require("taco-tests-utils"); var CommandHelper = require("./utils/commandHelper"); var MemoryStream = tacoTestsUtils.MemoryStream; describe("help for a command", function () { var help = CommandHelper.getCommand("help"); // because of function overloading assigning "(buffer: string, cb?: Function) => boolean" as the type for // stdoutWrite just doesn't work var stdoutWrite = process.stdout.write; // We save the original implementation, so we can restore it later var memoryStdout; var previous; function helpRun(command) { return help.run([command]); } function testHelpForCommand(command, expectedLines) { return helpRun(command).then(function () { var expected = expectedLines.join("\n"); var actual = colors.strip(memoryStdout.contentsAsText()); // The colors add extra characters actual = actual.replace(/ (\.+) ?\n +/gm, " $1 "); // We undo the word-wrapping actual = actual.replace(/ +$/gm, ""); // Remove useless spaces at the end of a line actual.should.be.equal(expected); }); } before(function () { previous = process.env["TACO_UNIT_TEST"]; process.env["TACO_UNIT_TEST"] = true; }); after(function () { // We just need to reset the stdout just once, after all the tests have finished process.stdout.write = stdoutWrite; process.env["TACO_UNIT_TEST"] = previous; }); beforeEach(function () { memoryStdout = new MemoryStream; // Each individual test gets a new and empty console process.stdout.write = memoryStdout.writeAsFunction(); // We'll be printing into an "in-memory" console, so we can test the output }); it("prints the help for create", function () { return testHelpForCommand("create", [ "", "CommandCreateDescription", "", " taco create <PATH> [ID [NAME [CONFIG]]] [--OPTIONS]", "", "CommandHelpUsageParameters", " PATH ............................ CommandCreateArgsPath", " ID .............................. CommandCreateArgsId", " NAME ............................ CommandCreateArgsName", " CONFIG .......................... CommandCreateArgsConfig", "CommandHelpUsageOptions", " --kit [NAME] ................. CommandCreateOptionsKit", " --template <NAME|GIT-URL> .... CommandCreateOptionsTemplate", " --cordova <VERSION> .......... CommandCreateOptionsCordova", " --copy-from|src <PATH> ....... CommandCreateOptionsCopy", " --link-to <PATH> ............. CommandCreateOptionsLinkto", ""]); }); it("prints the help for templates", function () { return testHelpForCommand("templates", [ "", "CommandTemplatesDescription", "", " taco templates", "", ""]); }); it("prints the help for templates using the template alias", function () { return testHelpForCommand("template", [ "", "CommandTemplatesDescription", "", " taco templates", "", ""]); }); it("prints the help for remote", function () { return testHelpForCommand("remote", [ "", "CommandRemoteDescription", "", " taco remote COMMAND", "", "CommandHelpUsageParameters", " COMMAND .............. CommandRemoteSubcommandDescription", " add <PLATFORM> ....... CommandRemoteAddSubcommandDescription", " remove <PLATFORM> .... CommandRemoteRemoveSubcommandDescription", " list ................. CommandRemoteListSubcommandDescription", "CommandHelpUsageAliases", " rm -> remove", " ls -> list", ""]); }); it("prints the help for platform", function () { return testHelpForCommand("platform", [ "", "CommandPlatformDescription", "", " taco platform [COMMAND] [--OPTIONS]", "", "CommandHelpUsageParameters", " add <PLAT-SPEC> ....... CommandPlatformAddSubcommandDescription", " --usegit ......... CommandPlatformUsegitDescription", " --save ........... CommandPlatformSaveAddDescription", " --link ........... CommandPlatformLinkDescription", " remove <PLATFORM> ..... CommandPlatformRemoveSubcommandDescription", " --save ........... CommandPlatformSaveRemoveDescription", " list .................. CommandPlatformListSubcommandDescription", " update <PLAT-SPEC> .... CommandPlatformUpdateSubcommandDescription", " --usegit ......... CommandPlatformUsegitDescription", " --save ........... CommandPlatformSaveUpdateDescription", " check ................. CommandPlatformCheckSubcommandDescription", "CommandHelpUsageAliases", " rm -> remove", " ls -> list", ""]); }); it("prints the help for platform using the platforms alias", function () { return testHelpForCommand("platforms", [ "", "CommandPlatformDescription", "", " taco platform [COMMAND] [--OPTIONS]", "", "CommandHelpUsageParameters", " add <PLAT-SPEC> ....... CommandPlatformAddSubcommandDescription", " --usegit ......... CommandPlatformUsegitDescription", " --save ........... CommandPlatformSaveAddDescription", " --link ........... CommandPlatformLinkDescription", " remove <PLATFORM> ..... CommandPlatformRemoveSubcommandDescription", " --save ........... CommandPlatformSaveRemoveDescription", " list .................. CommandPlatformListSubcommandDescription", " update <PLAT-SPEC> .... CommandPlatformUpdateSubcommandDescription", " --usegit ......... CommandPlatformUsegitDescription", " --save ........... CommandPlatformSaveUpdateDescription", " check ................. CommandPlatformCheckSubcommandDescription", "CommandHelpUsageAliases", " rm -> remove", " ls -> list", ""]); }); it("prints the help for plugin", function () { return testHelpForCommand("plugin", [ "", "CommandPluginDescription", "", " taco plugin [COMMAND] [--OPTIONS]", "", "CommandHelpUsageParameters", " add <PLAT-SPEC> .................... CommandPluginAddSubcommandDescription", " [--searchpath <DIRECTORY>] .... CommandPluginSearchPathDescription", " [--noregistry] ................ CommandPluginNoRegistryDescription", " [--link] ...................... CommandPluginLinkDescription", " [--save] ...................... CommandPluginSaveAddDescription", " [--shrinkwrap] ................ CommandPluginShrinkwrapDescription", " [--browserify] ................ CommandPluginBrowserifyDescription", " remove <PLUGINID> [...] ............ CommandPluginRemoveSubcommandDescription", " [--save] ...................... CommandPluginSaveRemoveDescription", " list ............................... CommandPluginListSubcommandDescription", " search ............................. CommandPluginSearchSubcommandDescription", "CommandHelpUsageAliases", " rm -> remove", " ls -> list", ""]); }); it("prints the help for plugin using the plugins alias", function () { return testHelpForCommand("plugins", [ "", "CommandPluginDescription", "", " taco plugin [COMMAND] [--OPTIONS]", "", "CommandHelpUsageParameters", " add <PLAT-SPEC> .................... CommandPluginAddSubcommandDescription", " [--searchpath <DIRECTORY>] .... CommandPluginSearchPathDescription", " [--noregistry] ................ CommandPluginNoRegistryDescription", " [--link] ...................... CommandPluginLinkDescription", " [--save] ...................... CommandPluginSaveAddDescription", " [--shrinkwrap] ................ CommandPluginShrinkwrapDescription", " [--browserify] ................ CommandPluginBrowserifyDescription", " remove <PLUGINID> [...] ............ CommandPluginRemoveSubcommandDescription", " [--save] ...................... CommandPluginSaveRemoveDescription", " list ............................... CommandPluginListSubcommandDescription", " search ............................. CommandPluginSearchSubcommandDescription", "CommandHelpUsageAliases", " rm -> remove", " ls -> list", ""]); }); it("prints the help for kit", function () { return testHelpForCommand("kit", [ "", "CommandKitDescription", "", " taco kit [COMMAND] [--OPTIONS]", "", "CommandHelpUsageParameters", " list ........................ CommandKitListSubcommandDescription", " --json <PATH> .......... CommandKitJsonOptionDescription", " --kit <KIT-ID> ......... CommandKitOptionKitDescription", " select ...................... CommandKitSelectSubcommandDescription", " --kit <KIT-ID> ......... CommandKitSelectOptionKitDescription", " --cordova <VERSION> .... CommandKitSelectOptionCordovaDescription", "CommandHelpUsageExamples", " * TacoKitListExample", "", " taco kit list --kit tacokit@2.0.0", "", " * TacoKitSelectExample1", "", " taco kit select --kit tacokit@2.0.0", "", " * TacoKitSelectExample2", "", " taco kit select --cordova 5.2.0", "", "CommandHelpUsageNotes", " * TacoKitNotes", "", ""]); }); it("prints the help for build", function () { return testHelpForCommand("build", [ "", "CommandBuildDescription", "", " taco build [PLATFORM] [--OPTIONS]", "", "CommandHelpUsageParameters", " PLATFORM .............. CommandBuildPlatformDescription", "CommandHelpUsageOptions", " --remote ........... CommandBuildRemoteDescription", " --local ............ CommandBuildLocalDescription", " --clean ............ CommandBuildCleanDescription", " --debug ............ CommandBuildDebugDescription", " --release .......... CommandBuildReleaseDescription", " --device ........... CommandBuildDeviceDescription", " --emulator ......... CommandBuildEmulatorDescription", " --target=TARGET .... CommandBuildTargetDescription", ""]); }); it("prints the help for run", function () { return testHelpForCommand("run", [ "", "CommandRunDescription", "", " taco run [PLATFORM] [--OPTIONS]", "", "CommandHelpUsageParameters", " PLATFORM .................... CommandRunPlatformDescription", "CommandHelpUsageOptions", " --remote ................. CommandRunRemoteDescription", " --local .................. CommandRunLocalDescription", " --nobuild ................ CommandRunNobuildDescription", " --debuginfo .............. CommandRunDebuginfoDescription", " --debug .................. CommandRunDebugDescription", " --release ................ CommandRunReleaseDescription", " --device ................. CommandRunDeviceDescription", " --emulator ............... CommandRunEmulatorDescription", " --target=TARGET .......... CommandRunTargetDescription", " --list ................... CommandRunListDescription", " --livereload ............. CommandRunLiveReloadDescription", " --tunnel ............ CommandRunTunnelDescription", " --ignore=PATTERN .... CommandRunIgnoreDescription", " --devicesync ............. CommandRunDeviceSyncDescription", " --tunnel ............ CommandRunTunnelDescription", " --ignore=PATTERN .... CommandRunIgnoreDescription", "CommandHelpUsageExamples", " * TacoRunLivereloadExample1", "", " taco run --livereload --ignore=/**/*.css", "", " * TacoRunLivereloadExample2", "", " taco run --livereload --tunnel", "", ""]); }); it("prints the help for install-reqs", function () { return testHelpForCommand("install-reqs", [ "", "CommandInstallReqsDescription", "", " taco install-reqs [PLATFORM] [--OPTIONS]", "", "CommandHelpUsageParameters", " [PLATFORM] .......... CommandInstallReqsPlatformDescription", "CommandHelpUsageOptions", " --no-prompt ...... CommandInstallReqsNoPromptDescription", ""]); }); it("prints the help for emulate", function () { return testHelpForCommand("emulate", [ "", "CommandEmulateDescription", "", " taco emulate [PLATFORM] [--OPTIONS]", "", "CommandHelpUsageParameters", " PLATFORM .................... CommandRunPlatformDescription", "CommandHelpUsageOptions", " --remote ................. CommandRunRemoteDescription", " --local .................. CommandRunLocalDescription", " --nobuild ................ CommandRunNobuildDescription", " --debuginfo .............. CommandRunDebuginfoDescription", " --debug .................. CommandRunDebugDescription", " --release ................ CommandRunReleaseDescription", " --target=TARGET .......... CommandRunTargetDescription", " --livereload ............. CommandRunLiveReloadDescription", " --tunnel ............ CommandRunTunnelDescription", " --ignore=PATTERN .... CommandRunIgnoreDescription", " --devicesync ............. CommandRunDeviceSyncDescription", " --tunnel ............ CommandRunTunnelDescription", " --ignore=PATTERN .... CommandRunIgnoreDescription", "CommandHelpUsageExamples", " * TacoRunLivereloadExample1", "", " taco emulate --livereload --ignore=/**/*.css", "", " * TacoRunLivereloadExample2", "", " taco emulate --livereload --tunnel", "", ""]); }); }); //# sourceMappingURL=help.js.map