You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by cs...@apache.org on 2013/10/23 01:57:55 UTC
[2/2] git commit: CB-5125 add tests for chil process spawn
CB-5125 add tests for chil process spawn
Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/dedc29a8
Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/dedc29a8
Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/dedc29a8
Branch: refs/heads/master
Commit: dedc29a81b1bc57ce25d88bbad51478d0d1091c1
Parents: 01c7ece
Author: Carlos Santana <cs...@gmail.com>
Authored: Mon Oct 21 23:14:36 2013 -0400
Committer: Carlos Santana <cs...@gmail.com>
Committed: Mon Oct 21 23:14:36 2013 -0400
----------------------------------------------------------------------
spec/compile.spec.js | 29 +++++++++++++++++++++--------
spec/emulate.spec.js | 28 ++++++++++++++++++++--------
spec/run.spec.js | 30 ++++++++++++++++++++++--------
3 files changed, 63 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/dedc29a8/spec/compile.spec.js
----------------------------------------------------------------------
diff --git a/spec/compile.spec.js b/spec/compile.spec.js
index 3b0fe0d..4b9ee43 100644
--- a/spec/compile.spec.js
+++ b/spec/compile.spec.js
@@ -28,8 +28,23 @@ var cordova = require('../cordova'),
var supported_platforms = Object.keys(platforms).filter(function(p) { return p != 'www'; });
describe('compile command', function() {
- var is_cordova, list_platforms, fire, exec, result;
+ var is_cordova, list_platforms, fire, result, child;
var project_dir = '/some/path';
+ child = {
+ on: function(child_event,cb){
+ if(child_event === 'close'){
+ cb(0);
+ }
+ },
+ stdout: {
+ setEncoding: function(){},
+ on: function(){}
+ },
+ stderr: {
+ setEncoding: function(){},
+ on: function(){}
+ }
+ };
function wrapper(f, post) {
runs(function() {
@@ -42,10 +57,7 @@ describe('compile command', function() {
is_cordova = spyOn(util, 'isCordova').andReturn(project_dir);
list_platforms = spyOn(util, 'listPlatforms').andReturn(supported_platforms);
fire = spyOn(hooker.prototype, 'fire').andReturn(Q());
- exec = spyOn(child_process, 'exec').andCallFake(function(cmd, opts, cb) {
- if (!cb) cb = opts;
- cb(null, '', '');
- });
+ spyOn(child_process, 'spawn').andReturn(child);
});
describe('failure', function() {
it('should not run inside a Cordova-based project with no added platforms by calling util.listPlatforms', function() {
@@ -65,14 +77,15 @@ describe('compile command', function() {
describe('success', function() {
it('should run inside a Cordova-based project with at least one added platform and shell out to build', function(done) {
cordova.raw.compile(['android','ios']).then(function() {
- expect(exec).toHaveBeenCalledWith('"' + path.join(project_dir, 'platforms', 'android', 'cordova', 'build') + '"', jasmine.any(Function));
+ expect(child_process.spawn).toHaveBeenCalledWith(path.join(project_dir, 'platforms', 'android', 'cordova', 'build'),[]);
+ expect(child_process.spawn).toHaveBeenCalledWith(path.join(project_dir, 'platforms', 'ios', 'cordova', 'build'),[]);
done();
});
+
});
it('should pass down optional parameters', function (done) {
cordova.raw.compile({platforms:["blackberry10"], options:["--release"]}).then(function () {
- var buildCommand = path.join(project_dir, 'platforms', 'blackberry10', 'cordova', 'build');
- expect(exec).toHaveBeenCalledWith('"' + buildCommand + '" --release', jasmine.any(Function));
+ expect(child_process.spawn).toHaveBeenCalledWith(path.join(project_dir, 'platforms', 'blackberry10', 'cordova', 'build'),['--release']);
done();
});
});
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/dedc29a8/spec/emulate.spec.js
----------------------------------------------------------------------
diff --git a/spec/emulate.spec.js b/spec/emulate.spec.js
index 79b5176..8f3303e 100644
--- a/spec/emulate.spec.js
+++ b/spec/emulate.spec.js
@@ -28,9 +28,24 @@ var cordova = require('../cordova'),
var supported_platforms = Object.keys(platforms).filter(function(p) { return p != 'www'; });
describe('emulate command', function() {
- var is_cordova, list_platforms, fire, exec, result;
+ var is_cordova, list_platforms, fire, result, child;
var project_dir = '/some/path';
var prepare_spy;
+ child = {
+ on: function(child_event,cb){
+ if(child_event === 'close'){
+ cb(0);
+ }
+ },
+ stdout: {
+ setEncoding: function(){},
+ on: function(){}
+ },
+ stderr: {
+ setEncoding: function(){},
+ on: function(){}
+ }
+ };
function wrapper(f, post) {
runs(function() {
@@ -45,10 +60,7 @@ describe('emulate command', function() {
list_platforms = spyOn(util, 'listPlatforms').andReturn(supported_platforms);
fire = spyOn(hooker.prototype, 'fire').andReturn(Q());
prepare_spy = spyOn(cordova.raw, 'prepare').andReturn(Q());
- exec = spyOn(child_process, 'exec').andCallFake(function(cmd, opts, cb) {
- if (!cb) cb = opts;
- cb(null, '', '');
- });
+ spyOn(child_process, 'spawn').andReturn(child);
});
describe('failure', function() {
it('should not run inside a Cordova-based project with no added platforms by calling util.listPlatforms', function() {
@@ -69,15 +81,15 @@ describe('emulate command', function() {
it('should run inside a Cordova-based project with at least one added platform and call prepare and shell out to the emulate script', function(done) {
cordova.raw.emulate(['android','ios']).then(function(err) {
expect(prepare_spy).toHaveBeenCalledWith(['android', 'ios']);
- expect(exec).toHaveBeenCalledWith('"' + path.join(project_dir, 'platforms', 'android', 'cordova', 'run') + '" --emulator', jasmine.any(Function));
- expect(exec).toHaveBeenCalledWith('"' + path.join(project_dir, 'platforms', 'ios', 'cordova', 'run') + '" --emulator', jasmine.any(Function));
+ expect(child_process.spawn).toHaveBeenCalledWith(path.join(project_dir, 'platforms', 'android', 'cordova', 'run'), ['--emulator']);
+ expect(child_process.spawn).toHaveBeenCalledWith(path.join(project_dir, 'platforms', 'ios', 'cordova', 'run'), ['--emulator']);
done();
});
});
it('should pass down options', function(done) {
cordova.raw.emulate({platforms: ['ios'], options:["--optionTastic"]}).then(function(err) {
expect(prepare_spy).toHaveBeenCalledWith(['ios']);
- expect(exec).toHaveBeenCalledWith('"' + path.join(project_dir, 'platforms', 'ios', 'cordova', 'run') + '" --emulator --optionTastic', jasmine.any(Function));
+ expect(child_process.spawn).toHaveBeenCalledWith(path.join(project_dir, 'platforms', 'ios', 'cordova', 'run'), ['--emulator', '--optionTastic']);
done();
});
});
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/dedc29a8/spec/run.spec.js
----------------------------------------------------------------------
diff --git a/spec/run.spec.js b/spec/run.spec.js
index 7d13a96..65e6bbe 100644
--- a/spec/run.spec.js
+++ b/spec/run.spec.js
@@ -28,18 +28,31 @@ var cordova = require('../cordova'),
var supported_platforms = Object.keys(platforms).filter(function(p) { return p != 'www'; });
describe('run command', function() {
- var is_cordova, list_platforms, fire, exec;
+ var is_cordova, list_platforms, fire, child;
var project_dir = '/some/path';
var prepare_spy;
+ child = {
+ on: function(child_event,cb){
+ if(child_event === 'close'){
+ cb(0);
+ }
+ },
+ stdout: {
+ setEncoding: function(){},
+ on: function(){}
+ },
+ stderr: {
+ setEncoding: function(){},
+ on: function(){}
+ }
+ };
+
beforeEach(function() {
is_cordova = spyOn(util, 'isCordova').andReturn(project_dir);
list_platforms = spyOn(util, 'listPlatforms').andReturn(supported_platforms);
fire = spyOn(hooker.prototype, 'fire').andReturn(Q());
prepare_spy = spyOn(cordova.raw, 'prepare').andReturn(Q());
- exec = spyOn(child_process, 'exec').andCallFake(function(cmd, opts, cb) {
- if (!cb) cb = opts;
- cb(0, '', '');
- });
+ spyOn(child_process, 'spawn').andReturn(child);
});
describe('failure', function() {
it('should not run inside a Cordova-based project with no added platforms by calling util.listPlatforms', function(done) {
@@ -64,8 +77,9 @@ describe('run command', function() {
it('should run inside a Cordova-based project with at least one added platform and call prepare and shell out to the run script', function(done) {
cordova.raw.run(['android','ios']).then(function() {
expect(prepare_spy).toHaveBeenCalledWith(['android', 'ios']);
- expect(exec).toHaveBeenCalledWith('"' + path.join(project_dir, 'platforms', 'android', 'cordova', 'run') + '" --device', jasmine.any(Function));
- expect(exec).toHaveBeenCalledWith('"' + path.join(project_dir, 'platforms', 'ios', 'cordova', 'run') + '" --device', jasmine.any(Function));
+ expect(child_process.spawn).toHaveBeenCalledWith(path.join(project_dir, 'platforms', 'android', 'cordova', 'run'), ['--device']);
+ expect(child_process.spawn).toHaveBeenCalledWith(path.join(project_dir, 'platforms', 'ios', 'cordova', 'run'), ['--device']);
+
}, function(err) {
console.log(err);
expect(err).toBeUndefined();
@@ -74,7 +88,7 @@ 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(['blackberry10']);
- expect(exec).toHaveBeenCalledWith('"' + path.join(project_dir, 'platforms', 'blackberry10', 'cordova', 'run') + '" --device --password 1q1q', jasmine.any(Function));
+ expect(child_process.spawn).toHaveBeenCalledWith(path.join(project_dir, 'platforms', 'blackberry10', 'cordova', 'run'), ['--device', '--password', '1q1q']);
}, function(err) {
expect(err).toBeUndefined();
}).fin(done);