You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by fi...@apache.org on 2013/06/14 19:31:44 UTC
[75/83] [abbrv] git commit: run specs
run specs
Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/78479070
Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/78479070
Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/78479070
Branch: refs/heads/lazy
Commit: 78479070fd589e709ffd78ad3aa80f666963bca1
Parents: 20d8b8a
Author: Fil Maj <ma...@gmail.com>
Authored: Wed Jun 12 23:28:09 2013 -0700
Committer: Fil Maj <ma...@gmail.com>
Committed: Thu Jun 13 11:13:22 2013 -0700
----------------------------------------------------------------------
spec/run.spec.js | 134 ++++++++++++++++++++------------------------------
src/run.js | 19 ++++---
2 files changed, 63 insertions(+), 90 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/78479070/spec/run.spec.js
----------------------------------------------------------------------
diff --git a/spec/run.spec.js b/spec/run.spec.js
index 7e505ef..02cf21d 100644
--- a/spec/run.spec.js
+++ b/spec/run.spec.js
@@ -16,125 +16,99 @@
specific language governing permissions and limitations
under the License.
*/
-var cordova = require('../../cordova'),
- et = require('elementtree'),
+var cordova = require('../cordova'),
+ platforms = require('../platforms'),
shell = require('shelljs'),
path = require('path'),
fs = require('fs'),
- config_parser = require('../../src/config_parser'),
- android_parser = require('../../src/metadata/android_parser'),
- hooker = require('../../src/hooker'),
- fixtures = path.join(__dirname, '..', 'fixtures'),
- hooks = path.join(fixtures, 'hooks'),
- tempDir = path.join(__dirname, '..', '..', 'temp'),
- cordova_project = path.join(fixtures, 'projects', 'cordova');
+ hooker = require('../src/hooker'),
+ util = require('../src/util');
-var cwd = process.cwd();
+var supported_platforms = Object.keys(platforms).filter(function(p) { return p != 'www'; });
describe('run command', function() {
+ var is_cordova, list_platforms, fire, exec;
+ var project_dir = '/some/path';
+ var prepare_spy;
beforeEach(function() {
- shell.rm('-rf', tempDir);
- cordova.create(tempDir);
+ is_cordova = spyOn(util, 'isCordova').andReturn(project_dir);
+ list_platforms = spyOn(util, 'listPlatforms').andReturn(supported_platforms);
+ fire = spyOn(hooker.prototype, 'fire').andCallFake(function(e, opts, cb) {
+ cb(false);
+ });
+ prepare_spy = spyOn(cordova, 'prepare').andCallFake(function(platforms, cb) {
+ cb();
+ });
+ exec = spyOn(shell, 'exec').andCallFake(function(cmd, opts, cb) { cb(0, ''); });
});
-
describe('failure', function() {
- afterEach(function() {
- process.chdir(cwd);
- });
- it('should not run inside a Cordova-based project with no added platforms', function() {
- process.chdir(tempDir);
+ it('should not run inside a Cordova-based project with no added platforms by calling util.listPlatforms', function() {
+ list_platforms.andReturn([]);
expect(function() {
cordova.run();
- }).toThrow();
+ }).toThrow('No platforms added to this project. Please use `cordova platform add <platform>`.');
});
it('should not run outside of a Cordova-based project', function() {
- shell.mkdir('-p', tempDir);
- process.chdir(tempDir);
-
+ is_cordova.andReturn(false);
expect(function() {
cordova.run();
- }).toThrow();
+ }).toThrow('Current working directory is not a Cordova-based project.');
+ });
+ it('should throw if no BlackBerry simulator targets exist and blackberry is to be rund', function() {
+ var bb_project = path.join(project_dir, 'platforms', 'blackberry');
+ spyOn(platforms.blackberry, 'parser').andReturn({
+ has_device_target:function() { return false; }
+ });
+ expect(function() {
+ cordova.run('blackberry');
+ }).toThrow('No BlackBerry device targets defined. If you want to run `run` with BB10, please add a device target. For more information run "' + path.join(bb_project, 'cordova', 'target') + '" -h');
});
});
-
+
describe('success', function() {
- beforeEach(function() {
- shell.cp('-Rf', path.join(cordova_project, 'platforms', 'android'), path.join(tempDir, 'platforms'));
- process.chdir(tempDir);
- });
- afterEach(function() {
- process.chdir(cwd);
- });
- it('should invoke prepare', function() {
- var spy = spyOn(cordova, 'prepare');
- spyOn(shell, 'exec');
- cordova.run();
- expect(spy).toHaveBeenCalled();
- });
- it('should shell out to underlying `run` platform-level scripts', function(done) {
- spyOn(cordova, 'prepare').andCallFake(function(platforms, callback) {
- callback(false);
- });
- var spy = spyOn(shell, 'exec').andCallFake(function(cmd, options, cb) {
- cb(0, 'yep');
+ 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.run(['android','ios'], function(err) {
+ expect(prepare_spy).toHaveBeenCalledWith(['android', 'ios'], jasmine.any(Function));
+ expect(exec).toHaveBeenCalledWith('"' + path.join(project_dir, 'platforms', 'android', 'cordova', 'run') + '" --device', jasmine.any(Object), jasmine.any(Function));
+ expect(exec).toHaveBeenCalledWith('"' + path.join(project_dir, 'platforms', 'ios', 'cordova', 'run') + '" --device', jasmine.any(Object), jasmine.any(Function));
+ done();
});
- cordova.run('android', function() {
- expect(spy.mostRecentCall.args[0]).toMatch(/cordova.run" --device$/gi);
- done();
+ });
+ it('should execute a different BlackBerry-specific command to run blackberry', function() {
+ var bb_project = path.join(project_dir, 'platforms', 'blackberry');
+ spyOn(platforms.blackberry, 'parser').andReturn({
+ has_device_target:function() { return true; },
+ get_device_targets:function() { return [{name:'fifi'}]; },
+ get_cordova_config:function() { return {signing_password:'secret'}; }
});
+ expect(function() {
+ cordova.run('blackberry');
+ expect(exec.mostRecentCall.args[0]).toMatch(/blackberry.cordova.run" --target=fifi -k secret/gi);
+ }).not.toThrow();
});
});
-
describe('hooks', function() {
- var s;
- beforeEach(function() {
- s = spyOn(hooker.prototype, 'fire').andCallFake(function(hook, opts, cb) {
- if (cb) cb();
- else opts();
- });
- });
-
describe('when platforms are added', function() {
- beforeEach(function() {
- shell.cp('-Rf', path.join(cordova_project, 'platforms', 'android'), path.join(tempDir, 'platforms'));
- process.chdir(tempDir);
- });
- afterEach(function() {
- process.chdir(cwd);
- });
-
it('should fire before hooks through the hooker module', function() {
-
- spyOn(shell, 'exec');
- cordova.run();
- expect(hooker.prototype.fire).toHaveBeenCalledWith('before_run', {platforms:['android']}, jasmine.any(Function));
+ cordova.run(['android', 'ios']);
+ expect(fire).toHaveBeenCalledWith('before_run', {platforms:['android', 'ios']}, jasmine.any(Function));
});
it('should fire after hooks through the hooker module', function(done) {
- spyOn(shell, 'exec').andCallFake(function(cmd, options, callback) {
- callback(0, 'fucking eh');
- });
cordova.run('android', function() {
- expect(hooker.prototype.fire).toHaveBeenCalledWith('after_run', {platforms:['android']}, jasmine.any(Function));
+ expect(fire).toHaveBeenCalledWith('after_run', {platforms:['android']}, jasmine.any(Function));
done();
});
});
});
describe('with no platforms added', function() {
- beforeEach(function() {
- process.chdir(tempDir);
- });
- afterEach(function() {
- process.chdir(cwd);
- });
it('should not fire the hooker', function() {
- spyOn(shell, 'exec');
+ list_platforms.andReturn([]);
expect(function() {
cordova.run();
}).toThrow();
- expect(s).not.toHaveBeenCalledWith('before_run');
- expect(s).not.toHaveBeenCalledWith('after_run');
+ expect(fire).not.toHaveBeenCalled();
});
});
});
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/78479070/src/run.js
----------------------------------------------------------------------
diff --git a/src/run.js b/src/run.js
index 6913a21..4110e1b 100644
--- a/src/run.js
+++ b/src/run.js
@@ -18,16 +18,14 @@
*/
var cordova_util = require('./util'),
path = require('path'),
- config_parser = require('./config_parser'),
fs = require('fs'),
shell = require('shelljs'),
- et = require('elementtree'),
hooker = require('./hooker'),
platforms = require('./../platforms'),
events = require('./events'),
n = require('ncallbacks');
-function shell_out_to_run(projectRoot, platform, callback) {
+function shell_out_to_run(projectRoot, platform, error_callback, done) {
var cmd = '"' + path.join(projectRoot, 'platforms', platform, 'cordova', 'run') + '" --device';
// TODO: inconsistent API for BB10 run command
if (platform == 'blackberry') {
@@ -38,7 +36,9 @@ function shell_out_to_run(projectRoot, platform, callback) {
var device = project.get_device_targets()[0].name;
cmd = '"' + path.join(bb_project, 'cordova', 'run') + '" --target=' + device + ' -k ' + bb_config.signing_password;
} else {
- throw new Error('No BlackBerry device targets defined. If you want to run `run` with BB10, please add a device target. For more information run "' + path.join(bb_project, 'cordova', 'target') + '" -h');
+ var err = new Error('No BlackBerry device targets defined. If you want to run `run` with BB10, please add a device target. For more information run "' + path.join(bb_project, 'cordova', 'target') + '" -h');
+ if (error_callback) error_callback(err);
+ else throw err;
}
}
@@ -46,10 +46,12 @@ function shell_out_to_run(projectRoot, platform, callback) {
shell.exec(cmd, {silent:true, async:true}, function(code, output) {
events.emit('log', output);
if (code > 0) {
- throw new Error('An error occurred while running the ' + platform + ' project. ' + output);
+ var err = new Error('An error occurred while running the ' + platform + ' project. ' + output);
+ if (error_callback) error_callback(err);
+ else throw err;
} else {
events.emit('log', 'Platform "' + platform + '" ran successfully.');
- if (callback) callback();
+ if (done) done();
}
});
}
@@ -64,9 +66,6 @@ module.exports = function run(platformList, callback) {
return;
}
- var xml = cordova_util.projectConfig(projectRoot);
- var cfg = new config_parser(xml);
-
if (arguments.length === 0 || (platformList instanceof Array && platformList.length === 0)) {
platformList = cordova_util.listPlatforms(projectRoot);
} else if (typeof platformList == 'string') platformList = [platformList];
@@ -110,7 +109,7 @@ module.exports = function run(platformList, callback) {
} else {
platformList.forEach(function(platform) {
try {
- shell_out_to_run(projectRoot, platform, end);
+ shell_out_to_run(projectRoot, platform, callback, end);
} catch(e) {
if (callback) callback(e);
else throw e;