Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id E815D200CAF for ; Thu, 22 Jun 2017 14:52:24 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id E6BED160BF1; Thu, 22 Jun 2017 12:52:24 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 0D38E160BE5 for ; Thu, 22 Jun 2017 14:52:23 +0200 (CEST) Received: (qmail 30910 invoked by uid 500); 22 Jun 2017 12:52:23 -0000 Mailing-List: contact dev-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 dev@cordova.apache.org Received: (qmail 30899 invoked by uid 99); 22 Jun 2017 12:52:22 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Jun 2017 12:52:22 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id C2188DFE5C; Thu, 22 Jun 2017 12:52:22 +0000 (UTC) From: filmaj To: dev@cordova.apache.org Reply-To: dev@cordova.apache.org References: In-Reply-To: Subject: [GitHub] cordova-lib pull request #567: CB-12361: Added unit tests for prepare.js Content-Type: text/plain Message-Id: <20170622125222.C2188DFE5C@git1-us-west.apache.org> Date: Thu, 22 Jun 2017 12:52:22 +0000 (UTC) archived-at: Thu, 22 Jun 2017 12:52:25 -0000 Github user filmaj commented on a diff in the pull request: https://github.com/apache/cordova-lib/pull/567#discussion_r123500548 --- Diff: spec-cordova/prepare.spec.js --- @@ -63,103 +63,103 @@ describe('cordova/prepare', function () { spyOn(cordova_config, 'read').and.returnValue({}); spyOn(restore, 'installPlatformsFromConfigXML').and.returnValue(Q()); spyOn(restore, 'installPluginsFromConfigXML').and.returnValue(Q()); - + spyOn(util, 'cdProjectRoot').and.returnValue(project_dir); + spyOn(util, 'preProcessOptions').and.callFake(function (options) { + var platforms = options.platforms || []; + return {'platforms':platforms}; + }); spyOn(prepare, 'preparePlatforms').and.returnValue(Q); }); describe('failure', function () { - it('should invoke util.preProcessOptions as preflight task checker, which, if fails, should trigger promise rejection and only fire the before_prepare hook', function(done) { - spyOn(util, 'cdProjectRoot').and.returnValue(project_dir); - spyOn(util, 'preProcessOptions').and.throwError(); - prepare({}).fail(function(err) { - expect(err).toBeDefined(); - expect(HooksRunner.prototype.fire.calls.count()).toBe(1); - expect(HooksRunner.prototype.fire.calls.argsFor(0)[0]).toEqual('before_prepare'); - done(); + it('should invoke util.preProcessOptions as preflight task checker, which, if fails, should trigger promise rejection and only fire the before_prepare hook', function (done) { + util.preProcessOptions.and.callFake(function () { + throw new Error('preProcessOption error'); }); + prepare({}).then(function () { + fail('unexpected failure handler invoked'); + }).fail(function (e) { + expect(e.message).toBe('preProcessOption error'); + expect(HooksRunner.prototype.fire).toHaveBeenCalledWith('before_prepare', jasmine.any(Object)); + }).done(done); }); - it('should invoke util.cdProjectRoot as a preflight task checker, which, if fails, should trigger a promise rejection and fire no hooks', function(done) { - spyOn(util, 'cdProjectRoot').and.throwError(); - prepare({}).fail(function(err) { - expect(err).toBeDefined(); - expect(HooksRunner.prototype.fire.calls.any()).toBe(false); - done(); + it('should invoke util.cdProjectRoot as a preflight task checker, which, if fails, should trigger a promise rejection and fire no hooks', function (done) { + util.cdProjectRoot.and.callFake(function () { + throw new Error('cdProjectRoot error'); }); + prepare({}).then(function () { + fail('unexpected failure handler invoked'); + }).fail(function (e) { + expect(e.message).toBe('cdProjectRoot error'); + expect(HooksRunner.prototype.fire).not.toHaveBeenCalledWith(); + }).done(done); }); }); describe('success', function () { - beforeEach(function () { - spyOn(util, 'cdProjectRoot').and.returnValue(project_dir); - spyOn(util, 'preProcessOptions').and.callFake(function(options) { - let platforms = options.platforms || []; - return {'platforms':platforms}; - }); - }); - it('should fire the before_prepare hook and provide platform and path information as arguments', function(done) { - prepare({}).then(function() { - expect(HooksRunner.prototype.fire.calls.argsFor(0)[0]).toEqual('before_prepare'); - done(); - }); + it('should fire the before_prepare hook and provide platform and path information as arguments', function (done) { + prepare({}).then(function () { + expect(HooksRunner.prototype.fire).toHaveBeenCalledWith('before_prepare', jasmine.any(Object)); + }).fail(function (e) { + fail('unexpected failure handler invoked'); + console.error(e); + }).done(done); }); - it('should invoke restore module\'s installPlatformsFromConfigXML method', function(done) { - prepare({}).then(function() { + it('should invoke restore module\'s installPlatformsFromConfigXML method', function (done) { + prepare({}).then(function () { expect(restore.installPlatformsFromConfigXML).toHaveBeenCalled(); - done(); - }).fail(function(err){ - expect(err).toBeUndefined(); - done(); - }); + }).fail(function (e) { + fail('unexpected failure handler invoked'); + console.error(e); + }).done(done); }); - it('should retrieve PlatformApi instances for each platform provided', function(done) { - prepare({'platforms':['android', 'ios']}).then(function() { - expect(platforms.getPlatformApi.calls.count()).toBe(4); - expect(platforms.getPlatformApi.calls.argsFor(0)[0]).toBe('android'); - expect(platforms.getPlatformApi.calls.argsFor(0)[1]).toBe('/some/path/platforms/android'); - expect(platforms.getPlatformApi.calls.argsFor(1)[0]).toBe('ios'); - expect(platforms.getPlatformApi.calls.argsFor(1)[1]).toBe('/some/path/platforms/ios'); - expect(platforms.getPlatformApi.calls.argsFor(2)[0]).toBe('android'); - expect(platforms.getPlatformApi.calls.argsFor(3)[0]).toBe('ios'); - done(); - }).fail(function(err){ - expect(err).toBeUndefined(); - done(); - }); + it('should retrieve PlatformApi instances for each platform provided', function (done) { + prepare({'platforms':['android', 'ios']}).then(function () { + expect(platforms.getPlatformApi).toHaveBeenCalledTimes(4); --- End diff -- O I didn't know this was available! --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org For additional commands, e-mail: dev-help@cordova.apache.org