The plan: Wrap cypress in a script that watches its output, kills the process when cypress is done.
We'll need to capture the line Failures: 0
or Failures: 5
in order for the wrapper script to produce an appropriate exit code. That is, it should sys.exit(0)
if all tests passed, and sys.exit(1)
if any failed.
Here we run into a bit of a problem: The ANSI escape codes that Cypress uses to color it's output include numbers to specify the color. For example, green text is prepended with \e[30m
. Even though these color codes aren't visible in the terminal, pexpect can see them, and thinks that they are the number of failed tests. So we need to strip out all color codes prior to pexpect seeing the output. That's the perl one-liner in the script.
Make sure you pip install pexpect
on your CI server.