3

I am having an issue running Testcafe through cucumber. for whatever reason, When I run testCafe through cucumber, the process will always exit with exit code 0 even in the test fails.

If I run puppeteer through cucumber I don't get this issue. I am thinking that this behavior is due to the way I have things set up in my hooks file where I am not properly interpreting the test cafe exit code.

In my hooks file, I am creating a testCafe runner and in my Before hook and then closing it during my after hook.

I am wondering what command I could use to get the TestCafe exit code, and I haven't been able to find any info on this.

For example, is the exit code returned from the close function or what?

Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47
switch201
  • 587
  • 1
  • 4
  • 16

1 Answers1

5

TestCafe API does not call the process.exit method since it should work inside custom node scripts.

TestCafe calls process.exit only in CLI.

I suppose that you want to get information about failed tests in API. The runner.run method returns this information. Please see the following example:

const createTestCafe = require('testcafe');
let runner           = null;
let tc               = null;

createTestCafe('localhost', 1337, 1338)
    .then(testcafe => {
        tc     = testcafe;
        runner = tc.createRunner();
    })
    .then(() => {
        return runner
            .src('...')
            .browsers('chrome')
            .run();
    })
    .then(failedCount => {
        console.log(failedCount)

        return tc.close();
    });

Here, you can call process.exit if you find that failedCount > 0;

Dmitry Ostashev
  • 2,305
  • 1
  • 5
  • 21
Alex Kamaev
  • 6,198
  • 1
  • 14
  • 29
  • 1
    Thanks. I will try this out when I get a chance and come back here to update – switch201 Jul 18 '19 at 17:24
  • I know its been like 2 months but I still haven't gotten around to trying this out... just got side tracked with other things, but I can still accept it as the answer (since its likely the only one I will get at this point) thanks again, and I will come back and and leave a comment if something doesn't work when I try it – switch201 Sep 06 '19 at 20:00