Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 3A8BC200CBC for ; Tue, 20 Jun 2017 19:46:44 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 39743160BCC; Tue, 20 Jun 2017 17:46:44 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id AE03B160BE1 for ; Tue, 20 Jun 2017 19:46:42 +0200 (CEST) Received: (qmail 36227 invoked by uid 500); 20 Jun 2017 17:46:41 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 36218 invoked by uid 99); 20 Jun 2017 17:46:41 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 20 Jun 2017 17:46:41 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 3E182E01C3; Tue, 20 Jun 2017 17:46:41 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: purplecabbage@apache.org To: commits@cordova.apache.org Date: Tue, 20 Jun 2017 17:46:43 -0000 Message-Id: <02d030c8dcfb4563bec85aa5ab68856c@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [3/4] cordova-cli git commit: adjusted tests to call cordova instead of cordova.raw, added tests to compare cordova.raw and cordova, changed some console.log to logger.log; help module returns help text and does not print it, this is to make testing easi archived-at: Tue, 20 Jun 2017 17:46:44 -0000 adjusted tests to call cordova instead of cordova.raw, added tests to compare cordova.raw and cordova, changed some console.log to logger.log; help module returns help text and does not print it, this is to make testing easier and not have it spit all over jasmine output. various minor refactors, removed some un-needed promises Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/10aec775 Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/10aec775 Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/10aec775 Branch: refs/heads/master Commit: 10aec77569e47e43fbcfa0551b8557f6d5dffdf7 Parents: 417504e Author: Jesse MacFadyen Authored: Mon Jun 19 22:22:13 2017 -0700 Committer: Jesse MacFadyen Committed: Tue Jun 20 10:46:18 2017 -0700 ---------------------------------------------------------------------- .travis.yml | 6 +- appveyor.yml | 6 +- spec/cli.spec.js | 193 ++++++++++++++++++++++++++----------------------- spec/help.spec.js | 36 ++------- src/cli.js | 33 +++++---- src/help.js | 8 +- 6 files changed, 140 insertions(+), 142 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/10aec775/.travis.yml ---------------------------------------------------------------------- diff --git a/.travis.yml b/.travis.yml index 07d3865..30ede3b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ git: node_js: - "4" - "6" - + before_install: - npm cache clean -f - npm install -g npm@2 @@ -20,11 +20,11 @@ install: - npm link - cd .. - git clone https://github.com/apache/cordova-lib --depth 10 - - cd cordova-lib/cordova-lib + - cd cordova-lib/ - npm install - npm link cordova-js - npm link - - cd ../../cordova-cli + - cd ../cordova-cli - npm link cordova-lib - npm install # # Workaround for npm/npm#10343 http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/10aec775/appveyor.yml ---------------------------------------------------------------------- diff --git a/appveyor.yml b/appveyor.yml index 6735734..bf5c6f3 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -19,11 +19,11 @@ install: - npm link - cd .. - git clone https://github.com/apache/cordova-lib --depth 10 - - cd cordova-lib/cordova-lib + - cd cordova-lib - npm install - npm link cordova-js - npm link - - cd ../../cordova-cli + - cd ../cordova-cli - npm link cordova-lib - npm install # # Workaround for npm/npm#10343 @@ -35,7 +35,7 @@ install: # - npm install # - npm link ../../cordova-js # - cd ../../cordova-cli - + build: off test_script: http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/10aec775/spec/cli.spec.js ---------------------------------------------------------------------- diff --git a/spec/cli.spec.js b/spec/cli.spec.js index fba7bb2..60cebf2 100644 --- a/spec/cli.spec.js +++ b/spec/cli.spec.js @@ -61,7 +61,7 @@ describe("cordova cli", function () { describe("options", function () { describe("version", function () { var version = require("../package").version; - + it("Test#001 : will spit out the version with -v", function (done) { cli(["node", "cordova", "-v"], function() { expect(logger.results.calls.mostRecent().args[0]).toMatch(version); @@ -69,7 +69,7 @@ describe("cordova cli", function () { }); }, 60000); - it("Test#002 : will spit out the version with --version", function (done) { + it("Test#002 : will spit out the version with --version", function (done) { cli(["node", "cordova", "--version"], function () { expect(logger.results.calls.mostRecent().args[0]).toMatch(version); done(); @@ -87,60 +87,60 @@ describe("cordova cli", function () { describe("Test#004 : project commands other than plugin and platform", function () { beforeEach(function () { - spyOn(cordova.raw, "build").and.returnValue(Q()); + spyOn(cordova, "build").and.returnValue(Q()); }); it("Test#005 : will call command with all arguments passed through", function (done) { cli(["node", "cordova", "build", "blackberry10", "--", "-k", "abcd1234"], function () { - expect(cordova.raw.build).toHaveBeenCalledWith({ platforms: ['blackberry10'], options: { argv: ['-k', 'abcd1234'], fetch: true }, verbose: false, silent: false, browserify: false, fetch: true, nohooks: [ ], searchpath: undefined }); + expect(cordova.build).toHaveBeenCalledWith({ platforms: ['blackberry10'], options: { argv: ['-k', 'abcd1234'], fetch: true }, verbose: false, silent: false, browserify: false, fetch: true, nohooks: [ ], searchpath: undefined }); done(); }); }, 60000); it("Test#006 : will consume the first instance of -d", function (done) { cli(["node", "cordova", "-d", "build", "blackberry10", "--", "-k", "abcd1234", "-d"], function () { - expect(cordova.raw.build).toHaveBeenCalledWith({ platforms: ['blackberry10'], options: { verbose: true, argv: ['-k', 'abcd1234', '-d'], fetch: true }, verbose: true, silent: false, browserify: false, fetch: true, nohooks: [ ], searchpath: undefined }); + expect(cordova.build).toHaveBeenCalledWith({ platforms: ['blackberry10'], options: { verbose: true, argv: ['-k', 'abcd1234', '-d'], fetch: true }, verbose: true, silent: false, browserify: false, fetch: true, nohooks: [ ], searchpath: undefined }); done(); }); }); it("Test#007 : will consume the first instance of --verbose", function (done) { cli(["node", "cordova", "--verbose", "build", "blackberry10", "--", "-k", "abcd1234", "--verbose"], function () { - expect(cordova.raw.build).toHaveBeenCalledWith({ platforms: ['blackberry10'], options: { verbose: true, argv: ['-k', 'abcd1234', '--verbose'], fetch: true }, verbose: true, silent: false, browserify: false, fetch: true, nohooks: [ ], searchpath: undefined }); + expect(cordova.build).toHaveBeenCalledWith({ platforms: ['blackberry10'], options: { verbose: true, argv: ['-k', 'abcd1234', '--verbose'], fetch: true }, verbose: true, silent: false, browserify: false, fetch: true, nohooks: [ ], searchpath: undefined }); done(); }); }); it("Test#008 : will consume the first instance of either --verbose or -d", function (done) { cli(["node", "cordova", "--verbose", "build", "blackberry10", "--", "-k", "abcd1234", "-d"], function () { - expect(cordova.raw.build).toHaveBeenCalledWith({ platforms: ['blackberry10'], options: { verbose: true, argv: ['-k', 'abcd1234', '-d'], fetch: true }, verbose: true, silent: false, browserify: false, fetch: true, nohooks: [ ], searchpath: undefined }); + expect(cordova.build).toHaveBeenCalledWith({ platforms: ['blackberry10'], options: { verbose: true, argv: ['-k', 'abcd1234', '-d'], fetch: true }, verbose: true, silent: false, browserify: false, fetch: true, nohooks: [ ], searchpath: undefined }); done(); }); }); it("Test#009 : will consume the first instance of either --verbose or -d", function (done) { cli(["node", "cordova", "-d", "build", "blackberry10", "--", "-k", "abcd1234", "--verbose"], function () { - expect(cordova.raw.build).toHaveBeenCalledWith({ platforms: ['blackberry10'], options: { verbose: true, argv: ['-k', 'abcd1234', '--verbose'], fetch: true }, verbose: true, silent: false, browserify: false, fetch: true, nohooks: [ ], searchpath: undefined }); + expect(cordova.build).toHaveBeenCalledWith({ platforms: ['blackberry10'], options: { verbose: true, argv: ['-k', 'abcd1234', '--verbose'], fetch: true }, verbose: true, silent: false, browserify: false, fetch: true, nohooks: [ ], searchpath: undefined }); done(); }); }); it("Test#010 : will consume the first instance of --silent", function (done) { cli(["node", "cordova", "--silent", "build", "blackberry10", "--", "-k", "abcd1234", "--silent"], function () { - expect(cordova.raw.build).toHaveBeenCalledWith({ platforms: ['blackberry10'], options: { silent: true, argv: ['-k', 'abcd1234', '--silent'], fetch: true }, verbose: false, silent: true, browserify: false, fetch: true, nohooks: [ ], searchpath: undefined }); + expect(cordova.build).toHaveBeenCalledWith({ platforms: ['blackberry10'], options: { silent: true, argv: ['-k', 'abcd1234', '--silent'], fetch: true }, verbose: false, silent: true, browserify: false, fetch: true, nohooks: [ ], searchpath: undefined }); done(); }); }); }); - + describe("create", function () { beforeEach(function () { - spyOn(cordova.raw, "create").and.returnValue(Q()); + spyOn(cordova, "create").and.returnValue(Q()); }); - it("Test#011 : calls cordova raw create", function (done) { + it("Test#011 : calls cordova create", function (done) { cli(["node", "cordova", "create", "a", "b", "c", "--link-to", "c:\\personalWWW"], function () { - expect(cordova.raw.create).toHaveBeenCalledWith("a", "b", "c", jasmine.any(Object), jasmine.any(Object)); + expect(cordova.create).toHaveBeenCalledWith("a", "b", "c", jasmine.any(Object), jasmine.any(Object)); done(); }); }); @@ -148,17 +148,17 @@ describe("cordova cli", function () { describe("plugin", function () { beforeEach(function () { - spyOn(cordova.raw, "plugin").and.returnValue(Q()); + spyOn(cordova, "plugin").and.returnValue(Q()); }); it("Test#012 : will pass variables", function (done) { cli(["node", "cordova", "plugin", "add", "facebook", "--variable", "FOO=foo"], function () { - expect(cordova.raw.plugin).toHaveBeenCalledWith( + expect(cordova.plugin).toHaveBeenCalledWith( "add", ["facebook"], jasmine.any(Object) ); - var opts = cordova.raw.plugin.calls.argsFor(0)[2]; + var opts = cordova.plugin.calls.argsFor(0)[2]; expect(opts.cli_variables.FOO).toBe('foo'); done(); }); @@ -166,12 +166,12 @@ describe("cordova cli", function () { it("Test#013 : will support variables with =", function (done) { cli(["node", "cordova", "plugin", "add", "facebook", "--variable", "MOTO=DELTA=WAS=HERE"], function () { - expect(cordova.raw.plugin).toHaveBeenCalledWith( + expect(cordova.plugin).toHaveBeenCalledWith( "add", ["facebook"], jasmine.any(Object) ); - var opts = cordova.raw.plugin.calls.argsFor(0)[2]; + var opts = cordova.plugin.calls.argsFor(0)[2]; expect(opts.cli_variables.MOTO).toBe('DELTA=WAS=HERE'); done(); }); @@ -179,12 +179,12 @@ describe("cordova cli", function () { it("Test#014 : will pass hook patterns to suppress", function (done) { cli(["node", "cordova", "plugin", "add", "facebook", "--nohooks", "before_plugin_add"], function () { - expect(cordova.raw.plugin).toHaveBeenCalledWith( + expect(cordova.plugin).toHaveBeenCalledWith( "add", ["facebook"], jasmine.any(Object) ); - var opts = cordova.raw.plugin.calls.argsFor(0)[2]; + var opts = cordova.plugin.calls.argsFor(0)[2]; expect(opts.nohooks[0]).toBe("before_plugin_add"); done(); }); @@ -192,12 +192,12 @@ describe("cordova cli", function () { it("Test #015 : (add) will pass save:true", function (done) { cli(["node", "cordova", "plugin", "add", "device"], function () { - expect(cordova.raw.plugin).toHaveBeenCalledWith( + expect(cordova.plugin).toHaveBeenCalledWith( "add", ["device"], jasmine.any(Object) ); - var opts = cordova.raw.plugin.calls.argsFor(0)[2]; + var opts = cordova.plugin.calls.argsFor(0)[2]; expect(opts.save).toBe(true); done(); }); @@ -205,12 +205,12 @@ describe("cordova cli", function () { it("Test #016 : (add) will pass save:false", function (done) { cli(["node", "cordova", "plugin", "add", "device", "--nosave"], function () { - expect(cordova.raw.plugin).toHaveBeenCalledWith( + expect(cordova.plugin).toHaveBeenCalledWith( "add", ["device"], jasmine.any(Object) ); - var opts = cordova.raw.plugin.calls.argsFor(0)[2]; + var opts = cordova.plugin.calls.argsFor(0)[2]; expect(opts.save).toBe(false); done(); }); @@ -218,12 +218,12 @@ describe("cordova cli", function () { it("Test #017: (remove) will pass save:false", function (done) { cli(["node", "cordova", "plugin", "remove", "device", "--nosave"], function () { - expect(cordova.raw.plugin).toHaveBeenCalledWith( + expect(cordova.plugin).toHaveBeenCalledWith( "remove", ["device"], jasmine.any(Object) ); - var opts = cordova.raw.plugin.calls.argsFor(0)[2]; + var opts = cordova.plugin.calls.argsFor(0)[2]; expect(opts.save).toBe(false); done(); }); @@ -231,12 +231,12 @@ describe("cordova cli", function () { it("Test #018 : (remove) autosave is default and will pass save:true", function (done) { cli(["node", "cordova", "plugin", "remove", "device"], function () { - expect(cordova.raw.plugin).toHaveBeenCalledWith( + expect(cordova.plugin).toHaveBeenCalledWith( "remove", ["device"], jasmine.any(Object) ); - var opts = cordova.raw.plugin.calls.argsFor(0)[2]; + var opts = cordova.plugin.calls.argsFor(0)[2]; expect(opts.save).toBe(true); done(); }); @@ -244,12 +244,12 @@ describe("cordova cli", function () { it("Test #019 : (add) will pass fetch:false", function (done) { cli(["node", "cordova", "plugin", "add", "device", "--nofetch"], function () { - expect(cordova.raw.plugin).toHaveBeenCalledWith( + expect(cordova.plugin).toHaveBeenCalledWith( "add", ["device"], jasmine.any(Object) ); - var opts = cordova.raw.plugin.calls.argsFor(0)[2]; + var opts = cordova.plugin.calls.argsFor(0)[2]; expect(opts.fetch).toBe(false); done(); }); @@ -257,12 +257,12 @@ describe("cordova cli", function () { it("Test #020 : (add) fetch is true by default and will pass fetch:true", function (done) { cli(["node", "cordova", "plugin", "add", "device"], function () { - expect(cordova.raw.plugin).toHaveBeenCalledWith( + expect(cordova.plugin).toHaveBeenCalledWith( "add", ["device"], jasmine.any(Object) ); - var opts = cordova.raw.plugin.calls.argsFor(0)[2]; + var opts = cordova.plugin.calls.argsFor(0)[2]; expect(opts.fetch).toBe(true); done(); }); @@ -270,12 +270,12 @@ describe("cordova cli", function () { it("Test #021 : (remove) fetch is true by default and will pass fetch:true", function (done) { cli(["node", "cordova", "plugin", "remove", "device"], function () { - expect(cordova.raw.plugin).toHaveBeenCalledWith( + expect(cordova.plugin).toHaveBeenCalledWith( "remove", ["device"], jasmine.any(Object) ); - var opts = cordova.raw.plugin.calls.argsFor(0)[2]; + var opts = cordova.plugin.calls.argsFor(0)[2]; expect(opts.fetch).toBe(true); done(); }); @@ -283,18 +283,18 @@ describe("cordova cli", function () { it("Test #022 : (remove) will pass fetch:false", function (done) { cli(["node", "cordova", "plugin", "remove", "device", "--nofetch"], function () { - expect(cordova.raw.plugin).toHaveBeenCalledWith( + expect(cordova.plugin).toHaveBeenCalledWith( "remove", ["device"], jasmine.any(Object) ); - var opts = cordova.raw.plugin.calls.argsFor(0)[2]; + var opts = cordova.plugin.calls.argsFor(0)[2]; expect(opts.fetch).toBe(false); done(); }); }); }); - + describe("telemetry", function() { it("Test#023 : skips prompt when user runs 'cordova telemetry X'", function(done) { var wasPromptShown = false; @@ -307,138 +307,130 @@ describe("cordova cli", function () { expect(wasPromptShown).toBeFalsy(); done(); }); - }); + }); }); - + it("Test#024 : is NOT collected when user runs 'cordova telemetry on' while NOT opted-in", function(done) { spyOn(telemetry, "isOptedIn").and.returnValue(false); spyOn(telemetry, "isCI").and.returnValue(false); - spyOn(telemetry, "track"); - + cli(["node", "cordova", "telemetry", "on"], function () { expect(telemetry.track).not.toHaveBeenCalled(); done(); }); }); - + it("Test#025 : is collected when user runs 'cordova telemetry off' while opted-in", function(done) { spyOn(telemetry, "isOptedIn").and.returnValue(true); spyOn(telemetry, "isCI").and.returnValue(false); - spyOn(telemetry, "track"); - + cli(["node", "cordova", "telemetry", "off"], function () { expect(telemetry.track).toHaveBeenCalledWith("telemetry", "off", "via-cordova-telemetry-cmd", "successful"); done(); }); }); - + it("Test#026 : tracks platforms/plugins subcommands", function(done) { spyOn(telemetry, "isOptedIn").and.returnValue(true); spyOn(telemetry, "isCI").and.returnValue(false); spyOn(telemetry, "hasUserOptedInOrOut").and.returnValue(true); - spyOn(cordova.raw, "platform").and.returnValue(Q()); - + spyOn(cordova, "platform").and.returnValue(Q()); spyOn(telemetry, "track"); - + cli(["node", "cordova", "platform", "add", "ios"], function () { expect(telemetry.track).toHaveBeenCalledWith("platform", "add", "successful"); done(); }); }); - + it("Test#027 : shows prompt if user neither opted in or out yet", function(done) { - spyOn(cordova.raw, "prepare").and.returnValue(Q()); + spyOn(cordova, "prepare").and.returnValue(Q()); spyOn(telemetry, "hasUserOptedInOrOut").and.returnValue(false); - spyOn(telemetry, "isCI").and.returnValue(false); spyOn(telemetry, "isNoTelemetryFlag").and.returnValue(false); spyOn(telemetry, "showPrompt").and.returnValue(Q(false)); - + cli(["node", "cordova", "prepare"], function () { expect(telemetry.showPrompt).toHaveBeenCalled(); done(); }); }); - // ToDO: Figure out a way to modify default timeout - // ... Timeout overriding isn't working anymore due to a bug with jasmine-node - xit("Test#028 : opts-out if prompt times out AND it tracks opt-out", function(done) { + // note: we override telemetry timeout here so we don't need to wait 30 seconds + it("Test#028 : opts-out if prompt times out AND it tracks opt-out", function(done) { // Remove any optOut settings that might have been saved // ... and force prompt to be shown telemetry.clear(); spyOn(telemetry, "hasUserOptedInOrOut").and.returnValue(false); spyOn(telemetry, "isCI").and.returnValue(false); spyOn(telemetry, "track"); - + + telemetry.timeoutInSecs = 1; cli(["node", "cordova", "--version"], function () { expect(telemetry.isOptedIn()).toBeFalsy(); expect(telemetry.track).toHaveBeenCalledWith("telemetry", "off", "via-cli-prompt-choice", "successful"); done(); }); - }/*, 45000*/); - + }); + it("Test#029 : is NOT collected in CI environments and doesn't prompt", function(done) { spyOn(telemetry, "hasUserOptedInOrOut").and.returnValue(true); spyOn(telemetry, "isOptedIn").and.returnValue(true); spyOn(telemetry, "isCI").and.returnValue(true); - spyOn(telemetry, "showPrompt"); spyOn(telemetry, "track"); - + cli(["node", "cordova", "--version"], function () { expect(telemetry.showPrompt).not.toHaveBeenCalled(); expect(telemetry.track).not.toHaveBeenCalled(); done(); }); }); - + it("Test#030 : is NOT collected when --no-telemetry flag found and doesn't prompt", function(done) { spyOn(telemetry, "hasUserOptedInOrOut").and.returnValue(false); spyOn(telemetry, "isOptedIn").and.returnValue(true); spyOn(telemetry, "isCI").and.returnValue(false); - spyOn(telemetry, "showPrompt"); spyOn(telemetry, "track"); - + cli(["node", "cordova", "--version", "--no-telemetry"], function () { expect(telemetry.showPrompt).not.toHaveBeenCalled(); expect(telemetry.track).not.toHaveBeenCalled(); done(); }); }); - + it("Test#031 : is NOT collected if user opted out", function(done) { spyOn(telemetry, "hasUserOptedInOrOut").and.returnValue(true); spyOn(telemetry, "isOptedIn").and.returnValue(false); spyOn(telemetry, "isCI").and.returnValue(false); - spyOn(telemetry, "showPrompt"); spyOn(telemetry, "track"); - + cli(["node", "cordova", "--version"], function () { expect(telemetry.showPrompt).not.toHaveBeenCalled(); expect(telemetry.track).not.toHaveBeenCalled(); done(); }); }); - + it("Test#032 : is collected if user opted in", function(done) { spyOn(telemetry, "hasUserOptedInOrOut").and.returnValue(true); spyOn(telemetry, "isOptedIn").and.returnValue(true); spyOn(telemetry, "isCI").and.returnValue(false); - spyOn(telemetry, "showPrompt"); spyOn(telemetry, "track"); - + cli(["node", "cordova", "--version"], function () { expect(telemetry.showPrompt).not.toHaveBeenCalled(); expect(telemetry.track).toHaveBeenCalled(); done(); }); }); - + it("Test#033 : track opt-out that happened via 'cordova telemetry off' even if user is NOT opted-in ", function(done) { spyOn(telemetry, "isCI").and.returnValue(false); spyOn(telemetry, "isOptedIn").and.returnValue(false); // same as calling `telemetry.turnOff();` @@ -456,19 +448,34 @@ describe("cordova cli", function () { }); }); +describe("raw", function () { + var rawInterface = cordova.raw; + it("has a raw implementation of previously callable commands", function (done) { + Object.keys(rawInterface).forEach(function(key) { + expect(typeof rawInterface[key]).toBe('function'); + spyOn(cordova,key); + rawInterface[key](); // call the raw version + expect(cordova[key]).toHaveBeenCalled(); + }); + done(); + }); +}); + describe("platform", function () { + beforeEach(function () { - spyOn(cordova.raw, "platform").and.returnValue(Q()); + spyOn(cordova, "platform").and.returnValue(Q()); + logger.setLevel('error'); }); it("Test #034 : (add) autosave is the default setting for platform add", function (done) { cli(["node", "cordova", "platform", "add", "ios"], function () { - expect(cordova.raw.platform).toHaveBeenCalledWith( + expect(cordova.platform).toHaveBeenCalledWith( "add", ["ios"], jasmine.any(Object) ); - var opts = cordova.raw.platform.calls.argsFor(0)[2]; + var opts = cordova.platform.calls.argsFor(0)[2]; expect(opts.save).toBe(true); done(); }); @@ -476,12 +483,12 @@ describe("platform", function () { it("Test #035 : (add) platform is not saved when --nosave is passed in", function (done) { cli(["node", "cordova", "platform", "add", "ios", "--nosave"], function () { - expect(cordova.raw.platform).toHaveBeenCalledWith( + expect(cordova.platform).toHaveBeenCalledWith( "add", ["ios"], jasmine.any(Object) ); - var opts = cordova.raw.platform.calls.argsFor(0)[2]; + var opts = cordova.platform.calls.argsFor(0)[2]; expect(opts.save).toBe(false); done(); }); @@ -489,12 +496,12 @@ describe("platform", function () { it("Test #036 : (remove) autosave is the default setting for platform remove", function (done) { cli(["node", "cordova", "platform", "remove", "ios"], function () { - expect(cordova.raw.platform).toHaveBeenCalledWith( + expect(cordova.platform).toHaveBeenCalledWith( "remove", ["ios"], jasmine.any(Object) ); - var opts = cordova.raw.platform.calls.argsFor(0)[2]; + var opts = cordova.platform.calls.argsFor(0)[2]; expect(opts.save).toBe(true); done(); }); @@ -502,12 +509,12 @@ describe("platform", function () { it("Test #037 : (remove) platform is not removed when --nosave is passed in", function (done) { cli(["node", "cordova", "platform", "remove", "ios", "--nosave"], function () { - expect(cordova.raw.platform).toHaveBeenCalledWith( + expect(cordova.platform).toHaveBeenCalledWith( "remove", ["ios"], jasmine.any(Object) ); - var opts = cordova.raw.platform.calls.argsFor(0)[2]; + var opts = cordova.platform.calls.argsFor(0)[2]; expect(opts.save).toBe(false); done(); }); @@ -515,12 +522,12 @@ describe("platform", function () { it("Test #038 : (add) will pass fetch:false", function (done) { cli(["node", "cordova", "platform", "add", "device", "--nofetch"], function () { - expect(cordova.raw.platform).toHaveBeenCalledWith( + expect(cordova.platform).toHaveBeenCalledWith( "add", ["device"], jasmine.any(Object) ); - var opts = cordova.raw.platform.calls.argsFor(0)[2]; + var opts = cordova.platform.calls.argsFor(0)[2]; expect(opts.fetch).toBe(false); done(); }); @@ -528,12 +535,12 @@ describe("platform", function () { it("Test #039 : (add) fetch is true by default and will pass fetch:true", function (done) { cli(["node", "cordova", "platform", "add", "device"], function () { - expect(cordova.raw.platform).toHaveBeenCalledWith( + expect(cordova.platform).toHaveBeenCalledWith( "add", ["device"], jasmine.any(Object) ); - var opts = cordova.raw.platform.calls.argsFor(0)[2]; + var opts = cordova.platform.calls.argsFor(0)[2]; expect(opts.fetch).toBe(true); done(); }); @@ -541,12 +548,12 @@ describe("platform", function () { it("Test #040 : (remove) fetch is true by default and will pass fetch:true", function (done) { cli(["node", "cordova", "platform", "remove", "device"], function () { - expect(cordova.raw.platform).toHaveBeenCalledWith( + expect(cordova.platform).toHaveBeenCalledWith( "remove", ["device"], jasmine.any(Object) ); - var opts = cordova.raw.platform.calls.argsFor(0)[2]; + var opts = cordova.platform.calls.argsFor(0)[2]; expect(opts.fetch).toBe(true); done(); }); @@ -554,18 +561,20 @@ describe("platform", function () { it("Test #041 : (remove) will pass fetch:false", function (done) { cli(["node", "cordova", "platform", "remove", "device", "--nofetch"], function () { - expect(cordova.raw.platform).toHaveBeenCalledWith( + expect(cordova.platform).toHaveBeenCalledWith( "remove", ["device"], jasmine.any(Object) ); - var opts = cordova.raw.platform.calls.argsFor(0)[2]; + var opts = cordova.platform.calls.argsFor(0)[2]; expect(opts.fetch).toBe(false); done(); }); }); }); + + describe("config", function () { var clirevert, confrevert, @@ -596,9 +605,9 @@ describe("config", function () { cb(); }); - confrevert = cli.__set__('conf', confMock); - - spyOn(console, 'log'); + confrevert = cli.__set__('conf', confMock); + logger.setLevel('error'); + //spyOn(console, 'log'); }); afterEach(function() { @@ -608,7 +617,7 @@ describe("config", function () { }); it("Test#042 : config set autosave is called with true", function (done) { - cli(["node", "cordova", "config", "set", "autosave", "true"], function () { + cli(["node", "cordova", "config", "set", "autosave", "true", "--silent"], function () { expect(cordovaConfig.autosave).toBe('true'); done(); }); @@ -653,5 +662,7 @@ describe("config", function () { done(); }); }); + + }); http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/10aec775/spec/help.spec.js ---------------------------------------------------------------------- diff --git a/spec/help.spec.js b/spec/help.spec.js index 78dc132..868cde5 100644 --- a/spec/help.spec.js +++ b/spec/help.spec.js @@ -31,29 +31,13 @@ describe('help', function() { afterEach(function() { cordova.removeAllListeners('results'); }); - describe('emit results', function () { + describe('return results, and no long lines', function () { allcommands.forEach(function (k) { it(k, function(done) { - cordova.on('results', function(h) { - expect(h).toMatch(/^Synopsis/); - done(); - }); - help([k]).then(function () { - expect(done).toHaveBeenCalled(); - }); - }); - }); - }); - describe('not have overly long lines:', function () { - allcommands.forEach(function (k) { - it(k || '(default)', function(done) { - cordova.on('results', function(h) { - expect(h.split("\n").filter(function (l) { return l.length > 130; }).length).toBe(0); - done(); - }); - help([k]).then(function () { - expect(done).toHaveBeenCalled(); - }); + var result = help([k]); + expect(result).toMatch(/^Synopsis/); + expect(result.split("\n").filter(function (l) { return l.length > 130; }).length).toBe(0); + done(); }); }); }); @@ -68,13 +52,9 @@ describe('help', function() { }); allcommands.forEach(function (k) { it(k || '(default)', function(done) { - cordova.on('results', function(h) { - expect(h.split("\n")[2]).toMatch(RegExp(testname + ' (?:' + k + '|command)\\b')); - done(); - }); - help([k]).then(function () { - expect(done).toHaveBeenCalled(); - }); + var result = help([k]); + expect(result.split("\n")[2]).toMatch(RegExp(testname + ' (?:' + k + '|command)\\b')); + done(); }); }); }); http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/10aec775/src/cli.js ---------------------------------------------------------------------- diff --git a/src/cli.js b/src/cli.js index a71e16a..46d68eb 100644 --- a/src/cli.js +++ b/src/cli.js @@ -158,20 +158,22 @@ module.exports = function (inputArgs, cb) { // If "edit" is called if (isConfigCmd && inputArgs[3] === 'edit') { editor(conf.path, function (code, sig) { - console.log('Finished editing with code ' + code); + logger.warn('Finished editing with code ' + code); }); } // If "ls" is called if (isConfigCmd && inputArgs[3] === 'ls' || inputArgs[3] === 'list') { fs.readFile(conf.path, 'utf8', function (err,data) { - if (err) { - return console.log(err); - } - console.log(data); + if (err) { + logger.error(err); + } + else { + logger.log(data); + } }); } - + Q().then(function() { /** * Skip telemetry prompt if: @@ -225,17 +227,23 @@ module.exports = function (inputArgs, cb) { }; function getSubCommand(args, cmd) { - if(cmd === 'platform' || cmd === 'platforms' || cmd === 'plugin' || cmd === 'plugins' || cmd === 'telemetry' || cmd === 'config') { + if(['platform','platforms','plugin','plugins','telemetry','config'].indexOf(cmd) > -1) { return args[3]; // e.g: args='node cordova platform rm ios', 'node cordova telemetry on' } return null; } +function printHelp(command) { + var result = help([command]); + cordova.emit('results', result); +} + function handleTelemetryCmd(subcommand, isOptedIn) { if (subcommand !== 'on' && subcommand !== 'off') { logger.subscribe(events); - return help(['telemetry']); + printHelp('telemetry'); + return; } var turnOn = subcommand === 'on' ? true : false; @@ -293,8 +301,7 @@ function cli(inputArgs) { if (args.silent) { logger.setLevel('error'); } - - if (args.verbose) { + else if (args.verbose) { // can't be both silent AND verbose, silent wins logger.setLevel('verbose'); } @@ -310,8 +317,8 @@ function cli(inputArgs) { if (args.version) { logger.results(toPrint); - return Q(); - } else { + return Q(); // Important! this will return and cease execution + } else { // must be usingPrerelease // Show a warning and continue logger.warn('Warning: using prerelease version ' + toPrint); } @@ -347,7 +354,7 @@ function cli(inputArgs) { if (!args.help && remain[0] == 'help') { remain.shift(); } - return help(remain); + return printHelp(remain); } if ( !cordova.hasOwnProperty(cmd) ) { http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/10aec775/src/help.js ---------------------------------------------------------------------- diff --git a/src/help.js b/src/help.js index 2f2053c..d1df0cf 100644 --- a/src/help.js +++ b/src/help.js @@ -40,11 +40,11 @@ module.exports = function help (args) { if (fs.existsSync(f)) { return f; } - return null; }).filter(function (f) { - return f !== null; + return !!f; }); raw = fs.readFileSync(file[0]).toString('utf8').replace(/cordova-cli/g, cordova_lib.binname); - cordova.emit('results', raw); - return Q(); + //cordova.emit('results', raw); + + return raw; }; --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org For additional commands, e-mail: commits-help@cordova.apache.org