CB-11982: rewrote cordova config tests
Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/627c9872 Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/627c9872 Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/627c9872 Branch: refs/heads/master Commit: 627c98727c141430d9e21a24326572d4b71bd698 Parents: 9053ed0 Author: Steve Gill <[email protected]> Authored: Wed Apr 19 16:27:32 2017 -0700 Committer: Steve Gill <[email protected]> Committed: Wed Apr 19 17:21:21 2017 -0700 ---------------------------------------------------------------------- package.json | 5 ++- spec/cli.spec.js | 104 ++++++++++++++++++++++++++++---------------------- src/cli.js | 8 ++-- 3 files changed, 67 insertions(+), 50 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/627c9872/package.json ---------------------------------------------------------------------- diff --git a/package.json b/package.json index 50976e1..e8f3cd8 100644 --- a/package.json +++ b/package.json @@ -41,9 +41,10 @@ "update-notifier": "0.5.0" }, "devDependencies": { - "jasmine": "^2.5.2", "istanbul": "^0.4.5", - "jshint": "^2.9.4" + "jasmine": "^2.5.2", + "jshint": "^2.9.4", + "rewire": "^2.5.2" }, "author": "Anis Kadri", "contributors": [ http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/627c9872/spec/cli.spec.js ---------------------------------------------------------------------- diff --git a/spec/cli.spec.js b/spec/cli.spec.js index e390282..dd5c18b 100644 --- a/spec/cli.spec.js +++ b/spec/cli.spec.js @@ -17,12 +17,16 @@ under the License. */ -var cli = require("../src/cli"), +var rewire = require('rewire'), + cli = rewire("../src/cli"), Q = require('q'), cordova_lib = require('cordova-lib'), events = cordova_lib.events, cordova = cordova_lib.cordova, telemetry = require('../src/telemetry'), + path = require('path'), + Configstore = require('configstore'), + fs = require('fs'), logger = require('cordova-common').CordovaLogger.get(); //avoid node complaining of too many event listener added @@ -459,80 +463,90 @@ describe("platform", function () { }); describe("config", function () { + var clirevert, + confrevert, + editorArgs, + cordovaConfig = {}, + confHolder; + + var confMock = { + set: function(key, value) { + cordovaConfig[key] = value; + }, + del: function(key) { + delete cordovaConfig[key]; + }, + path: function() { + confHolder = 'Pathcalled'; + return 'some/path/cordova-config.json'; + }, + get: function(key) { + confHolder = cordovaConfig[key]; + return cordovaConfig[key]; + } + }; + beforeEach(function () { - spyOn(cordova.raw, "config").and.returnValue(Q()); + clirevert = cli.__set__('editor', function(path1, cb) { + editorArgs = path1(); + cb(); + }); + + confrevert = cli.__set__('conf', confMock); + + spyOn(console, 'log'); + }); + + afterEach(function() { + clirevert(); + confrevert(); + confHolder = undefined; }); - it("Test#040 : config set is called with true and config delete is called", function (done) { + it("Test#040 : config set autosave is called with true", function (done) { cli(["node", "cordova", "config", "set", "autosave", "true"], function () { - expect(cordova.raw.config).toHaveBeenCalledWith( - 'set', - [ 'autosave', 'true' ], - jasmine.any(Object) - ); - done(); - }); - cordova.raw.config('delete', 'autosave') - .then(function () { - expect(cordova.raw.config).toHaveBeenCalledWith( - 'delete', 'autosave' - ); + expect(cordovaConfig.autosave).toBe('true'); done(); }); }); - it("Test#041 : config set is called with false", function (done) { - cli(["node", "cordova", "config", "set", "autosave", "false"], function () { - expect(cordova.raw.config).toHaveBeenCalledWith( - 'set', - [ 'autosave', 'false' ], - jasmine.any(Object) - ); + it("Test#041 : config delete autosave is called", function (done) { + cli(["node", "cordova", "config", "delete", "autosave"], function () { + expect(cordovaConfig.autosave).toBeUndefined(); done(); }); }); - it("Test#042 : config set is called even without true or false", function (done) { + it("Test#042 : config set is called even without value, defaults to true", function (done) { cli(["node", "cordova", "config", "set", "autosave"], function () { - expect(cordova.raw.config).toHaveBeenCalledWith( - 'set', - [ 'autosave' ], - jasmine.any(Object) - ); + expect(cordovaConfig.autosave).toBe(true); done(); }); }); it("Test #043 : config get is called", function (done) { cli(["node", "cordova", "config", "get", "autosave"], function () { - expect(cordova.raw.config).toHaveBeenCalledWith( - 'get', - [ 'autosave' ], - jasmine.any(Object) - ); + expect(confHolder).toBe(true); done(); }); }); it("Test #044 : config edit is called", function (done) { cli(["node", "cordova", "config", "edit"], function () { - expect(cordova.raw.config).toHaveBeenCalledWith( - 'edit', - [ ], - jasmine.any(Object) - ); + expect(path.basename(editorArgs)).toEqual('cordova-config.json'); + expect(confHolder).toEqual('Pathcalled'); done(); }); }); - it("Test #045 : config edit is called", function (done) { + it("Test #045 : config ls is called", function (done) { + spyOn(fs, 'readFile').and.callFake(function(confPath, cb){ + confHolder = confPath(); + }); + cli(["node", "cordova", "config", "ls"], function () { - expect(cordova.raw.config).toHaveBeenCalledWith( - 'ls', - [ ], - jasmine.any(Object) - ); + expect(path.basename(confHolder)).toEqual('cordova-config.json'); done(); }); }); -}); \ No newline at end of file +}); http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/627c9872/src/cli.js ---------------------------------------------------------------------- diff --git a/src/cli.js b/src/cli.js index 542b1bb..35776ad 100644 --- a/src/cli.js +++ b/src/cli.js @@ -105,7 +105,6 @@ function checkForUpdates() { var shouldCollectTelemetry = false; module.exports = function (inputArgs, cb) { - /** * mainly used for testing. */ @@ -417,11 +416,14 @@ function cli(inputArgs) { throw new CordovaError('Some of requirements check failed'); } }); - } else if (cmd == 'serve') { + } else if (cmd === 'serve') { var port = undashed[1]; return cordova.raw.serve(port); - } else if (cmd == 'create') { + } else if (cmd === 'create') { return create(undashed,args); + } else if (cmd === 'config') { + //Don't need to do anything with cordova-lib since config was handled above + return true; } else { // platform/plugins add/rm [target(s)] subcommand = undashed[1]; // sub-command like "add", "ls", "rm" etc. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
