You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by au...@apache.org on 2017/09/25 17:37:28 UTC
cordova-lib git commit: CB-12361 : added tests for plugin/save.js
Repository: cordova-lib
Updated Branches:
refs/heads/master e50c9b60e -> a4d91e401
CB-12361 : added tests for plugin/save.js
Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/a4d91e40
Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/a4d91e40
Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/a4d91e40
Branch: refs/heads/master
Commit: a4d91e4011e47d44f1c70a1f44e3d6d40decb986
Parents: e50c9b6
Author: Audrey So <au...@apache.org>
Authored: Wed Jul 26 15:51:44 2017 -0700
Committer: Audrey So <au...@apache.org>
Committed: Mon Sep 25 10:03:14 2017 -0700
----------------------------------------------------------------------
integration-tests/HooksRunner.spec.js | 4 +-
spec/cordova/plugin/save.spec.js | 142 +++++++++++++++++++++++++++--
2 files changed, 135 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/a4d91e40/integration-tests/HooksRunner.spec.js
----------------------------------------------------------------------
diff --git a/integration-tests/HooksRunner.spec.js b/integration-tests/HooksRunner.spec.js
index 7847443..fe2c010 100644
--- a/integration-tests/HooksRunner.spec.js
+++ b/integration-tests/HooksRunner.spec.js
@@ -285,7 +285,7 @@ describe('HooksRunner', function () {
}).then(function () {
done();
});
- });
+ }, 60000);
it('Test 006 : should execute hook scripts serially from config.xml', function (done) {
var test_event = 'before_build';
@@ -636,7 +636,7 @@ describe('HooksRunner', function () {
hooksRunner.fire(test_event, hookOptions).then(function () {
done();
});
- }, 60000);
+ }, 80000);
it('Test 022 : should pass data object that fire calls into sync handlers', function (done) {
var async = function (opts) {
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/a4d91e40/spec/cordova/plugin/save.spec.js
----------------------------------------------------------------------
diff --git a/spec/cordova/plugin/save.spec.js b/spec/cordova/plugin/save.spec.js
index aa4be04..d51cf11 100644
--- a/spec/cordova/plugin/save.spec.js
+++ b/spec/cordova/plugin/save.spec.js
@@ -24,6 +24,7 @@ var rewire = require('rewire');
var fs = require('fs');
var save = rewire('../../../src/cordova/plugin/save');
var cordova_util = require('../../../src/cordova/util');
+var semver = require('semver');
describe('cordova/plugin/save', function () {
var projectRoot = '/some/path';
@@ -31,15 +32,22 @@ describe('cordova/plugin/save', function () {
var cfg_parser_revert_mock;
var fake_plugin_list = ['VRPlugin', 'MastodonSocialPlugin'];
var fake_fetch_json = {'VRPlugin': {}, 'MastodonSocialPlugin': {}};
+ var plugin_info_provider_mock = function () {};
+ var plugin_info_provider_revert_mock;
+
beforeEach(function () {
- cfg_parser_mock.prototype = jasmine.createSpyObj('config parser protytpe mock', ['getPluginIdList', 'removePlugin']);
+ cfg_parser_mock.prototype = jasmine.createSpyObj('config parser protytpe mock', ['getPluginIdList', 'removePlugin', 'write', 'addPlugin']);
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));
+ spyOn(save, 'versionString');
+ plugin_info_provider_mock.prototype = jasmine.createSpyObj('plugin info provider mock', ['get']);
+ plugin_info_provider_revert_mock = save.__set__('PluginInfoProvider', plugin_info_provider_mock);
});
afterEach(function () {
cfg_parser_revert_mock();
+ plugin_info_provider_revert_mock();
});
describe('error conditions', function () {
it('should explode if there was an issue parsing or reading from fetch.json file', function (done) {
@@ -54,15 +62,131 @@ describe('cordova/plugin/save', function () {
});
});
describe('happy path', function () {
- it('should remove all plugins from config.xml and re-add new ones based on those retrieved from fetch.json');
- it('should only add top-level plugins to config.xml');
- it('should write individual plugin specs to config.xml');
- it('should write individual plugin variables to config.xml');
+ it('check that existing plugins are getting removed', function (done) {
+ save(projectRoot).then(function () {
+ expect(cfg_parser_mock.prototype.removePlugin).toHaveBeenCalledWith('VRPlugin');
+ expect(cfg_parser_mock.prototype.removePlugin).toHaveBeenCalledWith('MastodonSocialPlugin');
+ }).fail(function (e) {
+ expect(e).toBeUndefined();
+ fail('did not expect fail handler to be invoked');
+ }).done(done);
+ });
+
+ it('plugins are being removed first and then only top level plugins are being restored', function (done) {
+ var fake_fetch_json =
+ {'VRPlugin': {'source': {
+ 'type': 'registry',
+ 'id': 'id'
+ },
+ 'is_top_level': true
+ },
+ 'MastodonSocialPlugin': { 'source': {
+ 'type': 'registry',
+ 'id': 'id'
+ },
+ 'is_top_level': false }};
+
+ fs.readFileSync.and.returnValue(JSON.stringify(fake_fetch_json));
+ save(projectRoot).then(function () {
+ expect(cfg_parser_mock.prototype.removePlugin).toHaveBeenCalledWith('VRPlugin');
+ expect(cfg_parser_mock.prototype.removePlugin).toHaveBeenCalledWith('MastodonSocialPlugin');
+ expect(cfg_parser_mock.prototype.addPlugin).toHaveBeenCalledWith(Object({ name: 'VRPlugin' }), [ ]);
+ expect(cfg_parser_mock.prototype.addPlugin).not.toHaveBeenCalledWith(Object({ name: 'MastodonSocialPlugin' }), [ ]);
+ expect(cfg_parser_mock.prototype.write).toHaveBeenCalled();
+ }).fail(function (e) {
+ expect(e).toBeUndefined();
+ fail('did not expect fail handler to be invoked');
+ }).done(done);
+ });
+
+ it('should write individual plugin specs to config.xml', function (done) {
+ var fake_fetch_json =
+ {'VRPlugin': {'source': {
+ 'type': 'registry',
+ 'id': 'id'
+ },
+ 'is_top_level': true }};
+ fs.readFileSync.and.returnValue(JSON.stringify(fake_fetch_json));
+ spyOn(save, 'getSpec').and.returnValue('1.0.0');
+ save(projectRoot).then(function () {
+ expect(cfg_parser_mock.prototype.addPlugin).toHaveBeenCalledWith(Object({ name: 'VRPlugin', spec: '1.0.0' }), jasmine.any(Object));
+ expect(cfg_parser_mock.prototype.write).toHaveBeenCalled();
+ }).fail(function (e) {
+ expect(e).toBeUndefined();
+ fail('did not expect fail handler to be invoked');
+ }).done(done);
+ });
+
+ it('should write individual plugin variables to config.xml', function (done) {
+ var fake_fetch_json =
+ {'VRPlugin': {'source': {
+ 'type': 'registry',
+ 'id': 'id'
+ },
+ 'is_top_level': true,
+ 'variables': {
+ 'var 1': ' '
+ }}};
+ fs.readFileSync.and.returnValue(JSON.stringify(fake_fetch_json));
+ save(projectRoot).then(function () {
+ expect(cfg_parser_mock.prototype.addPlugin).toHaveBeenCalledWith(jasmine.any(Object), [ Object({ name: 'var 1', value: ' ' }) ]);
+ expect(cfg_parser_mock.prototype.write).toHaveBeenCalled();
+ }).fail(function (e) {
+ expect(e).toBeUndefined();
+ fail('did not expect fail handler to be invoked');
+ }).done(done);
+ });
});
describe('getSpec helper method', function () {
- it('should return a plugin source\'s url or path property immediately');
- it('should return a version if a version was provided to plugin id');
- it('should return a version that includes scope if scope was part of plugin id');
- it('should fall back to using PluginInfoProvider to retrieve a version as last resort');
+ it('should return a plugin source\'s url or path property immediately', function () {
+ spyOn(save, 'getSpec').and.callThrough();
+ save.getSpec({ url: 'https://git-wip-us.apache.org/repos/asf/cordova-plugin-camera.git' }, '/some/path', 'VRPlugin');
+ expect(save.getSpec).toHaveBeenCalledWith(Object({ url: 'https://git-wip-us.apache.org/repos/asf/cordova-plugin-camera.git' }), '/some/path', 'VRPlugin');
+ expect(save.getSpec({ url: 'https://git-wip-us.apache.org/repos/asf/cordova-plugin-camera.git' }, '/some/path', 'VRPlugin')).toEqual('https://git-wip-us.apache.org/repos/asf/cordova-plugin-camera.git');
+ });
+
+ it('getSpec should return a version if a version was provided to plugin id', function () {
+ save.versionString.and.callThrough();
+ expect(save.getSpec({id: 'cordova-plugin-camera@^1.1.0'}, '/some/path', 'cordova-plugin-camera')).toEqual('^1.1.0');
+ });
+
+ it('should return a version that includes scope if scope was part of plugin id', function () {
+ save.versionString.and.callThrough();
+ expect(save.getSpec({ type: 'registry', id: '@scoped/package@^1.0.0' }, '/some/path', 'cordova-plugin-camera')).toEqual('@scoped/package@^1.0.0');
+ });
+
+ it('should fall back to using PluginInfoProvider to retrieve a version as last resort', function () {
+ expect(save.getSpec({ id: 'cordova-plugin-camera' }, '/some/path', 'cordova-plugin-camera')).toEqual(null);
+ expect(plugin_info_provider_mock.prototype.get).toHaveBeenCalled();
+ });
+ });
+
+ describe('getPluginVariables helper method', function () {
+ it('if no variables are passed in, should return empty', function () {
+ expect(save.getPluginVariables()).toEqual([]);
+ });
+ it('if variables are passed in, should return result & get added to name and value', function () {
+ expect(save.getPluginVariables({ variable: 'var 1' })).toEqual([ { name: 'variable', value: 'var 1' } ]);
+ });
+ });
+
+ describe('versionString helper method', function () {
+ it('if no version, should return null', function () {
+ save.versionString.and.callThrough();
+ spyOn(semver, 'valid').and.returnValue(null);
+ spyOn(semver, 'validRange').and.returnValue(null);
+ expect(save.versionString()).toBe(null);
+ });
+ it('return version passed in, if it is within the valid range', function () {
+ save.versionString.and.callThrough();
+ spyOn(semver, 'valid').and.returnValue(null);
+ spyOn(semver, 'validRange').and.returnValue('^1.3.2');
+ expect(save.versionString('^1.3.2')).toBe('^1.3.2');
+ });
+ it('should check and return a valid version', function () {
+ save.versionString.and.callThrough();
+ spyOn(semver, 'valid').and.returnValue('1.3.2');
+ expect(save.versionString('1.3.2')).toBe('~1.3.2');
+ });
});
});
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org