cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fil...@apache.org
Subject [63/83] [abbrv] updating part of the config_parser specs
Date Fri, 14 Jun 2013 17:31:32 GMT
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/9828b9c1/spec/cordova-cli/run.spec.js
----------------------------------------------------------------------
diff --git a/spec/cordova-cli/run.spec.js b/spec/cordova-cli/run.spec.js
deleted file mode 100644
index 7e505ef..0000000
--- a/spec/cordova-cli/run.spec.js
+++ /dev/null
@@ -1,141 +0,0 @@
-/**
-    Licensed to the Apache Software Foundation (ASF) under one
-    or more contributor license agreements.  See the NOTICE file
-    distributed with this work for additional information
-    regarding copyright ownership.  The ASF licenses this file
-    to you under the Apache License, Version 2.0 (the
-    "License"); you may not use this file except in compliance
-    with the License.  You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-    Unless required by applicable law or agreed to in writing,
-    software distributed under the License is distributed on an
-    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-    KIND, either express or implied.  See the License for the
-    specific language governing permissions and limitations
-    under the License.
-*/
-var cordova = require('../../cordova'),
-    et = require('elementtree'),
-    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');
-
-var cwd = process.cwd();
-
-describe('run command', function() {
-    beforeEach(function() {
-        shell.rm('-rf', tempDir);
-        cordova.create(tempDir);
-    });
-
-    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);
-            expect(function() {
-                cordova.run();
-            }).toThrow();
-        });
-        it('should not run outside of a Cordova-based project', function() {
-            shell.mkdir('-p', tempDir);
-            process.chdir(tempDir);
-
-            expect(function() {
-                cordova.run();
-            }).toThrow();
-        });
-    });
-    
-    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');
-            });
-            cordova.run('android', function() {
-                 expect(spy.mostRecentCall.args[0]).toMatch(/cordova.run" --device$/gi);
-                 done();
-            });
-        });
-    });
-
-
-    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));
-            });
-            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));
-                     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');
-                expect(function() {
-                    cordova.run();
-                }).toThrow();
-                expect(s).not.toHaveBeenCalledWith('before_run');
-                expect(s).not.toHaveBeenCalledWith('after_run');
-            });
-        });
-    });
-});

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/9828b9c1/spec/cordova-cli/serve.spec.js
----------------------------------------------------------------------
diff --git a/spec/cordova-cli/serve.spec.js b/spec/cordova-cli/serve.spec.js
deleted file mode 100644
index 0139da8..0000000
--- a/spec/cordova-cli/serve.spec.js
+++ /dev/null
@@ -1,134 +0,0 @@
-
-/**
-    Licensed to the Apache Software Foundation (ASF) under one
-    or more contributor license agreements.  See the NOTICE file
-    distributed with this work for additional information
-    regarding copyright ownership.  The ASF licenses this file
-    to you under the Apache License, Version 2.0 (the
-    "License"); you may not use this file except in compliance
-    with the License.  You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-    Unless required by applicable law or agreed to in writing,
-    software distributed under the License is distributed on an
-    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-    KIND, either express or implied.  See the License for the
-    specific language governing permissions and limitations
-    under the License.
-*/
-var cordova = require('../../cordova'),
-    path = require('path'),
-    shell = require('shelljs'),
-    request = require('request'),
-    fs = require('fs'),
-    util = require('../../src/util'),
-    hooker = require('../../src/hooker'),
-    tempDir = path.join(__dirname, '..', '..', 'temp'),
-    http = require('http'),
-    android_parser = require('../../src/metadata/android_parser'),
-    ios_parser = require('../../src/metadata/ios_parser'),
-    blackberry_parser = require('../../src/metadata/blackberry_parser'),
-    wp7_parser        = require('../../src/metadata/wp7_parser'),
-    wp8_parser        = require('../../src/metadata/wp8_parser');
-
-var cwd = process.cwd();
-
-xdescribe('serve command', function() {
-    beforeEach(function() {
-        // Make a temp directory
-        shell.rm('-rf', tempDir);
-        shell.mkdir('-p', tempDir);
-    });
-    it('should not run outside of a Cordova-based project', function() {
-        this.after(function() {
-            process.chdir(cwd);
-        });
-
-        process.chdir(tempDir);
-
-        expect(function() {
-            cordova.serve('android');
-        }).toThrow();
-    });
-
-
-    describe('`serve`', function() {
-        var payloads = {
-            android: 'This is the Android test file.',
-            ios: 'This is the iOS test file.'
-        };
-
-        beforeEach(function() {
-            cordova.create(tempDir);
-            process.chdir(tempDir);
-            cordova.platform('add', 'android');
-            cordova.platform('add', 'ios');
-
-            // Write testing HTML files into the directory.
-            fs.writeFileSync(path.join(tempDir, 'platforms', 'android', 'assets', 'www', 'test.html'), payloads.android);
-            fs.writeFileSync(path.join(tempDir, 'platforms', 'ios', 'www', 'test.html'), payloads.ios);
-        });
-
-        afterEach(function() {
-            process.chdir(cwd);
-        });
-
-        function test_serve(platform, path, expectedContents, port) {
-            return function() {
-                var ret;
-                runs(function() {
-                    ret = port ? cordova.serve(platform, port) : cordova.serve(platform);
-                });
-
-                waitsFor(function() {
-                    return ret.server;
-                }, 'the server should start', 1000);
-
-                var done, errorCB;
-                runs(function() {
-                    expect(ret.server).toBeDefined();
-                    errorCB = jasmine.createSpy();
-                    http.get({
-                        host: 'localhost',
-                        port: port || 8000,
-                        path: path
-                    }).on('response', function(res) {
-                        var response = '';
-                        res.on('data', function(data) {
-                            response += data;
-                        });
-                        res.on('end', function() {
-                            expect(res.statusCode).toEqual(200);
-                            expect(response).toEqual(expectedContents);
-                            done = true;
-                        });
-                    }).on('error', errorCB);
-                });
-
-                waitsFor(function() {
-                    return done;
-                }, 'the HTTP request should complete', 1000);
-
-                runs(function() {
-                    expect(done).toBeTruthy();
-                    expect(errorCB).not.toHaveBeenCalled();
-
-                    ret.server.close();
-                });
-            };
-        };
-
-        it('should serve from top-level www if the file exists there', function() {
-            var payload = 'This is test file.';
-            fs.writeFileSync(path.join(util.projectWww(tempDir), 'test.html'), payload);
-            test_serve('android', '/test.html', payload)();
-        });
-
-        it('should fall back to assets/www on Android', test_serve('android', '/test.html', payloads.android));
-        it('should fall back to www on iOS', test_serve('ios', '/test.html', payloads.ios));
-
-        it('should honour a custom port setting', test_serve('android', '/test.html', payloads.android, 9001));
-    });
-});
-

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/9828b9c1/spec/cordova-cli/util.spec.js
----------------------------------------------------------------------
diff --git a/spec/cordova-cli/util.spec.js b/spec/cordova-cli/util.spec.js
deleted file mode 100644
index a57d551..0000000
--- a/spec/cordova-cli/util.spec.js
+++ /dev/null
@@ -1,13 +0,0 @@
-var cordova = require('../../cordova'),
-    shell = require('shelljs'),
-    path = require('path'),
-    fs = require('fs'),
-    cordova_util = require('../../src/util'),
-    fixtures = path.join(__dirname, '..', 'fixtures');
-
-var cwd = process.cwd();
-
-describe('util module', function() {
-    describe('isCordova method', function() {
-    });
-});

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/9828b9c1/spec/create.spec.js
----------------------------------------------------------------------
diff --git a/spec/create.spec.js b/spec/create.spec.js
new file mode 100644
index 0000000..4fa4e23
--- /dev/null
+++ b/spec/create.spec.js
@@ -0,0 +1,127 @@
+var cordova = require('../cordova'),
+    path    = require('path'),
+    shell   = require('shelljs'),
+    fs      = require('fs'),
+    util    = require('../src/util'),
+    config    = require('../src/config'),
+    lazy_load = require('../src/lazy_load'),
+    tempDir = path.join(__dirname, '..', 'temp');
+
+describe('create command', function () {
+    var mkdir, cp, config_spy, load_cordova, load_custom, exists, config_read, parser, package, name;
+    beforeEach(function() {
+        shell.rm('-rf', tempDir);
+        mkdir = spyOn(shell, 'mkdir');
+        cp = spyOn(shell, 'cp');
+        config_spy = spyOn(cordova, 'config');
+        config_read = spyOn(config, 'read').andReturn({});
+        exists = spyOn(fs, 'existsSync').andReturn(true);
+        load_cordova = spyOn(lazy_load, 'cordova').andCallFake(function(platform, cb) {
+            cb();
+        });
+        load_custom = spyOn(lazy_load, 'custom').andCallFake(function(url, id, platform, version, cb) {
+            cb();
+        });
+        package = jasmine.createSpy('config.packageName');
+        name = jasmine.createSpy('config.name');
+        parser = spyOn(util, 'config_parser').andReturn({
+            packageName:package,
+            name:name
+        });
+    });
+
+    describe('failure', function() {
+        it('should return a help message if incorrect number of parameters is used', function() {
+            expect(cordova.create()).toMatch(/synopsis/gi);
+        });
+    });
+
+    describe('success', function() {
+        it('should create a default project if only directory is specified', function(done) {
+            cordova.create(tempDir, function() {
+                expect(mkdir).toHaveBeenCalledWith('-p', path.join(tempDir, '.cordova'));
+                expect(package).toHaveBeenCalledWith('io.cordova.hellocordova');
+                expect(name).toHaveBeenCalledWith('HelloCordova');
+                done();
+            });
+        });
+        it('should create a default project if only directory and id is specified', function(done) {
+            cordova.create(tempDir, 'ca.filmaj.canucks', function() {
+                expect(mkdir).toHaveBeenCalledWith('-p', path.join(tempDir, '.cordova'));
+                expect(package).toHaveBeenCalledWith('ca.filmaj.canucks');
+                expect(name).toHaveBeenCalledWith('HelloCordova');
+                done();
+            });
+        });
+        it('should create a project in specified directory with specified name and id', function(done) {
+            cordova.create(tempDir, 'ca.filmaj.canucks', 'IHateTheBruins', function() {
+                expect(mkdir).toHaveBeenCalledWith('-p', path.join(tempDir, '.cordova'));
+                expect(package).toHaveBeenCalledWith('ca.filmaj.canucks');
+                expect(name).toHaveBeenCalledWith('IHateTheBruins');
+                done();
+            });
+        });
+        it('should create top-level directory structure appropriate for a cordova-cli project', function(done) {
+            cordova.create(tempDir, function() {
+                expect(mkdir).toHaveBeenCalledWith('-p', path.join(tempDir, 'platforms'));
+                expect(mkdir).toHaveBeenCalledWith('-p', path.join(tempDir, 'merges'));
+                expect(mkdir).toHaveBeenCalledWith('-p', path.join(tempDir, 'plugins'));
+                expect(mkdir).toHaveBeenCalledWith('-p', path.join(tempDir, 'www'));
+                done();
+            });
+        });
+        it('should create appropriate directories for hooks', function(done) {
+            var hooks_dir = path.join(tempDir, '.cordova', 'hooks');
+            cordova.create(tempDir, function() {
+                expect(mkdir).toHaveBeenCalledWith('-p', hooks_dir);
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'after_build')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'after_compile')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'after_docs')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'after_emulate')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'after_platform_add')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'after_platform_rm')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'after_platform_ls')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'after_plugin_add')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'after_plugin_ls')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'after_plugin_rm')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'after_prepare')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'after_run')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'before_build')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'before_compile')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'before_docs')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'before_emulate')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'before_platform_add')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'before_platform_rm')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'before_platform_ls')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'before_plugin_add')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'before_plugin_ls')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'before_plugin_rm')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'before_prepare')));
+                expect(mkdir).toHaveBeenCalledWith( (path.join(hooks_dir, 'before_run')));
+                done();
+            });
+        });
+        it('should by default use cordova-app-hello-world as www assets', function(done) {
+            cordova.create(tempDir, function() {
+                expect(load_cordova).toHaveBeenCalledWith('www', jasmine.any(Function));
+                done();
+            });
+        });
+        it('should try to lazy load custom www location if specified', function(done) {
+            var fake_config = {
+                lib:{
+                    www:{
+                        id:'supercordova',
+                        uri:'/supacordoba',
+                        version:'1337'
+                    }
+                }
+            };
+            config_read.andReturn(fake_config);
+            cordova.create(tempDir, function() {
+                expect(load_custom).toHaveBeenCalledWith(fake_config.lib.www.uri, fake_config.lib.www.id, 'www', fake_config.lib.www.version, jasmine.any(Function));
+                done();
+            });
+        });
+    });
+});

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/9828b9c1/spec/emulate.spec.js
----------------------------------------------------------------------
diff --git a/spec/emulate.spec.js b/spec/emulate.spec.js
new file mode 100644
index 0000000..4f8e14b
--- /dev/null
+++ b/spec/emulate.spec.js
@@ -0,0 +1,125 @@
+/**
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+*/
+var cordova = require('../../cordova'),
+    et = require('elementtree'),
+    shell = require('shelljs'),
+    path = require('path'),
+    fs = require('fs'),
+    hooker = require('../../src/hooker'),
+    tempDir = path.join(__dirname, '..', '..', 'temp');
+
+var cwd = process.cwd();
+
+describe('emulate command', function() {
+    beforeEach(function() {
+        shell.rm('-rf', tempDir);
+        cordova.create(tempDir);
+    });
+
+    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);
+            expect(function() {
+                cordova.emulate();
+            }).toThrow();
+        });
+        it('should not run outside of a Cordova-based project', function() {
+            shell.mkdir('-p', tempDir);
+            process.chdir(tempDir);
+
+            expect(function() {
+                cordova.emulate();
+            }).toThrow();
+        });
+    });
+
+    describe('success', function() {
+        beforeEach(function() {
+            process.chdir(tempDir);
+            spyOn(cordova, 'prepare').andCallFake(function(ps, cb) {
+                cb();
+            });
+        });
+        afterEach(function() {
+            process.chdir(cwd);
+        });
+        it('should run inside a Cordova-based project with at least one added platform', function(done) {
+            var s = spyOn(shell, 'exec').andCallFake(function(cmd, opts, cb) {
+                cb(0, 'yokay');
+            });
+            cordova.emulate(['android', 'beer'], function(err) {
+                expect(s).toHaveBeenCalled();
+                expect(s.mostRecentCall.args[0]).toMatch(/cordova.run" --emulator$/gi);
+                done();
+            });
+        });
+    });
+
+    describe('hooks', function() {
+        var hook_spy;
+        var shell_spy;
+        var prepare_spy;
+        beforeEach(function() {
+            hook_spy = spyOn(hooker.prototype, 'fire').andCallFake(function(hook, opts, cb) {
+                if (cb) cb();
+                else opts();
+            });
+            prepare_spy = spyOn(cordova, 'prepare').andCallFake(function(ps, 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
+            });
+            process.chdir(tempDir);
+        });
+        afterEach(function() {
+            hook_spy.reset();
+            prepare_spy.reset();
+            shell_spy.reset();
+            process.chdir(cwd);
+        });
+
+        describe('when platforms are added', function() {
+            it('should fire before hooks through the hooker module', function(done) {
+                cordova.emulate(['android', 'ios'], function(err) {
+                    expect(hook_spy).toHaveBeenCalledWith('before_emulate', {platforms:['android', 'ios']}, jasmine.any(Function));
+                    done();
+                });
+            });
+            it('should fire after hooks through the hooker module', function(done) {
+                cordova.emulate('android', function() {
+                     expect(hook_spy).toHaveBeenCalledWith('after_emulate', {platforms:['android']}, jasmine.any(Function));
+                     done();
+                });
+            });
+        });
+
+        describe('with no platforms added', function() {
+            it('should not fire the hooker', function() {
+                expect(function() {
+                    cordova.emulate();
+                }).toThrow();
+                expect(hook_spy).not.toHaveBeenCalled();
+            });
+        });
+    });
+});

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/9828b9c1/spec/helper.js
----------------------------------------------------------------------
diff --git a/spec/helper.js b/spec/helper.js
new file mode 100644
index 0000000..351e6e4
--- /dev/null
+++ b/spec/helper.js
@@ -0,0 +1,19 @@
+/**
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+*/
+jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/9828b9c1/spec/hooker.spec.js
----------------------------------------------------------------------
diff --git a/spec/hooker.spec.js b/spec/hooker.spec.js
new file mode 100644
index 0000000..6b0129a
--- /dev/null
+++ b/spec/hooker.spec.js
@@ -0,0 +1,202 @@
+ /**
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+*/
+var hooker = require('../../src/hooker'),
+    shell  = require('shelljs'),
+    path   = require('path'),
+    fs     = require('fs'),
+    os     = require('os'),
+    tempDir= path.join(__dirname, '..', '..', 'temp'),
+    hooks  = path.join(__dirname, '..', 'fixtures', 'hooks'),
+    cordova= require('../../cordova');
+
+var platform = os.platform();
+var cwd = process.cwd();
+
+describe('hooker', function() {
+    it('should throw if provided directory is not a cordova project', function() {
+        shell.rm('-rf', tempDir);
+        shell.mkdir('-p', tempDir); 
+        this.after(function() {
+            shell.rm('-rf', tempDir);
+        });
+
+        expect(function() {
+            var h = new hooker(tempDir);
+        }).toThrow();
+    });
+    it('should not throw if provided directory is a cordova project', function() {
+        cordova.create(tempDir);
+        this.after(function() {
+            shell.rm('-rf', tempDir);
+        });
+
+        expect(function() {
+            var h = new hooker(tempDir);
+        }).not.toThrow();
+    });
+
+    describe('fire method', function() {
+        var h;
+
+        beforeEach(function() {
+            cordova.create(tempDir);
+            h = new hooker(tempDir);
+        });
+        afterEach(function() {
+            shell.rm('-rf', tempDir);
+        });
+
+        describe('failure', function() {
+            it('should not error if the hook is unrecognized', function(done) {
+                h.fire('CLEAN YOUR SHORTS GODDAMNIT LIKE A BIG BOY!', function(err){
+                    expect(err).not.toBeDefined();
+                    done();
+                });
+            });
+            it('should error if any script exits with non-zero code', function(done) {
+                var script;
+                if (platform.match(/(win32|win64)/)) {
+                    script = path.join(tempDir, '.cordova', 'hooks', 'before_build', 'fail.bat');
+                    shell.cp(path.join(hooks, 'fail', 'fail.bat'), script);
+                } else {
+                    script = path.join(tempDir, '.cordova', 'hooks', 'before_build', 'fail.sh');
+                    shell.cp(path.join(hooks, 'fail', 'fail.sh'), script);
+                }
+                fs.chmodSync(script, '754');
+                h.fire('before_build', function(err){
+                    expect(err).toBeDefined();
+                    done();
+                });
+            });
+        });
+
+        describe('success', function() {
+            it('should execute all scripts in order and fire callback', function(done) {
+                var hook = path.join(tempDir, '.cordova', 'hooks', 'before_build');
+                if (platform.match(/(win32|win64)/)) {
+                    shell.cp(path.join(hooks, 'test', '0.bat'), hook);
+                    shell.cp(path.join(hooks, 'test', '1.bat'), hook);
+                } else {
+                    shell.cp(path.join(hooks, 'test', '0.sh'), hook);
+                    shell.cp(path.join(hooks, 'test', '1.sh'), hook);
+                }
+                fs.readdirSync(hook).forEach(function(script) {
+                    fs.chmodSync(path.join(hook, script), '754');
+                });
+                var returnValue;
+                var s = spyOn(shell, 'exec').andCallFake(function(cmd, opts, cb) {
+                    cb(0, '');
+                });
+                h.fire('before_build', function(err) {
+                    expect(err).not.toBeDefined();
+                    if (platform.match(/(win32|win64)/)) {
+                        expect(s.calls[0].args[0]).toMatch(/0.bat/);
+                        expect(s.calls[1].args[0]).toMatch(/1.bat/);
+                    } else {
+                        expect(s.calls[0].args[0]).toMatch(/0.sh/);
+                        expect(s.calls[1].args[0]).toMatch(/1.sh/);
+                    }
+                    done();
+                });
+            });
+            it('should pass the project root folder as parameter into the project-level hooks', function(done) {
+                var hook = path.join(tempDir, '.cordova', 'hooks', 'before_build');
+                if (platform.match(/(win32|win64)/)) {
+                    shell.cp(path.join(hooks, 'test', '0.bat'), hook);
+                } else {
+                    shell.cp(path.join(hooks, 'test', '0.sh'), hook);
+                }
+                fs.readdirSync(hook).forEach(function(script) {
+                    fs.chmodSync(path.join(hook, script), '754');
+                });
+                var s = spyOn(shell, 'exec').andCallFake(function(cmd, opts, cb) {
+                    cb(0, '');
+                });
+                h.fire('before_build', function(err) {
+                    expect(err).not.toBeDefined();
+                    var param_str;
+                    if (platform.match(/(win32|win64)/)) {
+                        param_str = '0.bat "'+tempDir+'"';
+                    } else { 
+                        param_str = '0.sh "'+tempDir+'"'; 
+                    }
+                    expect(s.calls[0].args[0].indexOf(param_str)).not.toEqual(-1);
+                    done();
+                });
+            });
+            describe('module-level hooks', function() {
+                var handler = jasmine.createSpy();
+                var test_event = 'before_build';
+                afterEach(function() {
+                    cordova.off(test_event, handler);
+                    handler.reset();
+                });
+
+                it('should fire handlers using cordova.on', function(done) {
+                    cordova.on(test_event, handler);
+                    h.fire(test_event, function(err) {
+                        expect(handler).toHaveBeenCalled();
+                        expect(err).not.toBeDefined();
+                        done();
+                    });
+                });
+                it('should pass the project root folder as parameter into the module-level handlers', function(done) {
+                    cordova.on(test_event, handler);
+                    h.fire(test_event, function(err) {
+                        expect(handler).toHaveBeenCalledWith({root:tempDir});
+                        expect(err).not.toBeDefined();
+                        done();
+                    });
+                });
+                it('should be able to stop listening to events using cordova.off', function(done) {
+                    cordova.on(test_event, handler);
+                    cordova.off(test_event, handler);
+                    h.fire(test_event, function(err) {
+                        expect(handler).not.toHaveBeenCalled();
+                        done();
+                    });
+                });
+                it('should allow for hook to opt into asynchronous execution and block further hooks from firing using the done callback', function(done) {
+                    var h1_fired = false;
+                    var h1 = function(root, cb) {
+                        h1_fired = true;
+                        setTimeout(cb, 100);
+                    };
+                    var h2_fired = false;
+                    var h2 = function() {
+                        h2_fired = true;
+                    };
+                    runs(function() {
+                        cordova.on(test_event, h1);
+                        cordova.on(test_event, h2);
+                        h.fire(test_event, function(err) {
+                            done();
+                        });
+                        expect(h1_fired).toBe(true);
+                        expect(h2_fired).toBe(false);
+                    });
+                    waits(100);
+                    runs(function() {
+                        expect(h2_fired).toBe(true);
+                    });
+                });
+            });
+        });
+    });
+});

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/9828b9c1/spec/platform.spec.js
----------------------------------------------------------------------
diff --git a/spec/platform.spec.js b/spec/platform.spec.js
new file mode 100644
index 0000000..fed1f3b
--- /dev/null
+++ b/spec/platform.spec.js
@@ -0,0 +1,284 @@
+/**
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+*/
+var cordova = require('../../cordova'),
+    path = require('path'),
+    shell = require('shelljs'),
+    fs = require('fs'),
+    util = require('../../src/util'),
+    hooker = require('../../src/hooker'),
+    platform = require('../../src/platform'),
+    platforms = require('../../platforms'),
+    tempDir = path.join(__dirname, '..', '..', 'temp');
+    android_parser = require('../../src/metadata/android_parser');
+
+var cwd = process.cwd();
+
+describe('platform command', function() {
+    beforeEach(function() {
+        // Make a temp directory
+        shell.rm('-rf', tempDir);
+        shell.mkdir('-p', tempDir);
+    });
+    it('should run inside a Cordova-based project', function() {
+        this.after(function() {
+            process.chdir(cwd);
+        });
+
+        cordova.create(tempDir);
+
+        process.chdir(tempDir);
+
+        expect(function() {
+            cordova.platform();
+        }).not.toThrow();
+    });
+    it('should not run outside of a Cordova-based project', function() {
+        this.after(function() {
+            process.chdir(cwd);
+        });
+
+        process.chdir(tempDir);
+
+        expect(function() {
+            cordova.platform();
+        }).toThrow();
+    });
+
+    describe('`ls`', function() { 
+        beforeEach(function() {
+            cordova.create(tempDir);
+            process.chdir(tempDir);
+        });
+
+        afterEach(function() {
+            process.chdir(cwd);
+            cordova.removeAllListeners('results'); // clean up event listener
+        });
+
+        it('should list out no platforms for a fresh project', function(done) {
+            shell.rm('-rf', path.join(tempDir, 'platforms', '*'));
+            cordova.on('results', function(res) {
+                expect(res).toEqual('No platforms added. Use `cordova platform add <platform>`.');
+                done();
+            });
+            cordova.platform('list');
+        });
+
+        it('should list out added platforms in a project', function(done) {
+            var platforms = path.join(tempDir, 'platforms');
+            shell.mkdir(path.join(platforms, 'android'));
+            shell.mkdir(path.join(platforms, 'ios'));
+            
+            cordova.on('results', function(res) {
+                expect(res.length).toEqual(2);
+                done();
+            });
+            cordova.platform('list');
+        });
+    });
+
+    describe('`add`', function() {
+        beforeEach(function() {
+            cordova.create(tempDir);
+            process.chdir(tempDir);
+        });
+
+        afterEach(function() {
+            process.chdir(cwd);
+        });
+
+        it('should handle multiple platforms and shell out to specified platform\'s bin/create', function() {
+            spyOn(platform, 'supports').andCallFake(function(target, callback) {
+                    callback(null);
+            });
+            var sh = spyOn(shell, 'exec');
+            cordova.platform('add', ['foo', 'bar']);
+            var foo_create = path.join('foo', 'bin', 'create');
+            var bar_create = path.join('bar', 'bin', 'create');
+            expect(sh.argsForCall[0][0]).toContain(foo_create);
+            expect(sh.argsForCall[1][0]).toContain(bar_create);
+        });
+    });
+
+    describe('`remove`',function() {
+        beforeEach(function() {
+            cordova.create(tempDir);
+            process.chdir(tempDir);
+        });
+
+        afterEach(function() {
+            process.chdir(cwd);
+            cordova.removeAllListeners('results');
+        });
+
+        it('should remove a supported and added platform', function(done) {
+            shell.mkdir(path.join(tempDir, 'platforms', 'android'));
+            shell.mkdir(path.join(tempDir, 'platforms', 'ios'));
+            cordova.platform('remove', 'android', function() {
+                cordova.on('results', function(res) {
+                    expect(res.length).toEqual(1);
+                    done();
+                });
+                cordova.platform('list');
+            });
+        });
+
+        it('should be able to remove multiple platforms', function(done) {
+            shell.mkdir(path.join(tempDir, 'platforms', 'android'));
+            shell.mkdir(path.join(tempDir, 'platforms', 'blackberry'));
+            shell.mkdir(path.join(tempDir, 'platforms', 'ios'));
+            cordova.platform('remove', ['android','blackberry'], function() {
+                cordova.on('results', function(res) {
+                    expect(res.length).toEqual(1);
+                    done();
+                });
+                cordova.platform('list');
+            });
+        });
+    });
+
+    describe('hooks', function() {
+        var s;
+        beforeEach(function() {
+            cordova.create(tempDir);
+            process.chdir(tempDir);
+            s = spyOn(hooker.prototype, 'fire').andCallFake(function(hook, opts, cb) {
+                if (cb) cb();
+                else opts();
+            });
+        });
+        afterEach(function() {
+            process.chdir(cwd);
+            shell.rm('-rf', tempDir);
+        });
+
+        describe('list (ls) hooks', function() {
+            it('should fire before hooks through the hooker module', function() {
+                cordova.platform();
+                expect(s).toHaveBeenCalledWith('before_platform_ls', jasmine.any(Function));
+            });
+            it('should fire after hooks through the hooker module', function() {
+                cordova.platform();
+                expect(s).toHaveBeenCalledWith('after_platform_ls', jasmine.any(Function));
+            });
+        });
+        describe('remove (rm) hooks', function() {
+            it('should fire before hooks through the hooker module', function() {
+                cordova.platform('rm', 'android');
+                expect(s).toHaveBeenCalledWith('before_platform_rm', {platforms:['android']}, jasmine.any(Function));
+            });
+            it('should fire after hooks through the hooker module', function() {
+                cordova.platform('rm', 'android');
+                expect(s).toHaveBeenCalledWith('after_platform_rm', {platforms:['android']}, jasmine.any(Function));
+            });
+        });
+        describe('add hooks', function() {
+            var sh, cr;
+            beforeEach(function() {
+                sh = spyOn(shell, 'exec').andCallFake(function(cmd, opts, cb) {
+                    var a_path = path.join(tempDir, 'platforms','android'); 
+                    shell.mkdir('-p',a_path); 
+                    fs.writeFileSync(path.join(a_path, 'AndroidManifest.xml'), 'hi', 'utf-8');
+                    cb(0, 'mkay');
+                });
+                cr = spyOn(android_parser.prototype, 'update_project').andCallFake(function(cfg, cb) {
+                    cb();
+                });
+                spyOn(platform, 'supports').andCallFake(function (t, cb) {
+                    cb();
+                });
+            });
+            it('should fire before and after hooks through the hooker module', function() {
+                cordova.platform('add', 'android');
+                expect(s).toHaveBeenCalledWith('before_platform_add', {platforms:['android']}, jasmine.any(Function));
+                expect(s).toHaveBeenCalledWith('after_platform_add', {platforms:['android']}, jasmine.any(Function));
+            });
+        });
+    });
+});
+
+describe('platform.supports(name, callback)', function() {
+    var androidParser = require('../../src/metadata/android_parser');
+
+    beforeEach(function() {
+        spyOn(androidParser, 'check_requirements');
+    });
+
+    it('should require a platform name', function() {
+        expect(function() {
+            cordova.platform.supports(undefined, function(e){});
+        }).toThrow();
+    });
+
+    it('should require a callback function', function() {
+        expect(function() {
+            cordova.platform.supports('android', undefined);
+        }).toThrow();
+    });
+
+    describe('when platform is unknown', function() {
+        it('should trigger callback with false', function(done) {
+            cordova.platform.supports('windows-3.1', function(e) {
+                expect(e).toEqual(jasmine.any(Error));
+                done();
+            });
+        });
+    });
+
+    describe('when platform is supported', function() {
+        beforeEach(function() {
+            androidParser.check_requirements.andCallFake(function(callback) {
+                callback(null);
+            });
+        });
+
+        it('should trigger callback without error', function(done) {
+            cordova.platform.supports('android', function(e) {
+                expect(e).toBeNull();
+                done();
+            });
+        });
+    });
+
+    describe('when platform is unsupported', function() {
+        beforeEach(function() {
+            androidParser.check_requirements.andCallFake(function(callback) {
+                callback(new Error('could not find the android sdk'));
+            });
+        });
+
+        it('should trigger callback with error', function(done) {
+            cordova.platform.supports('android', function(e) {
+                expect(e).toEqual(jasmine.any(Error));
+                done();
+            });
+        });
+    });
+});
+
+describe('platform parsers', function() {
+    it('should be exposed on the platform module', function() {
+        for (var platform in platforms) {
+            expect(cordova.platform[platform]).toBeDefined();
+            for (var prop in platforms[platform]) {
+                expect(cordova.platform[platform][prop]).toBeDefined();
+            }
+        }
+    });
+});

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/9828b9c1/spec/plugin.spec.js
----------------------------------------------------------------------
diff --git a/spec/plugin.spec.js b/spec/plugin.spec.js
new file mode 100644
index 0000000..d042841
--- /dev/null
+++ b/spec/plugin.spec.js
@@ -0,0 +1,146 @@
+/**
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+*/
+var cordova = require('../../cordova'),
+    path = require('path'),
+    shell = require('shelljs'),
+    fs = require('fs'),
+    hooker = require('../../src/hooker'),
+    tempDir = path.join(__dirname, '..', '..', 'temp'),
+    fixturesDir = path.join(__dirname, '..', 'fixtures'),
+    testPlugin = path.join(fixturesDir, 'plugins', 'test'),
+    cordova_project = path.join(fixturesDir, 'projects', 'cordova'),
+    androidPlugin = path.join(fixturesDir, 'plugins', 'android');
+
+var cwd = process.cwd();
+
+describe('plugin command', function() {
+    beforeEach(function() {
+        // Make a temp directory
+        shell.rm('-rf', tempDir);
+        shell.mkdir('-p', tempDir);
+    });
+
+    it('should run inside a Cordova-based project', function() {
+        this.after(function() {
+            process.chdir(cwd);
+        });
+
+        cordova.create(tempDir);
+
+        process.chdir(tempDir);
+
+        expect(function() {
+            cordova.plugin();
+        }).not.toThrow();
+    });
+    it('should not run outside of a Cordova-based project', function() {
+        this.after(function() {
+            process.chdir(cwd);
+        });
+
+        process.chdir(tempDir);
+
+        expect(function() {
+            cordova.plugin();
+        }).toThrow();
+    });
+
+    describe('edge cases', function() {
+       beforeEach(function() {
+           cordova.create(tempDir);
+           process.chdir(tempDir);
+       });
+
+       afterEach(function() {
+           process.chdir(cwd);
+           cordova.removeAllListeners('results');
+       });
+
+       it('should not fail when the plugins directory is missing', function() {
+           fs.rmdirSync('plugins');
+
+           expect(function() {
+               cordova.plugin();
+           }).not.toThrow();
+       });
+
+       it('should ignore files, like .gitignore, in the plugins directory', function(done) {
+           var someFile = path.join(tempDir, 'plugins', '.gitignore');
+           fs.writeFileSync(someFile, 'not a plugin');
+           cordova.on('results', function(res) {
+               expect(res).toEqual('No plugins added. Use `cordova plugin add <plugin>`.');
+               done();
+           });
+
+           cordova.plugin('list');
+       });
+    });
+
+    describe('`ls`', function() {
+        beforeEach(function() {
+            cordova.create(tempDir);
+            process.chdir(tempDir);
+        });
+
+        afterEach(function() {
+            process.chdir(cwd);
+            cordova.removeAllListeners('results');
+        });
+
+        it('should list out no plugins for a fresh project', function(done) {
+            cordova.on('results', function(res) {
+                expect(res).toEqual('No plugins added. Use `cordova plugin add <plugin>`.');
+                done();
+            });
+            cordova.plugin('list');
+        });
+        it('should list out any added plugins in a project', function(done) {
+            var random_plug = 'randomplug';
+            shell.mkdir('-p', path.join(tempDir, 'plugins', random_plug));
+            cordova.on('results', function(res) {
+                expect(res).toEqual([random_plug]);
+                done();
+            });
+            cordova.plugin('list');
+        });
+    });
+
+    describe('`add`', function() {
+        beforeEach(function() {
+            cordova.create(tempDir);
+            process.chdir(tempDir);
+        });
+
+        afterEach(function() {
+            process.chdir(cwd);
+        });
+        describe('failure', function() {
+            it('should throw if plugin does not have a plugin.xml', function() {
+                process.chdir(cordova_project);
+                this.after(function() {
+                    process.chdir(cwd);
+                });
+                expect(function() {
+                    cordova.plugin('add', fixturesDir);
+                }).toThrow();
+            });
+        });
+    });
+});
+

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/9828b9c1/spec/plugin_parser.spec.js
----------------------------------------------------------------------
diff --git a/spec/plugin_parser.spec.js b/spec/plugin_parser.spec.js
new file mode 100644
index 0000000..15b5993
--- /dev/null
+++ b/spec/plugin_parser.spec.js
@@ -0,0 +1,42 @@
+
+/**
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+*/
+var cordova = require('../../cordova'),
+    path = require('path'),
+    fs = require('fs'),
+    plugin_parser = require('../../src/plugin_parser'),
+    et = require('elementtree'),
+    xml = path.join(__dirname, '..', 'fixtures', 'plugins', 'test', 'plugin.xml');
+
+describe('plugin.xml parser', function () {
+    it('should read a proper plugin.xml file', function() {
+        var cfg;
+        expect(function () {
+            cfg = new plugin_parser(xml);
+        }).not.toThrow();
+        expect(cfg).toBeDefined();
+        expect(cfg.doc).toBeDefined();
+    });
+    it('should be able to figure out which platforms the plugin supports', function() {
+        var cfg = new plugin_parser(xml);
+        expect(cfg.platforms.length).toBe(1);
+        expect(cfg.platforms.indexOf('ios') > -1).toBe(true);
+    });
+});
+

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/9828b9c1/spec/prepare.spec.js
----------------------------------------------------------------------
diff --git a/spec/prepare.spec.js b/spec/prepare.spec.js
new file mode 100644
index 0000000..d7c7d28
--- /dev/null
+++ b/spec/prepare.spec.js
@@ -0,0 +1,153 @@
+/**
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+*/
+var cordova = require('../../cordova'),
+    et = require('elementtree'),
+    shell = require('shelljs'),
+    plugman = require('plugman'),
+    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'),
+    test_plugin = path.join(fixtures, 'plugins', 'android'),
+    hooks = path.join(fixtures, 'hooks'),
+    tempDir = path.join(__dirname, '..', '..', 'temp'),
+    cordova_project = path.join(fixtures, 'projects', 'cordova');
+
+var cwd = process.cwd();
+
+describe('prepare command', function() {
+    beforeEach(function() {
+        shell.rm('-rf', tempDir);
+        cordova.create(tempDir);
+    });
+
+    it('should not run inside a Cordova-based project with no added platforms', function() {
+        this.after(function() {
+            process.chdir(cwd);
+        });
+
+        process.chdir(tempDir);
+        expect(function() {
+            cordova.prepare();
+        }).toThrow();
+    });
+    
+    it('should run inside a Cordova-based project with at least one added platform', function(done) {
+        process.chdir(tempDir);
+        var android_path = path.join(tempDir, 'platforms', 'android');
+        shell.mkdir(android_path);
+        fs.writeFileSync(path.join(android_path, 'AndroidManifest.xml'), 'hi', 'utf-8');
+        spyOn(plugman, 'prepare');
+        cordova.prepare(['android'], function(err) {
+            done();
+        });
+    });
+    it('should not run outside of a Cordova-based project', function() {
+        this.after(function() {
+            process.chdir(cwd);
+        });
+
+        shell.mkdir('-p', tempDir);
+        process.chdir(tempDir);
+
+        expect(function() {
+            cordova.prepare();
+        }).toThrow();
+    });
+
+    describe('plugman integration', 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 plugman.prepare after update_project', function() {
+            var a_parser_spy = spyOn(android_parser.prototype, 'update_project');
+            var prep_spy = spyOn(plugman, 'prepare');
+            cordova.prepare();
+            a_parser_spy.mostRecentCall.args[1](); // fake out android_parser
+            var android_path = path.join(tempDir, 'platforms', 'android');
+            var plugins_dir = path.join(tempDir, 'plugins');
+            expect(prep_spy).toHaveBeenCalledWith(android_path, 'android', plugins_dir);
+        });
+        it('should invoke add_plugin_changes for any added plugins to verify configuration changes for plugins are in place', function() {
+            var platform_path  = path.join(tempDir, 'platforms', 'android');
+            var plugins_dir = path.join(tempDir, 'plugins');
+            plugman.install('android', platform_path, test_plugin, plugins_dir, {});
+            var a_parser_spy = spyOn(android_parser.prototype, 'update_project');
+            var prep_spy = spyOn(plugman, 'prepare');
+            var plugin_changes_spy = spyOn(plugman.config_changes, 'add_plugin_changes');
+            cordova.prepare();
+            a_parser_spy.mostRecentCall.args[1](); // fake out android_parser
+            expect(plugin_changes_spy).toHaveBeenCalledWith('android', platform_path, plugins_dir, 'ca.filmaj.AndroidPlugin', {PACKAGE_NAME:"org.apache.cordova.cordovaExample"}, true, false); 
+        });
+    });
+
+    describe('hooks', function() {
+        var s;
+        beforeEach(function() {
+            s = spyOn(hooker.prototype, 'fire').andReturn(true);
+        });
+
+        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() {
+                shell.rm('-rf', path.join(tempDir, 'platforms', 'android'));
+                process.chdir(cwd);
+            });
+
+            it('should fire before hooks through the hooker module', function() {
+                cordova.prepare();
+                expect(s).toHaveBeenCalledWith('before_prepare', jasmine.any(Function));
+            });
+            it('should fire after hooks through the hooker module', function() {
+                spyOn(shell, 'exec');
+                cordova.prepare('android', function() {
+                     expect(hooker.prototype.fire).toHaveBeenCalledWith('after_prepare');
+                });
+            });
+        });
+
+        describe('with no platforms added', function() {
+            beforeEach(function() {
+                shell.rm('-rf', tempDir);
+                cordova.create(tempDir);
+                process.chdir(tempDir);
+            });
+            afterEach(function() {
+                process.chdir(cwd);
+            });
+            it('should not fire the hooker', function() {
+                expect(function() {
+                    cordova.prepare();
+                }).toThrow();
+                expect(s).not.toHaveBeenCalledWith('before_prepare');
+                expect(s).not.toHaveBeenCalledWith('after_prepare');
+            });
+        });
+    });
+});

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/9828b9c1/spec/run.spec.js
----------------------------------------------------------------------
diff --git a/spec/run.spec.js b/spec/run.spec.js
new file mode 100644
index 0000000..7e505ef
--- /dev/null
+++ b/spec/run.spec.js
@@ -0,0 +1,141 @@
+/**
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+*/
+var cordova = require('../../cordova'),
+    et = require('elementtree'),
+    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');
+
+var cwd = process.cwd();
+
+describe('run command', function() {
+    beforeEach(function() {
+        shell.rm('-rf', tempDir);
+        cordova.create(tempDir);
+    });
+
+    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);
+            expect(function() {
+                cordova.run();
+            }).toThrow();
+        });
+        it('should not run outside of a Cordova-based project', function() {
+            shell.mkdir('-p', tempDir);
+            process.chdir(tempDir);
+
+            expect(function() {
+                cordova.run();
+            }).toThrow();
+        });
+    });
+    
+    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');
+            });
+            cordova.run('android', function() {
+                 expect(spy.mostRecentCall.args[0]).toMatch(/cordova.run" --device$/gi);
+                 done();
+            });
+        });
+    });
+
+
+    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));
+            });
+            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));
+                     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');
+                expect(function() {
+                    cordova.run();
+                }).toThrow();
+                expect(s).not.toHaveBeenCalledWith('before_run');
+                expect(s).not.toHaveBeenCalledWith('after_run');
+            });
+        });
+    });
+});

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/9828b9c1/spec/serve.spec.js
----------------------------------------------------------------------
diff --git a/spec/serve.spec.js b/spec/serve.spec.js
new file mode 100644
index 0000000..0139da8
--- /dev/null
+++ b/spec/serve.spec.js
@@ -0,0 +1,134 @@
+
+/**
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+*/
+var cordova = require('../../cordova'),
+    path = require('path'),
+    shell = require('shelljs'),
+    request = require('request'),
+    fs = require('fs'),
+    util = require('../../src/util'),
+    hooker = require('../../src/hooker'),
+    tempDir = path.join(__dirname, '..', '..', 'temp'),
+    http = require('http'),
+    android_parser = require('../../src/metadata/android_parser'),
+    ios_parser = require('../../src/metadata/ios_parser'),
+    blackberry_parser = require('../../src/metadata/blackberry_parser'),
+    wp7_parser        = require('../../src/metadata/wp7_parser'),
+    wp8_parser        = require('../../src/metadata/wp8_parser');
+
+var cwd = process.cwd();
+
+xdescribe('serve command', function() {
+    beforeEach(function() {
+        // Make a temp directory
+        shell.rm('-rf', tempDir);
+        shell.mkdir('-p', tempDir);
+    });
+    it('should not run outside of a Cordova-based project', function() {
+        this.after(function() {
+            process.chdir(cwd);
+        });
+
+        process.chdir(tempDir);
+
+        expect(function() {
+            cordova.serve('android');
+        }).toThrow();
+    });
+
+
+    describe('`serve`', function() {
+        var payloads = {
+            android: 'This is the Android test file.',
+            ios: 'This is the iOS test file.'
+        };
+
+        beforeEach(function() {
+            cordova.create(tempDir);
+            process.chdir(tempDir);
+            cordova.platform('add', 'android');
+            cordova.platform('add', 'ios');
+
+            // Write testing HTML files into the directory.
+            fs.writeFileSync(path.join(tempDir, 'platforms', 'android', 'assets', 'www', 'test.html'), payloads.android);
+            fs.writeFileSync(path.join(tempDir, 'platforms', 'ios', 'www', 'test.html'), payloads.ios);
+        });
+
+        afterEach(function() {
+            process.chdir(cwd);
+        });
+
+        function test_serve(platform, path, expectedContents, port) {
+            return function() {
+                var ret;
+                runs(function() {
+                    ret = port ? cordova.serve(platform, port) : cordova.serve(platform);
+                });
+
+                waitsFor(function() {
+                    return ret.server;
+                }, 'the server should start', 1000);
+
+                var done, errorCB;
+                runs(function() {
+                    expect(ret.server).toBeDefined();
+                    errorCB = jasmine.createSpy();
+                    http.get({
+                        host: 'localhost',
+                        port: port || 8000,
+                        path: path
+                    }).on('response', function(res) {
+                        var response = '';
+                        res.on('data', function(data) {
+                            response += data;
+                        });
+                        res.on('end', function() {
+                            expect(res.statusCode).toEqual(200);
+                            expect(response).toEqual(expectedContents);
+                            done = true;
+                        });
+                    }).on('error', errorCB);
+                });
+
+                waitsFor(function() {
+                    return done;
+                }, 'the HTTP request should complete', 1000);
+
+                runs(function() {
+                    expect(done).toBeTruthy();
+                    expect(errorCB).not.toHaveBeenCalled();
+
+                    ret.server.close();
+                });
+            };
+        };
+
+        it('should serve from top-level www if the file exists there', function() {
+            var payload = 'This is test file.';
+            fs.writeFileSync(path.join(util.projectWww(tempDir), 'test.html'), payload);
+            test_serve('android', '/test.html', payload)();
+        });
+
+        it('should fall back to assets/www on Android', test_serve('android', '/test.html', payloads.android));
+        it('should fall back to www on iOS', test_serve('ios', '/test.html', payloads.ios));
+
+        it('should honour a custom port setting', test_serve('android', '/test.html', payloads.android, 9001));
+    });
+});
+

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/9828b9c1/spec/util.spec.js
----------------------------------------------------------------------
diff --git a/spec/util.spec.js b/spec/util.spec.js
new file mode 100644
index 0000000..a57d551
--- /dev/null
+++ b/spec/util.spec.js
@@ -0,0 +1,13 @@
+var cordova = require('../../cordova'),
+    shell = require('shelljs'),
+    path = require('path'),
+    fs = require('fs'),
+    cordova_util = require('../../src/util'),
+    fixtures = path.join(__dirname, '..', 'fixtures');
+
+var cwd = process.cwd();
+
+describe('util module', function() {
+    describe('isCordova method', function() {
+    });
+});

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/9828b9c1/src/config_parser.js
----------------------------------------------------------------------
diff --git a/src/config_parser.js b/src/config_parser.js
index 082b7f2..33a1c38 100644
--- a/src/config_parser.js
+++ b/src/config_parser.js
@@ -1,4 +1,3 @@
-
 /**
     Licensed to the Apache Software Foundation (ASF) under one
     or more contributor license agreements.  See the NOTICE file


Mime
View raw message