[
https://issues.apache.org/jira/browse/CB-12361?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16156419#comment-16156419
]
ASF GitHub Bot commented on CB-12361:
-------------------------------------
Github user stevengill commented on a diff in the pull request:
https://github.com/apache/cordova-lib/pull/584#discussion_r137442686
--- Diff: spec/cordova/plugin/save.spec.js ---
@@ -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('', false);
+ spyOn(semver, 'validRange').and.returnValue('', false);
+ 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('', false);
+ spyOn(semver, 'validRange').and.returnValue('1.3.0', true);
+ expect(save.versionString('1.3.2')).toBe('1.3.2');
--- End diff --
I think this should be
```
spyOn(semver, 'validRange').and.returnValue('^1.3.2');
expect(save.versionString('^1.3.2')).toBe('^1.3.2');
```
`semver.validRange` takes in a range (`^1.3.2`) and returns it if it is
valid. Returns `null` if it is invalid. So for testing, we need to pass in a
range and expect the range to be returned (like my example)
> Speed up cordova-lib tests
> --------------------------
>
> Key: CB-12361
> URL: https://issues.apache.org/jira/browse/CB-12361
> Project: Apache Cordova
> Issue Type: Improvement
> Components: cordova-lib
> Reporter: Steve Gill
> Assignee: Steve Gill
> Labels: cordova-next
>
> * Split out e2e tests into own folder
> * stub i/o and network requests
> * use local fixtures when possible & makes sense
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]