The JSON reporter

The JSON reporter is especially versatile. Since it produces a literal
serialization of the reporter event stream, it can be used to transport reporter
events to another process and format them there. For example, say we build a
WebSocket server that, when a new connection is made, runs our example test
suite as a child process using the json format, and pipes the
output into the socket.

For example if you open a connection to ws://localhost:8888/?test=foo this
server will run this process:

This will send a stream of messages over the WebSocket with the format:

{"jstest": [eventType, data]}

jstest includes a class called JS.Test.Reporters.JSON.Reader, whose job is
to process this stream of messages and use them to notify another reporter. We
could use it to accept the data from the WebSocket and display the test
results in the browser, like this:

If you open this page, it will open a WebSocket, which will trigger a test
run. The socket will receive the test output as a JSON stream, which it hands
off to the JSON.Reader, which displays the results with the Browser
reporter. Now you can selectively run your server-side tests from the browser!

You can do a similar thing to send browser results to the terminal by overriding
where the JSON reporter writes output to. When you run your tests, try this: