# node-subunit

> Subunit stream I/O for Node

Latest version **0.0.2** (published 2016-06-08) · Apache-2.0 license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install node-subunit
pnpm add node-subunit
yarn add node-subunit
bun add node-subunit
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2016-06-08 |
| First published | 2016-05-27 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | OpenStack |
| Maintainers | timothyb89 |
| Keywords | subunit |

## Links

- npm: https://www.npmjs.com/package/node-subunit
- Repository: https://github.com/timothyb89/node-subunit
- Homepage: https://github.com/timothyb89/node-subunit#readme
- Issues: https://github.com/timothyb89/node-subunit/issues
- npm.io page: https://npm.io/package/node-subunit

## Dependencies (2)

- [bl](https://npm.io/package/bl.md) ^1.1.2
- [buffer-crc32](https://npm.io/package/buffer-crc32.md) ^0.2.5

## Recent versions

- 0.0.2 (latest) — 2016-06-08
- 0.0.1 — 2016-05-27

## README

node-subunit
============

Provides utilities for reading and writing
[Subunit streams](https://github.com/testing-cabal/subunit) 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](https://github.com/testing-cabal) namespace and renamed
to [subunit-js](https://github.com/testing-cabal/subunit-js). Future updates
will only occur in that repository.**

Installation
------------

    npm install --save node-subunit

Usage
-----
### Native Packet Format
Subunit packets are represented in JavaScript like so:
```javascript
{
    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`:

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

fs.createReadStream('testrepository.subunit')
    .pipe(new subunit.SubunitToObjectStream())
    .on('data', function(packet) {
      console.log(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:
```javascript
var fs = require('fs');
var subunit = require('./index.js');

var stream = subunit.ObjectToSubunitStream();
stream.pipe(fs.createWriteStream('./test1.subunit'));
stream.write({
  testId: 'TestyMcTestface',
  status: 'success',
  timestamp: new Date(),
  _packet: {
    flags: { runnable: true }
  }
});
```

... is equivalent to this (save for timestamps and thus the CRC):
```bash
subunit-output --success TestyMcTestface
```

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

```javascript
fs.createReadStream('testrepository.subunit')
    .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.

---
_Source: https://npm.io/package/node-subunit · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
