You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by mm...@apache.org on 2013/12/10 19:43:53 UTC
[1/3] git commit: CB-5330: Fix hooks test on windows, move to e2e.
Updated Branches:
refs/heads/master b365138c2 -> 8b764c3c9
CB-5330: Fix hooks test on windows, move to e2e.
Refactored the hooker.spec.js to use real files like the e2e tests.
Moved the spec and corresponding fixtures to live under e2e dir.
Rearranged the hooks fixtures into two separate dirs for Win and non-Win
platforms.
Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/8b764c3c
Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/8b764c3c
Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/8b764c3c
Branch: refs/heads/master
Commit: 8b764c3c993c8bf2813d0dfa7155b12507962660
Parents: c5ac48d
Author: Mark Koudritsky <ka...@chromium.org>
Authored: Mon Dec 9 16:53:40 2013 -0500
Committer: Michal Mocny <mm...@gmail.com>
Committed: Tue Dec 10 13:24:49 2013 -0500
----------------------------------------------------------------------
e2e/create.spec.js | 4 +-
e2e/fixtures/hooks_bat/fail/fail.bat | 2 +
e2e/fixtures/hooks_bat/test/.dotted.bat | 2 +
e2e/fixtures/hooks_bat/test/07.bat | 3 +
e2e/fixtures/hooks_bat/test/1.bat | 5 +
e2e/fixtures/hooks_sh/fail/fail.sh | 1 +
e2e/fixtures/hooks_sh/test/.dotted.sh | 1 +
e2e/fixtures/hooks_sh/test/07.sh | 2 +
e2e/fixtures/hooks_sh/test/1.sh | 4 +
e2e/helpers.js | 5 +-
e2e/hooker.spec.js | 433 +++++++++++++--------------
e2e/platform.spec.js | 2 +-
e2e/plugin.spec.js | 4 +-
spec/fixtures/hooks/fail/fail.bat | 2 -
spec/fixtures/hooks/fail/fail.sh | 1 -
spec/fixtures/hooks/test/07.bat | 2 -
spec/fixtures/hooks/test/07.sh | 1 -
spec/fixtures/hooks/test/1.bat | 2 -
spec/fixtures/hooks/test/1.sh | 1 -
src/hooker.js | 2 +-
20 files changed, 244 insertions(+), 235 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/8b764c3c/e2e/create.spec.js
----------------------------------------------------------------------
diff --git a/e2e/create.spec.js b/e2e/create.spec.js
index 3f1304c..560f82a 100644
--- a/e2e/create.spec.js
+++ b/e2e/create.spec.js
@@ -41,7 +41,7 @@ var crossConcat = function(a, b, delimiter){
return result;
};
-var tmpDir = helpers.tmpDir();
+var tmpDir = helpers.tmpDir('create_test');
var appName = 'TestCreate';
var appId = 'io.cordova.' + appName.toLocaleLowerCase();
var project = path.join(tmpDir, appName);
@@ -63,7 +63,7 @@ describe('create end-to-end', function() {
});
afterEach(function() {
process.chdir(path.join(__dirname, '..')); // Needed to rm the dir on Windows.
- shell.rm('-rf', project);
+ shell.rm('-rf', tmpDir);
});
var results;
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/8b764c3c/e2e/fixtures/hooks_bat/fail/fail.bat
----------------------------------------------------------------------
diff --git a/e2e/fixtures/hooks_bat/fail/fail.bat b/e2e/fixtures/hooks_bat/fail/fail.bat
new file mode 100644
index 0000000..0c810b7
--- /dev/null
+++ b/e2e/fixtures/hooks_bat/fail/fail.bat
@@ -0,0 +1,2 @@
+@ECHO OFF
+EXIT /B 1
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/8b764c3c/e2e/fixtures/hooks_bat/test/.dotted.bat
----------------------------------------------------------------------
diff --git a/e2e/fixtures/hooks_bat/test/.dotted.bat b/e2e/fixtures/hooks_bat/test/.dotted.bat
new file mode 100644
index 0000000..ada7136
--- /dev/null
+++ b/e2e/fixtures/hooks_bat/test/.dotted.bat
@@ -0,0 +1,2 @@
+@ECHO OFF
+ECHO "Dotted files in hook dirs should not be called" > dotted_hook_should_not_fire.txt
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/8b764c3c/e2e/fixtures/hooks_bat/test/07.bat
----------------------------------------------------------------------
diff --git a/e2e/fixtures/hooks_bat/test/07.bat b/e2e/fixtures/hooks_bat/test/07.bat
new file mode 100644
index 0000000..97caf28
--- /dev/null
+++ b/e2e/fixtures/hooks_bat/test/07.bat
@@ -0,0 +1,3 @@
+@ECHO OFF
+ECHO this is script 0 in %~dp0
+ECHO b >> hooks_order.txt
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/8b764c3c/e2e/fixtures/hooks_bat/test/1.bat
----------------------------------------------------------------------
diff --git a/e2e/fixtures/hooks_bat/test/1.bat b/e2e/fixtures/hooks_bat/test/1.bat
new file mode 100644
index 0000000..8d97402
--- /dev/null
+++ b/e2e/fixtures/hooks_bat/test/1.bat
@@ -0,0 +1,5 @@
+@ECHO OFF
+ECHO this is script 1 in %~dp0
+ECHO a >> hooks_order.txt
+ECHO %1 > hooks_params.txt
+node -e "console.log(JSON.stringify(process.env, null, 2))" > hooks_env.json
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/8b764c3c/e2e/fixtures/hooks_sh/fail/fail.sh
----------------------------------------------------------------------
diff --git a/e2e/fixtures/hooks_sh/fail/fail.sh b/e2e/fixtures/hooks_sh/fail/fail.sh
new file mode 100755
index 0000000..379a4c9
--- /dev/null
+++ b/e2e/fixtures/hooks_sh/fail/fail.sh
@@ -0,0 +1 @@
+exit 1
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/8b764c3c/e2e/fixtures/hooks_sh/test/.dotted.sh
----------------------------------------------------------------------
diff --git a/e2e/fixtures/hooks_sh/test/.dotted.sh b/e2e/fixtures/hooks_sh/test/.dotted.sh
new file mode 100755
index 0000000..e5fa07f
--- /dev/null
+++ b/e2e/fixtures/hooks_sh/test/.dotted.sh
@@ -0,0 +1 @@
+echo "Dotted files in hook dirs should not be called" > dotted_hook_should_not_fire.txt
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/8b764c3c/e2e/fixtures/hooks_sh/test/07.sh
----------------------------------------------------------------------
diff --git a/e2e/fixtures/hooks_sh/test/07.sh b/e2e/fixtures/hooks_sh/test/07.sh
new file mode 100755
index 0000000..172de1c
--- /dev/null
+++ b/e2e/fixtures/hooks_sh/test/07.sh
@@ -0,0 +1,2 @@
+echo "this is script 0 in `pwd`";
+echo b >> hooks_order.txt
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/8b764c3c/e2e/fixtures/hooks_sh/test/1.sh
----------------------------------------------------------------------
diff --git a/e2e/fixtures/hooks_sh/test/1.sh b/e2e/fixtures/hooks_sh/test/1.sh
new file mode 100755
index 0000000..82abb8b
--- /dev/null
+++ b/e2e/fixtures/hooks_sh/test/1.sh
@@ -0,0 +1,4 @@
+echo "this is script 1 in `pwd`";
+echo a >> hooks_order.txt
+echo $1 > hooks_params.txt
+node -e "console.log(JSON.stringify(process.env, null, 2))" > hooks_env.json
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/8b764c3c/e2e/helpers.js
----------------------------------------------------------------------
diff --git a/e2e/helpers.js b/e2e/helpers.js
index aa1c790..3236516 100644
--- a/e2e/helpers.js
+++ b/e2e/helpers.js
@@ -4,8 +4,11 @@ var path = require('path'),
shell = require('shelljs'),
os = require('os');
-module.exports.tmpDir = function() {
+module.exports.tmpDir = function(subdir) {
var dir = path.join(os.tmpdir(), 'e2e-test');
+ if (subdir) {
+ dir = path.join(dir, subdir);
+ }
shell.mkdir('-p', dir);
return dir;
};
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/8b764c3c/e2e/hooker.spec.js
----------------------------------------------------------------------
diff --git a/e2e/hooker.spec.js b/e2e/hooker.spec.js
index d4b073e..beffa49 100644
--- a/e2e/hooker.spec.js
+++ b/e2e/hooker.spec.js
@@ -17,248 +17,243 @@
under the License.
**/
-var hooker = require('../src/hooker'),
- util = require('../src/util'),
+
+var cordova = require('../cordova'),
+ hooker = require('../src/hooker'),
shell = require('shelljs'),
- child_process = require('child_process'),
path = require('path'),
fs = require('fs'),
os = require('os'),
Q = require('q'),
- tempDir= path.join(__dirname, '..', 'temp'),
- hooks = path.join(__dirname, 'fixtures', 'hooks'),
- cordova= require('../cordova');
+ child_process = require('child_process'),
+ helpers = require('./helpers');
var platform = os.platform();
-var cwd = process.cwd();
+var tmpDir = helpers.tmpDir('hooks_test');
+var project = path.join(tmpDir, 'project');
+var dotCordova = path.join(project, '.cordova');
+var hooksDir = path.join(project, '.cordova', 'hooks');
+var ext = platform.match(/(win32|win64)/)?'bat':'sh';
-// Note: because there are numerous issues with these tests on windows, the entire spec is skipped if we
-// are in win32 ~jm
-if(platform != "win32" ) {
+// copy fixture
+shell.rm('-rf', tmpDir);
+shell.mkdir('-p', dotCordova);
+shell.cp('-R', path.join(__dirname, 'fixtures', 'hooks_' + ext), dotCordova);
+shell.mv(path.join(dotCordova, 'hooks_' + ext), hooksDir);
+shell.chmod('-R', 'ug+x', hooksDir);
+
describe('hooker', function() {
it('should throw if provided directory is not a cordova project', function() {
- spyOn(util, 'isCordova').andReturn(false);
expect(function() {
- new hooker(tempDir);
+ new hooker(tmpDir);
}).toThrow('Not a Cordova project, can\'t use hooks.');
});
- it('should not throw if provided directory is a cordova project', function() {
- var root = '/some/root';
- spyOn(util, 'isCordova').andReturn(root);
- expect(function() {
- var h = new hooker(tempDir);
- expect(h.root).toEqual(root);
- }).not.toThrow();
- });
+});
- describe('global (static) fire method', function() {
- it('should execute listeners serially', function(done) {
- var timeout = 20;
- var test_event = 'foo';
- var h1_fired = false;
- var h1 = function() {
+describe('global (static) fire method', function() {
+ it('should execute listeners serially', function(done) {
+ var test_event = 'foo';
+ var h1_fired = false;
+ var h1 = function() {
+ expect(h2_fired).toBe(false);
+ // Delay 100 ms here to check that h2 is not executed until after
+ // the promise returned by h1 is resolved.
+ var q = Q.delay(100).then(function() {
h1_fired = true;
- expect(h2_fired).toBe(false);
- return Q();
- };
- var h2_fired = false;
- var h2 = function() {
- h2_fired = true;
- expect(h1_fired).toBe(true);
- return Q();
- };
-
- cordova.on(test_event, h1);
- cordova.on(test_event, h2);
- hooker.fire(test_event).then(function() {
- expect(h1_fired).toBe(true);
- expect(h2_fired).toBe(true);
- done();
});
+ return q;
+ };
+ var h2_fired = false;
+ var h2 = function() {
+ h2_fired = true;
+ expect(h1_fired).toBe(true);
+ return Q();
+ };
+
+ cordova.on(test_event, h1);
+ cordova.on(test_event, h2);
+ hooker.fire(test_event).then(function() {
+ expect(h1_fired).toBe(true);
+ expect(h2_fired).toBe(true);
+ done();
});
});
- describe('project-level fire method', function() {
- var h;
- beforeEach(function() {
- spyOn(util, 'isCordova').andReturn(tempDir);
- h = new hooker(tempDir);
- });
+});
- describe('failure', function() {
- it('should not error if the hook is unrecognized', function() {
- var p;
- runs(function() {
- p = h.fire('CLEAN YOUR SHORTS GODDAMNIT LIKE A BIG BOY!');
- });
- waitsFor(function() { return !p.isPending() }, 'promise not resolved', 500);
- runs(function() {
- expect(p.isFulfilled()).toBe(true);
- });
- });
- it('should error if any script exits with non-zero code', function(done) {
- var script = path.join(tempDir, '.cordova', 'hooks', 'before_build');
- shell.mkdir('-p', script);
- this.after(function() { shell.rm('-rf', tempDir); });
- if (platform.match(/(win32|win64)/)) {
- script = path.join(script, 'fail.bat');
- shell.cp(path.join(hooks, 'fail', 'fail.bat'), script);
- } else {
- script = path.join(script, 'fail.sh');
- shell.cp(path.join(hooks, 'fail', 'fail.sh'), script);
- }
- fs.chmodSync(script, '754');
- h.fire('before_build').then(function() {
- expect('the call').toBe('a failure');
- }, function(err) {
- expect(err).toBeDefined();
- }).fin(done);
- });
- });
+describe('module-level hooks', function() {
+ var handler = jasmine.createSpy().andReturn(Q());
+ var test_event = 'before_build';
+ var h;
- describe('success', function() {
- describe('project-level hooks', function() {
- var hook = path.join(tempDir, '.cordova', 'hooks', 'before_build'),
- s;
- beforeEach(function() {
- shell.mkdir('-p', hook);
- if (platform.match(/(win32|win64)/)) {
- shell.cp(path.join(hooks, 'test', '1.bat'), hook);
- shell.cp(path.join(hooks, 'test', '07.bat'), hook);
- } else {
- shell.cp(path.join(hooks, 'test', '1.sh'), hook);
- shell.cp(path.join(hooks, 'test', '07.sh'), hook);
- }
- fs.readdirSync(hook).forEach(function(script) {
- fs.chmodSync(path.join(hook, script), '754');
- });
- s = spyOn(child_process, 'exec').andCallFake(function(cmd, opts, cb) {
- if (!cb) cb = opts;
- cb(0, '', '');
- });
- });
- afterEach(function() {
- shell.rm('-rf', tempDir);
- });
- it('should execute all scripts in order and fire callback', function(done) {
- h.fire('before_build').then(function() {
- if (platform.match(/(win32|win64)/)) {
- expect(s.calls[0].args[0]).toMatch(/1.bat/);
- expect(s.calls[1].args[0]).toMatch(/07.bat/);
- } else {
- expect(s.calls[0].args[0]).toMatch(/1.sh/);
- expect(s.calls[1].args[0]).toMatch(/07.sh/);
- }
- }, function(err) {
- expect(err).not.toBeDefined();
- }).fin(done);
- });
- it('should pass the project root folder as parameter into the project-level hooks', function(done) {
- h.fire('before_build').then(function() {
- var param_str;
- if (platform.match(/(win32|win64)/)) {
- param_str = '1.bat "'+tempDir+'"';
- } else {
- param_str = '1.sh "'+tempDir+'"';
- }
- expect(s.calls[0].args[0].indexOf(param_str)).not.toEqual(-1);
- }, function(err) {
- expect(err).toBeUndefined();
- }).fin(done);
- });
- it('should skip any files starting with a dot on the scripts', function(done) {
- shell.cp(path.join(hooks, 'test', '07.bat'), path.join(hook, '.swp.file'));
- h.fire('before_build').then(function() {
- expect(s).not.toHaveBeenCalledWith(path.join(tempDir, '.cordova', 'hooks', 'before_build', '.swp.file') + ' "' + tempDir + '"', jasmine.any(Object), jasmine.any(Function));
- }, function(err) {
- expect(err).not.toBeDefined();
- }).fin(done);
- });
- });
- describe('module-level hooks', function() {
- var handler = jasmine.createSpy().andReturn(Q());
- var test_event = 'before_build';
- afterEach(function() {
- cordova.removeAllListeners(test_event);
- handler.reset();
- });
-
- it('should fire handlers using cordova.on', function(done) {
- cordova.on(test_event, handler);
- h.fire(test_event).then(function() {
- expect(handler).toHaveBeenCalled();
- }, function(err) {
- expect(err).not.toBeDefined();
- }).fin(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).then(function() {
- expect(handler).toHaveBeenCalledWith({root:tempDir});
- }, function(err) {
- expect(err).not.toBeDefined();
- }).fin(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).then(function() {
- expect(handler).not.toHaveBeenCalled();
- }, function(err) {
- expect(err).toBeUndefined();
- }).fin(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() {
- h1_fired = true;
- expect(h2_fired).toBe(false);
- return Q();
- };
- var h2_fired = false;
- var h2 = function() {
- h2_fired = true;
- expect(h1_fired).toBe(true);
- return Q();
- };
-
- cordova.on(test_event, h1);
- cordova.on(test_event, h2);
- h.fire(test_event).then(function() {
- expect(h1_fired).toBe(true);
- expect(h2_fired).toBe(true);
- done();
- });
- });
- it('should pass data object that fire calls into async handlers', function(done) {
- var data = {
- "hi":"ho",
- "offtowork":"wego"
- };
- var async = function(opts) {
- data.root = tempDir;
- expect(opts).toEqual(data);
- return Q();
- };
- cordova.on(test_event, async);
- h.fire(test_event, data).then(done);
- });
- it('should pass data object that fire calls into sync handlers', function(done) {
- var data = {
- "hi":"ho",
- "offtowork":"wego"
- };
- var async = function(opts) {
- data.root = tempDir;
- expect(opts).toEqual(data);
- };
- cordova.on(test_event, async);
- h.fire(test_event, data).then(done);
- });
- });
+ beforeEach(function() {
+ h = new hooker(project);
+ });
+
+ afterEach(function() {
+ cordova.removeAllListeners(test_event);
+ handler.reset();
+ });
+
+ it('should fire handlers using cordova.on', function(done) {
+ cordova.on(test_event, handler);
+ h.fire(test_event)
+ .then(function() {
+ expect(handler).toHaveBeenCalled();
+ })
+ .fail(function(err) {
+ expect(err).not.toBeDefined();
+ })
+ .fin(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)
+ .then(function() {
+ expect(handler).toHaveBeenCalledWith({root:project});
+ })
+ .fail(function(err) {
+ console.log(err);
+ expect(err).not.toBeDefined();
+ })
+ .fin(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)
+ .then(function() {
+ expect(handler).not.toHaveBeenCalled();
+ })
+ .fail(function(err) {
+ console.log(err);
+ expect(err).toBeUndefined();
+ })
+ .fin(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() {
+ h1_fired = true;
+ expect(h2_fired).toBe(false);
+ return Q();
+ };
+ var h2_fired = false;
+ var h2 = function() {
+ h2_fired = true;
+ expect(h1_fired).toBe(true);
+ return Q();
+ };
+
+ cordova.on(test_event, h1);
+ cordova.on(test_event, h2);
+ h.fire(test_event).then(function() {
+ expect(h1_fired).toBe(true);
+ expect(h2_fired).toBe(true);
+ done();
});
});
+
+ it('should pass data object that fire calls into async handlers', function(done) {
+ var data = {
+ "hi":"ho",
+ "offtowork":"wego"
+ };
+ var async = function(opts) {
+ data.root = tmpDir;
+ expect(opts).toEqual(data);
+ return Q();
+ };
+ cordova.on(test_event, async);
+ h.fire(test_event, data).then(done);
+ });
+
+ it('should pass data object that fire calls into sync handlers', function(done) {
+ var data = {
+ "hi":"ho",
+ "offtowork":"wego"
+ };
+ var async = function(opts) {
+ data.root = tmpDir;
+ expect(opts).toEqual(data);
+ };
+ cordova.on(test_event, async);
+ h.fire(test_event, data).then(done);
+ });
});
-}
+
+describe('hooks', function() {
+ var h;
+ beforeEach(function() {
+ h = new hooker(project);
+ });
+
+
+ it('should not error if the hook is unrecognized', function(done) {
+ h.fire('CLEAN YOUR SHORTS GODDAMNIT LIKE A BIG BOY!')
+ .fail(function (err) {
+ expect('Call with unrecogized hook ').toBe('successful.\n' + err);
+ })
+ .fin(done);
+ });
+
+ it('should error if any script exits with non-zero code', function(done) {
+ h.fire('fail').then(function() {
+ expect('the call').toBe('a failure');
+ }, function(err) {
+ expect(err).toBeDefined();
+ })
+ .fin(done);
+ });
+
+ it('should execute all scripts in order', function(done) {
+ h.fire('test')
+ .then(function() {
+ var hooksOrderFile = path.join(project, 'hooks_order.txt');
+ var hooksEnvFile = path.join(project, 'hooks_env.json');
+ var hooksParamsFile = path.join(project, 'hooks_params.txt');
+ expect(hooksOrderFile).toExist();
+ expect(hooksEnvFile).toExist();
+ expect(hooksParamsFile).toExist();
+ expect(path.join(project, 'dotted_hook_should_not_fire.txt')).not.toExist();
+
+ var order = fs.readFileSync(hooksOrderFile, 'ascii').replace(/\W/gm, '');
+ expect(order).toBe('ab');
+
+ var params = fs.readFileSync(hooksParamsFile, 'ascii').trim().trim('"');
+ expect(params).toMatch(project.replace(/\\/g, '\\\\'));
+
+ var env = JSON.parse(fs.readFileSync(hooksEnvFile, 'ascii'));
+ expect(env.CORDOVA_VERSION).toEqual(require('../package').version);
+ })
+ .fail(function(err) {
+ console.log(err);
+ expect('Test hook call').toBe('successful');
+ })
+ .fin(done);
+
+ });
+
+ // Cleanup. Must be the last spec. Is there a better place for final cleanup in Jasmine?
+ it('should not fail during cleanup', function() {
+ process.chdir(path.join(__dirname, '..')); // Non e2e tests assume CWD is repo root.
+ if(ext == 'sh') {
+ shell.rm('-rf', tmpDir);
+ } else { // Windows:
+ // For some mysterious reason, both shell.rm and RMDIR /S /Q won't
+ // delete the dir on Windows, but they do remove the files leaving
+ // only folders. But the dir is removed just fine by
+ // shell.rm('-rf', tmpDir) at the top of this file with the next
+ // invocation of this test. The benefit of RMDIR /S /Q is that it
+ // doesn't print warnings like shell.rmdir() that look like this:
+ // rm: could not remove directory (code ENOTEMPTY): C:\Users\...
+ var cmd = 'RMDIR /S /Q ' + tmpDir;
+ child_process.exec(cmd);
+ }
+ });
+});
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/8b764c3c/e2e/platform.spec.js
----------------------------------------------------------------------
diff --git a/e2e/platform.spec.js b/e2e/platform.spec.js
index be5761e..1e8dd0c 100644
--- a/e2e/platform.spec.js
+++ b/e2e/platform.spec.js
@@ -10,7 +10,7 @@ var helpers = require('./helpers'),
events = require('../src/events'),
cordova = require('../cordova');
-var tmpDir = helpers.tmpDir();
+var tmpDir = helpers.tmpDir('platform_test');
var project = path.join(tmpDir, 'project');
var platformParser = platforms[helpers.testPlatform].parser;
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/8b764c3c/e2e/plugin.spec.js
----------------------------------------------------------------------
diff --git a/e2e/plugin.spec.js b/e2e/plugin.spec.js
index dd493bb..2ad7b08 100644
--- a/e2e/plugin.spec.js
+++ b/e2e/plugin.spec.js
@@ -7,7 +7,7 @@ var helpers = require('./helpers'),
events = require('../src/events'),
cordova = require('../cordova');
-var tmpDir = helpers.tmpDir();
+var tmpDir = helpers.tmpDir('plugin_test');
var project = path.join(tmpDir, 'project');
var pluginsDir = path.join(__dirname, 'fixtures', 'plugins');
var pluginId = 'org.apache.cordova.fakeplugin1';
@@ -20,7 +20,7 @@ describe('plugin end-to-end', function() {
});
afterEach(function() {
process.chdir(path.join(__dirname, '..')); // Needed to rm the dir on Windows.
- shell.rm('-rf', project);
+ shell.rm('-rf', tmpDir);
});
// The flow tested is: ls, add, ls, rm, ls.
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/8b764c3c/spec/fixtures/hooks/fail/fail.bat
----------------------------------------------------------------------
diff --git a/spec/fixtures/hooks/fail/fail.bat b/spec/fixtures/hooks/fail/fail.bat
deleted file mode 100644
index 0c810b7..0000000
--- a/spec/fixtures/hooks/fail/fail.bat
+++ /dev/null
@@ -1,2 +0,0 @@
-@ECHO OFF
-EXIT /B 1
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/8b764c3c/spec/fixtures/hooks/fail/fail.sh
----------------------------------------------------------------------
diff --git a/spec/fixtures/hooks/fail/fail.sh b/spec/fixtures/hooks/fail/fail.sh
deleted file mode 100755
index 379a4c9..0000000
--- a/spec/fixtures/hooks/fail/fail.sh
+++ /dev/null
@@ -1 +0,0 @@
-exit 1
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/8b764c3c/spec/fixtures/hooks/test/07.bat
----------------------------------------------------------------------
diff --git a/spec/fixtures/hooks/test/07.bat b/spec/fixtures/hooks/test/07.bat
deleted file mode 100644
index 1095fc0..0000000
--- a/spec/fixtures/hooks/test/07.bat
+++ /dev/null
@@ -1,2 +0,0 @@
-@ECHO OFF
-ECHO this is script 0 in %~dp0
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/8b764c3c/spec/fixtures/hooks/test/07.sh
----------------------------------------------------------------------
diff --git a/spec/fixtures/hooks/test/07.sh b/spec/fixtures/hooks/test/07.sh
deleted file mode 100755
index 6e25461..0000000
--- a/spec/fixtures/hooks/test/07.sh
+++ /dev/null
@@ -1 +0,0 @@
-echo "this is script 0 in `pwd`";
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/8b764c3c/spec/fixtures/hooks/test/1.bat
----------------------------------------------------------------------
diff --git a/spec/fixtures/hooks/test/1.bat b/spec/fixtures/hooks/test/1.bat
deleted file mode 100644
index 4e76af0..0000000
--- a/spec/fixtures/hooks/test/1.bat
+++ /dev/null
@@ -1,2 +0,0 @@
-@ECHO OFF
-ECHO this is script 1 in %~dp0
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/8b764c3c/spec/fixtures/hooks/test/1.sh
----------------------------------------------------------------------
diff --git a/spec/fixtures/hooks/test/1.sh b/spec/fixtures/hooks/test/1.sh
deleted file mode 100755
index 53d5e97..0000000
--- a/spec/fixtures/hooks/test/1.sh
+++ /dev/null
@@ -1 +0,0 @@
-echo "this is script 1 in `pwd`";
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/8b764c3c/src/hooker.js
----------------------------------------------------------------------
diff --git a/src/hooker.js b/src/hooker.js
index b976798..8ac51a0 100644
--- a/src/hooker.js
+++ b/src/hooker.js
@@ -122,7 +122,7 @@ function execute_scripts_serially(scripts, root, dir, opts) {
var execOpts = {cwd: root};
execOpts.env = _.extend({}, process.env);
execOpts.env.CORDOVA_VERSION = require('../package').version;
- execOpts.env.CORDOVA_PLATFORMS = opts.platforms?opts.platforms.join():'';
+ execOpts.env.CORDOVA_PLATFORMS = opts.platforms ? opts.platforms.join() : '';
execOpts.env.CORDOVA_PLUGINS = opts.plugins?opts.plugins.join():'';
execOpts.env.CORDOVA_HOOK = fullpath;
execOpts.env.CORDOVA_CMDLINE = process.argv.join(' ');
[2/3] git commit: Moved hooker.spec.js to e2e
Posted by mm...@apache.org.
Moved hooker.spec.js to e2e
Checking whether moving and editing in 2 separate commits will produce
better diffs.
Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/c5ac48dc
Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/c5ac48dc
Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/c5ac48dc
Branch: refs/heads/master
Commit: c5ac48dc99bcad8b3a56706548b2c600f514b30b
Parents: 6f5ebb8
Author: Mark Koudritsky <ka...@chromium.org>
Authored: Mon Dec 9 16:49:41 2013 -0500
Committer: Michal Mocny <mm...@gmail.com>
Committed: Tue Dec 10 13:24:49 2013 -0500
----------------------------------------------------------------------
e2e/hooker.spec.js | 264 +++++++++++++++++++++++++++++++++++++++++++++++
spec/hooker.spec.js | 264 -----------------------------------------------
2 files changed, 264 insertions(+), 264 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/c5ac48dc/e2e/hooker.spec.js
----------------------------------------------------------------------
diff --git a/e2e/hooker.spec.js b/e2e/hooker.spec.js
new file mode 100644
index 0000000..d4b073e
--- /dev/null
+++ b/e2e/hooker.spec.js
@@ -0,0 +1,264 @@
+ /**
+ 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'),
+ util = require('../src/util'),
+ shell = require('shelljs'),
+ child_process = require('child_process'),
+ path = require('path'),
+ fs = require('fs'),
+ os = require('os'),
+ Q = require('q'),
+ tempDir= path.join(__dirname, '..', 'temp'),
+ hooks = path.join(__dirname, 'fixtures', 'hooks'),
+ cordova= require('../cordova');
+
+var platform = os.platform();
+var cwd = process.cwd();
+
+// Note: because there are numerous issues with these tests on windows, the entire spec is skipped if we
+// are in win32 ~jm
+
+if(platform != "win32" ) {
+
+describe('hooker', function() {
+ it('should throw if provided directory is not a cordova project', function() {
+ spyOn(util, 'isCordova').andReturn(false);
+ expect(function() {
+ new hooker(tempDir);
+ }).toThrow('Not a Cordova project, can\'t use hooks.');
+ });
+ it('should not throw if provided directory is a cordova project', function() {
+ var root = '/some/root';
+ spyOn(util, 'isCordova').andReturn(root);
+ expect(function() {
+ var h = new hooker(tempDir);
+ expect(h.root).toEqual(root);
+ }).not.toThrow();
+ });
+
+ describe('global (static) fire method', function() {
+ it('should execute listeners serially', function(done) {
+ var timeout = 20;
+ var test_event = 'foo';
+ var h1_fired = false;
+ var h1 = function() {
+ h1_fired = true;
+ expect(h2_fired).toBe(false);
+ return Q();
+ };
+ var h2_fired = false;
+ var h2 = function() {
+ h2_fired = true;
+ expect(h1_fired).toBe(true);
+ return Q();
+ };
+
+ cordova.on(test_event, h1);
+ cordova.on(test_event, h2);
+ hooker.fire(test_event).then(function() {
+ expect(h1_fired).toBe(true);
+ expect(h2_fired).toBe(true);
+ done();
+ });
+ });
+ });
+ describe('project-level fire method', function() {
+ var h;
+ beforeEach(function() {
+ spyOn(util, 'isCordova').andReturn(tempDir);
+ h = new hooker(tempDir);
+ });
+
+ describe('failure', function() {
+ it('should not error if the hook is unrecognized', function() {
+ var p;
+ runs(function() {
+ p = h.fire('CLEAN YOUR SHORTS GODDAMNIT LIKE A BIG BOY!');
+ });
+ waitsFor(function() { return !p.isPending() }, 'promise not resolved', 500);
+ runs(function() {
+ expect(p.isFulfilled()).toBe(true);
+ });
+ });
+ it('should error if any script exits with non-zero code', function(done) {
+ var script = path.join(tempDir, '.cordova', 'hooks', 'before_build');
+ shell.mkdir('-p', script);
+ this.after(function() { shell.rm('-rf', tempDir); });
+ if (platform.match(/(win32|win64)/)) {
+ script = path.join(script, 'fail.bat');
+ shell.cp(path.join(hooks, 'fail', 'fail.bat'), script);
+ } else {
+ script = path.join(script, 'fail.sh');
+ shell.cp(path.join(hooks, 'fail', 'fail.sh'), script);
+ }
+ fs.chmodSync(script, '754');
+ h.fire('before_build').then(function() {
+ expect('the call').toBe('a failure');
+ }, function(err) {
+ expect(err).toBeDefined();
+ }).fin(done);
+ });
+ });
+
+ describe('success', function() {
+ describe('project-level hooks', function() {
+ var hook = path.join(tempDir, '.cordova', 'hooks', 'before_build'),
+ s;
+ beforeEach(function() {
+ shell.mkdir('-p', hook);
+ if (platform.match(/(win32|win64)/)) {
+ shell.cp(path.join(hooks, 'test', '1.bat'), hook);
+ shell.cp(path.join(hooks, 'test', '07.bat'), hook);
+ } else {
+ shell.cp(path.join(hooks, 'test', '1.sh'), hook);
+ shell.cp(path.join(hooks, 'test', '07.sh'), hook);
+ }
+ fs.readdirSync(hook).forEach(function(script) {
+ fs.chmodSync(path.join(hook, script), '754');
+ });
+ s = spyOn(child_process, 'exec').andCallFake(function(cmd, opts, cb) {
+ if (!cb) cb = opts;
+ cb(0, '', '');
+ });
+ });
+ afterEach(function() {
+ shell.rm('-rf', tempDir);
+ });
+ it('should execute all scripts in order and fire callback', function(done) {
+ h.fire('before_build').then(function() {
+ if (platform.match(/(win32|win64)/)) {
+ expect(s.calls[0].args[0]).toMatch(/1.bat/);
+ expect(s.calls[1].args[0]).toMatch(/07.bat/);
+ } else {
+ expect(s.calls[0].args[0]).toMatch(/1.sh/);
+ expect(s.calls[1].args[0]).toMatch(/07.sh/);
+ }
+ }, function(err) {
+ expect(err).not.toBeDefined();
+ }).fin(done);
+ });
+ it('should pass the project root folder as parameter into the project-level hooks', function(done) {
+ h.fire('before_build').then(function() {
+ var param_str;
+ if (platform.match(/(win32|win64)/)) {
+ param_str = '1.bat "'+tempDir+'"';
+ } else {
+ param_str = '1.sh "'+tempDir+'"';
+ }
+ expect(s.calls[0].args[0].indexOf(param_str)).not.toEqual(-1);
+ }, function(err) {
+ expect(err).toBeUndefined();
+ }).fin(done);
+ });
+ it('should skip any files starting with a dot on the scripts', function(done) {
+ shell.cp(path.join(hooks, 'test', '07.bat'), path.join(hook, '.swp.file'));
+ h.fire('before_build').then(function() {
+ expect(s).not.toHaveBeenCalledWith(path.join(tempDir, '.cordova', 'hooks', 'before_build', '.swp.file') + ' "' + tempDir + '"', jasmine.any(Object), jasmine.any(Function));
+ }, function(err) {
+ expect(err).not.toBeDefined();
+ }).fin(done);
+ });
+ });
+ describe('module-level hooks', function() {
+ var handler = jasmine.createSpy().andReturn(Q());
+ var test_event = 'before_build';
+ afterEach(function() {
+ cordova.removeAllListeners(test_event);
+ handler.reset();
+ });
+
+ it('should fire handlers using cordova.on', function(done) {
+ cordova.on(test_event, handler);
+ h.fire(test_event).then(function() {
+ expect(handler).toHaveBeenCalled();
+ }, function(err) {
+ expect(err).not.toBeDefined();
+ }).fin(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).then(function() {
+ expect(handler).toHaveBeenCalledWith({root:tempDir});
+ }, function(err) {
+ expect(err).not.toBeDefined();
+ }).fin(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).then(function() {
+ expect(handler).not.toHaveBeenCalled();
+ }, function(err) {
+ expect(err).toBeUndefined();
+ }).fin(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() {
+ h1_fired = true;
+ expect(h2_fired).toBe(false);
+ return Q();
+ };
+ var h2_fired = false;
+ var h2 = function() {
+ h2_fired = true;
+ expect(h1_fired).toBe(true);
+ return Q();
+ };
+
+ cordova.on(test_event, h1);
+ cordova.on(test_event, h2);
+ h.fire(test_event).then(function() {
+ expect(h1_fired).toBe(true);
+ expect(h2_fired).toBe(true);
+ done();
+ });
+ });
+ it('should pass data object that fire calls into async handlers', function(done) {
+ var data = {
+ "hi":"ho",
+ "offtowork":"wego"
+ };
+ var async = function(opts) {
+ data.root = tempDir;
+ expect(opts).toEqual(data);
+ return Q();
+ };
+ cordova.on(test_event, async);
+ h.fire(test_event, data).then(done);
+ });
+ it('should pass data object that fire calls into sync handlers', function(done) {
+ var data = {
+ "hi":"ho",
+ "offtowork":"wego"
+ };
+ var async = function(opts) {
+ data.root = tempDir;
+ expect(opts).toEqual(data);
+ };
+ cordova.on(test_event, async);
+ h.fire(test_event, data).then(done);
+ });
+ });
+ });
+ });
+});
+
+}
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/c5ac48dc/spec/hooker.spec.js
----------------------------------------------------------------------
diff --git a/spec/hooker.spec.js b/spec/hooker.spec.js
deleted file mode 100644
index d4b073e..0000000
--- a/spec/hooker.spec.js
+++ /dev/null
@@ -1,264 +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 hooker = require('../src/hooker'),
- util = require('../src/util'),
- shell = require('shelljs'),
- child_process = require('child_process'),
- path = require('path'),
- fs = require('fs'),
- os = require('os'),
- Q = require('q'),
- tempDir= path.join(__dirname, '..', 'temp'),
- hooks = path.join(__dirname, 'fixtures', 'hooks'),
- cordova= require('../cordova');
-
-var platform = os.platform();
-var cwd = process.cwd();
-
-// Note: because there are numerous issues with these tests on windows, the entire spec is skipped if we
-// are in win32 ~jm
-
-if(platform != "win32" ) {
-
-describe('hooker', function() {
- it('should throw if provided directory is not a cordova project', function() {
- spyOn(util, 'isCordova').andReturn(false);
- expect(function() {
- new hooker(tempDir);
- }).toThrow('Not a Cordova project, can\'t use hooks.');
- });
- it('should not throw if provided directory is a cordova project', function() {
- var root = '/some/root';
- spyOn(util, 'isCordova').andReturn(root);
- expect(function() {
- var h = new hooker(tempDir);
- expect(h.root).toEqual(root);
- }).not.toThrow();
- });
-
- describe('global (static) fire method', function() {
- it('should execute listeners serially', function(done) {
- var timeout = 20;
- var test_event = 'foo';
- var h1_fired = false;
- var h1 = function() {
- h1_fired = true;
- expect(h2_fired).toBe(false);
- return Q();
- };
- var h2_fired = false;
- var h2 = function() {
- h2_fired = true;
- expect(h1_fired).toBe(true);
- return Q();
- };
-
- cordova.on(test_event, h1);
- cordova.on(test_event, h2);
- hooker.fire(test_event).then(function() {
- expect(h1_fired).toBe(true);
- expect(h2_fired).toBe(true);
- done();
- });
- });
- });
- describe('project-level fire method', function() {
- var h;
- beforeEach(function() {
- spyOn(util, 'isCordova').andReturn(tempDir);
- h = new hooker(tempDir);
- });
-
- describe('failure', function() {
- it('should not error if the hook is unrecognized', function() {
- var p;
- runs(function() {
- p = h.fire('CLEAN YOUR SHORTS GODDAMNIT LIKE A BIG BOY!');
- });
- waitsFor(function() { return !p.isPending() }, 'promise not resolved', 500);
- runs(function() {
- expect(p.isFulfilled()).toBe(true);
- });
- });
- it('should error if any script exits with non-zero code', function(done) {
- var script = path.join(tempDir, '.cordova', 'hooks', 'before_build');
- shell.mkdir('-p', script);
- this.after(function() { shell.rm('-rf', tempDir); });
- if (platform.match(/(win32|win64)/)) {
- script = path.join(script, 'fail.bat');
- shell.cp(path.join(hooks, 'fail', 'fail.bat'), script);
- } else {
- script = path.join(script, 'fail.sh');
- shell.cp(path.join(hooks, 'fail', 'fail.sh'), script);
- }
- fs.chmodSync(script, '754');
- h.fire('before_build').then(function() {
- expect('the call').toBe('a failure');
- }, function(err) {
- expect(err).toBeDefined();
- }).fin(done);
- });
- });
-
- describe('success', function() {
- describe('project-level hooks', function() {
- var hook = path.join(tempDir, '.cordova', 'hooks', 'before_build'),
- s;
- beforeEach(function() {
- shell.mkdir('-p', hook);
- if (platform.match(/(win32|win64)/)) {
- shell.cp(path.join(hooks, 'test', '1.bat'), hook);
- shell.cp(path.join(hooks, 'test', '07.bat'), hook);
- } else {
- shell.cp(path.join(hooks, 'test', '1.sh'), hook);
- shell.cp(path.join(hooks, 'test', '07.sh'), hook);
- }
- fs.readdirSync(hook).forEach(function(script) {
- fs.chmodSync(path.join(hook, script), '754');
- });
- s = spyOn(child_process, 'exec').andCallFake(function(cmd, opts, cb) {
- if (!cb) cb = opts;
- cb(0, '', '');
- });
- });
- afterEach(function() {
- shell.rm('-rf', tempDir);
- });
- it('should execute all scripts in order and fire callback', function(done) {
- h.fire('before_build').then(function() {
- if (platform.match(/(win32|win64)/)) {
- expect(s.calls[0].args[0]).toMatch(/1.bat/);
- expect(s.calls[1].args[0]).toMatch(/07.bat/);
- } else {
- expect(s.calls[0].args[0]).toMatch(/1.sh/);
- expect(s.calls[1].args[0]).toMatch(/07.sh/);
- }
- }, function(err) {
- expect(err).not.toBeDefined();
- }).fin(done);
- });
- it('should pass the project root folder as parameter into the project-level hooks', function(done) {
- h.fire('before_build').then(function() {
- var param_str;
- if (platform.match(/(win32|win64)/)) {
- param_str = '1.bat "'+tempDir+'"';
- } else {
- param_str = '1.sh "'+tempDir+'"';
- }
- expect(s.calls[0].args[0].indexOf(param_str)).not.toEqual(-1);
- }, function(err) {
- expect(err).toBeUndefined();
- }).fin(done);
- });
- it('should skip any files starting with a dot on the scripts', function(done) {
- shell.cp(path.join(hooks, 'test', '07.bat'), path.join(hook, '.swp.file'));
- h.fire('before_build').then(function() {
- expect(s).not.toHaveBeenCalledWith(path.join(tempDir, '.cordova', 'hooks', 'before_build', '.swp.file') + ' "' + tempDir + '"', jasmine.any(Object), jasmine.any(Function));
- }, function(err) {
- expect(err).not.toBeDefined();
- }).fin(done);
- });
- });
- describe('module-level hooks', function() {
- var handler = jasmine.createSpy().andReturn(Q());
- var test_event = 'before_build';
- afterEach(function() {
- cordova.removeAllListeners(test_event);
- handler.reset();
- });
-
- it('should fire handlers using cordova.on', function(done) {
- cordova.on(test_event, handler);
- h.fire(test_event).then(function() {
- expect(handler).toHaveBeenCalled();
- }, function(err) {
- expect(err).not.toBeDefined();
- }).fin(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).then(function() {
- expect(handler).toHaveBeenCalledWith({root:tempDir});
- }, function(err) {
- expect(err).not.toBeDefined();
- }).fin(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).then(function() {
- expect(handler).not.toHaveBeenCalled();
- }, function(err) {
- expect(err).toBeUndefined();
- }).fin(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() {
- h1_fired = true;
- expect(h2_fired).toBe(false);
- return Q();
- };
- var h2_fired = false;
- var h2 = function() {
- h2_fired = true;
- expect(h1_fired).toBe(true);
- return Q();
- };
-
- cordova.on(test_event, h1);
- cordova.on(test_event, h2);
- h.fire(test_event).then(function() {
- expect(h1_fired).toBe(true);
- expect(h2_fired).toBe(true);
- done();
- });
- });
- it('should pass data object that fire calls into async handlers', function(done) {
- var data = {
- "hi":"ho",
- "offtowork":"wego"
- };
- var async = function(opts) {
- data.root = tempDir;
- expect(opts).toEqual(data);
- return Q();
- };
- cordova.on(test_event, async);
- h.fire(test_event, data).then(done);
- });
- it('should pass data object that fire calls into sync handlers', function(done) {
- var data = {
- "hi":"ho",
- "offtowork":"wego"
- };
- var async = function(opts) {
- data.root = tempDir;
- expect(opts).toEqual(data);
- };
- cordova.on(test_event, async);
- h.fire(test_event, data).then(done);
- });
- });
- });
- });
-});
-
-}
[3/3] git commit: CB-4382: Pass cli arguments to project-level hooks
Posted by mm...@apache.org.
CB-4382: Pass cli arguments to project-level hooks
Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/6f5ebb87
Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/6f5ebb87
Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/6f5ebb87
Branch: refs/heads/master
Commit: 6f5ebb87ceb01c55026bf84e3c173b07af3b0415
Parents: b365138
Author: Mark Koudritsky <ka...@chromium.org>
Authored: Sun Dec 1 15:32:18 2013 -0500
Committer: Michal Mocny <mm...@gmail.com>
Committed: Tue Dec 10 13:24:49 2013 -0500
----------------------------------------------------------------------
package.json | 3 ++-
src/hooker.js | 28 +++++++++++++++++++---------
2 files changed, 21 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/6f5ebb87/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 6c1c753..ec16d7f 100644
--- a/package.json
+++ b/package.json
@@ -48,7 +48,8 @@
"q": "~0.9",
"optimist": "0.6.0",
"jshint": "~1.1.0",
- "mime": "~1.2.11"
+ "mime": "~1.2.11",
+ "lodash": "~2.4.0"
},
"devDependencies": {
"jasmine-node": "1.8.x"
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/6f5ebb87/src/hooker.js
----------------------------------------------------------------------
diff --git a/src/hooker.js b/src/hooker.js
index 06acec7..b976798 100644
--- a/src/hooker.js
+++ b/src/hooker.js
@@ -22,13 +22,14 @@ var util = require('./util'),
events= require('./events'),
child_process = require('child_process'),
Q = require('q'),
- path = require('path');
+ path = require('path'),
+ _ = require('lodash');
module.exports = function hooker(root) {
var r = util.isCordova(root);
if (!r) throw new Error('Not a Cordova project, can\'t use hooks.');
else this.root = r;
-}
+};
// Returns a promise.
module.exports.fire = function global_fire(hook, opts) {
@@ -63,20 +64,21 @@ module.exports.prototype = {
var scripts = fs.readdirSync(dir).sort(compareNumbers).filter(function(s) {
return s[0] != '.';
});
- return execute_scripts_serially(scripts, self.root, dir);
+ return execute_scripts_serially(scripts, self.root, dir, opts);
}
});
}
-}
+};
// Returns a promise.
-function execute_scripts_serially(scripts, root, dir) {
+function execute_scripts_serially(scripts, root, dir, opts) {
+ opts = opts || {};
if (scripts.length) {
var s = scripts.shift();
var fullpath = path.join(dir, s);
if (fs.statSync(fullpath).isDirectory()) {
events.emit('verbose', 'skipped directory "' + fullpath + '" within hook directory');
- return execute_scripts_serially(scripts, root, dir); // skip directories if they're in there.
+ return execute_scripts_serially(scripts, root, dir, opts); // skip directories if they're in there.
} else {
var command = fullpath + ' "' + root + '"';
@@ -108,7 +110,7 @@ function execute_scripts_serially(scripts, root, dir) {
events.emit('verbose', 'hook file "' + fullpath + '" skipped');
// found windows script, without shebang this script definitely
// will not run on unix
- return execute_scripts_serially(scripts, root, dir);
+ return execute_scripts_serially(scripts, root, dir, opts);
}
}
@@ -117,14 +119,22 @@ function execute_scripts_serially(scripts, root, dir) {
command = hookCmd + ' ' + command;
}
+ var execOpts = {cwd: root};
+ execOpts.env = _.extend({}, process.env);
+ execOpts.env.CORDOVA_VERSION = require('../package').version;
+ execOpts.env.CORDOVA_PLATFORMS = opts.platforms?opts.platforms.join():'';
+ execOpts.env.CORDOVA_PLUGINS = opts.plugins?opts.plugins.join():'';
+ execOpts.env.CORDOVA_HOOK = fullpath;
+ execOpts.env.CORDOVA_CMDLINE = process.argv.join(' ');
+
events.emit('verbose', 'Executing hook "' + command + '" (output to follow)...');
var d = Q.defer();
- child_process.exec(command, function(err, stdout, stderr) {
+ child_process.exec(command, execOpts, function(err, stdout, stderr) {
events.emit('verbose', stdout, stderr);
if (err) {
d.reject(new Error('Script "' + fullpath + '" exited with non-zero status code. Aborting. Output: ' + stdout + stderr));
} else {
- d.resolve(execute_scripts_serially(scripts, root, dir));
+ d.resolve(execute_scripts_serially(scripts, root, dir, opts));
}
});
return d.promise;