angular/jasminewd

An error in beforeAll which passes through done.fail and causes test process to halt

rishaselfing opened this issue · 0 comments

If you try to use protractor functions and some ES6 promises calls in single beforeAll you could encounter that if promise gets rejected an Error occurs in done.fail function which terminates test flow instead of failing suite.

 /usr/local/bin/node /usr/lib/node_modules/protractor/lib/cli.js test.conf.js
Starting selenium standalone server...
[launcher] Running 1 instances of WebDriver
Selenium standalone server started at http://127.0.0.1:50109/wd/hub
Started
[launcher] Process exited with error code 1

/usr/local/lib/node_modules/protractor/node_modules/jasminewd2/index.js:89
                var wrappedErr = new Error(err);
                                 ^
Error: done rejected
    at Function.proxyDone.fail (/usr/local/lib/node_modules/protractor/node_modules/jasminewd2/index.js:89:34)
    at /home/vagrant/WebstormProjects/untitled/test.js:7:53
    at process._tickCallback (node.js:368:9)

Process finished with exit code 1

Here is the sample code to reproduce an error:

describe ("describe", function() {
    beforeAll(function (done) {
        browser.sleep(10000); //some **long** protractor action
        Promise.reject("rejected").catch((err) => {done.fail("done " + err)}); //some promise chain with catch
    });

    it("dummy spec", function () {
        console.log("do something")
    });
});

While expected behavior is to get suite finished and failed. If you comment browser.sleep the result will be as expected

/usr/local/bin/node /usr/lib/node_modules/protractor/lib/cli.js test.conf.js
Starting selenium standalone server...
[launcher] Running 1 instances of WebDriver
Selenium standalone server started at http://172.17.0.3:65049/wd/hub
Started
do something
F

Failures:
1) describe dummy spec
  Message:
    Failed: done rejected
  Stack:
    Error: done rejected
        at /home/vagrant/WebstormProjects/untitled/test.js:7:57
        at process._tickCallback (node.js:368:9)
    From: Task: Run beforeAll in control flow
    From asynchronous test: 
    Error
        at Suite.<anonymous> (/home/vagrant/WebstormProjects/untitled/test.js:5:5)
        at Object.<anonymous> (/home/vagrant/WebstormProjects/untitled/test.js:4:1)

1 spec, 1 failure
Finished in 0.011 seconds

I understand that mixing protractor actions and es6 promises is not the best practice and could cause unexpected behavior, but maybe it is not only protractor + es6 issue.
node version v4.2.3
protractor 3.0.0.
jasminewd2: 0.0.8
jasmine: 2.4.1