compile 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/4b8118c3 Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/4b8118c3 Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/4b8118c3 Branch: refs/heads/master2 Commit: 4b8118c32aff3ac190cc0ff4ba53ecec897d496b Parents: 4ddae0c Author: Fil Maj <[email protected]> Authored: Wed Jun 12 22:37:45 2013 -0700 Committer: Fil Maj <[email protected]> Committed: Thu Jun 13 11:13:22 2013 -0700 ---------------------------------------------------------------------- spec/compile.spec.js | 80 ++++++++++++++++------------------------------- src/compile.js | 4 --- 2 files changed, 27 insertions(+), 57 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/4b8118c3/spec/compile.spec.js ---------------------------------------------------------------------- diff --git a/spec/compile.spec.js b/spec/compile.spec.js index b79d889..54226f2 100644 --- a/spec/compile.spec.js +++ b/spec/compile.spec.js @@ -16,89 +16,62 @@ specific language governing permissions and limitations under the License. */ -var cordova = require('../../cordova'), +var cordova = require('../cordova'), + platforms = require('../platforms'), shell = require('shelljs'), path = require('path'), fs = require('fs'), - events = require('../../src/events'), - hooker = require('../../src/hooker'), - tempDir = path.join(__dirname, '..', '..', 'temp'); + 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('compile command', function() { + var is_cordova, list_platforms, fire, exec; + var project_dir = '/some/path'; beforeEach(function() { - shell.rm('-rf', tempDir); - shell.mkdir('-p', 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); + }); + 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() { - cordova.create(tempDir); - 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.compile(); - }).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.compile(); - }).toThrow(); + }).toThrow('Current working directory is not a Cordova-based project.'); }); }); describe('success', function() { - beforeEach(function() { - cordova.create(tempDir); - process.chdir(tempDir); - }); - afterEach(function() { - process.chdir(cwd); - }); - it('should run inside a Cordova-based project with at least one added platform and shell out to a build command', function(done) { - var sh_spy = spyOn(shell, 'exec').andCallFake(function(cmd, opts, cb) { - cb(0, 'mhmm'); - }); - cordova.compile(['android', 'ios'], function(err) { - expect(sh_spy).toHaveBeenCalled(); - expect(sh_spy.mostRecentCall.args[0]).toMatch(/cordova.build"$/gi); + it('should run inside a Cordova-based project with at least one added platform and shell out to build', function(done) { + cordova.compile(['android','ios'], function(err) { + expect(exec).toHaveBeenCalledWith('"' + path.join(project_dir, 'platforms', 'android', 'cordova', 'build') + '"', jasmine.any(Object), jasmine.any(Function)); done(); }); }); }); describe('hooks', function() { - var hook_spy; - var shell_spy; - beforeEach(function() { - hook_spy = spyOn(hooker.prototype, 'fire').andCallFake(function(hook, opts, cb) { - cb(); - }); - shell_spy = spyOn(shell, 'exec').andCallFake(function(cmd, opts, cb) { - cb(0, 'yup'); // fake out shell so system thinks every shell-out is successful - }); - cordova.create(tempDir); - process.chdir(tempDir); - }); - afterEach(function() { - hook_spy.reset(); - shell_spy.reset(); - process.chdir(cwd); - }); - describe('when platforms are added', function() { it('should fire before hooks through the hooker module', function() { cordova.compile(['android', 'ios']); - expect(hook_spy).toHaveBeenCalledWith('before_compile', {platforms:['android', 'ios']}, jasmine.any(Function)); + expect(fire).toHaveBeenCalledWith('before_compile', {platforms:['android', 'ios']}, jasmine.any(Function)); }); it('should fire after hooks through the hooker module', function(done) { cordova.compile('android', function() { - expect(hook_spy).toHaveBeenCalledWith('after_compile', {platforms:['android']}, jasmine.any(Function)); + expect(fire).toHaveBeenCalledWith('after_compile', {platforms:['android']}, jasmine.any(Function)); done(); }); }); @@ -106,10 +79,11 @@ describe('compile command', function() { describe('with no platforms added', function() { it('should not fire the hooker', function() { + list_platforms.andReturn([]); expect(function() { cordova.compile(); }).toThrow(); - expect(hook_spy).not.toHaveBeenCalled(); + expect(fire).not.toHaveBeenCalled(); }); }); }); http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/4b8118c3/src/compile.js ---------------------------------------------------------------------- diff --git a/src/compile.js b/src/compile.js index 39c78bc..d2608cd 100644 --- a/src/compile.js +++ b/src/compile.js @@ -18,7 +18,6 @@ */ var cordova_util = require('./util'), path = require('path'), - config_parser = require('./config_parser'), fs = require('fs'), shell = require('shelljs'), et = require('elementtree'), @@ -50,9 +49,6 @@ module.exports = function compile(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];
