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/07 05:00:08 UTC
[49/51] [partial] cordova-lib git commit: CB-11980: removed fetch,
common and serve into their own repos
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/fc72293c/cordova-common/RELEASENOTES.md
----------------------------------------------------------------------
diff --git a/cordova-common/RELEASENOTES.md b/cordova-common/RELEASENOTES.md
deleted file mode 100644
index fa7f1d2..0000000
--- a/cordova-common/RELEASENOTES.md
+++ /dev/null
@@ -1,109 +0,0 @@
-<!--
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
--->
-# Cordova-common Release Notes
-
-### 2.0.3 (May 02, 2017)
-* [CB-8978](https://issues.apache.org/jira/browse/CB-8978) Add option to get `resource-file` from `root`
-* [CB-11908](https://issues.apache.org/jira/browse/CB-11908) Add tests for `edit-config` in `config.xml`
-* [CB-12665](https://issues.apache.org/jira/browse/CB-12665) removed `enginestrict` since it is deprecated
-
-### 2.0.2 (Apr 14, 2017)
-* [CB-11233](https://issues.apache.org/jira/browse/CB-11233) - Support installing frameworks into 'Embedded Binaries' section of the Xcode project
-* [CB-10438](https://issues.apache.org/jira/browse/CB-10438) - Install correct dependency version. Removed shell.remove, added pkg.json to dependency tests 1-3, and updated install.js (.replace) to fix tests in uninstall.spec.js and update to workw with jasmine 2.0
-* [CB-11120](https://issues.apache.org/jira/browse/CB-11120) - Allow short/display name in config.xml
-* [CB-11346](https://issues.apache.org/jira/browse/CB-11346) - Remove known platforms check
-* [CB-11977](https://issues.apache.org/jira/browse/CB-11977) - updated engines and enginescript for common, fetch, and serve
-
-### 2.0.1 (Mar 09, 2017)
-* [CB-12557](https://issues.apache.org/jira/browse/CB-12557) add both stdout and stderr properties to the error object passed to superspawn reject handler.
-
-### 2.0.0 (Jan 17, 2017)
-* [CB-8978](https://issues.apache.org/jira/browse/CB-8978) Add `resource-file` parsing to `config.xml`
-* [CB-12018](https://issues.apache.org/jira/browse/CB-12018): updated `jshint` and updated tests to work with `jasmine@2` instead of `jasmine-node`
-* [CB-12163](https://issues.apache.org/jira/browse/CB-12163) Add reference attrib to `resource-file` for **Windows**
-* Move windows-specific logic to `cordova-windows`
-* [CB-12189](https://issues.apache.org/jira/browse/CB-12189) Add implementation attribute to framework
-
-### 1.5.1 (Oct 12, 2016)
-* [CB-12002](https://issues.apache.org/jira/browse/CB-12002) Add `getAllowIntents()` to `ConfigParser`
-* [CB-11998](https://issues.apache.org/jira/browse/CB-11998) `cordova platform add` error with `cordova-common@1.5.0`
-
-### 1.5.0 (Oct 06, 2016)
-* [CB-11776](https://issues.apache.org/jira/browse/CB-11776) Add test case for different `edit-config` targets
-* [CB-11908](https://issues.apache.org/jira/browse/CB-11908) Add `edit-config` to `config.xml`
-* [CB-11936](https://issues.apache.org/jira/browse/CB-11936) Support four new **App Transport Security (ATS)** keys
-* update `config.xml` location if it is a **Android Studio** project.
-* use `array` methods and `object.keys` for iterating. avoiding `for-in` loops
-* [CB-11517](https://issues.apache.org/jira/browse/CB-11517) Allow `.folder` matches
-* [CB-11776](https://issues.apache.org/jira/browse/CB-11776) check `edit-config` target exists
-
-### 1.4.1 (Aug 09, 2016)
-* Add general purpose `ConfigParser.getAttribute` API
-* [CB-11653](https://issues.apache.org/jira/browse/CB-11653) moved `findProjectRoot` from `cordova-lib` to `cordova-common`
-* [CB-11636](https://issues.apache.org/jira/browse/CB-11636) Handle attributes with quotes correctly
-* [CB-11645](https://issues.apache.org/jira/browse/CB-11645) added check to see if `getEditConfig` exists before trying to use it
-* [CB-9825](https://issues.apache.org/jira/browse/CB-9825) framework tag spec parsing
-
-### 1.4.0 (Jul 12, 2016)
-* [CB-11023](https://issues.apache.org/jira/browse/CB-11023) Add edit-config functionality
-
-### 1.3.0 (May 12, 2016)
-* [CB-11259](https://issues.apache.org/jira/browse/CB-11259): Improving prepare and build logging
-* [CB-11194](https://issues.apache.org/jira/browse/CB-11194) Improve cordova load time
-* [CB-1117](https://issues.apache.org/jira/browse/CB-1117) Add `FileUpdater` module to `cordova-common`.
-* [CB-11131](https://issues.apache.org/jira/browse/CB-11131) Fix `TypeError: message.toUpperCase` is not a function in `CordovaLogger`
-
-### 1.2.0 (Apr 18, 2016)
-* [CB-11022](https://issues.apache.org/jira/browse/CB-11022) Save modulesMetadata to both www and platform_www when necessary
-* [CB-10833](https://issues.apache.org/jira/browse/CB-10833) Deduplicate common logic for plugin installation/uninstallation
-* [CB-10822](https://issues.apache.org/jira/browse/CB-10822) Manage plugins/modules metadata using PlatformJson
-* [CB-10940](https://issues.apache.org/jira/browse/CB-10940) Can't add Android platform from path
-* [CB-10965](https://issues.apache.org/jira/browse/CB-10965) xml helper allows multiple instances to be merge in config.xml
-
-### 1.1.1 (Mar 18, 2016)
-* [CB-10694](https://issues.apache.org/jira/browse/CB-10694) Update test to reflect merging of [CB-9264](https://issues.apache.org/jira/browse/CB-9264) fix
-* [CB-10694](https://issues.apache.org/jira/browse/CB-10694) Platform-specific configuration preferences don't override global settings
-* [CB-9264](https://issues.apache.org/jira/browse/CB-9264) Duplicate entries in `config.xml`
-* [CB-10791](https://issues.apache.org/jira/browse/CB-10791) Add `adjustLoggerLevel` to `cordova-common.CordovaLogger`
-* [CB-10662](https://issues.apache.org/jira/browse/CB-10662) Add tests for `ConfigParser.getStaticResources`
-* [CB-10622](https://issues.apache.org/jira/browse/CB-10622) fix target attribute being ignored for images in `config.xml`.
-* [CB-10583](https://issues.apache.org/jira/browse/CB-10583) Protect plugin preferences from adding extra Array properties.
-
-### 1.1.0 (Feb 16, 2016)
-* [CB-10482](https://issues.apache.org/jira/browse/CB-10482) Remove references to windows8 from cordova-lib/cli
-* [CB-10430](https://issues.apache.org/jira/browse/CB-10430) Adds forwardEvents method to easily connect two EventEmitters
-* [CB-10176](https://issues.apache.org/jira/browse/CB-10176) Adds CordovaLogger class, based on logger module from cordova-cli
-* [CB-10052](https://issues.apache.org/jira/browse/CB-10052) Expose child process' io streams via promise progress notification
-* [CB-10497](https://issues.apache.org/jira/browse/CB-10497) Prefer .bat over .cmd on windows platform
-* [CB-9984](https://issues.apache.org/jira/browse/CB-9984) Bumps plist version and fixes failing cordova-common test
-
-### 1.0.0 (Oct 29, 2015)
-
-* [CB-9890](https://issues.apache.org/jira/browse/CB-9890) Documents cordova-common
-* [CB-9598](https://issues.apache.org/jira/browse/CB-9598) Correct cordova-lib -> cordova-common in README
-* Pick ConfigParser changes from apache@0c3614e
-* [CB-9743](https://issues.apache.org/jira/browse/CB-9743) Removes system frameworks handling from ConfigChanges
-* [CB-9598](https://issues.apache.org/jira/browse/CB-9598) Cleans out code which has been moved to `cordova-common`
-* Pick ConfigParser changes from apache@ddb027b
-* Picking CordovaError changes from apache@a3b1fca
-* [CB-9598](https://issues.apache.org/jira/browse/CB-9598) Adds tests and fixtures based on existing cordova-lib ones
-* [CB-9598](https://issues.apache.org/jira/browse/CB-9598) Initial implementation for cordova-common
-
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/fc72293c/cordova-common/cordova-common.js
----------------------------------------------------------------------
diff --git a/cordova-common/cordova-common.js b/cordova-common/cordova-common.js
deleted file mode 100644
index 801d510..0000000
--- a/cordova-common/cordova-common.js
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-
-var addProperty = require('./src/util/addProperty');
-
-module.exports = { };
-
-addProperty(module, 'events', './src/events');
-addProperty(module, 'superspawn', './src/superspawn');
-
-addProperty(module, 'ActionStack', './src/ActionStack');
-addProperty(module, 'CordovaError', './src/CordovaError/CordovaError');
-addProperty(module, 'CordovaLogger', './src/CordovaLogger');
-addProperty(module, 'CordovaCheck', './src/CordovaCheck');
-addProperty(module, 'CordovaExternalToolErrorContext', './src/CordovaError/CordovaExternalToolErrorContext');
-addProperty(module, 'PlatformJson', './src/PlatformJson');
-addProperty(module, 'ConfigParser', './src/ConfigParser/ConfigParser');
-addProperty(module, 'FileUpdater', './src/FileUpdater');
-
-addProperty(module, 'PluginInfo', './src/PluginInfo/PluginInfo');
-addProperty(module, 'PluginInfoProvider', './src/PluginInfo/PluginInfoProvider');
-
-addProperty(module, 'PluginManager', './src/PluginManager');
-
-addProperty(module, 'ConfigChanges', './src/ConfigChanges/ConfigChanges');
-addProperty(module, 'ConfigKeeper', './src/ConfigChanges/ConfigKeeper');
-addProperty(module, 'ConfigFile', './src/ConfigChanges/ConfigFile');
-addProperty(module, 'mungeUtil', './src/ConfigChanges/munge-util');
-
-addProperty(module, 'xmlHelpers', './src/util/xml-helpers');
-
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/fc72293c/cordova-common/package.json
----------------------------------------------------------------------
diff --git a/cordova-common/package.json b/cordova-common/package.json
deleted file mode 100644
index 44ccd3c..0000000
--- a/cordova-common/package.json
+++ /dev/null
@@ -1,48 +0,0 @@
-{
- "author": "Apache Software Foundation",
- "name": "cordova-common",
- "description": "Apache Cordova tools and platforms shared routines",
- "license": "Apache-2.0",
- "version": "2.0.4-dev",
- "repository": {
- "type": "git",
- "url": "https://github.com/apache/cordova-lib"
- },
- "bugs": {
- "url": "https://issues.apache.org/jira/browse/CB",
- "email": "dev@cordova.apache.org"
- },
- "main": "cordova-common.js",
- "engines": {
- "node": ">=4.0.0"
- },
- "scripts": {
- "test": "npm run jshint && npm run jasmine",
- "jshint": "jshint src && jshint spec",
- "jasmine": "jasmine JASMINE_CONFIG_PATH=spec/support/jasmine.json",
- "cover": "istanbul cover --root src --print detail jasmine"
- },
- "dependencies": {
- "ansi": "^0.3.1",
- "bplist-parser": "^0.1.0",
- "cordova-registry-mapper": "^1.1.8",
- "elementtree": "0.1.6",
- "glob": "^5.0.13",
- "minimatch": "^3.0.0",
- "osenv": "^0.1.3",
- "plist": "^1.2.0",
- "q": "^1.4.1",
- "semver": "^5.0.1",
- "shelljs": "^0.5.3",
- "underscore": "^1.8.3",
- "unorm": "^1.3.3"
- },
- "devDependencies": {
- "istanbul": "^0.4.5",
- "jasmine": "^2.5.2",
- "jshint": "^2.8.0",
- "promise-matchers": "^0.9.6",
- "rewire": "^2.5.1"
- },
- "contributors": []
-}
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/fc72293c/cordova-common/spec/.jshintrc
----------------------------------------------------------------------
diff --git a/cordova-common/spec/.jshintrc b/cordova-common/spec/.jshintrc
deleted file mode 100644
index 17eae32..0000000
--- a/cordova-common/spec/.jshintrc
+++ /dev/null
@@ -1,11 +0,0 @@
-{
- "node": true
- , "bitwise": true
- , "undef": true
- , "trailing": true
- , "quotmark": true
- , "indent": 4
- , "unused": "vars"
- , "latedef": "nofunc"
- , "jasmine": true
-}
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/fc72293c/cordova-common/spec/ActionStack.spec.js
----------------------------------------------------------------------
diff --git a/cordova-common/spec/ActionStack.spec.js b/cordova-common/spec/ActionStack.spec.js
deleted file mode 100644
index 80d6c4d..0000000
--- a/cordova-common/spec/ActionStack.spec.js
+++ /dev/null
@@ -1,77 +0,0 @@
-/**
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-var path = require('path');
-var action_stack = require('../src/ActionStack');
-var android_one_project = path.join(__dirname, '..', 'projects', 'android_one');
-
-describe('action-stack', function() {
- var stack;
- beforeEach(function() {
- stack = new action_stack();
- });
- describe('processing of actions', function() {
- it('Test 001 : should process actions one at a time until all are done', function() {
- var first_spy = jasmine.createSpy();
- var first_args = [1];
- var second_spy = jasmine.createSpy();
- var second_args = [2];
- var third_spy = jasmine.createSpy();
- var third_args = [3];
- stack.push(stack.createAction(first_spy, first_args, function(){}, []));
- stack.push(stack.createAction(second_spy, second_args, function(){}, []));
- stack.push(stack.createAction(third_spy, third_args, function(){}, []));
- stack.process('android', android_one_project);
- expect(first_spy).toHaveBeenCalledWith(first_args[0]);
- expect(second_spy).toHaveBeenCalledWith(second_args[0]);
- expect(third_spy).toHaveBeenCalledWith(third_args[0]);
- });
- it('Test 002 : should revert processed actions if an exception occurs', function(done) {
- spyOn(console, 'log');
- var first_spy = jasmine.createSpy();
- var first_args = [1];
- var first_reverter = jasmine.createSpy();
- var first_reverter_args = [true];
- var process_err = new Error('process_err');
- var second_spy = jasmine.createSpy().and.callFake(function() {
- throw process_err;
- });
- var second_args = [2];
- var third_spy = jasmine.createSpy();
- var third_args = [3];
- stack.push(stack.createAction(first_spy, first_args, first_reverter, first_reverter_args));
- stack.push(stack.createAction(second_spy, second_args, function(){}, []));
- stack.push(stack.createAction(third_spy, third_args, function(){}, []));
- // process should throw
- var error;
- stack.process('android', android_one_project)
- .then(function(){
- expect(false).toBe(true);
- }).fail(function(err){
- error = err;
- expect(error).toEqual(process_err);
- // first two actions should have been called, but not the third
- expect(first_spy).toHaveBeenCalledWith(first_args[0]);
- expect(second_spy).toHaveBeenCalledWith(second_args[0]);
- expect(third_spy).not.toHaveBeenCalledWith(third_args[0]);
- // first reverter should have been called after second action exploded
- expect(first_reverter).toHaveBeenCalledWith(first_reverter_args[0]);
- }).fin(done);
- });
- });
-});
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/fc72293c/cordova-common/spec/ConfigChanges/ConfigChanges.spec.js
----------------------------------------------------------------------
diff --git a/cordova-common/spec/ConfigChanges/ConfigChanges.spec.js b/cordova-common/spec/ConfigChanges/ConfigChanges.spec.js
deleted file mode 100644
index 096a8ec..0000000
--- a/cordova-common/spec/ConfigChanges/ConfigChanges.spec.js
+++ /dev/null
@@ -1,548 +0,0 @@
-/**
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-
-/* jshint sub:true */
-
-var configChanges = require('../../src/ConfigChanges/ConfigChanges'),
- xml_helpers = require('../../src/util/xml-helpers'),
- fs = require('fs'),
- os = require('osenv'),
- et = require('elementtree'),
- path = require('path'),
- shell = require('shelljs'),
- temp = path.join(os.tmpdir(), 'plugman'),
- dummyplugin = path.join(__dirname, '../fixtures/plugins/org.test.plugins.dummyplugin'),
- cbplugin = path.join(__dirname, '../fixtures/plugins/org.test.plugins.childbrowser'),
- childrenplugin = path.join(__dirname, '../fixtures/plugins/org.test.multiple-children'),
- shareddepsplugin = path.join(__dirname, '../fixtures/plugins/org.test.shareddeps'),
- configplugin = path.join(__dirname, '../fixtures/plugins/org.test.configtest'),
- editconfigplugin = path.join(__dirname, '../fixtures/plugins/org.test.editconfigtest'),
- editconfigplugin_two = path.join(__dirname, '../fixtures/plugins/org.test.editconfigtest_two'),
- varplugin = path.join(__dirname, '../fixtures/plugins/com.adobe.vars'),
- plistplugin = path.join(__dirname, '../fixtures/plugins/org.apache.plist'),
- android_two_project = path.join(__dirname, '../fixtures/projects/android_two/*'),
- android_two_no_perms_project = path.join(__dirname, '../fixtures/projects/android_two_no_perms', '*'),
- ios_config_xml = path.join(__dirname, '../fixtures/projects/ios-config-xml/*'),
- plugins_dir = path.join(temp, 'cordova', 'plugins');
-var mungeutil = require('../../src/ConfigChanges/munge-util');
-var PlatformJson = require('../../src/PlatformJson');
-var PluginInfoProvider = require('../../src/PluginInfo/PluginInfoProvider');
-var PluginInfo = require('../../src/PluginInfo/PluginInfo');
-var ConfigParser = require('../../src/ConfigParser/ConfigParser');
-var xml = path.join(__dirname, '../fixtures/test-config.xml');
-var editconfig_xml = path.join(__dirname, '../fixtures/test-editconfig.xml');
-var cfg = new ConfigParser(xml);
-
-// TODO: dont do fs so much
-
-var pluginInfoProvider = new PluginInfoProvider();
-
-function innerXML(xmltext) {
- return xmltext.replace(/^<[\w\s\-=\/"\.]+>/, '').replace(/<\/[\w\s\-=\/"\.]+>$/,'');
-}
-
-function get_munge_change(munge, keys) {
- return mungeutil.deep_find.apply(null, arguments);
-}
-
-describe('config-changes module', function() {
- beforeEach(function() {
- shell.mkdir('-p', temp);
- shell.mkdir('-p', plugins_dir);
- });
- afterEach(function() {
- shell.rm('-rf', temp);
- });
-
- describe('queue methods', function() {
- describe('addInstalledPluginToPrepareQueue', function() {
- it('Test 001 : should append specified plugin to platform.json', function() {
- var platformJson = new PlatformJson(null, 'android', null);
- platformJson.addInstalledPluginToPrepareQueue('org.test.plugins.dummyplugin', {});
- var json = platformJson.root;
- expect(json.prepare_queue.installed[0].plugin).toEqual('org.test.plugins.dummyplugin');
- expect(json.prepare_queue.installed[0].vars).toEqual({});
- });
- it('Test 002 : should append specified plugin with any variables to platform.json', function() {
- var platformJson = new PlatformJson(null, 'android', null);
- platformJson.addInstalledPluginToPrepareQueue('org.test.plugins.dummyplugin', {'dude':'man'});
- var json = platformJson.root;
- expect(json.prepare_queue.installed[0].plugin).toEqual('org.test.plugins.dummyplugin');
- expect(json.prepare_queue.installed[0].vars).toEqual({'dude':'man'});
- });
- });
-
- describe('addUninstalledPluginToPrepareQueue', function() {
- it('Test 003 : should append specified plugin to platform.json', function() {
- var platformJson = new PlatformJson(null, 'android', null);
- platformJson.addUninstalledPluginToPrepareQueue('org.test.plugins.dummyplugin');
- var json = platformJson.root;
- expect(json.prepare_queue.uninstalled[0].plugin).toEqual('org.test.plugins.dummyplugin');
- });
- });
- });
-
- describe('load method', function() {
- it('Test 004 : should return an empty config json object if file doesn\'t exist', function() {
- var platformJson = PlatformJson.load(plugins_dir, 'android');
- expect(platformJson.root).toBeDefined();
- expect(platformJson.root.prepare_queue).toBeDefined();
- expect(platformJson.root.config_munge).toBeDefined();
- expect(platformJson.root.installed_plugins).toBeDefined();
- });
- it('Test 005 : should return the json file if it exists', function() {
- var filepath = path.join(plugins_dir, 'android.json');
- var json = {
- prepare_queue: {installed: [], uninstalled: []},
- config_munge: {files: {'some_file': {parents: {'some_parent': [{'xml': 'some_change', 'count': 1}]}}}},
- installed_plugins: {},
- dependent_plugins: {}};
- fs.writeFileSync(filepath, JSON.stringify(json), 'utf-8');
- var platformJson = PlatformJson.load(plugins_dir, 'android');
- expect(JSON.stringify(json)).toEqual(JSON.stringify(platformJson.root));
- });
- });
-
- describe('save method', function() {
- it('Test 006 : should write out specified json', function() {
- var filepath = path.join(plugins_dir, 'android.json');
- var platformJson = new PlatformJson(filepath, 'android', {foo:true});
- platformJson.save();
- expect(JSON.parse(fs.readFileSync(filepath, 'utf-8'))).toEqual(platformJson.root);
- });
- });
-
- describe('generate_plugin_config_munge method', function() {
- describe('for android projects', function() {
- beforeEach(function() {
- shell.cp('-rf', android_two_project, temp);
- });
- it('Test 007 : should return a flat config hierarchy for simple, one-off config changes', function() {
- var xml;
- var dummy_xml = new et.ElementTree(et.XML(fs.readFileSync(path.join(dummyplugin, 'plugin.xml'), 'utf-8')));
- var munger = new configChanges.PlatformMunger('android', temp, 'unused', null, pluginInfoProvider);
- var munge = munger.generate_plugin_config_munge(pluginInfoProvider.get(dummyplugin), {});
- expect(munge.files['AndroidManifest.xml']).toBeDefined();
- expect(munge.files['AndroidManifest.xml'].parents['/manifest/application']).toBeDefined();
- xml = (new et.ElementTree(dummy_xml.find('./platform[@name="android"]/config-file[@target="AndroidManifest.xml"]'))).write({xml_declaration:false});
- xml = innerXML(xml);
- expect(get_munge_change(munge, 'AndroidManifest.xml', '/manifest/application', xml).count).toEqual(1);
- expect(munge.files['res/xml/plugins.xml']).toBeDefined();
- expect(munge.files['res/xml/plugins.xml'].parents['/plugins']).toBeDefined();
- xml = (new et.ElementTree(dummy_xml.find('./platform[@name="android"]/config-file[@target="res/xml/plugins.xml"]'))).write({xml_declaration:false});
- xml = innerXML(xml);
- expect(get_munge_change(munge, 'res/xml/plugins.xml', '/plugins', xml).count).toEqual(1);
- expect(munge.files['res/xml/config.xml']).toBeDefined();
- expect(munge.files['res/xml/config.xml'].parents['/cordova/plugins']).toBeDefined();
- xml = (new et.ElementTree(dummy_xml.find('./platform[@name="android"]/config-file[@target="res/xml/config.xml"]'))).write({xml_declaration:false});
- xml = innerXML(xml);
- expect(get_munge_change(munge, 'res/xml/config.xml', '/cordova/plugins', xml).count).toEqual(1);
- });
- it('Test 008 : should split out multiple children of config-file elements into individual leaves', function() {
- var munger = new configChanges.PlatformMunger('android', temp, 'unused', null, pluginInfoProvider);
- var munge = munger.generate_plugin_config_munge(pluginInfoProvider.get(childrenplugin), {PACKAGE_NAME: 'com.alunny.childapp'});
- expect(munge.files['AndroidManifest.xml']).toBeDefined();
- expect(munge.files['AndroidManifest.xml'].parents['/manifest']).toBeDefined();
- expect(get_munge_change(munge, 'AndroidManifest.xml', '/manifest', '<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />')).toBeDefined();
- expect(get_munge_change(munge, 'AndroidManifest.xml', '/manifest', '<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />')).toBeDefined();
- expect(get_munge_change(munge, 'AndroidManifest.xml', '/manifest', '<uses-permission android:name="android.permission.READ_PHONE_STATE" />')).toBeDefined();
- expect(get_munge_change(munge, 'AndroidManifest.xml', '/manifest', '<uses-permission android:name="android.permission.INTERNET" />')).toBeDefined();
- expect(get_munge_change(munge, 'AndroidManifest.xml', '/manifest', '<uses-permission android:name="android.permission.GET_ACCOUNTS" />')).toBeDefined();
- expect(get_munge_change(munge, 'AndroidManifest.xml', '/manifest', '<uses-permission android:name="android.permission.WAKE_LOCK" />')).toBeDefined();
- expect(get_munge_change(munge, 'AndroidManifest.xml', '/manifest', '<permission android:name="com.alunny.childapp.permission.C2D_MESSAGE" android:protectionLevel="signature" />')).toBeDefined();
- expect(get_munge_change(munge, 'AndroidManifest.xml', '/manifest', '<uses-permission android:name="com.alunny.childapp.permission.C2D_MESSAGE" />')).toBeDefined();
- expect(get_munge_change(munge, 'AndroidManifest.xml', '/manifest', '<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />')).toBeDefined();
- });
- it('Test 009 : should not use xml comments as config munge leaves', function() {
- var munger = new configChanges.PlatformMunger('android', temp, 'unused', null, pluginInfoProvider);
- var munge = munger.generate_plugin_config_munge(pluginInfoProvider.get(childrenplugin), {});
- expect(get_munge_change(munge, 'AndroidManifest.xml', '/manifest', '<!--library-->')).not.toBeDefined();
- expect(get_munge_change(munge, 'AndroidManifest.xml', '/manifest', '<!-- GCM connects to Google Services. -->')).not.toBeDefined();
- });
- it('Test 010 : should increment config hierarchy leaves if different config-file elements target the same file + selector + xml', function() {
- var munger = new configChanges.PlatformMunger('android', temp, 'unused', null, pluginInfoProvider);
- var munge = munger.generate_plugin_config_munge(pluginInfoProvider.get(configplugin), {});
- expect(get_munge_change(munge, 'res/xml/config.xml', '/widget', '<poop />').count).toEqual(2);
- });
- it('Test 011 : should take into account interpolation variables', function() {
- var munger = new configChanges.PlatformMunger('android', temp, 'unused', null, pluginInfoProvider);
- var munge = munger.generate_plugin_config_munge(pluginInfoProvider.get(childrenplugin), {PACKAGE_NAME:'ca.filmaj.plugins'});
- expect(get_munge_change(munge, 'AndroidManifest.xml', '/manifest', '<uses-permission android:name="ca.filmaj.plugins.permission.C2D_MESSAGE" />')).toBeDefined();
- });
- it('Test 012 : should create munges for platform-agnostic config.xml changes', function() {
- var munger = new configChanges.PlatformMunger('android', temp, 'unused', null, pluginInfoProvider);
- var munge = munger.generate_plugin_config_munge(pluginInfoProvider.get(dummyplugin), {});
- expect(get_munge_change(munge, 'config.xml', '/*', '<access origin="build.phonegap.com" />')).toBeDefined();
- expect(get_munge_change(munge, 'config.xml', '/*', '<access origin="s3.amazonaws.com" />')).toBeDefined();
- });
- });
- });
-
- describe('processing of plugins (via process method)', function() {
- beforeEach(function() {
- shell.cp('-rf', dummyplugin, plugins_dir);
- });
- it('Test 014 : should generate config munges for queued plugins', function() {
- shell.cp('-rf', android_two_project, temp);
- var platformJson = PlatformJson.load(plugins_dir, 'android');
- platformJson.root.prepare_queue.installed = [{'plugin':'org.test.plugins.dummyplugin', 'vars':{}}];
- var munger = new configChanges.PlatformMunger('android', temp, platformJson, pluginInfoProvider);
- var spy = spyOn(munger, 'generate_plugin_config_munge').and.returnValue({});
- munger.process(plugins_dir);
- expect(spy).toHaveBeenCalledWith(jasmine.any(PluginInfo), {});
- });
- describe(': installation', function() {
- describe('of xml config files', function() {
- beforeEach(function() {
- shell.cp('-rf', android_two_project, temp);
- });
- it('Test 015 : should call graftXML for every new config munge it introduces (every leaf in config munge that does not exist)', function() {
- var platformJson = PlatformJson.load(plugins_dir, 'android');
- platformJson.root.prepare_queue.installed = [{'plugin':'org.test.plugins.dummyplugin', 'vars':{}}];
-
- var spy = spyOn(xml_helpers, 'graftXML').and.returnValue(true);
-
- var munger = new configChanges.PlatformMunger('android', temp, platformJson, pluginInfoProvider);
- munger.process(plugins_dir);
- expect(spy.calls.count()).toEqual(4);
- expect(spy.calls.argsFor(0)[2]).toEqual('/*');
- expect(spy.calls.argsFor(1)[2]).toEqual('/*');
- expect(spy.calls.argsFor(2)[2]).toEqual('/manifest/application');
- expect(spy.calls.argsFor(3)[2]).toEqual('/cordova/plugins');
- });
- it('Test 016 : should not call graftXML for a config munge that already exists from another plugin', function() {
- shell.cp('-rf', configplugin, plugins_dir);
- var platformJson = PlatformJson.load(plugins_dir, 'android');
- platformJson.addInstalledPluginToPrepareQueue('org.test.configtest', {});
-
- var spy = spyOn(xml_helpers, 'graftXML').and.returnValue(true);
- var munger = new configChanges.PlatformMunger('android', temp, platformJson, pluginInfoProvider);
- munger.process(plugins_dir);
- expect(spy.calls.count()).toEqual(1);
- });
- it('Test 017 : should not call graftXML for a config munge targeting a config file that does not exist', function() {
- var platformJson = PlatformJson.load(plugins_dir, 'android');
- platformJson.addInstalledPluginToPrepareQueue('org.test.plugins.dummyplugin', {});
-
- var spy = spyOn(fs, 'readFileSync').and.callThrough();
-
- var munger = new configChanges.PlatformMunger('android', temp, platformJson, pluginInfoProvider);
- munger.process(plugins_dir);
- expect(spy).not.toHaveBeenCalledWith(path.join(temp, 'res', 'xml', 'plugins.xml'), 'utf-8');
- });
- it('Test 018 : should call graftXMLMerge for every new config munge with mode \'merge\' it introduces', function() {
- shell.cp('-rf', editconfigplugin, plugins_dir);
- var platformJson = PlatformJson.load(plugins_dir, 'android');
- platformJson.addInstalledPluginToPrepareQueue('org.test.editconfigtest', {});
-
- var spy = spyOn(xml_helpers, 'graftXMLMerge').and.returnValue(true);
-
- var munger = new configChanges.PlatformMunger('android', temp, platformJson, pluginInfoProvider);
- munger.process(plugins_dir);
- expect(spy.calls.count()).toEqual(1);
- expect(spy.calls.argsFor(0)[2]).toEqual('/manifest/application/activity[@android:name=\'org.test.DroidGap\']');
- });
- it('Test 019 : should call graftXMLMerge with --force for every new config munge with mode \'merge\' it introduces', function() {
- shell.cp('-rf', editconfigplugin, plugins_dir);
- shell.cp('-rf', editconfigplugin_two, plugins_dir);
- var platformJson = PlatformJson.load(plugins_dir, 'android');
- platformJson.addInstalledPluginToPrepareQueue('org.test.editconfigtest', {});
- platformJson.addInstalledPluginToPrepareQueue('org.test.editconfigtest_two', {}, true, true);
-
- var spy = spyOn(xml_helpers, 'graftXMLMerge').and.returnValue(true);
-
- var munger = new configChanges.PlatformMunger('android', temp, platformJson, pluginInfoProvider);
- munger.process(plugins_dir);
- expect(spy.calls.count()).toEqual(3);
- expect(spy.calls.argsFor(0)[2]).toEqual('/manifest/application/activity[@android:name=\'org.test.DroidGap\']');
- expect(spy.calls.argsFor(1)[2]).toEqual('/manifest/application/activity[@android:name=\'org.test.DroidGap\']');
- expect(spy.calls.argsFor(2)[2]).toEqual('/manifest/uses-sdk');
- });
- it('Test 020 : should call graftXMLOverwrite for every new config munge with mode \'overwrite\' it introduces', function() {
- shell.cp('-rf', editconfigplugin, plugins_dir);
- var platformJson = PlatformJson.load(plugins_dir, 'android');
- platformJson.addInstalledPluginToPrepareQueue('org.test.editconfigtest', {});
-
- var spy = spyOn(xml_helpers, 'graftXMLOverwrite').and.returnValue(true);
-
- var munger = new configChanges.PlatformMunger('android', temp, platformJson, pluginInfoProvider);
- munger.process(plugins_dir);
- expect(spy.calls.count()).toEqual(1);
- expect(spy.calls.argsFor(0)[2]).toEqual('/manifest/application/activity');
- });
- it('Test 021 : should call graftXMLOverwrite with --force for every new config munge with mode \'overwrite\' it introduces', function() {
- shell.cp('-rf', editconfigplugin, plugins_dir);
- shell.cp('-rf', editconfigplugin_two, plugins_dir);
- var platformJson = PlatformJson.load(plugins_dir, 'android');
- platformJson.addInstalledPluginToPrepareQueue('org.test.editconfigtest', {});
- platformJson.addInstalledPluginToPrepareQueue('org.test.editconfigtest_two', {}, true, true);
-
- var spy = spyOn(xml_helpers, 'graftXMLOverwrite').and.returnValue(true);
-
- var munger = new configChanges.PlatformMunger('android', temp, platformJson, pluginInfoProvider);
- munger.process(plugins_dir);
- expect(spy.calls.count()).toEqual(2);
- expect(spy.calls.argsFor(0)[2]).toEqual('/manifest/application/activity');
- expect(spy.calls.argsFor(1)[2]).toEqual('/manifest/application/activity[@android:name=\'ChildApp\']');
- });
- it('Test 022 : should not install plugin when there are edit-config conflicts', function() {
- shell.cp('-rf', editconfigplugin, plugins_dir);
- shell.cp('-rf', editconfigplugin_two, plugins_dir);
- var platformJson = PlatformJson.load(plugins_dir, 'android');
- platformJson.addInstalledPluginToPrepareQueue('org.test.editconfigtest', {});
- platformJson.addInstalledPluginToPrepareQueue('org.test.editconfigtest_two', {});
-
- var munger = new configChanges.PlatformMunger('android', temp, platformJson, pluginInfoProvider);
- expect(function() {munger.process(plugins_dir);}).toThrow(new Error('There was a conflict trying to modify attributes with <edit-config> in plugin org.test.editconfigtest_two. The conflicting plugin, org.test.editconfigtest, already modified the same attributes. The conflict must be resolved before org.test.editconfigtest_two can be added. You may use --force to add the plugin and overwrite the conflicting attributes.'));
- });
- it('should call graftXMLMerge for every new config.xml config munge with mode \'merge\' it introduces', function() {
- var platformJson = PlatformJson.load(plugins_dir, 'android');
-
- var spy = spyOn(xml_helpers, 'graftXMLMerge').and.returnValue(true);
-
- var munger = new configChanges.PlatformMunger('android', temp, platformJson);
- munger.add_config_changes(cfg, true);
-
- expect(spy.calls.count()).toEqual(1);
- expect(spy.calls.argsFor(0)[2]).toEqual('/manifest/uses-sdk');
- });
- it('should call graftXMLOverwrite for every new config.xml config munge with mode \'overwrite\' it introduces', function() {
- var platformJson = PlatformJson.load(plugins_dir, 'android');
-
- var spy = spyOn(xml_helpers, 'graftXMLOverwrite').and.returnValue(true);
-
- var munger = new configChanges.PlatformMunger('android', temp, platformJson);
- munger.add_config_changes(cfg, true);
-
- expect(spy.calls.count()).toEqual(1);
- expect(spy.calls.argsFor(0)[2]).toEqual('/manifest/uses-sdk');
- });
- it('should call pruneXMLRemove for every new config.xml config munge with mode \'remove\' it introduces', function() {
- var platformJson = PlatformJson.load(plugins_dir, 'android');
-
- // var spy = spyOn(xml_helpers, 'pruneXMLRemove').andReturn(true);
-
- var munger = new configChanges.PlatformMunger('android', temp, platformJson);
- munger.add_config_changes(cfg, true).save_all();
-
- var am_xml = new et.ElementTree(et.XML(fs.readFileSync(path.join(temp, 'AndroidManifest.xml'), 'utf-8')));
- var sdk = am_xml.find('./uses-sdk');
-
- expect(sdk).toBeDefined();
- expect(sdk.attrib['android:maxSdkVersion']).toBeUndefined();
- });
- it('should overwrite plugin config munge for every conflicting config.xml config munge', function() {
- shell.cp('-rf', editconfigplugin_two, plugins_dir);
- var platformJson = PlatformJson.load(plugins_dir, 'android');
- platformJson.addInstalledPluginToPrepareQueue('org.test.editconfigtest_two', {}, true, true);
-
- var munger = new configChanges.PlatformMunger('android', temp, platformJson, pluginInfoProvider);
- munger.process(plugins_dir);
- munger.add_config_changes(cfg, true).save_all();
-
- var am_xml = new et.ElementTree(et.XML(fs.readFileSync(path.join(temp, 'AndroidManifest.xml'), 'utf-8')));
- var sdk = am_xml.find('./uses-sdk');
- expect(sdk).toBeDefined();
- expect(sdk.attrib['android:targetSdkVersion']).toEqual('24');
- });
- it('should overwrite config.xml config munge for every new config.xml config munge that has the same target', function() {
- var editconfig_cfg = new ConfigParser(editconfig_xml);
- var platformJson = PlatformJson.load(plugins_dir, 'android');
- var munger = new configChanges.PlatformMunger('android', temp, platformJson, pluginInfoProvider);
-
- munger.add_config_changes(cfg, true).save_all();
- munger.add_config_changes(editconfig_cfg, true).save_all();
-
- var am_xml = new et.ElementTree(et.XML(fs.readFileSync(path.join(temp, 'AndroidManifest.xml'), 'utf-8')));
- var sdk = am_xml.find('./uses-sdk');
- expect(sdk).toBeDefined();
- expect(sdk.attrib['android:targetSdkVersion']).toEqual('23');
- expect(sdk.attrib['android:minSdkVersion']).toEqual('5');
- expect(sdk.attrib['android:maxSdkVersion']).toBeUndefined();
- });
- it('should throw error for conflicting plugin config munge with config.xml config munge', function() {
- shell.cp('-rf', editconfigplugin_two, plugins_dir);
- var platformJson = PlatformJson.load(plugins_dir, 'android');
- platformJson.addInstalledPluginToPrepareQueue('org.test.editconfigtest_two', {}, true, true);
-
- var munger = new configChanges.PlatformMunger('android', temp, platformJson, pluginInfoProvider);
- munger.add_config_changes(cfg, true);
- expect(function() {munger.process(plugins_dir);}).toThrow(new Error('org.test.editconfigtest_two cannot be added. <edit-config> changes in this plugin conflicts with <edit-config> changes in config.xml. Conflicts must be resolved before plugin can be added.'));
-
- });
- });
- describe('of plist config files', function() {
- it('Test 023 : should write empty string nodes with no whitespace', function() {
- shell.cp('-rf', ios_config_xml, temp);
- shell.cp('-rf', varplugin, plugins_dir);
- var platformJson = PlatformJson.load(plugins_dir, 'ios');
- platformJson.addInstalledPluginToPrepareQueue('com.adobe.vars', {});
- configChanges.process(plugins_dir, temp, 'ios', platformJson, pluginInfoProvider);
- expect(fs.readFileSync(path.join(temp, 'SampleApp', 'SampleApp-Info.plist'), 'utf-8')).toMatch(/<key>APluginNode<\/key>\n <string\/>/m);
- });
- it('Test 024 : should merge dictionaries and arrays, removing duplicates', function() {
- shell.cp('-rf', ios_config_xml, temp);
- shell.cp('-rf', plistplugin, plugins_dir);
- var platformJson = PlatformJson.load(plugins_dir, 'ios');
- platformJson.addInstalledPluginToPrepareQueue('org.apache.plist', {});
- configChanges.process(plugins_dir, temp, 'ios', platformJson, pluginInfoProvider);
- expect(fs.readFileSync(path.join(temp, 'SampleApp', 'SampleApp-Info.plist'), 'utf-8')).toMatch(/<key>UINewsstandIcon<\/key>[\s\S]*<key>CFBundlePrimaryIcon<\/key>/);
- expect(fs.readFileSync(path.join(temp, 'SampleApp', 'SampleApp-Info.plist'), 'utf-8')).toMatch(/<string>schema-b<\/string>/);
- expect(fs.readFileSync(path.join(temp, 'SampleApp', 'SampleApp-Info.plist'), 'utf-8')).not.toMatch(/(<string>schema-a<\/string>[^]*){2,}/);
- });
- });
- it('Test 025 : should resolve wildcard config-file targets to the project, if applicable', function() {
- shell.cp('-rf', ios_config_xml, temp);
- shell.cp('-rf', cbplugin, plugins_dir);
- var platformJson = PlatformJson.load(plugins_dir, 'ios');
- platformJson.addInstalledPluginToPrepareQueue('org.test.plugins.childbrowser', {});
- var spy = spyOn(fs, 'readFileSync').and.callThrough();
-
- var munger = new configChanges.PlatformMunger('ios', temp, platformJson, pluginInfoProvider);
- munger.process(plugins_dir);
- expect(spy).toHaveBeenCalledWith(path.join(temp, 'SampleApp', 'SampleApp-Info.plist').replace(/\\/g, '/'), 'utf8');
- });
- it('Test 026 : should move successfully installed plugins from queue to installed plugins section, and include/retain vars if applicable', function() {
- shell.cp('-rf', android_two_project, temp);
- shell.cp('-rf', varplugin, plugins_dir);
- var platformJson = PlatformJson.load(plugins_dir, 'android');
- platformJson.addInstalledPluginToPrepareQueue('com.adobe.vars', {'API_KEY':'hi'}, true);
-
- var munger = new configChanges.PlatformMunger('android', temp, platformJson, pluginInfoProvider);
- munger.process(plugins_dir);
-
- expect(platformJson.root.prepare_queue.installed.length).toEqual(0);
- expect(platformJson.root.installed_plugins['com.adobe.vars']).toBeDefined();
- expect(platformJson.root.installed_plugins['com.adobe.vars']['API_KEY']).toEqual('hi');
- });
- });
-
- describe(': uninstallation', function() {
- it('Test 027 : should call pruneXML for every config munge it completely removes from the app (every leaf that is decremented to 0)', function() {
- shell.cp('-rf', android_two_project, temp);
-
- // Run through an "install"
- var platformJson = PlatformJson.load(plugins_dir, 'android');
- platformJson.addInstalledPluginToPrepareQueue('org.test.plugins.dummyplugin', {});
- var munger = new configChanges.PlatformMunger('android', temp, platformJson, pluginInfoProvider);
- munger.process(plugins_dir);
-
- // Now set up an uninstall and make sure prunexml is called properly
- platformJson.addUninstalledPluginToPrepareQueue('org.test.plugins.dummyplugin');
- var spy = spyOn(xml_helpers, 'pruneXML').and.returnValue(true);
- munger.process(plugins_dir);
- expect(spy.calls.count()).toEqual(4);
- expect(spy.calls.argsFor(0)[2]).toEqual('/*');
- expect(spy.calls.argsFor(1)[2]).toEqual('/*');
- expect(spy.calls.argsFor(2)[2]).toEqual('/manifest/application');
- expect(spy.calls.argsFor(3)[2]).toEqual('/cordova/plugins');
- });
- it('Test 028 : should generate a config munge that interpolates variables into config changes, if applicable', function() {
- shell.cp('-rf', android_two_project, temp);
- shell.cp('-rf', varplugin, plugins_dir);
- // Run through an "install"
- var platformJson = PlatformJson.load(plugins_dir, 'android');
- platformJson.addInstalledPluginToPrepareQueue('com.adobe.vars', {'API_KEY':'canucks'});
- var munger = new configChanges.PlatformMunger('android', temp, platformJson, pluginInfoProvider);
- munger.process(plugins_dir);
-
- // Now set up an uninstall and make sure prunexml is called properly
- platformJson.addUninstalledPluginToPrepareQueue('com.adobe.vars');
- var spy = spyOn(munger, 'generate_plugin_config_munge').and.returnValue({});
- munger.process(plugins_dir);
- var munge_params = spy.calls.argsFor(0);
- expect(munge_params[0]).toEqual(jasmine.any(PluginInfo));
- expect(munge_params[0].dir).toEqual(path.join(plugins_dir, 'com.adobe.vars'));
- expect(munge_params[1]['API_KEY']).toEqual('canucks');
- });
- it('Test 029 : should not call pruneXML for a config munge that another plugin depends on', function() {
- shell.cp('-rf', android_two_no_perms_project, temp);
- shell.cp('-rf', childrenplugin, plugins_dir);
- shell.cp('-rf', shareddepsplugin, plugins_dir);
-
- // Run through and "install" two plugins (they share a permission for INTERNET)
- var platformJson = PlatformJson.load(plugins_dir, 'android');
- platformJson.addInstalledPluginToPrepareQueue('org.test.multiple-children', {});
- platformJson.addInstalledPluginToPrepareQueue('org.test.shareddeps', {});
- var munger = new configChanges.PlatformMunger('android', temp, platformJson, pluginInfoProvider);
- munger.process(plugins_dir);
-
- // Now set up an uninstall for multi-child plugin
- platformJson.addUninstalledPluginToPrepareQueue('org.test.multiple-children');
- munger.process(plugins_dir);
- munger.save_all();
- var am_xml = new et.ElementTree(et.XML(fs.readFileSync(path.join(temp, 'AndroidManifest.xml'), 'utf-8')));
- var permission = am_xml.find('./uses-permission');
- expect(permission).toBeDefined();
- expect(permission.attrib['android:name']).toEqual('android.permission.INTERNET');
- });
- it('Test 030 : should not call pruneXML for a config munge targeting a config file that does not exist', function() {
- shell.cp('-rf', android_two_project, temp);
- // install a plugin
- var platformJson = PlatformJson.load(plugins_dir, 'android');
- platformJson.addInstalledPluginToPrepareQueue('org.test.plugins.dummyplugin', {});
- var munger = new configChanges.PlatformMunger('android', temp, platformJson, pluginInfoProvider);
- munger.process(plugins_dir);
-
- // set up an uninstall for the same plugin
- platformJson.addUninstalledPluginToPrepareQueue('org.test.plugins.dummyplugin');
-
- var spy = spyOn(fs, 'readFileSync').and.callThrough();
- munger.process(plugins_dir);
-
- expect(spy).not.toHaveBeenCalledWith(path.join(temp, 'res', 'xml', 'plugins.xml'), 'utf-8');
- });
- it('Test 031 : should remove uninstalled plugins from installed plugins list', function() {
- shell.cp('-rf', android_two_project, temp);
- shell.cp('-rf', varplugin, plugins_dir);
- // install the var plugin
- var platformJson = PlatformJson.load(plugins_dir, 'android');
- platformJson.addInstalledPluginToPrepareQueue('com.adobe.vars', {'API_KEY':'eat my shorts'});
- var munger = new configChanges.PlatformMunger('android', temp, platformJson, pluginInfoProvider);
- munger.process(plugins_dir);
-
- // queue up an uninstall for the same plugin
- platformJson.addUninstalledPluginToPrepareQueue('com.adobe.vars');
- munger.process(plugins_dir);
-
- expect(platformJson.root.prepare_queue.uninstalled.length).toEqual(0);
- expect(platformJson.root.installed_plugins['com.adobe.vars']).not.toBeDefined();
- });
- it('Test 032 : should call pruneXMLRestore for every config munge with mode \'merge\' or \'overwrite\' it removes from the app', function() {
- shell.cp('-rf', android_two_project, temp);
- shell.cp('-rf', editconfigplugin, plugins_dir);
-
- // Run through an "install"
- var platformJson = PlatformJson.load(plugins_dir, 'android');
- platformJson.addInstalledPluginToPrepareQueue('org.test.editconfigtest', {});
- var munger = new configChanges.PlatformMunger('android', temp, platformJson, pluginInfoProvider);
- munger.process(plugins_dir);
-
- // Now set up an uninstall and make sure pruneXMLMerge is called properly
- platformJson.addUninstalledPluginToPrepareQueue('org.test.editconfigtest');
- var spy = spyOn(xml_helpers, 'pruneXMLRestore').and.returnValue(true);
- munger.process(plugins_dir);
-
- expect(spy.calls.count()).toEqual(2);
- expect(spy.calls.argsFor(0)[1]).toEqual('/manifest/application/activity[@android:name=\'org.test.DroidGap\']');
- expect(spy.calls.argsFor(1)[1]).toEqual('/manifest/application/activity');
- });
- });
- });
-});
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/fc72293c/cordova-common/spec/ConfigParser/ConfigParser.spec.js
----------------------------------------------------------------------
diff --git a/cordova-common/spec/ConfigParser/ConfigParser.spec.js b/cordova-common/spec/ConfigParser/ConfigParser.spec.js
deleted file mode 100644
index 034f3d7..0000000
--- a/cordova-common/spec/ConfigParser/ConfigParser.spec.js
+++ /dev/null
@@ -1,322 +0,0 @@
-/**
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-var path = require('path'),
- fs = require('fs'),
- ConfigParser = require('../../src/ConfigParser/ConfigParser'),
- xml = path.join(__dirname, '../fixtures/test-config.xml'),
- xml_contents = fs.readFileSync(xml, 'utf-8');
-
-describe('config.xml parser', function () {
- var readFile;
- beforeEach(function() {
- readFile = spyOn(fs, 'readFileSync').and.returnValue(xml_contents);
- });
-
- it('Test 001 : should create an instance based on an xml file', function() {
- var cfg;
- expect(function () {
- cfg = new ConfigParser(xml);
- }).not.toThrow();
- expect(cfg).toBeDefined();
- expect(cfg.doc).toBeDefined();
- });
-
- describe('methods', function() {
- var cfg;
- beforeEach(function() {
- cfg = new ConfigParser(xml);
- });
-
- describe('package name / id', function() {
- it('Test 002 : should get the (default) packagename', function() {
- expect(cfg.packageName()).toEqual('io.cordova.hellocordova');
- });
- it('Test 003 : should allow setting the packagename', function() {
- cfg.setPackageName('this.is.bat.country');
- expect(cfg.packageName()).toEqual('this.is.bat.country');
- });
- });
-
- describe('package name / android-packageName', function() {
- it('Test 004 : should get the android packagename', function() {
- expect(cfg.android_packageName()).toEqual('io.cordova.hellocordova.android');
- });
- });
-
- describe('package name / ios-CFBundleIdentifier', function() {
- it('Test 005 : should get the ios packagename', function() {
- expect(cfg.ios_CFBundleIdentifier()).toEqual('io.cordova.hellocordova.ios');
- });
- });
-
- describe('version', function() {
- it('Test 006 : should get the version', function() {
- expect(cfg.version()).toEqual('0.0.1');
- });
- it('Test 007 : should allow setting the version', function() {
- cfg.setVersion('2.0.1');
- expect(cfg.version()).toEqual('2.0.1');
- });
- });
-
- describe('app name', function() {
- it('Test 008 : should get the (default) app name', function() {
- expect(cfg.name()).toEqual('Hello Cordova');
- });
- it('Test 009 : should allow setting the app name', function() {
- cfg.setName('this.is.bat.country');
- expect(cfg.name()).toEqual('this.is.bat.country');
- });
-
- describe('short name', function() {
- it('should default to the app name', function() {
- expect(cfg.shortName()).toEqual('Hello Cordova');
- });
-
- it('should allow setting the app short name', function() {
- cfg.setShortName('Hi CDV');
- expect(cfg.name()).toEqual('Hello Cordova');
- expect(cfg.shortName()).toEqual('Hi CDV');
- });
- });
- });
-
- describe('preference', function() {
- it('Test 010 : should return the value of a global preference', function() {
- expect(cfg.getPreference('fullscreen')).toEqual('true');
- });
- it('Test 011 : should return the value of a platform-specific preference', function() {
- expect(cfg.getPreference('android-minSdkVersion', 'android')).toEqual('10');
- });
- it('Test 012 : should return an empty string for a non-existing preference', function() {
- expect(cfg.getPreference('zimzooo!')).toEqual('');
- });
- });
- describe('global preference', function() {
- it('Test 013 : should return the value of a global preference', function() {
- expect(cfg.getGlobalPreference('orientation')).toEqual('portrait');
- });
- it('Test 014 : should return an empty string for a non-existing preference', function() {
- expect(cfg.getGlobalPreference('foobar')).toEqual('');
- });
- });
- describe('platform-specific preference', function() {
- it('Test 015 : should return the value of a platform specific preference', function() {
- expect(cfg.getPlatformPreference('orientation', 'android')).toEqual('landscape');
- });
- it('Test 016 : should return an empty string when querying for a non-existing preference', function() {
- expect(cfg.getPlatformPreference('foobar', 'android')).toEqual('');
- });
- it('Test 017 : should return an empty string when querying with unsupported platform', function() {
- expect(cfg.getPlatformPreference('orientation', 'foobar')).toEqual('');
- });
- });
- describe('plugin',function(){
- it('Test 018 : should read plugin id list', function() {
- var expectedList = [
- 'org.apache.cordova.pluginwithvars',
- 'org.apache.cordova.pluginwithurl',
- 'org.apache.cordova.pluginwithversion',
- 'org.apache.cordova.pluginwithurlandversion',
- 'org.apache.cordova.justaplugin',
- 'org.apache.cordova.legacyfeatureversion',
- 'org.apache.cordova.legacyfeatureurl',
- 'org.apache.cordova.legacyfeatureversionandurl'
- ];
- var list = cfg.getPluginIdList();
- expect(list.length).toEqual(expectedList.length);
- expectedList.forEach(function(plugin){
- expect(list).toContain(plugin);
- });
- });
- it('Test 019 : should read plugin given id', function(){
- var plugin = cfg.getPlugin('org.apache.cordova.justaplugin');
- expect(plugin).toBeDefined();
- expect(plugin.name).toEqual('org.apache.cordova.justaplugin');
- expect(plugin.variables).toBeDefined();
- });
- it('Test 020 : should not read plugin given undefined id', function(){
- var plugin = cfg.getPlugin('org.apache.cordova.undefinedplugin');
- expect(plugin).not.toBeDefined();
- });
- it('Test 021 : should read plugin with src and store it in spec field', function(){
- var plugin = cfg.getPlugin('org.apache.cordova.pluginwithurl');
- expect(plugin.spec).toEqual('http://cordova.apache.org/pluginwithurl');
- });
- it('Test 022 : should read plugin with version and store it in spec field', function(){
- var plugin = cfg.getPlugin('org.apache.cordova.pluginwithversion');
- expect(plugin.spec).toEqual('1.1.1');
- });
- it('Test 023 : should read plugin with source and version and store source in spec field', function(){
- var plugin = cfg.getPlugin('org.apache.cordova.pluginwithurlandversion');
- expect(plugin.spec).toEqual('http://cordova.apache.org/pluginwithurlandversion');
- });
- it('Test 024 : should read plugin variables', function () {
- var plugin = cfg.getPlugin('org.apache.cordova.pluginwithvars');
- expect(plugin.variables).toBeDefined();
- expect(plugin.variables.var).toBeDefined();
- expect(plugin.variables.var).toEqual('varvalue');
- });
- it('Test 025 : should allow adding a new plugin', function(){
- cfg.addPlugin({name:'myplugin'});
- var plugins = cfg.doc.findall('plugin');
- var pluginNames = plugins.map(function(plugin){
- return plugin.attrib.name;
- });
- expect(pluginNames).toContain('myplugin');
- });
- it('Test 026 : should allow adding features with params', function(){
- cfg.addPlugin({name:'aplugin'}, [{name:'paraname',value:'paravalue'}]);
- // Additional check for new parameters syntax
- cfg.addPlugin({name:'bplugin'}, {paraname: 'paravalue'});
- var plugins = cfg.doc.findall('plugin')
- .filter(function (plugin) {
- return plugin.attrib.name === 'aplugin' || plugin.attrib.name === 'bplugin';
- });
- expect(plugins.length).toBe(2);
- plugins.forEach(function (plugin) {
- var variables = plugin.findall('variable');
- expect(variables[0].attrib.name).toEqual('paraname');
- expect(variables[0].attrib.value).toEqual('paravalue');
- });
- });
- it('Test 027 : should be able to read legacy feature entries with a version', function(){
- var plugin = cfg.getPlugin('org.apache.cordova.legacyfeatureversion');
- expect(plugin).toBeDefined();
- expect(plugin.name).toEqual('org.apache.cordova.legacyfeatureversion');
- expect(plugin.spec).toEqual('1.2.3');
- expect(plugin.variables).toBeDefined();
- expect(plugin.variables.aVar).toEqual('aValue');
- });
- it('Test 028 : should be able to read legacy feature entries with a url', function(){
- var plugin = cfg.getPlugin('org.apache.cordova.legacyfeatureurl');
- expect(plugin).toBeDefined();
- expect(plugin.name).toEqual('org.apache.cordova.legacyfeatureurl');
- expect(plugin.spec).toEqual('http://cordova.apache.org/legacyfeatureurl');
- });
- it('Test 029 : should be able to read legacy feature entries with a version and a url', function(){
- var plugin = cfg.getPlugin('org.apache.cordova.legacyfeatureversionandurl');
- expect(plugin).toBeDefined();
- expect(plugin.name).toEqual('org.apache.cordova.legacyfeatureversionandurl');
- expect(plugin.spec).toEqual('http://cordova.apache.org/legacyfeatureversionandurl');
- });
- it('Test 030 : it should remove given plugin', function(){
- cfg.removePlugin('org.apache.cordova.justaplugin');
- var plugins = cfg.doc.findall('plugin');
- var pluginNames = plugins.map(function(plugin){
- return plugin.attrib.name;
- });
- expect(pluginNames).not.toContain('org.apache.cordova.justaplugin');
- });
- it('Test 031 : it should remove given legacy feature id', function(){
- cfg.removePlugin('org.apache.cordova.legacyplugin');
- var plugins = cfg.doc.findall('feature');
- var pluginNames = plugins.map(function(plugin){
- return plugin.attrib.name;
- });
- expect(pluginNames).not.toContain('org.apache.cordova.legacyplugin');
- });
- it('Test 032 : it should read <access> tag entries', function(){
- var accesses = cfg.getAccesses();
- expect(accesses.length).not.toEqual(0);
- });
- it('Test 033 : it should read <allow-navigation> tag entries', function(){
- var navigations = cfg.getAllowNavigations();
- expect(navigations.length).not.toEqual(0);
- });
- it('Test 034 : it should read <allow-intent> tag entries', function(){
- var intents = cfg.getAllowIntents();
- expect(intents.length).not.toEqual(0);
- });
- it('it should read <edit-config> tag entries', function(){
- var editConfigs = cfg.getEditConfigs('android');
- expect(editConfigs.length).not.toEqual(0);
- });
- });
- describe('static resources', function() {
- var hasPlatformPropertyDefined = function (e) { return !!e.platform; };
- var hasSrcPropertyDefined = function (e) { return !!e.src; };
- var hasTargetPropertyDefined = function (e) { return !!e.target; };
- var hasDensityPropertyDefined = function (e) { return !!e.density; };
- var hasPlatformPropertyUndefined = function (e) { return !e.platform; };
-
- it('Test 035 : should fetch shared resources if platform parameter is not specified', function() {
- expect(cfg.getStaticResources(null, 'icon').length).toBe(2);
- expect(cfg.getStaticResources(null, 'icon').every(hasPlatformPropertyUndefined)).toBeTruthy();
- });
-
- it('Test 036 : should fetch platform-specific resources along with shared if platform parameter is specified', function() {
- expect(cfg.getStaticResources('android', 'icon').length).toBe(5);
- expect(cfg.getStaticResources('android', 'icon').some(hasPlatformPropertyDefined)).toBeTruthy();
- expect(cfg.getStaticResources('android', 'icon').filter(hasPlatformPropertyDefined).length).toBe(3);
- expect(cfg.getStaticResources('android', 'icon').some(hasPlatformPropertyUndefined)).toBeTruthy();
- });
-
- it('Test 037 : should parse resources\' attributes', function() {
- expect(cfg.getStaticResources(null, 'icon').every(hasSrcPropertyDefined)).toBeTruthy();
- expect(cfg.getStaticResources('windows', 'icon').filter(hasPlatformPropertyDefined).every(hasTargetPropertyDefined)).toBeTruthy();
- expect(cfg.getStaticResources('android', 'icon').filter(hasPlatformPropertyDefined).every(hasDensityPropertyDefined)).toBeTruthy();
- expect(cfg.getStaticResources('android', 'icon').filter(hasPlatformPropertyDefined).every(hasDensityPropertyDefined)).toBeTruthy();
- });
-
- it('Test 038 : should have defaultResource property', function() {
- expect(cfg.getStaticResources(null, 'icon').defaultResource).toBeDefined();
- expect(cfg.getStaticResources(null, 'icon').defaultResource.src).toBe('icon.png');
- });
-
- it('Test 039 : should have getDefault method returning defaultResource property', function() {
- expect(cfg.getStaticResources(null, 'icon').defaultResource).toEqual(cfg.getStaticResources(null, 'icon').getDefault());
- });
-
- it('Test 040 : should have getBySize method returning resource with size specified or null', function() {
- expect(cfg.getStaticResources('windows', 'icon').getBySize(128)).toBe(null);
- expect(cfg.getStaticResources('windows', 'icon').getBySize(72)).toBeDefined();
- expect(cfg.getStaticResources('windows', 'icon').getBySize(72).width).toBe(72);
- expect(cfg.getStaticResources('windows', 'icon').getBySize(null, 48)).toBeDefined();
- expect(cfg.getStaticResources('windows', 'icon').getBySize(null, 48).height).toBe(48);
- });
-
- it('Test 041 : should have getByDensity method returning resource with density specified or null', function() {
- expect(cfg.getStaticResources('android', 'icon').getByDensity('hdpi')).toBe(null);
- expect(cfg.getStaticResources('android', 'icon').getByDensity('mdpi')).toBeDefined();
- expect(cfg.getStaticResources('android', 'icon').getByDensity('mdpi').src).toBe('logo-android.png');
- });
- });
-
- describe('file resources', function() {
- var hasSrcPropertyDefined = function (e) { return !!e.src; };
- var hasTargetPropertyDefined = function (e) { return !!e.target; };
- var hasArchPropertyDefined = function (e) { return !!e.arch; };
-
- it('should fetch platform-specific resources', function() {
- expect(cfg.getFileResources('android').length).toBe(2);
- });
-
- it('should parse resources\' attributes', function() {
- expect(cfg.getFileResources('android').every(hasSrcPropertyDefined)).toBeTruthy();
- expect(cfg.getFileResources('android').every(hasTargetPropertyDefined)).toBeTruthy();
- expect(cfg.getFileResources('windows').every(hasArchPropertyDefined)).toBeTruthy();
- });
-
- it('should find resources at the top level', function() {
- expect(cfg.getFileResources('android', true).length).toBe(3);
- });
- });
- });
-});
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/fc72293c/cordova-common/spec/CordovaCheck.spec.js
----------------------------------------------------------------------
diff --git a/cordova-common/spec/CordovaCheck.spec.js b/cordova-common/spec/CordovaCheck.spec.js
deleted file mode 100644
index 8745a40..0000000
--- a/cordova-common/spec/CordovaCheck.spec.js
+++ /dev/null
@@ -1,95 +0,0 @@
-/**
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-
-var shell = require('shelljs'),
- path = require('path'),
- CordovaCheck = require('../src/CordovaCheck');
-
-var cwd = process.cwd();
-var home = process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'];
-var origPWD = process.env.PWD;
-
-describe('findProjectRoot method', function() {
- afterEach(function() {
- process.env.PWD = origPWD;
- process.chdir(cwd);
- });
- function removeDir(someDirectory) {
- shell.rm('-rf', someDirectory);
- }
- it('Test 001 : should return false if it hits the home directory', function() {
- var somedir = path.join(home, 'somedir');
- removeDir(somedir);
- shell.mkdir(somedir);
- expect(CordovaCheck.findProjectRoot(somedir)).toEqual(false);
- });
- it('Test 002 : should return false if it cannot find a .cordova directory up the directory tree', function() {
- var somedir = path.join(home, '..');
- expect(CordovaCheck.findProjectRoot(somedir)).toEqual(false);
- });
- it('Test 003 : should return the first directory it finds with a .cordova folder in it', function() {
- var somedir = path.join(home,'somedir');
- var anotherdir = path.join(somedir, 'anotherdir');
- removeDir(somedir);
- shell.mkdir('-p', anotherdir);
- shell.mkdir('-p', path.join(somedir, 'www', 'config.xml'));
- expect(CordovaCheck.findProjectRoot(somedir)).toEqual(somedir);
- });
- it('Test 004 : should ignore PWD when its undefined', function() {
- delete process.env.PWD;
- var somedir = path.join(home,'somedir');
- var anotherdir = path.join(somedir, 'anotherdir');
- removeDir(somedir);
- shell.mkdir('-p', anotherdir);
- shell.mkdir('-p', path.join(somedir, 'www'));
- shell.mkdir('-p', path.join(somedir, 'config.xml'));
- process.chdir(anotherdir);
- expect(CordovaCheck.findProjectRoot()).toEqual(somedir);
- });
- it('Test 005 : should use PWD when available', function() {
- var somedir = path.join(home,'somedir');
- var anotherdir = path.join(somedir, 'anotherdir');
- removeDir(somedir);
- shell.mkdir('-p', anotherdir);
- shell.mkdir('-p', path.join(somedir, 'www', 'config.xml'));
- process.env.PWD = anotherdir;
- process.chdir(path.sep);
- expect(CordovaCheck.findProjectRoot()).toEqual(somedir);
- });
- it('Test 006 : should use cwd as a fallback when PWD is not a cordova dir', function() {
- var somedir = path.join(home,'somedir');
- var anotherdir = path.join(somedir, 'anotherdir');
- removeDir(somedir);
- shell.mkdir('-p', anotherdir);
- shell.mkdir('-p', path.join(somedir, 'www', 'config.xml'));
- process.env.PWD = path.sep;
- process.chdir(anotherdir);
- expect(CordovaCheck.findProjectRoot()).toEqual(somedir);
- });
- it('Test 007 : should ignore platform www/config.xml', function() {
- var somedir = path.join(home,'somedir');
- var anotherdir = path.join(somedir, 'anotherdir');
- removeDir(somedir);
- shell.mkdir('-p', anotherdir);
- shell.mkdir('-p', path.join(anotherdir, 'www', 'config.xml'));
- shell.mkdir('-p', path.join(somedir, 'www'));
- shell.mkdir('-p', path.join(somedir, 'config.xml'));
- expect(CordovaCheck.findProjectRoot(anotherdir)).toEqual(somedir);
- });
-});
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/fc72293c/cordova-common/spec/CordovaLogger.spec.js
----------------------------------------------------------------------
diff --git a/cordova-common/spec/CordovaLogger.spec.js b/cordova-common/spec/CordovaLogger.spec.js
deleted file mode 100644
index fb46e73..0000000
--- a/cordova-common/spec/CordovaLogger.spec.js
+++ /dev/null
@@ -1,192 +0,0 @@
-/**
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-
-var CordovaError = require('../src/CordovaError/CordovaError');
-var CordovaLogger = require('../src/CordovaLogger');
-var EventEmitter = require('events').EventEmitter;
-
-var DEFAULT_LEVELS = ['verbose', 'normal', 'warn', 'info', 'error', 'results'];
-
-describe('CordovaLogger class', function() {
- it('Test 001 : should be constructable', function () {
- expect(new CordovaLogger()).toEqual(jasmine.any(CordovaLogger));
- });
-
- it('Test 002 : should expose default levels as constants', function () {
- DEFAULT_LEVELS.forEach(function (level) {
- var constant = level.toUpperCase();
- expect(CordovaLogger[constant]).toBeDefined();
- expect(CordovaLogger[constant]).toBe(level);
- });
- });
-
- it('Test 003 : should return the same instance via "get" method', function () {
- expect(CordovaLogger.get()).toBeDefined();
- expect(CordovaLogger.get()).toBe(CordovaLogger.get());
- expect(CordovaLogger.get()).toEqual(jasmine.any(CordovaLogger));
- });
-
- describe('instance', function () {
-
- var logger;
-
- beforeEach(function () {
- logger = new CordovaLogger();
- });
-
- it('Test 004 : should have defaults levels', function () {
- DEFAULT_LEVELS.forEach(function (level) {
- expect(logger.levels[level]).toBeDefined();
- expect(logger.levels[level]).toEqual(jasmine.any(Number));
- expect(logger[level]).toBeDefined();
- expect(logger[level]).toEqual(jasmine.any(Function));
- expect(logger[level].length).toBe(1);
- });
- });
-
- describe('addLevel method', function () {
- it('Test 005 : should add a new level and a corresponding shortcut method', function () {
- spyOn(logger, 'log');
- logger.addLevel('debug', 100000, 'grey');
- expect(logger.levels.debug).toBe(100000);
- expect(logger.debug).toEqual(jasmine.any(Function));
-
- logger.debug('debug message');
- expect(logger.log).toHaveBeenCalledWith('debug', 'debug message');
- });
-
- it('Test 006 : should not add a shortcut method fi the property with the same name already exists', function () {
- var logMethod = logger.log;
- logger.addLevel('log', 500);
- expect(logger.log).toBe(logMethod); // "log" method remains unchanged
- });
- });
-
- describe('setLevel method', function () {
- it('Test 007 : should set logger\'s level to \'NORMAL\' if provided level does not exist', function () {
- logger.setLevel('debug');
- expect(logger.logLevel).toBe(CordovaLogger.NORMAL); // default value
- });
- });
-
- describe('subscribe method', function () {
- it('Test 008 : should throw if called without EventEmitter instance', function () {
- expect(function () { logger.subscribe(); }).toThrow();
- expect(function () { logger.subscribe(123); }).toThrow();
- });
-
- it('Test 009 : should attach corresponding listeners to supplied emitter', function () {
-
- var eventNamesExclusions = {
- log: 'normal',
- warning: 'warn'
- };
-
- var listenerSpy = jasmine.createSpy('listenerSpy')
- .and.callFake(function (eventName) {
- eventName = eventNamesExclusions[eventName] || eventName;
- expect(logger.levels[eventName]).toBeDefined();
- });
-
- var emitter = new EventEmitter().on('newListener', listenerSpy);
- logger.subscribe(emitter);
- });
- });
-
- describe('log method', function () {
-
- function CursorSpy (name) {
- var cursorMethods = ['reset', 'write'];
- var spy = jasmine.createSpyObj(name, cursorMethods);
-
- // Make spy methods chainable, as original Cursor acts
- cursorMethods.forEach(function (method) { spy[method].and.returnValue(spy); });
-
- return spy;
- }
-
- beforeEach(function () {
- // Empty colors table to make it easier to mock
- logger.colors = {};
- logger.stdoutCursor = new CursorSpy('stdoutCursor');
- logger.stderrCursor = new CursorSpy('stderrCursor');
- });
-
- it('Test 010 : should ignore message if severity is less than logger\'s level', function () {
- logger.setLevel('error').log('verbose', 'some_messgge');
- expect(logger.stdoutCursor.write).not.toHaveBeenCalled();
- expect(logger.stderrCursor.write).not.toHaveBeenCalled();
- });
-
- it('Test 011 : should log everything except error messages to stdout', function () {
- logger.setLevel('verbose');
- DEFAULT_LEVELS.forEach(function (level) {
- logger.log(level, 'message');
- });
-
- // Multiply calls number to 2 because 'write' method is get called twice (with message and EOL)
- expect(logger.stdoutCursor.write.calls.count()).toBe((DEFAULT_LEVELS.length - 1) * 2);
- expect(logger.stderrCursor.write.calls.count()).toBe(1 * 2);
- });
-
- it('Test 012 : should log Error objects to stderr despite of loglevel', function () {
- logger.setLevel('verbose').log('verbose', new Error());
- expect(logger.stdoutCursor.write).not.toHaveBeenCalled();
- expect(logger.stderrCursor.write).toHaveBeenCalled();
- });
-
- it('Test 013 : should handle CordovaError instances separately from Error ones', function () {
- var errorMock = new CordovaError();
- spyOn(errorMock, 'toString').and.returnValue('error_message');
-
- logger.setLevel('verbose').log('verbose', errorMock);
- expect(errorMock.toString).toHaveBeenCalled();
- expect(logger.stderrCursor.write.calls.argsFor(0)).toMatch('Error: error_message');
- });
- });
-
- describe('adjustLevel method', function () {
- it('Test 014 : should properly adjust log level', function () {
- var resetLogLevel = function() {
- logger.setLevel('normal');
- };
-
- resetLogLevel();
- expect(logger.adjustLevel({verbose: true}).logLevel).toEqual('verbose');
-
- resetLogLevel();
- expect(logger.adjustLevel(['--verbose']).logLevel).toEqual('verbose');
-
- resetLogLevel();
- expect(logger.adjustLevel({silent: true}).logLevel).toEqual('error');
-
- resetLogLevel();
- expect(logger.adjustLevel(['--silent']).logLevel).toEqual('error');
-
- resetLogLevel();
- expect(logger.adjustLevel({verbose: true, silent: true}).logLevel).toEqual('verbose');
-
- resetLogLevel();
- expect(logger.adjustLevel(['--verbose', '--silent']).logLevel).toEqual('verbose');
-
- resetLogLevel();
- });
- });
- });
-});
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org