gruntjs / grunt-contrib-jasmine

Run jasmine specs headlessly through Headless Chrome
http://gruntjs.com/
MIT License
354 stars 197 forks source link

PhantomJS timed out, possibly due to an unfinished async spec #183

Closed vladisakov88 closed 8 years ago

vladisakov88 commented 9 years ago

I am trying to integrate 'jasmine' with 'grunt' using 'grunt-contrib-jasmine' like so:

grunt.initConfig({
jasmine: {
    pivotal: {
        src: ['app/js/routers/*.js', 'app/js/models/task.js', 'app/js/models/*.js', 'app/js/views/*.js'],
        options: {
            specs: 'test/spec/**/*.js',
            vendor: [
                'app/bower_components/jquery/dist/jquery.js',
                'app/bower_components/underscore/underscore.js',
                'app/bower_components/backbone/backbone.js',
                'app/bower_components/handlebars/handlebars.js',
                'app/bower_components/bootstrap/dist/js/bootstrap.js',
                'app/bower_components/moment/moment.js',
                'app/bower_components/datetimepicker/jquery.datetimepicker.js',
                'app/bower_components/backbone-tastypie/backbone_tastypie/static/js/backbone-tastypie.js',
                'app/bower_components/bootstrap-multiselect/dist/js/bootstrap-multiselect.js',
                'app/bower_components/bootstrap-select/dist/js/bootstrap-select.js',
                'test/jasmine-1.2.0/jasmine.js',
                'test/jasmine-1.2.0/jasmine-html.js',
                'test/sinon.js'
            ]
        }
    }
}
});

grunt.loadNpmTasks('grunt-contrib-jasmine');

grunt.registerTask("test", ["jasmine"]);

And that's what I am getting :

//*TERMINAL***//

c:\some-dir>grunt test

Running "jasmine:pivotal" (jasmine) task

Testing jasmine specs via PhantomJS

Warning: PhantomJS timed out, possibly due to an unfinished async spec. Use --force to continue.

Aborted due to warnings.

c:\some-dir>

//*END OF TERMINAL***//

I really don't get it, I tried a lots of things.....

gyandeeps commented 9 years ago

Why are you supplying jasmine files under the vendor collection? What kind of test you have in your test files, can u give an example.

vladisakov88 commented 9 years ago

I supplying them because if I delete them I get a lots of errors like those: x should call 'select_time_filter' when target is clicked TypeError: 'undefined' is not a function (evaluating 'this.addMatchers') in file:///C:/xxxx/xxxx/test/spec/router/routerSpec.js (line 6) (1) Error: You must pass a string or Handlebars AST to Handlebars.compile.You passed undefined in file:///C:/xxxx/xxxx/app/bower_components/handlebars/handlebars.js (line2003) (2) Error: spyOn could not find an object to spy upon for select_time_filter() in file:///C:/xxxx/xxxx/.grunt/grunt-contrib-jasmine/jasmine.js (line 1858) (3)...

I am actually changed the src to be the 'SpecRunner.html' and deleted the jasmine files under vendor:

jasmine: {
        test: {
            src: 'test/SpecRunner.html',
            options: {
                vendor: [
                    'app/bower_components/jquery/dist/jquery.js',
                    'app/bower_components/underscore/underscore.js',
                    'app/bower_components/backbone/backbone.js',
                    'app/bower_components/handlebars/handlebars.js',
                    'app/bower_components/bootstrap/dist/js/bootstrap.js',
                    'app/bower_components/moment/moment.js',
                    'app/bower_components/datetimepicker/jquery.datetimepicker.js',
                    'app/bower_components/backbone-tastypie/backbone_tastypie/static/js/backbone-tastypie.js',
                    'app/bower_components/bootstrap-multiselect/dist/js/bootstrap-multiselect.js',
                    'app/bower_components/bootstrap-select/dist/js/bootstrap-select.js',

                ],
                specs: 'test/spec/**/*.js'
            }
        }
    }

