UNPKG

@hkvstore/taco-cli

Version:

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

121 lines (119 loc) 5.05 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/node.d.ts" /> /// <reference path="../../typings/should.d.ts" /> /// <reference path="../../typings/del.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 */ var del = require("del"); var fs = require("fs"); var os = require("os"); var path = require("path"); var Q = require("q"); var rimraf = require("rimraf"); var kitHelper = require("../cli/utils/kitHelper"); var PlatformHelper = require("../cli/utils/platformHelper"); var RemoteMock = require("./utils/remoteMock"); var TacoUtility = require("taco-utils"); var CommandHelper = require("./utils/commandHelper"); var utils = TacoUtility.UtilHelper; var create = CommandHelper.getCommand("create"); describe("taco PlatformHelper", function () { var tacoHome = path.join(os.tmpdir(), "taco-cli", "PlatformHelper"); var originalCwd; before(function (mocha) { originalCwd = process.cwd(); // Set up mocked out resources process.env["TACO_UNIT_TEST"] = true; // Use a dummy home location so we don't trash any real configurations process.env["TACO_HOME"] = tacoHome; // Force KitHelper to fetch the package fresh kitHelper.kitPackagePromise = null; // Configure a dummy platform "test" to use the mocked out remote server RemoteMock.saveConfig("ios", { host: "localhost", port: 3000, secure: false, mountPoint: "cordova" }).done(function () { mocha(); }, function (err) { mocha(err); }); }); after(function (done) { process.chdir(originalCwd); kitHelper.kitPackagePromise = null; rimraf(tacoHome, done); }); it("should correctly report build locations when --local is specified", function (mocha) { var data = { options: { local: true }, original: ["android", "ios", "--local"], remain: ["android", "ios"] }; PlatformHelper.determinePlatform(data).then(function (platforms) { platforms.forEach(function (platform) { platform.location.should.equal(PlatformHelper.BuildLocationType.Local); }); }).done(function () { mocha(); }, mocha); }); it("should correctly report build locations when --remote is specified", function (mocha) { var data = { options: { remote: true }, original: ["android", "ios", "--remote"], remain: ["android", "ios"] }; PlatformHelper.determinePlatform(data).then(function (platforms) { platforms.forEach(function (platform) { platform.location.should.equal(PlatformHelper.BuildLocationType.Remote); }); }).done(function () { mocha(); }, mocha); }); it("should correctly report build locations when neither --remote nor --local is specified", function (mocha) { var data = { options: {}, original: ["android", "ios"], remain: ["android", "ios"] }; PlatformHelper.determinePlatform(data).then(function (platforms) { platforms.length.should.equal(2); platforms[0].should.eql({ location: PlatformHelper.BuildLocationType.Local, platform: "android" }); platforms[1].should.eql({ location: PlatformHelper.BuildLocationType.Remote, platform: "ios" }); }).done(function () { mocha(); }, mocha); }); it("should correctly report build locations when no platforms are specified", function (mocha) { var data = { options: {}, original: [], remain: [] }; utils.createDirectoryIfNecessary(tacoHome); process.chdir(tacoHome); Q.denodeify(del)("example").then(function () { return create.run(["example"]); }).then(function () { process.chdir(path.join(tacoHome, "example")); fs.mkdirSync(path.join("platforms", "android")); }).then(function () { return PlatformHelper.determinePlatform(data); }).then(function (platforms) { platforms.length.should.equal(2); platforms[0].should.eql({ location: PlatformHelper.BuildLocationType.Remote, platform: "ios" }); platforms[1].should.eql({ location: PlatformHelper.BuildLocationType.Local, platform: "android" }); }).done(function () { mocha(); }, mocha); }); }); //# sourceMappingURL=platformHelper.js.map