From 3b9face5187857d354d85f3e3f4316cbace100db Mon Sep 17 00:00:00 2001 From: Vladimir Kotikov Date: Wed, 17 Feb 2016 18:48:31 +0300 Subject: [PATCH 1/2] CB-10641 Run prepare _after_ plugins were installed --- cordova-lib/src/cordova/platform.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/cordova-lib/src/cordova/platform.js b/cordova-lib/src/cordova/platform.js index 87f2e5881..96c5f2f98 100644 --- a/cordova-lib/src/cordova/platform.js +++ b/cordova-lib/src/cordova/platform.js @@ -180,18 +180,21 @@ function addHelper(cmd, hooksRunner, projectRoot, targets, opts) { PlatformApi.createPlatform.bind(null, destination, cfg, options, events) : PlatformApi.updatePlatform.bind(null, destination, options, events); - return promise().then(function () { + return promise() + .then(function() { + if (cmd == 'add') { + return installPluginsForNewPlatform(platform, projectRoot, opts); + } + }) + .then(function () { // Call prepare for the current platform. var prepOpts = { platforms :[platform], searchpath :opts.searchpath }; return require('./cordova').raw.prepare(prepOpts); - }).then(function() { - if (cmd == 'add') { - return installPluginsForNewPlatform(platform, projectRoot, opts); - } - }).then(function() { + }) + .then(function() { var saveVersion = !spec || semver.validRange(spec, true); // Save platform@spec into platforms.json, where 'spec' is a version or a soure location. If a From b04db5feaf5516836c8a157cc3331b75d6dca0eb Mon Sep 17 00:00:00 2001 From: Vladimir Kotikov Date: Thu, 18 Feb 2016 13:08:47 +0300 Subject: [PATCH 2/2] CB-10641 Adds tests for order of operations in platform add --- cordova-lib/spec-cordova/platform.spec.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/cordova-lib/spec-cordova/platform.spec.js b/cordova-lib/spec-cordova/platform.spec.js index de3631aff..2c99b4a33 100644 --- a/cordova-lib/spec-cordova/platform.spec.js +++ b/cordova-lib/spec-cordova/platform.spec.js @@ -26,6 +26,7 @@ var helpers = require('./helpers'), Q = require('q'), events = require('cordova-common').events, cordova = require('../src/cordova/cordova'), + plugman = require('../src/plugman/plugman'), rewire = require('rewire'), platform = rewire('../src/cordova/platform.js'); @@ -132,9 +133,6 @@ describe('platform end-to-end', function () { .then(function() { return cordova.raw.platform('add', [helpers.testPlatform]); }) - .then(function () { - return cordova.raw.prepare([helpers.testPlatform]); - }) .then(function() { // Check the platform add was successful. expect(path.join(project, 'platforms', helpers.testPlatform)).toExist(); @@ -146,6 +144,24 @@ describe('platform end-to-end', function () { }) .fin(done); }); + + it('should call prepare after plugins were installed into platform', function(done) { + var order = ''; + var fail = jasmine.createSpy(fail); + spyOn(plugman.raw, 'install').andCallFake(function() { order += 'I'; }); + spyOn(cordova.raw, 'prepare').andCallFake(function() { order += 'P'; }); + + cordova.raw.plugin('add', path.join(pluginsDir, 'test')) + .then(function() { + return cordova.raw.platform('add', [helpers.testPlatform]); + }) + .fail(fail) + .fin(function() { + expect(order).toBe('IP'); // Install first, then prepare + expect(fail).not.toHaveBeenCalled(); + done(); + }); + }); }); describe('add function', function () {