Repository: cordova-lib Updated Branches: refs/heads/master 8290d7e3e -> 7d367dcb0
CB-11491 Introduce before_deploy hook This closes #460 Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/7d367dcb Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/7d367dcb Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/7d367dcb Branch: refs/heads/master Commit: 7d367dcb01740450e0af447308c0b859616e709d Parents: 8290d7e Author: daserge <v-ses...@microsoft.com> Authored: Thu Jun 30 15:38:54 2016 +0300 Committer: Vladimir Kotikov <v-vlk...@microsoft.com> Committed: Wed Jul 13 12:31:55 2016 +0300 ---------------------------------------------------------------------- cordova-lib/spec-cordova/emulate.spec.js | 31 +++++++++++++++++++++++++-- cordova-lib/spec-cordova/run.spec.js | 31 +++++++++++++++++++++++++-- cordova-lib/src/cordova/emulate.js | 13 ++++++++++- cordova-lib/src/cordova/run.js | 13 ++++++++++- 4 files changed, 82 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/7d367dcb/cordova-lib/spec-cordova/emulate.spec.js ---------------------------------------------------------------------- diff --git a/cordova-lib/spec-cordova/emulate.spec.js b/cordova-lib/spec-cordova/emulate.spec.js index 3f9b093..c04c16d 100644 --- a/cordova-lib/spec-cordova/emulate.spec.js +++ b/cordova-lib/spec-cordova/emulate.spec.js @@ -36,7 +36,10 @@ describe('emulate command', function() { fire = spyOn(HooksRunner.prototype, 'fire').andReturn(Q()); prepare_spy = spyOn(cordova.raw, 'prepare').andReturn(Q()); fail = function (err) { expect(err.stack).not.toBeDefined(); }; - platformApi = { run: jasmine.createSpy('run').andReturn(Q()) }; + platformApi = { + run: jasmine.createSpy('run').andReturn(Q()), + build: jasmine.createSpy('build').andReturn(Q()) + }; getPlatformApi = spyOn(platforms, 'getPlatformApi').andReturn(platformApi); }); describe('failure', function() { @@ -73,6 +76,7 @@ describe('emulate command', function() { expect(prepare_spy).toHaveBeenCalledWith(jasmine.objectContaining({platforms: ['android', 'ios']})); expect(getPlatformApi).toHaveBeenCalledWith('android'); expect(getPlatformApi).toHaveBeenCalledWith('ios'); + expect(platformApi.build).toHaveBeenCalled(); expect(platformApi.run).toHaveBeenCalled(); }) .fail(fail) @@ -82,7 +86,8 @@ describe('emulate command', function() { cordova.raw.emulate({platforms: ['ios'], options: {optionTastic: true }}).then(function(err) { expect(prepare_spy).toHaveBeenCalledWith(jasmine.objectContaining({platforms: ['ios']})); expect(getPlatformApi).toHaveBeenCalledWith('ios'); - expect(platformApi.run).toHaveBeenCalledWith({ device: false, emulator: true, optionTastic: true }); + expect(platformApi.build).toHaveBeenCalledWith({ device: false, emulator: true, optionTastic: true }); + expect(platformApi.run).toHaveBeenCalledWith({ device: false, emulator: true, optionTastic: true, nobuild: true }); }) .fail(fail) .fin(done); @@ -104,6 +109,28 @@ describe('emulate command', function() { done(); }); }); + describe('run parameters should not be altered by intermediate build command', function() { + var originalBuildSpy; + beforeEach(function() { + originalBuildSpy = platformApi.build; + platformApi.build = jasmine.createSpy('build').andCallFake(function(opts) { + opts.couldBeModified = 'insideBuild'; + return Q(); + }); + }); + afterEach(function() { + platformApi.build = originalBuildSpy; + }); + it('should leave parameters unchanged', function(done) { + cordova.raw.run({platforms: ['blackberry10'], options:{password: '1q1q'}}).then(function() { + expect(prepare_spy).toHaveBeenCalledWith({ platforms: [ 'blackberry10' ], options: { password: '1q1q', 'couldBeModified': 'insideBuild' }, verbose: false }); + expect(platformApi.build).toHaveBeenCalledWith({password: '1q1q', 'couldBeModified': 'insideBuild'}); + expect(platformApi.run).toHaveBeenCalledWith({password: '1q1q', nobuild: true}); + }, function(err) { + expect(err).toBeUndefined(); + }).fin(done); + }); + }); }); describe('hooks', function() { http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/7d367dcb/cordova-lib/spec-cordova/run.spec.js ---------------------------------------------------------------------- diff --git a/cordova-lib/spec-cordova/run.spec.js b/cordova-lib/spec-cordova/run.spec.js index 13e6e13..b1dedd3 100644 --- a/cordova-lib/spec-cordova/run.spec.js +++ b/cordova-lib/spec-cordova/run.spec.js @@ -35,7 +35,10 @@ describe('run command', function() { list_platforms = spyOn(util, 'listPlatforms').andReturn(supported_platforms); fire = spyOn(HooksRunner.prototype, 'fire').andReturn(Q()); prepare_spy = spyOn(cordova.raw, 'prepare').andReturn(Q()); - platformApi = { run: jasmine.createSpy('run').andReturn(Q()) }; + platformApi = { + run: jasmine.createSpy('run').andReturn(Q()), + build: jasmine.createSpy('build').andReturn(Q()) + }; getPlatformApi = spyOn(platforms, 'getPlatformApi').andReturn(platformApi); }); describe('failure', function() { @@ -71,6 +74,7 @@ describe('run command', function() { cordova.raw.run(['android','ios']).then(function() { expect(getPlatformApi).toHaveBeenCalledWith('android'); expect(getPlatformApi).toHaveBeenCalledWith('ios'); + expect(platformApi.build).toHaveBeenCalled(); expect(platformApi.run).toHaveBeenCalled(); }, function(err) { expect(err).toBeUndefined(); @@ -79,7 +83,8 @@ describe('run command', function() { it('should pass down parameters', function(done) { cordova.raw.run({platforms: ['blackberry10'], options:{password: '1q1q'}}).then(function() { expect(prepare_spy).toHaveBeenCalledWith({ platforms: [ 'blackberry10' ], options: { password: '1q1q' }, verbose: false }); - expect(platformApi.run).toHaveBeenCalledWith({password: '1q1q'}); + expect(platformApi.build).toHaveBeenCalledWith({password: '1q1q'}); + expect(platformApi.run).toHaveBeenCalledWith({password: '1q1q', nobuild: true}); }, function(err) { expect(err).toBeUndefined(); }).fin(done); @@ -102,6 +107,28 @@ describe('run command', function() { done(); }); }); + describe('run parameters should not be altered by intermediate build command', function() { + var originalBuildSpy; + beforeEach(function() { + originalBuildSpy = platformApi.build; + platformApi.build = jasmine.createSpy('build').andCallFake(function(opts) { + opts.couldBeModified = 'insideBuild'; + return Q(); + }); + }); + afterEach(function() { + platformApi.build = originalBuildSpy; + }); + it('should leave parameters unchanged', function(done) { + cordova.raw.run({platforms: ['blackberry10'], options:{password: '1q1q'}}).then(function() { + expect(prepare_spy).toHaveBeenCalledWith({ platforms: [ 'blackberry10' ], options: { password: '1q1q', 'couldBeModified': 'insideBuild' }, verbose: false }); + expect(platformApi.build).toHaveBeenCalledWith({password: '1q1q', 'couldBeModified': 'insideBuild'}); + expect(platformApi.run).toHaveBeenCalledWith({password: '1q1q', nobuild: true}); + }, function(err) { + expect(err).toBeUndefined(); + }).fin(done); + }); + }); }); describe('hooks', function() { http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/7d367dcb/cordova-lib/src/cordova/emulate.js ---------------------------------------------------------------------- diff --git a/cordova-lib/src/cordova/emulate.js b/cordova-lib/src/cordova/emulate.js index 2c8fea4..b0b61aa 100644 --- a/cordova-lib/src/cordova/emulate.js +++ b/cordova-lib/src/cordova/emulate.js @@ -40,9 +40,20 @@ module.exports = function emulate(options) { }).then(function() { // Deploy in parallel (output gets intermixed though...) return Q.all(options.platforms.map(function(platform) { + // This is needed as .build modifies opts + var optsClone = _.clone(options.options); return platform_lib .getPlatformApi(platform) - .run(_.clone(options.options)); + .build(options.options) + .then(function() { + return hooksRunner.fire('before_deploy', options); + }) + .then(function() { + optsClone.nobuild = true; + return platform_lib + .getPlatformApi(platform) + .run(optsClone); + }); })); }).then(function() { return hooksRunner.fire('after_emulate', options); http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/7d367dcb/cordova-lib/src/cordova/run.js ---------------------------------------------------------------------- diff --git a/cordova-lib/src/cordova/run.js b/cordova-lib/src/cordova/run.js index be15205..74fe8f5 100644 --- a/cordova-lib/src/cordova/run.js +++ b/cordova-lib/src/cordova/run.js @@ -40,9 +40,20 @@ module.exports = function run(options) { }).then(function() { // Deploy in parallel (output gets intermixed though...) return Q.all(options.platforms.map(function(platform) { + // This is needed as .build modifies opts + var optsClone = _.clone(options.options); return platform_lib .getPlatformApi(platform) - .run(_.clone(options.options)); + .build(options.options) + .then(function() { + return hooksRunner.fire('before_deploy', options); + }) + .then(function() { + optsClone.nobuild = true; + return platform_lib + .getPlatformApi(platform) + .run(optsClone); + }); })); }).then(function() { return hooksRunner.fire('after_run', options); --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cordova.apache.org For additional commands, e-mail: commits-h...@cordova.apache.org