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

前端 未结 3 543
盖世英雄少女心
盖世英雄少女心 2021-01-26 01:32

We are facing an issue while running karma test cases with phantomJs our phantomJs crashes and gets disconnected. Is that due to memory leakage or some other issue.Kindly let

相关标签:
3条回答
  • 2021-01-26 02: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.
    0 讨论(0)
  • 2021-01-26 02:10

    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

    0 讨论(0)
  • 2021-01-26 02:22

    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.

    0 讨论(0)
提交回复
热议问题