Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4BBC21052B for ; Fri, 14 Jun 2013 17:31:09 +0000 (UTC) Received: (qmail 25417 invoked by uid 500); 14 Jun 2013 17:30:52 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 25365 invoked by uid 500); 14 Jun 2013 17:30:51 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cordova.apache.org Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 23404 invoked by uid 99); 14 Jun 2013 17:30:32 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 14 Jun 2013 17:30:32 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 8D84C8811B0; Fri, 14 Jun 2013 17:30:32 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: filmaj@apache.org To: commits@cordova.apache.org Date: Fri, 14 Jun 2013 17:31:35 -0000 Message-Id: In-Reply-To: <6a25de3d19804b849af17bab7ef68c0d@git.apache.org> References: <6a25de3d19804b849af17bab7ef68c0d@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [66/83] [abbrv] git commit: updates to hooker tests. updates to hooker tests. Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/090377b9 Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/090377b9 Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/090377b9 Branch: refs/heads/lazy Commit: 090377b900fb2e100d043b9b48416c8d24cd0955 Parents: 4b310a7 Author: Fil Maj Authored: Wed Jun 12 16:35:04 2013 -0700 Committer: Fil Maj Committed: Thu Jun 13 11:13:21 2013 -0700 ---------------------------------------------------------------------- spec/hooker.spec.js | 81 +++++++++++++++++++++++++++++++----------------- 1 file changed, 53 insertions(+), 28 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/090377b9/spec/hooker.spec.js ---------------------------------------------------------------------- diff --git a/spec/hooker.spec.js b/spec/hooker.spec.js index 6b0129a..2fe1705 100644 --- a/spec/hooker.spec.js +++ b/spec/hooker.spec.js @@ -16,51 +16,69 @@ specific language governing permissions and limitations under the License. */ -var hooker = require('../../src/hooker'), +var hooker = require('../src/hooker'), + util = require('../src/util'), 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'); + 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); - }); - + spyOn(util, 'isCordova').andReturn(false); expect(function() { - var h = new hooker(tempDir); - }).toThrow(); + new hooker(tempDir); + }).toThrow('Not a Cordova project, can\'t use hooks.'); }); it('should not throw if provided directory is a cordova project', function() { - cordova.create(tempDir); - this.after(function() { - shell.rm('-rf', tempDir); - }); - + var root = '/some/root'; + spyOn(util, 'isCordova').andReturn(root); expect(function() { var h = new hooker(tempDir); + expect(h.root).toEqual(root); }).not.toThrow(); }); - describe('fire method', function() { + describe('global (static) fire method', function() { + it('should execute listeners serially', function(done) { + var timeout = 20; + var test_event = 'poop'; + var h1_fired = false; + var h1 = function(root, cb) { + h1_fired = true; + setTimeout(cb, timeout); + }; + var h2_fired = false; + var h2 = function() { + h2_fired = true; + }; + runs(function() { + cordova.on(test_event, h1); + cordova.on(test_event, h2); + hooker.fire(test_event, function(err) { + done(); + }); + expect(h1_fired).toBe(true); + expect(h2_fired).toBe(false); + }); + waits(timeout); + runs(function() { + expect(h2_fired).toBe(true); + }); + }); + }); + describe('project-level fire method', function() { var h; - beforeEach(function() { - cordova.create(tempDir); + spyOn(util, 'isCordova').andReturn(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) { @@ -70,12 +88,14 @@ describe('hooker', function() { }); }); it('should error if any script exits with non-zero code', function(done) { - var script; + 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(tempDir, '.cordova', 'hooks', 'before_build', 'fail.bat'); + script = path.join(script, 'fail.bat'); shell.cp(path.join(hooks, 'fail', 'fail.bat'), script); } else { - script = path.join(tempDir, '.cordova', 'hooks', 'before_build', 'fail.sh'); + script = path.join(script, 'fail.sh'); shell.cp(path.join(hooks, 'fail', 'fail.sh'), script); } fs.chmodSync(script, '754'); @@ -89,6 +109,8 @@ describe('hooker', function() { describe('success', function() { it('should execute all scripts in order and fire callback', function(done) { var hook = path.join(tempDir, '.cordova', 'hooks', 'before_build'); + shell.mkdir('-p', hook); + this.after(function() { shell.rm('-rf', tempDir); }); if (platform.match(/(win32|win64)/)) { shell.cp(path.join(hooks, 'test', '0.bat'), hook); shell.cp(path.join(hooks, 'test', '1.bat'), hook); @@ -117,6 +139,8 @@ describe('hooker', function() { }); 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'); + shell.mkdir('-p', hook); + this.after(function() { shell.rm('-rf', tempDir); }); if (platform.match(/(win32|win64)/)) { shell.cp(path.join(hooks, 'test', '0.bat'), hook); } else { @@ -174,9 +198,10 @@ describe('hooker', function() { }); 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 timeout = 19; var h1 = function(root, cb) { h1_fired = true; - setTimeout(cb, 100); + setTimeout(cb, timeout); }; var h2_fired = false; var h2 = function() { @@ -191,7 +216,7 @@ describe('hooker', function() { expect(h1_fired).toBe(true); expect(h2_fired).toBe(false); }); - waits(100); + waits(timeout); runs(function() { expect(h2_fired).toBe(true); });