You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ra...@apache.org on 2019/11/15 15:36:40 UTC

[cordova-lib] branch master updated: test(e2e): re-enable HooksRunner#12 and move it to plugin#14 (#823)

This is an automated email from the ASF dual-hosted git repository.

raphinesse pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-lib.git


The following commit(s) were added to refs/heads/master by this push:
     new 6eef39e  test(e2e): re-enable HooksRunner#12 and move it to plugin#14 (#823)
6eef39e is described below

commit 6eef39e23d2cd5f16afa0cde685a70a4de933aad
Author: Raphael von der GrĂ¼n <ra...@gmail.com>
AuthorDate: Fri Nov 15 16:36:30 2019 +0100

    test(e2e): re-enable HooksRunner#12 and move it to plugin#14 (#823)
    
    HooksRunner#12 did not actually test the HooksRunner class at all but
    instead tested what arguments plugin (un)install hooks would receive.
    Therefore it's a better fit for the plugin E2E tests.
    
    The test code has been cleaned up in the process without making
    essential changes to what is being tested.
---
 integration-tests/HooksRunner.spec.js | 51 -----------------------------------
 integration-tests/plugin.spec.js      | 36 +++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 51 deletions(-)

diff --git a/integration-tests/HooksRunner.spec.js b/integration-tests/HooksRunner.spec.js
index d9e7a81..3d176cc 100644
--- a/integration-tests/HooksRunner.spec.js
+++ b/integration-tests/HooksRunner.spec.js
@@ -103,11 +103,9 @@ describe('HooksRunner', function () {
     describe('fire method', function () {
         const test_event = 'before_build';
         const hooksOrderFile = path.join(project, 'hooks_order.txt');
-        let fire;
 
         beforeEach(function () {
             fs.removeSync(hooksOrderFile);
-            fire = spyOn(HooksRunner.prototype, 'fire').and.callThrough();
         });
 
         // helper methods
@@ -267,55 +265,6 @@ describe('HooksRunner', function () {
                 });
             });
 
-            // FIXME Sometimes the paths returned in the hook context are resolved to their realpath, sometimes not.
-            // Furthermore, using npm@3 (default for node@6) will install the local plugin by copying not by symlinking.
-            // Disabling this test until the paths in the in the hook context are handled consistently.
-            xit('Test 012 : should run before_plugin_uninstall, before_plugin_install, after_plugin_install hooks for a plugin being installed with correct opts.plugin context', function () {
-                const hooksToTest = [
-                    'before_plugin_uninstall',
-                    'before_plugin_install',
-                    'after_plugin_install'
-                ];
-                const toPlainObject = o => JSON.parse(JSON.stringify(o));
-
-                const expectedContext = toPlainObject({
-                    cordova: {
-                        platforms: ['android'],
-                        plugins: [testPlugin],
-                        version: require('../package').version
-                    },
-                    plugin: {
-                        id: testPlugin,
-                        pluginInfo: new PluginInfo(testPluginInstalledPath),
-                        platform: 'android',
-                        dir: testPluginInstalledPath
-                    },
-                    projectRoot: project
-                });
-                // Delete unique ids to allow comparing PluginInfo
-                delete expectedContext.plugin.pluginInfo._et;
-
-                return Promise.resolve()
-                    .then(_ => cordova.plugin('rm', testPlugin))
-                    .then(_ => cordova.plugin('add', testPluginFixture))
-                    .then(_ => {
-                        fire.calls.all()
-                            .filter(call => hooksToTest.includes(call.args[0]))
-                            .forEach(call => {
-                                const context = toPlainObject(call.args[1]);
-
-                                expect(context).toBeDefined();
-                                expect(context.plugin).toBeDefined();
-                                expect(context.plugin.platform).toBe(testPlatform);
-
-                                // Delete unique ids to allow comparing PluginInfo
-                                delete context.plugin.pluginInfo._et;
-
-                                expect(context).toEqual(expectedContext);
-                            });
-                    });
-            }, 20 * 1000);
-
             it('Test 013 : should not execute the designated hook when --nohooks option specifies the exact hook name', function () {
                 hookOptions.nohooks = ['before_build'];
 
diff --git a/integration-tests/plugin.spec.js b/integration-tests/plugin.spec.js
index a4646f8..5a100a0 100644
--- a/integration-tests/plugin.spec.js
+++ b/integration-tests/plugin.spec.js
@@ -26,6 +26,7 @@ var platforms = require('../src/platforms/platforms');
 var plugman = require('../src/plugman/plugman');
 var install = require('../src/plugman/install');
 var plugin_util = require('../src/cordova/plugin/util');
+const HooksRunner = require('../src/hooks/HooksRunner');
 
 var util = require('../src/cordova/util');
 
@@ -269,4 +270,39 @@ describe('plugin end-to-end', function () {
                 return removePlugin(scopedTestPlugin);
             });
     }, 30000);
+
+    it('Test 014 : should run plugin (un)install hooks with correct opts', async () => {
+        const testPluginInstalledPath = path.join(project, 'plugins', npmInfoTestPlugin);
+        const expectedOpts = jasmine.objectContaining({
+            cordova: {
+                platforms: [helpers.testPlatform],
+                plugins: [npmInfoTestPlugin],
+                version: require('../package').version
+            },
+            plugin: {
+                id: npmInfoTestPlugin,
+                platform: helpers.testPlatform,
+                dir: testPluginInstalledPath,
+                pluginInfo: jasmine.objectContaining({
+                    id: npmInfoTestPlugin,
+                    dir: testPluginInstalledPath
+                })
+            },
+            projectRoot: project
+        });
+
+        mockPluginFetch(npmInfoTestPlugin, path.join(pluginsDir, npmInfoTestPlugin));
+        spyOn(HooksRunner.prototype, 'fire').and.callThrough();
+
+        await cordova.plugin('add', npmInfoTestPlugin);
+        await cordova.plugin('rm', npmInfoTestPlugin);
+
+        HooksRunner.prototype.fire.calls.allArgs()
+            .filter(([hook]) => /_plugin_(un)?install$/.test(hook))
+            .forEach(([hook, opts]) => {
+                expect(opts)
+                    .withContext(`${hook} hook options`)
+                    .toEqual(expectedOpts);
+            });
+    }, 20 * 1000);
 });


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