You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by er...@apache.org on 2020/03/15 07:17:41 UTC
[cordova-common] branch master updated: style: improve line spacing
& group like items (#85)
This is an automated email from the ASF dual-hosted git repository.
erisu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-common.git
The following commit(s) were added to refs/heads/master by this push:
new 20467ac style: improve line spacing & group like items (#85)
20467ac is described below
commit 20467accded394aa44210208bcf59cf6580a3c73
Author: Chris Brody <ch...@gmail.com>
AuthorDate: Sun Mar 15 03:17:35 2020 -0400
style: improve line spacing & group like items (#85)
Co-authored-by: Christopher J. Brody <ch...@brody.consulting>
Co-authored-by: Erisu <el...@gmail.com>
---
spec/ConfigChanges/ConfigChanges.spec.js | 48 +++++++++++++++++++++++++++++++-
spec/FileUpdater.spec.js | 30 +++++++++++++++++++-
spec/PluginManager.spec.js | 3 +-
spec/util/xml-helpers.spec.js | 24 +++++++++++++++-
src/ConfigChanges/ConfigChanges.js | 1 +
5 files changed, 102 insertions(+), 4 deletions(-)
diff --git a/spec/ConfigChanges/ConfigChanges.spec.js b/spec/ConfigChanges/ConfigChanges.spec.js
index cc77eab..84b2b35 100644
--- a/spec/ConfigChanges/ConfigChanges.spec.js
+++ b/spec/ConfigChanges/ConfigChanges.spec.js
@@ -88,13 +88,16 @@ describe('config-changes module', 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' });
@@ -105,6 +108,7 @@ describe('config-changes module', 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');
});
@@ -119,6 +123,7 @@ describe('config-changes module', function () {
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 = {
@@ -128,6 +133,7 @@ describe('config-changes module', function () {
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));
});
@@ -147,6 +153,7 @@ describe('config-changes module', function () {
beforeEach(function () {
fs.copySync(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')));
@@ -168,6 +175,7 @@ describe('config-changes module', function () {
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' });
@@ -183,22 +191,26 @@ describe('config-changes module', function () {
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), {});
@@ -212,6 +224,7 @@ describe('config-changes module', function () {
beforeEach(function () {
install_plugin(dummyplugin);
});
+
it('Test 014 : should generate config munges for queued plugins', function () {
fs.copySync(android_two_project, temp);
var platformJson = PlatformJson.load(plugins_dir, 'android');
@@ -221,11 +234,13 @@ describe('config-changes module', function () {
munger.process(plugins_dir);
expect(spy).toHaveBeenCalledWith(jasmine.any(PluginInfo), {});
});
+
describe(': installation', function () {
describe('of xml config files', function () {
beforeEach(function () {
fs.copySync(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: {} }];
@@ -240,6 +255,7 @@ describe('config-changes module', function () {
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 () {
install_plugin(configplugin);
var platformJson = PlatformJson.load(plugins_dir, 'android');
@@ -250,6 +266,7 @@ describe('config-changes module', function () {
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', {});
@@ -260,6 +277,7 @@ describe('config-changes module', function () {
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 () {
install_plugin(editconfigplugin);
@@ -273,6 +291,7 @@ describe('config-changes module', function () {
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 () {
install_plugin(editconfigplugin);
install_plugin(editconfigplugin_two);
@@ -290,6 +309,7 @@ describe('config-changes module', function () {
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 () {
install_plugin(editconfigplugin);
@@ -303,6 +323,7 @@ describe('config-changes module', function () {
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 () {
install_plugin(editconfigplugin);
install_plugin(editconfigplugin_two);
@@ -319,6 +340,7 @@ describe('config-changes module', function () {
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 () {
install_plugin(editconfigplugin);
install_plugin(editconfigplugin_two);
@@ -330,6 +352,7 @@ describe('config-changes module', function () {
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');
@@ -341,6 +364,7 @@ describe('config-changes module', function () {
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');
@@ -352,6 +376,7 @@ describe('config-changes module', function () {
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');
@@ -366,6 +391,7 @@ describe('config-changes module', function () {
expect(sdk).toBeDefined();
expect(sdk.attrib['android:maxSdkVersion']).toBeUndefined();
});
+
it('should overwrite plugin config munge for every conflicting config.xml config munge', function () {
install_plugin(editconfigplugin_two);
@@ -381,11 +407,11 @@ describe('config-changes module', function () {
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();
@@ -396,6 +422,7 @@ describe('config-changes module', function () {
expect(sdk.attrib['android:minSdkVersion']).toEqual('5');
expect(sdk.attrib['android:maxSdkVersion']).toBeUndefined();
});
+
it('should append new children to XML document tree', function () {
var configfile_cfg = new ConfigParser(configfile_xml);
var platformJson = PlatformJson.load(plugins_dir, 'android');
@@ -406,6 +433,7 @@ describe('config-changes module', function () {
expect(activity).toBeDefined();
expect(activity.attrib['android:label']).toEqual('@string/app_name');
});
+
// testing the "after" attribute of the <config-file> tag in config.xml
it('should append new children to XML document tree in the correct order', function () {
var configfile_cfg = new ConfigParser(configfile_xml);
@@ -415,6 +443,7 @@ describe('config-changes module', function () {
var am_file = fs.readFileSync(path.join(temp, 'AndroidManifest.xml'), 'utf-8');
expect(am_file.indexOf('android:name="zoo"')).toBeLessThan(am_file.indexOf('android:name="com.foo.Bar"'));
});
+
it('should throw error for conflicting plugin config munge with config.xml config munge', function () {
install_plugin(editconfigplugin_two);
@@ -426,6 +455,7 @@ describe('config-changes module', function () {
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 () {
fs.copySync(ios_config_xml, temp);
@@ -436,6 +466,7 @@ describe('config-changes module', function () {
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\t<string\/>/m);
});
+
it('Test 024 : should merge dictionaries and arrays, removing duplicates', function () {
fs.copySync(ios_config_xml, temp);
install_plugin(plistplugin);
@@ -448,6 +479,7 @@ describe('config-changes module', function () {
expect(fs.readFileSync(path.join(temp, 'SampleApp', 'SampleApp-Info.plist'), 'utf-8')).not.toMatch(/(<string>schema-a<\/string>[^]*){2,}/);
});
});
+
describe('of binary plist config files', function () {
it('should merge dictionaries and arrays, removing duplicates', function () {
fs.copySync(ios_config_xml, temp);
@@ -462,6 +494,7 @@ describe('config-changes module', function () {
expect(fs.readFileSync(path.join(temp, 'SampleApp', 'SampleApp-binary.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 () {
fs.copySync(ios_config_xml, temp);
install_plugin(cbplugin);
@@ -474,6 +507,7 @@ describe('config-changes module', function () {
munger.process(plugins_dir);
expect(spy).toHaveBeenCalledWith(path.join(temp, 'SampleApp', 'SampleApp-Info.plist'), 'utf8');
});
+
it('Test 026 : should move successfully installed plugins from queue to installed plugins section, and include/retain vars if applicable', function () {
fs.copySync(android_two_project, temp);
install_plugin(varplugin);
@@ -502,6 +536,7 @@ describe('config-changes module', function () {
// 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);
@@ -510,6 +545,7 @@ describe('config-changes module', function () {
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 () {
fs.copySync(android_two_project, temp);
install_plugin(varplugin);
@@ -522,13 +558,16 @@ describe('config-changes module', function () {
// 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 () {
fs.copySync(android_two_no_perms_project, temp);
install_plugin(childrenplugin);
@@ -538,6 +577,7 @@ describe('config-changes module', function () {
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);
@@ -545,11 +585,13 @@ describe('config-changes module', function () {
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 () {
fs.copySync(android_two_project, temp);
// install a plugin
@@ -566,6 +608,7 @@ describe('config-changes module', function () {
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 () {
fs.copySync(android_two_project, temp);
install_plugin(varplugin);
@@ -583,6 +626,7 @@ describe('config-changes module', function () {
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 () {
fs.copySync(android_two_project, temp);
install_plugin(editconfigplugin);
@@ -590,11 +634,13 @@ describe('config-changes module', function () {
// 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);
diff --git a/spec/FileUpdater.spec.js b/spec/FileUpdater.spec.js
index 803fe3b..81c9f4f 100644
--- a/spec/FileUpdater.spec.js
+++ b/spec/FileUpdater.spec.js
@@ -19,9 +19,10 @@
var path = require('path');
var rewire = require('rewire');
-var FileUpdater = rewire('../src/FileUpdater');
const { Stats } = require('@nodelib/fs.macchiato');
+var FileUpdater = rewire('../src/FileUpdater');
+
// Normally these are internal to the module; these lines use rewire to expose them for testing.
FileUpdater.mapDirectory = FileUpdater.__get__('mapDirectory');
FileUpdater.mergePathMaps = FileUpdater.__get__('mergePathMaps');
@@ -116,6 +117,7 @@ var mockFs = {
return map[p] || map[path.resolve(p)] || map[path.relative(process.cwd(), p)];
}
};
+
FileUpdater.__set__('fs', mockFs);
// Define some constants used in the test cases.
@@ -151,6 +153,7 @@ describe('FileUpdater class', function () {
expect(mockFs.mkdirPaths.length).toBe(0);
expect(mockFs.rmPaths.length).toBe(0);
});
+
it('Test 002 : should create a directory that exists at source and not at target', function () {
var updated = FileUpdater.updatePathWithStats(
testSourceDir, mockDirStats(), testTargetDir, null);
@@ -159,6 +162,7 @@ describe('FileUpdater class', function () {
expect(mockFs.rmPaths.length).toBe(0);
expect(mockFs.mkdirPaths[0]).toBe(testTargetDir);
});
+
it('Test 003 : should remove a directory that exists at target and not at source', function () {
var updated = FileUpdater.updatePathWithStats(
testSourceDir, null, testTargetDir, mockDirStats());
@@ -177,6 +181,7 @@ describe('FileUpdater class', function () {
expect(mockFs.rmPaths.length).toBe(0);
expect(mockFs.cpPaths[0]).toEqual([testSourceFile, testTargetFile]);
});
+
it('Test 005 : should copy when a file exists at source and target and target is older',
function () {
var updated = FileUpdater.updatePathWithStats(
@@ -186,6 +191,7 @@ describe('FileUpdater class', function () {
expect(mockFs.rmPaths.length).toBe(0);
expect(mockFs.cpPaths[0]).toEqual([testSourceFile, testTargetFile]);
});
+
it('Test 006 : should do nothing when a file exists at source and target and target is newer',
function () {
var updated = FileUpdater.updatePathWithStats(
@@ -194,6 +200,7 @@ describe('FileUpdater class', function () {
expect(mockFs.cpPaths.length).toBe(0);
expect(mockFs.rmPaths.length).toBe(0);
});
+
it('Test 007 : should copy when a file exists at source and target and forcing update', function () {
var updated = FileUpdater.updatePathWithStats(
testSourceFile, mockFileStats(now), testTargetFile, mockFileStats(now),
@@ -203,6 +210,7 @@ describe('FileUpdater class', function () {
expect(mockFs.rmPaths.length).toBe(0);
expect(mockFs.cpPaths[0]).toEqual([testSourceFile, testTargetFile]);
});
+
it('Test 008 : should copy when a file exists at source and target and target is newer ' +
'and forcing update', function () {
var updated = FileUpdater.updatePathWithStats(
@@ -213,6 +221,7 @@ describe('FileUpdater class', function () {
expect(mockFs.rmPaths.length).toBe(0);
expect(mockFs.cpPaths[0]).toEqual([testSourceFile, testTargetFile]);
});
+
it('Test 009 : should copy when a file exists at source and target and source is newer', function () {
var updated = FileUpdater.updatePathWithStats(
testSourceFile, mockFileStats(now), testTargetFile, mockFileStats(oneHourAgo));
@@ -221,6 +230,7 @@ describe('FileUpdater class', function () {
expect(mockFs.rmPaths.length).toBe(0);
expect(mockFs.cpPaths[0]).toEqual([testSourceFile, testTargetFile]);
});
+
it('Test 010 : should copy when a file exists at source and not at target', function () {
var updated = FileUpdater.updatePathWithStats(
testSourceFile, mockFileStats(now), testTargetFile, null);
@@ -229,6 +239,7 @@ describe('FileUpdater class', function () {
expect(mockFs.rmPaths.length).toBe(0);
expect(mockFs.cpPaths[0]).toEqual([testSourceFile, testTargetFile]);
});
+
it('Test 011 : should remove when a file exists at target and not at source', function () {
var updated = FileUpdater.updatePathWithStats(
testSourceFile, null, testTargetFile, mockFileStats(now));
@@ -248,6 +259,7 @@ describe('FileUpdater class', function () {
expect(mockFs.rmPaths[0]).toBe(testTargetDir);
expect(mockFs.mkdirPaths[0]).toBe(testTargetDir);
});
+
it('Test 013 : should remove and copy when source is a file and target is a directory', function () {
var updated = FileUpdater.updatePathWithStats(
testSourceFile, mockFileStats(now), testTargetFile, mockDirStats());
@@ -284,6 +296,7 @@ describe('FileUpdater class', function () {
expect(loggedTarget).toBe(1);
expect(loggedRoot).toBe(0);
});
+
it('Test 016 : should log dir removal', function () {
var loggedSource = 0;
var loggedTarget = 0;
@@ -299,6 +312,7 @@ describe('FileUpdater class', function () {
expect(loggedTarget).toBe(1);
expect(loggedRoot).toBe(0);
});
+
it('Test 017 : should log file copy', function () {
var loggedSource = 0;
var loggedTarget = 0;
@@ -314,6 +328,7 @@ describe('FileUpdater class', function () {
expect(loggedTarget).toBe(1);
expect(loggedRoot).toBe(0);
});
+
it('Test 018: should log file removal', function () {
var loggedSource = 0;
var loggedTarget = 0;
@@ -342,6 +357,7 @@ describe('FileUpdater class', function () {
expect(dirMap[''].subDir).toBe(testSourceDir);
expect(dirMap[''].stats).toBe(testDirStats);
});
+
it('Test 020 : should map a directory with a file', function () {
mockFs.statMap[path.join(testRootDir, testSourceDir)] = testDirStats;
mockFs.dirMap[path.join(testRootDir, testSourceDir)] = [testSourceFile];
@@ -353,6 +369,7 @@ describe('FileUpdater class', function () {
expect(dirMap[testSourceFile].subDir).toBe(testSourceDir);
expect(dirMap[testSourceFile].stats).toBe(testFileStats);
});
+
it('Test 021 : should map a directory with a subdirectory', function () {
mockFs.statMap[testSourceDir] = testDirStats;
mockFs.dirMap[testSourceDir] = [testSubDir];
@@ -365,6 +382,7 @@ describe('FileUpdater class', function () {
expect(dirMap[testSubDir].subDir).toBe(testSourceDir);
expect(dirMap[testSubDir].stats).toBe(testDirStats);
});
+
it('Test 022 : should map a directory with a file in a nested subdirectory', function () {
mockFs.statMap[testSourceDir] = testDirStats;
mockFs.dirMap[testSourceDir] = [testSubDir];
@@ -404,6 +422,7 @@ describe('FileUpdater class', function () {
expect(dirMap[testSourceFile].subDir).toBe(testSourceDir);
expect(dirMap[testSourceFile].stats).toBe(testFileStats);
});
+
it('Test 024 : should include files in a subdirectory that match include globs', function () {
mockFs.statMap[testSourceDir] = testDirStats;
mockFs.dirMap[testSourceDir] = [testSubDir];
@@ -421,6 +440,7 @@ describe('FileUpdater class', function () {
expect(dirMap[path.join(testSubDir, testSourceFile)].subDir).toBe(testSourceDir);
expect(dirMap[path.join(testSubDir, testSourceFile)].stats).toBe(testFileStats);
});
+
it('Test 025 : should exclude paths that match exclude globs', function () {
mockFs.statMap[testSourceDir] = testDirStats;
mockFs.dirMap[testSourceDir] = [testSourceFile, testSourceFile2];
@@ -433,6 +453,7 @@ describe('FileUpdater class', function () {
expect(dirMap[testSourceFile].subDir).toBe(testSourceDir);
expect(dirMap[testSourceFile].stats).toBe(testFileStats);
});
+
it('Test 026 : should exclude paths that match both exclude and include globs', function () {
mockFs.statMap[testSourceDir] = testDirStats;
mockFs.dirMap[testSourceDir] = [testSubDir];
@@ -454,6 +475,7 @@ describe('FileUpdater class', function () {
var testSourceFileStats = mockFileStats(now);
var testSourceFileStats2 = mockFileStats(now);
var testSourceFileStats3 = mockFileStats(now);
+
it('Test 027 : should prepend the target directory on target paths', function () {
var mergedPathMap = FileUpdater.mergePathMaps(
[{
@@ -477,6 +499,7 @@ describe('FileUpdater class', function () {
path.join(testSourceDir, testTargetFile));
expect(mergedPathMap[testTargetFile].sourceStats).toBe(testSourceFileStats);
});
+
it('Test 028 : should handle missing source files', function () {
var mergedPathMap = FileUpdater.mergePathMaps(
[{}],
@@ -491,6 +514,7 @@ describe('FileUpdater class', function () {
expect(mergedPathMap[testTargetFile].sourcePath).toBeNull();
expect(mergedPathMap[testTargetFile].sourceStats).toBeNull();
});
+
it('Tets 029 : should handle missing target files', function () {
var mergedPathMap = FileUpdater.mergePathMaps(
[{
@@ -506,6 +530,7 @@ describe('FileUpdater class', function () {
path.join(testSourceDir, testTargetFile));
expect(mergedPathMap[testTargetFile].sourceStats).toBe(testSourceFileStats);
});
+
it('Test 030 : should merge three source maps', function () {
var mergedPathMap = FileUpdater.mergePathMaps(
[
@@ -565,6 +590,7 @@ describe('FileUpdater class', function () {
expect(FileUpdater.updatePathWithStatsCalls[0][4]).toEqual(
{ rootDir: testRootDir, all: true });
});
+
it('Test 032 : should update a path without a separate root directory', function () {
mockFs.statMap[testTargetFile] = testFileStats;
mockFs.statMap[testSourceFile] = testFileStats2;
@@ -578,6 +604,7 @@ describe('FileUpdater class', function () {
expect(FileUpdater.updatePathWithStatsCalls[0][3]).toEqual(testFileStats);
expect(FileUpdater.updatePathWithStatsCalls[0][4]).toBeUndefined();
});
+
it('Test 033 : should update a path when the source doesn\'t exist', function () {
mockFs.statMap[testTargetFile] = testFileStats;
var updated = FileUpdater.updatePath(null, testTargetFile);
@@ -589,6 +616,7 @@ describe('FileUpdater class', function () {
expect(FileUpdater.updatePathWithStatsCalls[0][3]).toEqual(testFileStats);
expect(FileUpdater.updatePathWithStatsCalls[0][4]).toBeUndefined();
});
+
it('Test 034 : should update a path when the target doesn\'t exist', function () {
mockFs.statMap[testSourceFile] = testFileStats2;
var updated = FileUpdater.updatePath(testSourceFile, testTargetFile);
diff --git a/spec/PluginManager.spec.js b/spec/PluginManager.spec.js
index c999720..1e6ea36 100644
--- a/spec/PluginManager.spec.js
+++ b/spec/PluginManager.spec.js
@@ -21,10 +21,11 @@ var Q = require('q');
var fs = require('fs-extra');
var path = require('path');
var rewire = require('rewire');
-var PluginManager = rewire('../src/PluginManager');
var PluginInfo = require('../src/PluginInfo/PluginInfo');
var ConfigChanges = require('../src/ConfigChanges/ConfigChanges');
+var PluginManager = rewire('../src/PluginManager');
+
var DUMMY_PLUGIN = path.join(__dirname, 'fixtures/plugins/org.test.plugins.dummyplugin');
var FAKE_PLATFORM = 'cordova-atari';
var FAKE_LOCATIONS = {
diff --git a/spec/util/xml-helpers.spec.js b/spec/util/xml-helpers.spec.js
index bb14924..a5de372 100644
--- a/spec/util/xml-helpers.spec.js
+++ b/spec/util/xml-helpers.spec.js
@@ -18,8 +18,8 @@
*/
var path = require('path');
-var xml_helpers = require('../../src/util/xml-helpers');
var et = require('elementtree');
+var xml_helpers = require('../../src/util/xml-helpers');
var title = et.XML('<title>HELLO</title>');
var usesNetworkOne = et.XML(`<uses-permission
@@ -59,6 +59,7 @@ describe('xml-helpers', function () {
}).not.toThrow();
});
});
+
describe('equalNodes', function () {
it('Test 002 : should return false for different tags', function () {
expect(xml_helpers.equalNodes(usesNetworkOne, title)).toBe(false);
@@ -98,6 +99,7 @@ describe('xml-helpers', function () {
});
});
});
+
describe('pruneXML', function () {
var config_xml;
@@ -110,16 +112,19 @@ describe('xml-helpers', function () {
xml_helpers.pruneXML(config_xml, children, 'plugins');
expect(config_xml.find('plugins').getchildren().length).toEqual(0);
});
+
it('Test 010 : should do nothing if the children cannot be found', function () {
var children = [title];
xml_helpers.pruneXML(config_xml, children, 'plugins');
expect(config_xml.find('plugins').getchildren().length).toEqual(17);
});
+
it('Test 011 : should be able to handle absolute selectors', function () {
var children = config_xml.findall('plugins/plugin');
xml_helpers.pruneXML(config_xml, children, '/cordova/plugins');
expect(config_xml.find('plugins').getchildren().length).toEqual(0);
});
+
it('Test 012 : should be able to handle absolute selectors with wildcards', function () {
var children = config_xml.findall('plugins/plugin');
xml_helpers.pruneXML(config_xml, children, '/*/plugins');
@@ -133,6 +138,7 @@ describe('xml-helpers', function () {
beforeEach(function () {
android_manifest_xml = xml_helpers.parseElementtreeSync(path.join(__dirname, '../fixtures/projects/android/AndroidManifest.xml'));
});
+
it('Test 013 : should restore attributes at the specified selector', function () {
var xml = {
oldAttrib: { 'android:icon': '@drawable/icon', 'android:label': '@string/app_name', 'android:debuggable': 'false' }
@@ -142,6 +148,7 @@ describe('xml-helpers', function () {
expect(Object.keys(applicationAttr).length).toEqual(3);
expect(applicationAttr['android:debuggable']).toEqual('false');
});
+
it('Test 014 : should do nothing if the old attributes cannot be found', function () {
var xml = {
notOldAttrib: { 'android:icon': '@drawable/icon', 'android:label': '@string/app_name', 'android:debuggable': 'false' }
@@ -151,6 +158,7 @@ describe('xml-helpers', function () {
expect(Object.keys(applicationAttr).length).toEqual(3);
expect(applicationAttr['android:debuggable']).toEqual('true');
});
+
it('Test 015 : should be able to handle absolute selectors', function () {
var xml = {
oldAttrib: { 'android:icon': '@drawable/icon', 'android:label': '@string/app_name', 'android:debuggable': 'false' }
@@ -160,6 +168,7 @@ describe('xml-helpers', function () {
expect(Object.keys(applicationAttr).length).toEqual(3);
expect(applicationAttr['android:debuggable']).toEqual('false');
});
+
it('Test 016 : should be able to handle absolute selectors with wildcards', function () {
var xml = {
oldAttrib: { 'android:name': 'ChildApp', 'android:label': '@string/app_name', 'android:configChanges': 'orientation|keyboardHidden', 'android:enabled': 'true' }
@@ -169,6 +178,7 @@ describe('xml-helpers', function () {
expect(Object.keys(activityAttr).length).toEqual(4);
expect(activityAttr['android:enabled']).toEqual('true');
});
+
it('Test 017 : should be able to handle xpath selectors', function () {
var xml = {
oldAttrib: { 'android:name': 'com.phonegap.DroidGap', 'android:label': '@string/app_name', 'android:configChanges': 'orientation|keyboardHidden', 'android:enabled': 'true' }
@@ -193,16 +203,19 @@ describe('xml-helpers', function () {
xml_helpers.graftXML(config_xml, children, 'plugins');
expect(config_xml.find('plugins').getchildren().length).toEqual(19);
});
+
it('Test 019 : should be able to handle absolute selectors', function () {
var children = plugin_xml.find('config-file').getchildren();
xml_helpers.graftXML(config_xml, children, '/cordova');
expect(config_xml.findall('access').length).toEqual(3);
});
+
it('Test 020 : should be able to handle absolute selectors with wildcards', function () {
var children = plugin_xml.find('config-file').getchildren();
xml_helpers.graftXML(config_xml, children, '/*');
expect(config_xml.findall('access').length).toEqual(3);
});
+
it('Test 020-1 : should create parent', function () {
var config_xml0 = xml_helpers.parseElementtreeSync(path.join(__dirname, '../fixtures/test-config0.xml'));
var children = plugin_xml.find('platform[@name="ios"]/config-file').getchildren();
@@ -218,6 +231,7 @@ describe('xml-helpers', function () {
plugin_xml = xml_helpers.parseElementtreeSync(path.join(__dirname, '../fixtures/plugins/org.test.editconfigtest/plugin.xml'));
android_manifest_xml = xml_helpers.parseElementtreeSync(path.join(__dirname, '../fixtures/projects/android/AndroidManifest.xml'));
});
+
it('Test 021 : should merge attributes at specified selector', function () {
var children = plugin_xml.find('platform/edit-config[@mode="merge"]').getchildren();
xml_helpers.graftXMLMerge(android_manifest_xml, children, 'application/activity[@android:name="com.phonegap.DroidGap"]', {});
@@ -226,6 +240,7 @@ describe('xml-helpers', function () {
expect(activityAttr['android:enabled']).toEqual('true');
expect(activityAttr['android:configChanges']).toEqual('keyboardHidden');
});
+
it('Test 022 : should be able to handle absolute selectors', function () {
var children = plugin_xml.find('platform/edit-config[@mode="merge"]').getchildren();
xml_helpers.graftXMLMerge(android_manifest_xml, children, '/manifest/application/activity[@android:name="com.phonegap.DroidGap"]', {});
@@ -234,6 +249,7 @@ describe('xml-helpers', function () {
expect(activityAttr['android:enabled']).toEqual('true');
expect(activityAttr['android:configChanges']).toEqual('keyboardHidden');
});
+
it('Test 023 : should be able to handle absolute selectors with wildcards', function () {
var children = plugin_xml.find('platform/edit-config[@mode="merge"]').getchildren();
xml_helpers.graftXMLMerge(android_manifest_xml, children, '/*/*/activity[@android:name="com.phonegap.DroidGap"]', {});
@@ -242,6 +258,7 @@ describe('xml-helpers', function () {
expect(activityAttr['android:enabled']).toEqual('true');
expect(activityAttr['android:configChanges']).toEqual('keyboardHidden');
});
+
it('Test 024 : should be able to handle xpath selectors', function () {
var children = plugin_xml.find('platform/edit-config[@mode="merge"]').getchildren();
xml_helpers.graftXMLMerge(android_manifest_xml, children, 'application/activity[@android:name="com.phonegap.DroidGap"]', {});
@@ -259,6 +276,7 @@ describe('xml-helpers', function () {
plugin_xml = xml_helpers.parseElementtreeSync(path.join(__dirname, '../fixtures/plugins/org.test.editconfigtest/plugin.xml'));
android_manifest_xml = xml_helpers.parseElementtreeSync(path.join(__dirname, '../fixtures/projects/android/AndroidManifest.xml'));
});
+
it('Test 025 : should overwrite attributes at specified selector', function () {
var children = plugin_xml.find('platform/edit-config[@mode="overwrite"]').getchildren();
xml_helpers.graftXMLOverwrite(android_manifest_xml, children, 'application/activity', {});
@@ -267,6 +285,7 @@ describe('xml-helpers', function () {
expect(activityAttr['android:enabled']).toEqual('true');
expect(activityAttr['android:configChanges']).not.toBeDefined();
});
+
it('Test 026 : should be able to handle absolute selectors', function () {
var children = plugin_xml.find('platform/edit-config[@mode="overwrite"]').getchildren();
xml_helpers.graftXMLOverwrite(android_manifest_xml, children, '/manifest/application/activity', {});
@@ -275,6 +294,7 @@ describe('xml-helpers', function () {
expect(activityAttr['android:enabled']).toEqual('true');
expect(activityAttr['android:configChanges']).not.toBeDefined();
});
+
it('Test 027 : should be able to handle absolute selectors with wildcards', function () {
var children = plugin_xml.find('platform/edit-config[@mode="overwrite"]').getchildren();
xml_helpers.graftXMLOverwrite(android_manifest_xml, children, '/*/*/activity', {});
@@ -283,6 +303,7 @@ describe('xml-helpers', function () {
expect(activityAttr['android:enabled']).toEqual('true');
expect(activityAttr['android:configChanges']).not.toBeDefined();
});
+
it('Test 028 : should be able to handle xpath selectors', function () {
var children = plugin_xml.find('platform/edit-config[@mode="overwrite"]').getchildren();
xml_helpers.graftXMLOverwrite(android_manifest_xml, children, 'application/activity[@android:name="ChildApp"]', {});
@@ -295,6 +316,7 @@ describe('xml-helpers', function () {
describe('mergeXml', function () {
var dstXml;
+
beforeEach(function () {
dstXml = et.XML(TEST_XML);
});
diff --git a/src/ConfigChanges/ConfigChanges.js b/src/ConfigChanges/ConfigChanges.js
index 0df6498..cbd3b25 100644
--- a/src/ConfigChanges/ConfigChanges.js
+++ b/src/ConfigChanges/ConfigChanges.js
@@ -182,6 +182,7 @@ class PlatformMunger {
this.apply_file_munge(conflict_file, conflict_munge.files[conflict_file], /* remove = */ true);
}
}
+
if (Object.keys(isConflictingInfo.conflictingMunge.files).length !== 0) {
events.emit('warn', 'Conflict found, edit-config changes from config.xml will overwrite plugin.xml changes');
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org