PhantomJs Crashes while running with grunt-karma test cases ????/

岁酱吖の 提交于 2019-12-02 10:23:02

There are two reasons I found that this can happen.

  1. PhantomJS does not release memory until its tab is closed so if your test suite is too large, you could be running out of memory.
  2. karma-phantomjs-launcher & karma-phantomjs2-launcher do not hook the stdout/stderr output for their started browser process and so I've seen some instances that the started browser just hangs and gets disconnected, most likely due to its stderr output getting filled up

The first problem can be worked around by splitting your test suite into smaller ones. Or, you could research if there is perhaps a way to tell PhantomJS to run its JavaScript garbage collection, but I have not gone down that road so can't provide much more detail there.

The second problem can be fixed by:

  1. using the latest karma-phantomjs-launcher version that hooks browser the stdout/stderr output (fixed in version 0.2.1)
  2. using a version of karma-phantomjs2-launcher from its pull request #5 which brings in upstream changes from the base karma-phantomJS-launcher project and thus resolves the problem here as well.

I had the same kind of issue with handling random crashes. Though i did not find a way to avoid them, there is the possibility to restart the grunt-task upon a crash.

grunt.registerTask('karma-with-retry', function (opt) {
var done = this.async();
var count = 0;
var retry = function () {
    grunt.util.spawn({
        cmd : "grunt",
        args : ["connect", "karma"], // your tasks
        opts: {
            stdio: 'inherit'
        }
    }, function (error, result, code) {
        count++;
        if (error && code === 90 /* Replace with code thrown by karma */) {
            if(count < 5) {
                grunt.log.writeln("Retrying karma tests upon error: " + code );
                retry();
            } else {
                done(false);
            }
        } else {
            done(result);
        }
   });
}
retry();
});

Source https://github.com/ariya/phantomjs/issues/12325#issuecomment-56246505

I was getting Phantom crashed when asserting the following line

dom.should.be.instanceof(HTMLCollection);

Worked on chrome, but phantom was crashing without any useful error message. I've been able to see the real error message after running the same test on PhantomJS_debug browser with debug option set to true.

The following error message started showing up.

The instanceof assertion needs a constructor but object was given.

Instead of

PhantomJS has crashed. Please read the bug reporting guide at
<http://phantomjs.org/bug-reporting.html> and file a bug report.

So chrome was ok with the assertion but phantom 2.1.1 is crashing with the above error. Hope this will help.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!