Subunit stream I/O for Node

Usage no npm install needed!

<script type="module">
  import nodeSubunit from '';



Provides utilities for reading and writing Subunit streams with Node.js, targeting Node versions 0.10 (pre-packaged on Ubuntu Trusty) and higher.

WARNING: This package has been moved into the testing-cabal namespace and renamed to subunit-js. Future updates will only occur in that repository.


npm install --save node-subunit


Native Packet Format

Subunit packets are represented in JavaScript like so:

    timestamp: <Date>,
    testId: <string>,
    tags: <string[]>,
    mime: <string>,
    fileContent: <Buffer>,
    fileName: <string>,
    routingCode: <string>,
    status: <string>
    _packet: {
        length: <number>
        flags: {
            testId: <boolean>,
            routeCode: <boolean>,
            timestamp: <boolean>,
            runnable: <boolean>,
            tags: <boolean>,
            mimeType: <boolean,
            eof: <boolean>,
            fileContent: <boolean>

Note that true entries in _packet.flags generally imply an associated field of the same name, except for runnable and eof. All fields (except _packet) are optional and, when read, will be undefined if not included in the original bytes. The status field is a bit special in that it

Reading with SubunitToObjectStream

SubunitToObjectStream is a transform stream that accepts Subunit bytes and outputs objects as described above. To read a file testrepository.subunit:

var fs = require('fs');
var subunit = require('node-subunit');

    .pipe(new subunit.SubunitToObjectStream())
    .on('data', function(packet) {

Writing with ObjectToSubunitStream

The ObjectToSubunitStream is also a transform stream, but it accepts objects as formatted above and outputs Subunit-compatible bytes.

A few notes:

  • Flag masks for the status field will be looked up automatically based on its string value (e.g. success, skip, fail, etc)
  • Values in _packet are ignored, except for flags.runnable and flags.eof. These flag masks will automatically be added based on the defined values in the packet object.

As an example, this code:

var fs = require('fs');
var subunit = require('./index.js');

var stream = subunit.ObjectToSubunitStream();
  testId: 'TestyMcTestface',
  status: 'success',
  timestamp: new Date(),
  _packet: {
    flags: { runnable: true }

... is equivalent to this (save for timestamps and thus the CRC):

subunit-output --success TestyMcTestface


The streams are mostly idempotent, so they can be chained together (and perhaps mutated along the way). However, note the following:

    .pipe(new subunit.SubunitToObjectStream())
    .on('data', function(d) {
      console.log('<-', d.timestamp);
    .pipe(new subunit.ObjectToSubunitStream())
    .pipe(new subunit.SubunitToObjectStream())
    .on('data', function(d) {
        console.log('->', d.timestamp);

If you run this code, you might notice timestamps change (though the result should otherwise be bit-identical). Since JavaScript Date values don't have nanosecond resolution, timestamp values will be rounded down to the nearest millisecond when read initially. This generally isn't noticeable, but may lead to some unexpected trouble in some situations.