and now I am also getting a lots of errors like those: x should call 'select_time_filter' when target is clicked TypeError: 'undefined' is not a function (evaluating 'this.addMatchers') in file:///C:/xxxx/xxxx/test/spec/router/routerSpec.js (line 6) (1) ReferenceError: Can't find variable: Cellomat in file:///C:/xxxx/xxxx/test/spec/view/taskSelectionViewSpec.js (line 6) (2) Error: spyOn could not find an object to spy upon for select_time_filter() in file:///C:/xxxx/xxxx/.grunt/grunt-contrib-jasmine/jasmine.js (line 1858) (3)

Example to test:

(function() {
describe("Task Selection View:", function () {
    var taskSelectionView;
    var selectorModel;
    beforeEach(function () {
        selectorModel = new xxxx.Models.TaskSelector();
        taskSelectionView = new xxxx.Views.TaskSelectionView({model: selectorModel});
    });

    describe("Instantiation:", function () {

        it("should have class name 'row-fluid'", function () {
            expect(taskSelectionView.el.className).toEqual("row-fluid");
        });
        it("should have element 'DIV'", function () {
            expect(taskSelectionView.el.tagName).toEqual("DIV");
        });
    });

    describe('Initialize:', function () {
        it("should create template", function () {
            expect(taskSelectionView.template).toBeDefined();
        });
        it("should create CustomTimeView", function () {
            expect(taskSelectionView.customTimeView).toBeDefined();
        });
    });

    describe("Render:", function() {
        it ("should produces the correct HTML", function() {
            taskSelectionView.render();
            expect($(taskSelectionView.el).children().eq(0).children().attr('id')).toBe('timeSelectList');
            expect($(taskSelectionView.el).children().eq(0).children().eq(1).hasClass('dropdown-menu')).toBe(true);
            expect($(taskSelectionView.el).children().eq(1).children().attr('id')).toBe('levelSelect');
        });
    });

    describe('Event:', function () {
        it("should call 'select_time_filter' when target is clicked", function() {
            spyOn(taskSelectionView,'select_time_filter');
            taskSelectionView.delegateEvents();
            var time = $(".time", taskSelectionView.render().el);
            time.click();
            expect(taskSelectionView.select_time_filter).toHaveBeenCalled()
        });

    });

});
})();

Thank you for your efforts.....

gyandeeps commented 9 years ago

In the above case, src: 'test/SpecRunner.html', this is wrong. You want to keep config settings how you have it on top in your question but just remove jasmine references inside your vendor collection. Secondly, why have you wrapped all the test inside a self-executing anonymous function? Please remove that and then try it.

DenEwout commented 9 years ago

I'm having a similar issue. I provide my grunt configuration below:

        jasmine: {
            unittests: {
                src: 'target/js/script.js',
                options: {
                    specs: 'target/test/suiteSpec.js',
                    vendor: [
                        'target/lib/es6-promise/promise.js',
                        'target/lib/jquery/jquery.js',
                        'target/lib/jquery-ui/jquery-ui.js',
                        'target/lib/jqueryui-touch-punch/jquery.ui.touch-punch.min.js',
                        'target/lib/bootstrap/js/bootstrap.js',
                        'target/lib/bootstrap-tabdrop/bootstrap-tabdrop.js',
                        'target/lib/knockout/js/knockout.debug.js',
                        'target/lib/knockout-switch-case/knockout-switch-case.min.js',
                        'target/lib/knockstrap/knockstrap.js',
                        'target/lib/underscore/underscore.js',
                        'target/lib/backbone/backbone.js',
                        'target/lib/lodash/lodash.compat.js',
                        'target/lib/jointjs/geometry.js',
                        'target/lib/jointjs/vectorizer.js',
                        'target/lib/jointjs/joint.clean.js',
                        'target/js/ko-selectable-extender.js'
                    ]
                }
            }
        }
rjmacarthy commented 9 years ago

I am having similar issues.

mayainle commented 8 years ago

I am getting this issue too. After running npm install and running my tests afterwards I get this warning. When I install the grunt-contrib-jasmine version 0.6.5 the test run well again. The warning starts with 7.0.0. Any idea?