Server-Sent Event Test Suite
This page links to a series of test cases for the W3C Server-Sent Event Specification. It is organised by section, and (more or less) categorizes each test according to which statement in the specification it relates to.
The tests are designed to be run manually.
The web server work with Node.js. Few scripts (as 'Test 0077') need to stop and relaunch manually the web server. To try these tests, you can download the sse.js script and test using Node.js on your own server or computer. Don't forget to edit url argument of EventSource object.
When the EventSource() constructor is invoked, the UA must run these steps:
Test 0001: Resolve the URL specified in the first argument. If the previous step failed, then throw a SyntaxError exception.
Test 0002: Create a new EventSource object. Check if the object is of type EventSource.
The url attribute must return the absolute URL that resulted from resolving the value that was passed to the constructor.
Test 0012: check if the url attribute is the absolute url.
The withCredentials attribute must return the value to which it was last initialized. When the object is created, it must be initialized to false.
(no test...): create EventSource with withCredentials attribute to true, check if the withCredentials attribute is set to true after initialized it.
The readyState attribute represents the state of the connection. It can have the following values: 0 (CONNECTING), 1 (OPEN), 2 (CLOSED).
Test 0016: check the readyState attribute for each state of the connection.
The close() method must abort any instances of the fetch algorithm started for this EventSource object, and must set the readyState attribute to CLOSED.
Test 0022: call close() method, check if the EventSource is abort.
The event handlers (onopen, onmessage, onerror) must be supported, as IDL attributes, by all objects implementing the EventSource interface.
Test 0025: check the support of onopen, onmessage, onerror event handlers.
For HTTP connections, the Accept header may be included; if included, it must contain only formats of event framing that are supported by the user agent (one of which must be text/event-stream, as described below).
Test 0030: check if the Accept header include 'text/event-stream'.
When a user agent is to announce the connection, the user agent must queue a task which, if the readyState attribute is set to a value other than CLOSED, sets the readyState attribute to OPEN and fires a simple event named open at the EventSource object.
Test 0051: check the readyState attribute and the event 'open'.
Please send feedback, error reports, or new tests to email@example.com
Lines must be processed, in the order they are received, as follows:
(no test): If the line is empty (a blank line) dispatch the event, as defined below.
Test 0071: If the line starts with a U+003A COLON character, ignore the line.
Test 0072: If the line contains a U+003A COLON character (:), collect the characters on the line before the first (:), and let field be that string, collect the characters on the line after the first (:), and let value be that string. If value starts with a U+0020 SPACE character, remove it from value.
The steps to process the field given a field name and a field value depend on the field name, as given in the following list. Field names must be compared literally, with no case folding performed:
Test 0074: If the field name is "event": set the event name buffer to field value.
Test 0075: If the field name is "data": append the field value to the data buffer, then append a single U+000A LINE FEED (LF) character to the data buffer.
Test 0076: If the field name is "id": set the last event ID buffer to the field value.
Test 0077 (view source code only): If the field name is "retry": if the field value consists of only characters in the range U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9), then interpret the field value as an integer in base ten, and set the event stream's reconnection time to that integer. Otherwise, ignore the field.
Test 0078: Otherwise: the field is ignored.