You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by fi...@apache.org on 2017/06/22 17:34:45 UTC

[14/14] cordova-lib git commit: first unit test in each plugin submodule, jshint fixes

first unit test in each plugin submodule, jshint fixes


Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/1a289295
Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/1a289295
Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/1a289295

Branch: refs/heads/master
Commit: 1a28929564d32d8a85dca039ee8f34656c594dfd
Parents: ea8af45
Author: filmaj <ma...@gmail.com>
Authored: Wed Jun 21 10:17:18 2017 -0500
Committer: filmaj <ma...@gmail.com>
Committed: Wed Jun 21 14:58:42 2017 -0500

----------------------------------------------------------------------
 spec-cordova/plugin/add.spec.js    | 17 ++++++++++++++++-
 spec-cordova/plugin/index.spec.js  | 24 ++++++++++++++++++++++--
 spec-cordova/plugin/list.spec.js   | 22 +++++++++++++++++++++-
 spec-cordova/plugin/remove.spec.js | 11 ++++++++++-
 spec-cordova/plugin/save.spec.js   | 33 +++++++++++++++++++++++++++++++--
 spec-cordova/plugin/search.spec.js | 28 ++++++++++++++++++++++++++--
 src/cordova/plugin/add.js          |  2 +-
 src/cordova/plugin/search.js       |  2 +-
 8 files changed, 128 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/1a289295/spec-cordova/plugin/add.spec.js
----------------------------------------------------------------------
diff --git a/spec-cordova/plugin/add.spec.js b/spec-cordova/plugin/add.spec.js
index 4860578..2788d13 100644
--- a/spec-cordova/plugin/add.spec.js
+++ b/spec-cordova/plugin/add.spec.js
@@ -16,14 +16,29 @@
     specific language governing permissions and limitations
     under the License.
 */
+// TODO: remove once eslint lands
 /* eslint-env jasmine */
+/* globals fail */
 
