0

I am learning about PhantomJS and immediatelly found problem.
I want to test exit code but seems that phantomjs ignores it. Here is my code:

//say hello
console.log("Hello world");

//exit PhantomJS
phantom.exit(1);

In given example I expect to see message "FAIL" in the console but whatever I pass output is the same .. only "Hello world" is displaued.

I am using windows 7 with phantomjs version 2.1.1

gandra404
  • 5,727
  • 10
  • 52
  • 76

1 Answers1

1

PhantomJS doesn't print anything if it is exited regardless of exit code. If you want to write to the console in case of an error, you can use a simple console.log("FAIL") before calling phantom.exit(1).

On Windows you can also check the exit code of the previously executed program:

$ echo %errorlevel%
0
$ phantomjs
> phantom.exit(42)
$ echo %errorlevel%
42

See this question for more information on the exit code.

Community
  • 1
  • 1
Artjom B.
  • 61,146
  • 24
  • 125
  • 222