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 2025/07/15 05:40:54 UTC

(cordova-common) branch master updated: chore(tests): Improve test coverage (#232)

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 586b831  chore(tests): Improve test coverage (#232)
586b831 is described below

commit 586b8318342655e96e06e4a0827bfd0337bbcac7
Author: Darryl Pogue <da...@dpogue.ca>
AuthorDate: Mon Jul 14 22:40:50 2025 -0700

    chore(tests): Improve test coverage (#232)
    
    Also reduces the use of rewire down to just 1 file.
---
 spec/PlatformJson.spec.js                          |  6 ++--
 spec/PluginInfo/PluginInfo.spec.js                 | 12 +++++--
 spec/PluginManager.spec.js                         | 38 +++++++++++++++-------
 .../plugins/org.test.xmlpassthrough/plugin.xml     |  4 +++
 spec/util/xml-helpers.spec.js                      |  6 ++--
 src/PlatformJson.js                                |  1 +
 6 files changed, 47 insertions(+), 20 deletions(-)

diff --git a/spec/PlatformJson.spec.js b/spec/PlatformJson.spec.js
index b6dbdfd..53271a0 100644
--- a/spec/PlatformJson.spec.js
+++ b/spec/PlatformJson.spec.js
@@ -18,10 +18,9 @@
 */
 
 const fs = require('node:fs');
-const rewire = require('rewire');
-const PlatformJson = rewire('../src/PlatformJson');
-const ModuleMetadata = PlatformJson.__get__('ModuleMetadata');
+const PlatformJson = require('../src/PlatformJson');
 
+const ModuleMetadata = PlatformJson.ModuleMetadata;
 const FAKE_MODULE = {
     name: 'fakeModule',
     src: 'www/fakeModule.js',
@@ -160,6 +159,7 @@ describe('ModuleMetadata class', function () {
 
     it('Test 011 : should throw if either pluginId or jsModule argument isn\'t specified', function () {
         expect(ModuleMetadata).toThrow();
+        expect(() => new ModuleMetadata(null, {})).toThrow();
         expect(() => new ModuleMetadata('fakePlugin', {})).toThrow();
     });
 
diff --git a/spec/PluginInfo/PluginInfo.spec.js b/spec/PluginInfo/PluginInfo.spec.js
index 4057910..aed0669 100644
--- a/spec/PluginInfo/PluginInfo.spec.js
+++ b/spec/PluginInfo/PluginInfo.spec.js
@@ -90,6 +90,10 @@ describe('PluginInfo', function () {
             expect(assets.length).toBe(1);
             expect(assets[0].anattrib).toBe('value');
         });
+
+        it('throws if missing src or target attributes', function () {
+            expect(function () { pluginPassthrough.getAssets('ios'); }).toThrow();
+        });
     });
 
     describe('Dependency', () => {
@@ -98,6 +102,10 @@ describe('PluginInfo', function () {
             expect(dependencies.length).toBe(1);
             expect(dependencies[0].anattrib).toBe('value');
         });
+
+        it('throws if missing id attribute', function () {
+            expect(function () { pluginPassthrough.getDependencies('ios'); }).toThrow();
+        });
     });
 
     describe('Config File', () => {
@@ -175,13 +183,13 @@ describe('PluginInfo', function () {
     describe('Platform', () => {
         it('Test 019: platform supports xml passthrough', function () {
             const platforms = pluginPassthrough.getPlatforms();
-            expect(platforms.length).toBe(1);
+            expect(platforms.length).toBe(2);
             expect(platforms[0].anattrib).toBe('value');
         });
 
         it('should retrieve a list of platform names', function () {
             const platforms = pluginPassthrough.getPlatformsArray();
-            expect(platforms).toEqual(['android']);
+            expect(platforms).toEqual(['android', 'ios']);
         });
     });
 });
diff --git a/spec/PluginManager.spec.js b/spec/PluginManager.spec.js
index cccc321..4905fe2 100644
--- a/spec/PluginManager.spec.js
+++ b/spec/PluginManager.spec.js
@@ -19,11 +19,10 @@
 
 const fs = require('node:fs');
 const path = require('node:path');
-const rewire = require('rewire');
 const PluginInfo = require('../src/PluginInfo/PluginInfo');
 const ConfigChanges = require('../src/ConfigChanges/ConfigChanges');
-
-const PluginManager = rewire('../src/PluginManager');
+const ActionStack = require('../src/ActionStack');
+const PluginManager = require('../src/PluginManager');
 
 const DUMMY_PLUGIN = path.join(__dirname, 'fixtures/plugins/org.test.plugins.dummyplugin');
 const FAKE_PLATFORM = 'cordova-atari';
@@ -51,20 +50,21 @@ describe('PluginManager class', function () {
     });
 
     describe('instance', function () {
-        let actions, manager;
+        let manager;
         let FAKE_PROJECT;
-        const ActionStackOrig = PluginManager.__get__('ActionStack');
 
         beforeEach(function () {
             FAKE_PROJECT = jasmine.createSpyObj('project', ['getInstaller', 'getUninstaller', 'write']);
             manager = new PluginManager('windows', FAKE_LOCATIONS, FAKE_PROJECT);
-            actions = jasmine.createSpyObj('actions', ['createAction', 'push', 'process']);
-            actions.process.and.returnValue(Promise.resolve());
-            PluginManager.__set__('ActionStack', function () { return actions; });
+            spyOn(ActionStack.prototype, 'createAction');
+            spyOn(ActionStack.prototype, 'push');
+            spyOn(ActionStack.prototype, 'process').and.resolveTo();
         });
 
-        afterEach(function () {
-            PluginManager.__set__('ActionStack', ActionStackOrig);
+        describe('doOperation', function () {
+            it('should reject if the operation is invalid', function () {
+                return expectAsync(manager.doOperation('test', {}, {})).toBeRejected();
+            });
         });
 
         describe('addPlugin method', function () {
@@ -84,8 +84,8 @@ describe('PluginManager class', function () {
                         expect(FAKE_PROJECT.getInstaller.calls.count()).toBe(16);
                         expect(FAKE_PROJECT.getUninstaller.calls.count()).toBe(16);
 
-                        expect(actions.push.calls.count()).toBe(16);
-                        expect(actions.process).toHaveBeenCalled();
+                        expect(ActionStack.prototype.push.calls.count()).toBe(16);
+                        expect(ActionStack.prototype.process).toHaveBeenCalled();
                         expect(FAKE_PROJECT.write).toHaveBeenCalled();
                     });
             });
@@ -112,5 +112,19 @@ describe('PluginManager class', function () {
                     });
             });
         });
+
+        describe('removePlugin method', function () {
+            it('should return a promise', function () {
+                return expectAsync(manager.removePlugin(new PluginInfo(DUMMY_PLUGIN), {})).toBeResolved();
+            });
+
+            it('should reject if "plugin" parameter is not specified or not a PluginInfo instance', () => {
+                return Promise.resolve()
+                    .then(() => expectAsync(manager.removePlugin(null, {})).toBeRejected())
+                    .then(() => expectAsync(manager.removePlugin({}, {})).toBeRejected());
+            });
+
+            // The rest of this is essentially identical to the addPlugin flow
+        });
     });
 });
diff --git a/spec/fixtures/plugins/org.test.xmlpassthrough/plugin.xml b/spec/fixtures/plugins/org.test.xmlpassthrough/plugin.xml
index cbe2504..4032253 100644
--- a/spec/fixtures/plugins/org.test.xmlpassthrough/plugin.xml
+++ b/spec/fixtures/plugins/org.test.xmlpassthrough/plugin.xml
@@ -46,5 +46,9 @@
         <resource-file anattrib="value" />
         <lib-file anattrib="value" />
     </platform>
+    <platform name="ios" anattrib="value">
+        <asset src="nope" anattrib="value" />
+        <dependency anattrib="value" />
+    </platform>
     <framework src="hi" anattrib="value" />    
 </plugin>
diff --git a/spec/util/xml-helpers.spec.js b/spec/util/xml-helpers.spec.js
index bb0ae42..b7bfc86 100644
--- a/spec/util/xml-helpers.spec.js
+++ b/spec/util/xml-helpers.spec.js
@@ -412,7 +412,7 @@ describe('xml-helpers', function () {
             expect(testElements[0].text).toContain('SUPER_NAME');
         });
 
-        it('Test 038 : should append non singelton children', function () {
+        it('Test 038 : should append non singleton children', function () {
             const testXml = et.XML('<widget><preference num="1"/> <preference num="2"/></widget>');
 
             xml_helpers.mergeXml(testXml, dstXml, '', true);
@@ -430,7 +430,7 @@ describe('xml-helpers', function () {
             expect(testElement.text).toEqual('testText');
         });
 
-        it('Test 040 : should not append duplicate non singelton children', function () {
+        it('Test 040 : should not append duplicate non singleton children', function () {
             const testXml = et.XML('<widget><preference name="fullscreen" value="true"/></widget>');
 
             xml_helpers.mergeXml(testXml, dstXml, '', true);
@@ -438,7 +438,7 @@ describe('xml-helpers', function () {
             expect(testElements.length).toEqual(2);
         });
 
-        it('Test 041 : should not skip partial duplicate non singelton children', function () {
+        it('Test 041 : should not skip partial duplicate non singleton children', function () {
             // remove access tags from dstXML
             let testElements = dstXml.findall('access');
             for (let i = 0; i < testElements.length; i++) {
diff --git a/src/PlatformJson.js b/src/PlatformJson.js
index d783589..64f92d1 100644
--- a/src/PlatformJson.js
+++ b/src/PlatformJson.js
@@ -260,3 +260,4 @@ class ModuleMetadata {
 }
 
 module.exports = PlatformJson;
+module.exports.ModuleMetadata = ModuleMetadata;


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org