+var Q = require('q');
 var add = require('../../src/cordova/plugin/add');
 
 describe('cordova/plugin/add', function () {
+    var projectRoot = '/some/path';
+    var hook_mock;
+    beforeEach(function () {
+        hook_mock = jasmine.createSpyObj('hooks runner mock', ['fire']);
+        hook_mock.fire.and.returnValue(Q());
+    });
     describe('main method', function () {
         describe('error/warning conditions', function () {
-            it('should error out if at least one plugin is not specified');
+            it('should error out if at least one plugin is not specified', function (done) {
+                add(projectRoot, hook_mock, {plugins: []}).then(function () {
+                    fail('success handler unexpectedly invoked');
+                }).fail(function (e) {
+                    expect(e.message).toContain('No plugin specified');
+                }).done(done);
+            });
             it('should error out if any mandatory plugin variables are not provided');
         });
         describe('happy path', function () {

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/1a289295/spec-cordova/plugin/index.spec.js
----------------------------------------------------------------------
diff --git a/spec-cordova/plugin/index.spec.js b/spec-cordova/plugin/index.spec.js
index 479de82..565d6f9 100644
--- a/spec-cordova/plugin/index.spec.js
+++ b/spec-cordova/plugin/index.spec.js
@@ -16,14 +16,34 @@
     specific language governing permissions and limitations
     under the License.
 */
+// TODO: remove once eslint lands
 /* eslint-env jasmine */
+/* globals fail */
 
-var plugin = require('../../src/cordova/plugin');
+var rewire = require('rewire');
+var plugin = rewire('../../src/cordova/plugin');
+var cordova_util = require('../../src/cordova/util');
 
 describe('cordova/plugin', function () {
+    var projectRoot = '/some/path';
+    var hook_mock = function () {};
+    var hook_revert_mock;
+    beforeEach(function () {
+        hook_revert_mock = plugin.__set__('HooksRunner', hook_mock);
+        spyOn(cordova_util, 'cdProjectRoot').and.returnValue(projectRoot);
+    });
+    afterEach(function () {
+        hook_revert_mock();
+    });
     describe('error conditions', function () {
         // TODO: what about search cmd?
-        it('should require at least one target for add and rm commands');
+        it('should require at least one target for add and rm commands', function (done) {
+            plugin('add', null).then(function () {
+                fail('success handler unexpectedly invoked');
+            }).fail(function (e) {
+                expect(e.message).toContain('one or more plugins');
+            }).done(done);
+        });
     });
     describe('handling/massaging of parameters', function () {
         it('should be able to handle an array of targets');

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/1a289295/spec-cordova/plugin/list.spec.js
----------------------------------------------------------------------
diff --git a/spec-cordova/plugin/list.spec.js b/spec-cordova/plugin/list.spec.js
index 0bf27b4..d836418 100644
--- a/spec-cordova/plugin/list.spec.js
+++ b/spec-cordova/plugin/list.spec.js
@@ -16,12 +16,32 @@
     specific language governing permissions and limitations
     under the License.
 */
+// TODO: remove once eslint lands
 /* eslint-env jasmine */
+/* globals fail */
 
+var Q = require('q');
 var list = require('../../src/cordova/plugin/list');
+var plugin_util = require('../../src/cordova/plugin/util');
 
 describe('cordova/plugin/list', function () {
-    it('should fire the before_plugin_ls hook');
+    var projectRoot = '/some/path';
+    var hook_mock;
+    var fake_plugins_list = [{id: 'VRPlugin'}, {id: 'MastodonSocialPlugin'}];
+    beforeEach(function () {
+        hook_mock = jasmine.createSpyObj('hooks runner mock', ['fire']);
+        hook_mock.fire.and.returnValue(Q());
+        spyOn(plugin_util, 'getInstalledPlugins').and.returnValue(Q.resolve(fake_plugins_list));
+    });
+    it('should fire the before_plugin_ls hook', function (done) {
+        var opts = {important: 'options'};
+        list(projectRoot, hook_mock, opts).then(function () {
+            expect(hook_mock.fire).toHaveBeenCalledWith('before_plugin_ls', opts);
+        }).fail(function (e) {
+            fail('fail handler unexpectedly invoked');
+            console.error(e);
+        }).done(done);
+    });
     it('should emit a "no plugins added" result if there are no installed plugins');
     it('should warn if plugin list contains dependencies that are missing');
     it('should warn if plugin list contains a plugin dependency that does not have a version satisfied');

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/1a289295/spec-cordova/plugin/remove.spec.js
----------------------------------------------------------------------
diff --git a/spec-cordova/plugin/remove.spec.js b/spec-cordova/plugin/remove.spec.js
index cbe1747..ab7b572 100644
--- a/spec-cordova/plugin/remove.spec.js
+++ b/spec-cordova/plugin/remove.spec.js
@@ -16,13 +16,22 @@
     specific language governing permissions and limitations
     under the License.
 */
+// TODO: remove this once eslint lands
 /* eslint-env jasmine */
+/* globals fail */
 
 var remove = require('../../src/cordova/plugin/remove');
 
 describe('cordova/plugin/remove', function () {
+    var projectRoot = '/some/path';
     describe('error/warning conditions', function () {
-        it('should require that a plugin be provided');
+        it('should require that a plugin be provided', function (done) {
+            remove(projectRoot, null).then(function () {
+                fail('success handler unexpectedly invoked');
+            }).fail(function (e) {
+                expect(e.message).toContain('No plugin specified');
+            }).done(done);
+        });
         it('should require that a provided plugin be installed in the current project');
     });
     describe('happy path', function () {

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/1a289295/spec-cordova/plugin/save.spec.js
----------------------------------------------------------------------
diff --git a/spec-cordova/plugin/save.spec.js b/spec-cordova/plugin/save.spec.js
index c2b5f68..1fb8b46 100644
--- a/spec-cordova/plugin/save.spec.js
+++ b/spec-cordova/plugin/save.spec.js
@@ -16,13 +16,42 @@
     specific language governing permissions and limitations
     under the License.
 */
+// TODO: remove this once eslint lands
 /* eslint-env jasmine */
+/* globals fail */
 
-var save = require('../../src/cordova/plugin/save');
+var rewire = require('rewire');
+var fs = require('fs');
+var save = rewire('../../src/cordova/plugin/save');
+var cordova_util = require('../../src/cordova/util');
 
 describe('cordova/plugin/save', function () {
+    var projectRoot = '/some/path';
+    var cfg_parser_mock = function () {};
+    var cfg_parser_revert_mock;
+    var fake_plugin_list = ['VRPlugin', 'MastodonSocialPlugin'];
+    var fake_fetch_json = {'VRPlugin': {}, 'MastodonSocialPlugin': {}};
+    beforeEach(function () {
+        cfg_parser_mock.prototype = jasmine.createSpyObj('config parser protytpe mock', ['getPluginIdList', 'removePlugin']);
+        cfg_parser_mock.prototype.getPluginIdList.and.returnValue(fake_plugin_list);
+        cfg_parser_revert_mock = save.__set__('ConfigParser', cfg_parser_mock);
+        spyOn(cordova_util, 'projectConfig').and.returnValue(projectRoot + '/config.xml');
+        spyOn(fs, 'readFileSync').and.returnValue(JSON.stringify(fake_fetch_json));
+    });
+    afterEach(function () {
+        cfg_parser_revert_mock();
+    });
     describe('error conditions', function () {
-        it('should explode if there was an issue parsing or reading from fetch.json file');
+        it('should explode if there was an issue parsing or reading from fetch.json file', function (done) {
+            fs.readFileSync.and.callFake(function () {
+                throw new Error('massive explosions during file reading!');
+            });
+            save(projectRoot).then(function () {
+                fail('unexpected success handler invoked');
+            }).fail(function (e) {
+                expect(e).toContain('massive explosions');
+            }).done(done);
+        });
     });
     describe('happy path', function () {
         it('should remove all plugins from config.xml and re-add new ones based on those retrieved from fetch.json');

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/1a289295/spec-cordova/plugin/search.spec.js
----------------------------------------------------------------------
diff --git a/spec-cordova/plugin/search.spec.js b/spec-cordova/plugin/search.spec.js
index b940eeb..aa3ba54 100644
--- a/spec-cordova/plugin/search.spec.js
+++ b/spec-cordova/plugin/search.spec.js
@@ -16,12 +16,36 @@
     specific language governing permissions and limitations
     under the License.
 */
+// TODO: remove once eslint lands
 /* eslint-env jasmine */
+/* globals fail */
 
-var search = require('../../src/cordova/plugin/search');
+var Q = require('q');
+var rewire = require('rewire');
+var search = rewire('../../src/cordova/plugin/search');
 
 describe('cordova/plugin/search', function () {
-    it('should fire the before_plugin_search hook');
+    var hook_mock;
+    var opener_mock;
+    var opener_revert_mock;
+    beforeEach(function () {
+        hook_mock = jasmine.createSpyObj('hooks runner mock', ['fire']);
+        hook_mock.fire.and.returnValue(Q());
+        opener_mock = jasmine.createSpy('opener mock');
+        opener_revert_mock = search.__set__('opener', opener_mock);
+    });
+    afterEach(function () {
+        opener_revert_mock();
+    });
+    it('should fire the before_plugin_search hook', function (done) {
+        var opts = {important: 'options', plugins: []};
+        search(hook_mock, opts).then(function () {
+            expect(hook_mock.fire).toHaveBeenCalledWith('before_plugin_search', opts);
+        }).fail(function (e) {
+            fail('fail handler unexpectedly invoked');
+            console.error(e);
+        }).done(done);
+    });
     it('should open a link to cordova.apache.org/plugins if no plugins are provided as parameter');
     it('should open a link to cordova.apache.org/plugins, providing the plugins passed in as a query-string parameter');
     it('should fire the after_plugin_search hook');

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/1a289295/src/cordova/plugin/add.js
----------------------------------------------------------------------
diff --git a/src/cordova/plugin/add.js b/src/cordova/plugin/add.js
index 3b801d0..4e975d3 100644
--- a/src/cordova/plugin/add.js
+++ b/src/cordova/plugin/add.js
@@ -30,7 +30,7 @@ var CordovaError = require('cordova-common').CordovaError;
 var PluginInfoProvider = require('cordova-common').PluginInfoProvider;
 var events = require('cordova-common').events;
 var shell = require('shelljs');
-var Q = require('Q');
+var Q = require('q');
 var path = require('path');
 var fs = require('fs');
 var semver = require('semver');

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/1a289295/src/cordova/plugin/search.js
----------------------------------------------------------------------
diff --git a/src/cordova/plugin/search.js b/src/cordova/plugin/search.js
index e439c3b..0108e4e 100644
--- a/src/cordova/plugin/search.js
+++ b/src/cordova/plugin/search.js
@@ -18,7 +18,7 @@
 */
 
 var opener = require('opener');
-var Q = require('Q');
+var Q = require('q');
 
 module.exports = search;
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org