You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by st...@apache.org on 2017/06/16 00:20:07 UTC
[13/16] cordova-lib git commit: cordova/platform/index unit tests
complete.
cordova/platform/index unit tests complete.
Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/8784e801
Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/8784e801
Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/8784e801
Branch: refs/heads/master
Commit: 8784e801759903a88d24b71bfeada708667233df
Parents: 66cefa9
Author: filmaj <ma...@gmail.com>
Authored: Mon Jun 12 14:30:36 2017 -0500
Committer: filmaj <ma...@gmail.com>
Committed: Mon Jun 12 15:27:54 2017 -0500
----------------------------------------------------------------------
spec-cordova/platform/index.spec.js | 240 +++++++++++++++++++------------
src/cordova/platform/index.js | 4 +-
2 files changed, 148 insertions(+), 96 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/8784e801/spec-cordova/platform/index.spec.js
----------------------------------------------------------------------
diff --git a/spec-cordova/platform/index.spec.js b/spec-cordova/platform/index.spec.js
index d8b8c3e..f05ca85 100644
--- a/spec-cordova/platform/index.spec.js
+++ b/spec-cordova/platform/index.spec.js
@@ -17,113 +17,165 @@
/* eslint-env jasmine */
var rewire = require('rewire');
-var platform = rewire('../../src/cordova/platform'),
- cordova_util = require('../../src/cordova/util'),
- prepare = require('../../src/cordova/prepare'),
- cordova = require('../../src/cordova/cordova'),
- platformMetadata = require('../../src/cordova/platform_metadata'),
- platforms = require('../../src/platforms/platforms'),
- lazy_load = require('../../src/cordova/lazy_load'),
- Q = require('q');
-var config_xml_path = '../spec-cordova/fixtures/config.xml';
-var pinnedAndroidVer = platforms.android.version;
+var platform = rewire('../../src/cordova/platform');
+var cordova_util = require('../../src/cordova/util');
describe('cordova/platform', function () {
var hooksRunnerRevert;
- beforeEach(function() {
- hooksRunnerRevert = platform.__set__('HooksRunner', function() {});
- spyOn(cordova_util, 'cdProjectRoot').and.returnValue('somepath');
+ var projectRoot = 'somepath';
+ beforeEach(function () {
+ // TODO: if we can change HooksRunner from a prototypal class to a function or object,
+ // we could eliminate the need for rewire here and use just jasmine spies.
+ hooksRunnerRevert = platform.__set__('HooksRunner', function () {});
+ spyOn(cordova_util, 'cdProjectRoot').and.returnValue(projectRoot);
});
- afterEach(function() {
+ afterEach(function () {
hooksRunnerRevert();
});
describe('main module function', function () {
describe('error/warning conditions', function () {
// TODO: what about other commands? update? save?
- it('should require at least one platform for add and remove commands');
+ it('should require at least one platform for add and remove commands', function (done) {
+ // targets = empty array
+ platform('add', []).then(function () {
+ fail('should not succeed without targets');
+ }, function (err) {
+ expect(err).toMatch(/You need to qualify.* with one or more platforms/gi);
+ }).then(function () {
+ // targets = null
+ return platform('remove', null);
+ })
+ .then(function () {
+ fail('should not succeed without targets');
+ }, function (err) {
+ expect(err).toMatch(/You need to qualify.* with one or more platforms/gi);
+ }).done(done);
+ });
});
- describe('happy path (success conditions)', function () {
- it('should default to the list command if no command is provided');
- it('should be able to handle an array of platform targets, or a single platform target string');
- it('should direct `add` commands to the `add` method/module');
- it('should direct `remove` + `rm` commands to the `remove` method/module');
- it('should direct `update` + `up` commands to the `update` method/module');
- it('should direct `check` commands to the `check` method/module');
- it('should direct all other commands to the `list` method/module');
+ describe('handling of targets parameter', function () {
+ var cmd = 'add';
+ beforeEach(function () {
+ spyOn(platform, cmd).and.returnValue(true);
+ });
+ it('should be able to handle an array of platform targets', function (done) {
+ var targets = ['nokia brick', 'HAM radio', 'nintendo wii'];
+ platform(cmd, targets)
+ .then(function () {
+ expect(platform[cmd]).toHaveBeenCalledWith(jasmine.any(Object), projectRoot, targets, jasmine.any(Object));
+ }).fail(function (e) {
+ expect(e).toBeUndefined();
+ fail('did not expect fail handler to be invoked');
+ }).done(done);
+ });
+ it('should be able to handle a single platform target string', function (done) {
+ var target = 'motorola razr';
+ platform(cmd, target)
+ .then(function () {
+ expect(platform[cmd]).toHaveBeenCalledWith(jasmine.any(Object), projectRoot, [target], jasmine.any(Object));
+ }).fail(function (e) {
+ expect(e).toBeUndefined();
+ fail('did not expect fail handler to be invoked');
+ }).done(done);
+ });
});
- });
-
- xdescribe('old platform tests, please see how to fold these into new tests', function () {
- it('should successfuly call platform add function', function(done) {
- spyOn(platform, 'add').and.returnValue(true);
- return platform('add', ['android'], {})
- .then(function() {
- expect(platform.add.calls.count()).toEqual(1);
- }).fail(function(e) {
- expect(e).toBeUndefined();
- }).fin(done);
- });
-
- it('should successfuly call platform remove function', function(done) {
- spyOn(platform, 'remove').and.returnValue(true);
- return platform('remove', ['android'], {})
- .then(function() {
- expect(platform.remove.calls.count()).toEqual(1);
- }).fail(function(e) {
- expect(e).toBeUndefined();
- }).fin(done);
- });
-
- it('should successfuly call platform update function', function(done) {
- spyOn(platform, 'update').and.returnValue(true);
- return platform('update', ['android'], {})
- .then(function() {
- expect(platform.update.calls.count()).toEqual(1);
- }).fail(function(e) {
- expect(e).toBeUndefined();
- }).fin(done);
- });
-
- it('should successfuly call platform check function', function(done) {
- spyOn(platform, 'check').and.returnValue(true);
- return platform('check', ['android'], {})
- .then(function() {
- expect(platform.check.calls.count()).toEqual(1);
- }).fail(function(e) {
- expect(e).toBeUndefined();
- }).fin(done);
- });
-
- it('should successfuly call platform save function', function(done) {
- spyOn(platform, 'save').and.returnValue(true);
- return platform('save', ['android'], {})
- .then(function() {
- expect(platform.save.calls.count()).toEqual(1);
- }).fail(function(e) {
- expect(e).toBeUndefined();
- }).fin(done);
- });
-
- it('should successfuly call platform list function', function(done) {
- spyOn(platform, 'list').and.returnValue(true);
- return platform('list', ['android'], {})
- .then(function() {
- expect(platform.list.calls.count()).toEqual(1);
- }).fail(function(e) {
- expect(e).toBeUndefined();
- }).fin(done);
- });
-
- it('should successfuly throw an error if targets is undefined', function(done) {
- return platform('add', undefined, {})
- .then(false)
- .fail(function(e) {
- expect(e).toBeDefined();
- expect(e.message).toContain('You need to qualify `add` or `remove` with one or more platforms!');
- }).fin(done);
+ describe('happy path (success conditions)', function () {
+ it('should direct `add` commands to the `add` method/module', function (done) {
+ spyOn(platform, 'add').and.returnValue(true);
+ platform('add', ['android'])
+ .then(function () {
+ expect(platform.add).toHaveBeenCalled();
+ }).fail(function (e) {
+ expect(e).toBeUndefined();
+ fail('did not expect fail handler to be invoked');
+ }).done(done);
+ });
+ it('should direct `remove` + `rm` commands to the `remove` method/module', function (done) {
+ spyOn(platform, 'remove').and.returnValue(true);
+ platform('remove', ['android'])
+ .then(function () {
+ expect(platform.remove).toHaveBeenCalled();
+ }).fail(function (e) {
+ expect(e).toBeUndefined();
+ fail('did not expect fail handler to be invoked');
+ }).then(function () {
+ platform.remove.calls.reset(); // reset spy counter
+ return platform('rm', ['android']);
+ }).then(function () {
+ expect(platform.remove).toHaveBeenCalled();
+ }).fail(function (e) {
+ expect(e).toBeUndefined();
+ fail('did not expect fail handler to be invoked');
+ }).done(done);
+ });
+ it('should direct `update` + `up` commands to the `update` method/module', function (done) {
+ spyOn(platform, 'update').and.returnValue(true);
+ platform('update', ['android'])
+ .then(function () {
+ expect(platform.update).toHaveBeenCalled();
+ }).fail(function (e) {
+ expect(e).toBeUndefined();
+ fail('did not expect fail handler to be invoked');
+ }).then(function () {
+ platform.update.calls.reset(); // reset spy counter
+ return platform('up', ['android']);
+ }).then(function () {
+ expect(platform.update).toHaveBeenCalled();
+ }).fail(function (e) {
+ expect(e).toBeUndefined();
+ fail('did not expect fail handler to be invoked');
+ }).done(done);
+ });
+ it('should direct `check` commands to the `check` method/module', function (done) {
+ spyOn(platform, 'check').and.returnValue(true);
+ platform('check', ['android'])
+ .then(function () {
+ expect(platform.check).toHaveBeenCalled();
+ }).fail(function (e) {
+ expect(e).toBeUndefined();
+ fail('did not expect fail handler to be invoked');
+ }).done(done);
+ });
+ it('should direct `save` commands to the `save` method/module', function (done) {
+ spyOn(platform, 'save').and.returnValue(true);
+ platform('save', ['android'])
+ .then(function () {
+ expect(platform.save).toHaveBeenCalled();
+ }).fail(function (e) {
+ expect(e).toBeUndefined();
+ fail('did not expect fail handler to be invoked');
+ }).done(done);
+ });
+ it('should direct `list`, all other commands and no command at all to the `list` method/module', function (done) {
+ spyOn(platform, 'list').and.returnValue(true);
+ // test the `list` command directly
+ platform('list')
+ .then(function () {
+ expect(platform.list).toHaveBeenCalled();
+ }).fail(function (e) {
+ expect(e).toBeUndefined();
+ fail('did not expect fail handler to be invoked');
+ }).then(function () {
+ platform.list.calls.reset(); // reset spy counter
+ // test the list catch-all
+ return platform('please give me the list command');
+ }).then(function () {
+ expect(platform.list).toHaveBeenCalled();
+ }).fail(function (e) {
+ expect(e).toBeUndefined();
+ fail('did not expect fail handler to be invoked');
+ }).then(function () {
+ platform.list.calls.reset(); // reset spy counter
+ // test the lack of providing an argument.
+ return platform();
+ }).then(function () {
+ expect(platform.list).toHaveBeenCalled();
+ }).fail(function (e) {
+ expect(e).toBeUndefined();
+ fail('did not expect fail handler to be invoked');
+ }).done(done);
+ });
});
});
});
-
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/8784e801/src/cordova/platform/index.js
----------------------------------------------------------------------
diff --git a/src/cordova/platform/index.js b/src/cordova/platform/index.js
index b93b0b4..93c0aee 100644
--- a/src/cordova/platform/index.js
+++ b/src/cordova/platform/index.js
@@ -61,8 +61,8 @@ function platform (command, targets, opts) {
if (targets && !(targets instanceof Array)) targets = [targets];
// TODO: wouldn't update need a platform, too? what about save?
- if (!targets && (command === 'add' || command === 'rm')) {
- msg = 'You need to qualify `add` or `remove` with one or more platforms!';
+ if ((command === 'add' || command === 'rm' || command === 'remove') && (!targets || (targets instanceof Array && targets.length === 0))) {
+ msg = 'You need to qualify `' + command + '` with one or more platforms!';
return Q.reject(new CordovaError(msg));
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org