[ 
https://issues.apache.org/jira/browse/CB-12361?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16059295#comment-16059295
 ] 

ASF GitHub Bot commented on CB-12361:
-------------------------------------

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!


> Speed up cordova-lib tests
> --------------------------
>
>                 Key: CB-12361
>                 URL: https://issues.apache.org/jira/browse/CB-12361
>             Project: Apache Cordova
>          Issue Type: Improvement
>          Components: cordova-lib
>            Reporter: Steve Gill
>            Assignee: Steve Gill
>              Labels: cordova-next
>
> * Split out e2e tests into own folder
> * stub i/o and network requests
> * use local fixtures when possible & makes sense



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to