Skip to content

Commit

Permalink
Tests & docs: Stop relying on the exact output of a gzip stream
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed May 10, 2019
1 parent ebd74d9 commit 38c9fdd
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 191 deletions.
10 changes: 5 additions & 5 deletions documentation/assertions/Buffer/when-piped-through.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ It's intended to be used with the [to yield output satisfying](to-yield-output-s

```js#async:true
return expect(
Buffer.from([0x00, 0x01]),
'when piped through',
require('zlib').Gzip(),
'to yield output satisfying',
Buffer.from([
0x1f,
0x8b,
Expand All @@ -32,7 +28,11 @@ return expect(
0x00,
0x00,
0x00
])
]),
'when piped through',
require('zlib').Gunzip(),
'to yield output satisfying',
Buffer.from([0x00, 0x01])
);
```

Expand Down
25 changes: 13 additions & 12 deletions documentation/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,26 @@ Node.js stream plugin for the [Unexpected](https://unexpected.js.org/) assertion
[![Dependency Status](https://david-dm.org/unexpectedjs/unexpected-stream.svg)](https://david-dm.org/unexpectedjs/unexpected-stream)

```js#async:true
var base64Stream = require('base64-stream');
return expect(
['abc', 'def'],
['Zm9vYm', 'FyCg=='],
'when piped through',
require('zlib').Gzip(),
new base64Stream.Base64Decode(),
'to yield output satisfying',
Buffer.from([0x04, 0x08])
Buffer.from([0x66, 0x6f, 0x6f])
);
```

```output
expected [ 'abc', 'def' ]
when piped through Gzip to yield output satisfying Buffer.from([0x04, 0x08])
expected Gzip to yield output satisfying Buffer.from([0x04, 0x08])
expected Buffer.from([0x1F, 0x8B, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x4B, 0x4C, 0x4A, 0x4E, 0x49, 0x4D /* 10 more */ ])
to equal Buffer.from([0x04, 0x08])
-1F 8B 08 00 00 00 00 00 00 03 4B 4C 4A 4E 49 4D │..........KLJNIM│
-03 00 EF 39 8E 4B 06 00 00 00 │...9.K....│
+04 08 │..│
expected [ 'Zm9vYm', 'FyCg==' ]
when piped through Base64Decode to yield output satisfying Buffer.from([0x66, 0x6F, 0x6F])
expected Base64Decode to yield output satisfying Buffer.from([0x66, 0x6F, 0x6F])
expected Buffer.from([0x66, 0x6F, 0x6F, 0x62, 0x61, 0x72, 0x0A])
to equal Buffer.from([0x66, 0x6F, 0x6F])
-66 6F 6F 62 61 72 0A │foobar.│
+66 6F 6F │foo│
```

```js#async:true
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"unexpected": "10 || ^11.0.0"
},
"devDependencies": {
"base64-stream": "^1.0.0",
"coveralls": "^3.0.0",
"eslint": "^5.0.0",
"eslint-config-prettier": "^4.1.0",
Expand Down
212 changes: 38 additions & 174 deletions test/unexpectedStream.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
/* global describe, it, setImmediate, __dirname */
const unexpected = require('unexpected');

const pathModule = require('path');

const streamModule = require('stream');

const EventEmitter = require('events').EventEmitter;

const fs = require('fs');

const zlib = require('zlib');
const { Base64Encode } = require('base64-stream');

describe('unexpected-stream', () => {
const expect = unexpected
Expand Down Expand Up @@ -161,41 +157,9 @@ describe('unexpected-stream', () => {
expect(
fs.createReadStream(fooTxtPath),
'when piped through',
zlib.createGzip(),
'to yield output satisfying',
Buffer.from([
0x1f,
0x8b,
0x08,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x03,
0x4b,
0xcb,
0xcf,
0x4f,
0x4a,
0x2c,
0x2a,
0x2c,
0x2d,
0xad,
0xe0,
0x02,
0x00,
0xc8,
0x99,
0x6f,
0x44,
0x0b,
0x00,
0x00,
0x00
])
new Base64Encode(),
'to yield output satisfying to equal',
'Zm9vYmFycXV1eAo='
));

it('should pipe the data through multiple proxy streams', () =>
Expand All @@ -210,10 +174,6 @@ describe('unexpected-stream', () => {
describe('with a Buffer instance', () => {
it('should succeed', () =>
expect(
Buffer.from('foobarquux\n', 'utf-8'),
'when piped through',
zlib.createGzip(),
'to yield output satisfying',
Buffer.from([
0x1f,
0x8b,
Expand Down Expand Up @@ -246,16 +206,16 @@ describe('unexpected-stream', () => {
0x00,
0x00,
0x00
])
]),
'when piped through',
zlib.createGunzip(),
'to yield output satisfying',
Buffer.from('foobarquux\n', 'utf-8')
));

it('fails with a diff', () =>
expect(
expect(
Buffer.from('foobarqux', 'utf-8'),
'when piped through',
zlib.createGzip(),
'to yield output satisfying',
Buffer.from([
0x1f,
0x8b,
Expand Down Expand Up @@ -288,19 +248,21 @@ describe('unexpected-stream', () => {
0x00,
0x00,
0x00
])
]),
'when piped through',
zlib.createGunzip(),
'to yield output satisfying',
Buffer.from('foobarqux', 'utf-8')
),
'to be rejected with',
'expected Buffer.from([0x66, 0x6F, 0x6F, 0x62, 0x61, 0x72, 0x71, 0x75, 0x78])\n' +
'when piped through Gzip to yield output satisfying Buffer.from([0x1F, 0x8B, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x4B, 0xCB, 0xCF, 0x4F, 0x4A, 0x2C /* 15 more */ ])\n' +
' expected Gzip\n' +
' to yield output satisfying Buffer.from([0x1F, 0x8B, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x4B, 0xCB, 0xCF, 0x4F, 0x4A, 0x2C /* 15 more */ ])\n' +
' expected Buffer.from([0x1F, 0x8B, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x4B, 0xCB, 0xCF, 0x4F, 0x4A, 0x2C /* 13 more */ ])\n' +
' to equal Buffer.from([0x1F, 0x8B, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x4B, 0xCB, 0xCF, 0x4F, 0x4A, 0x2C /* 15 more */ ])\n' +
'expected Buffer.from([0x1F, 0x8B, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x4B, 0xCB, 0xCF, 0x4F, 0x4A, 0x2C /* 15 more */ ])\n' +
'when piped through Gunzip to yield output satisfying Buffer.from([0x66, 0x6F, 0x6F, 0x62, 0x61, 0x72, 0x71, 0x75, 0x78])\n' +
' expected Gunzip to yield output satisfying Buffer.from([0x66, 0x6F, 0x6F, 0x62, 0x61, 0x72, 0x71, 0x75, 0x78])\n' +
' expected Buffer.from([0x66, 0x6F, 0x6F, 0x62, 0x61, 0x72, 0x71, 0x75, 0x75, 0x78, 0x0A])\n' +
' to equal Buffer.from([0x66, 0x6F, 0x6F, 0x62, 0x61, 0x72, 0x71, 0x75, 0x78])\n' +
'\n' +
' 1F 8B 08 00 00 00 00 00 00 03 4B CB CF 4F 4A 2C │..........K..OJ,│\n' +
' -2A 2C AD 00 00 FA 8C B8 C4 09 00 00 00 │*,...........│\n' +
' +2A 2C 2D AD E0 02 00 C8 99 6F 44 0B 00 00 00 │*,-......oD....│'
' -66 6F 6F 62 61 72 71 75 75 78 0A │foobarquux.│\n' +
' +66 6F 6F 62 61 72 71 75 78 │foobarqux│'
));
});

Expand All @@ -309,41 +271,9 @@ describe('unexpected-stream', () => {
expect(
'foobarquux\n',
'when piped through',
zlib.createGzip(),
'to yield output satisfying',
Buffer.from([
0x1f,
0x8b,
0x08,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x03,
0x4b,
0xcb,
0xcf,
0x4f,
0x4a,
0x2c,
0x2a,
0x2c,
0x2d,
0xad,
0xe0,
0x02,
0x00,
0xc8,
0x99,
0x6f,
0x44,
0x0b,
0x00,
0x00,
0x00
])
new Base64Encode(),
'to yield output satisfying to equal',
'Zm9vYmFycXV1eAo='
));
});

Expand All @@ -352,61 +282,27 @@ describe('unexpected-stream', () => {
expect(
['foo', 'bar', 'quux\n'],
'when piped through',
zlib.createGzip(),
'to yield output satisfying',
Buffer.from([
0x1f,
0x8b,
0x08,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x03,
0x4b,
0xcb,
0xcf,
0x4f,
0x4a,
0x2c,
0x2a,
0x2c,
0x2d,
0xad,
0xe0,
0x02,
0x00,
0xc8,
0x99,
0x6f,
0x44,
0x0b,
0x00,
0x00,
0x00
])
new Base64Encode(),
'to yield output satisfying to equal',
'Zm9vYmFycXV1eAo='
));

it('fails with a diff', () =>
expect(
expect(
['f', 'oo'],
'when piped through',
zlib.createGzip(),
'to yield output satisfying',
Buffer.from([0x03, 0x4b, 0xcb, 0xcf, 0x4f, 0x4a, 0x2c])
new Base64Encode(),
'to yield output satisfying to equal',
'blah'
),
'to be rejected with',
"expected [ 'f', 'oo' ] when piped through Gzip to yield output satisfying Buffer.from([0x03, 0x4B, 0xCB, 0xCF, 0x4F, 0x4A, 0x2C])\n" +
' expected Gzip to yield output satisfying Buffer.from([0x03, 0x4B, 0xCB, 0xCF, 0x4F, 0x4A, 0x2C])\n' +
' expected Buffer.from([0x1F, 0x8B, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x4B, 0xCB, 0xCF, 0x07, 0x00, 0x21 /* 7 more */ ])\n' +
' to equal Buffer.from([0x03, 0x4B, 0xCB, 0xCF, 0x4F, 0x4A, 0x2C])\n' +
"expected [ 'f', 'oo' ] when piped through Base64Encode to yield output satisfying to equal 'blah'\n" +
" expected Base64Encode to yield output satisfying to equal 'blah'\n" +
" expected 'Zm9v' to equal 'blah'\n" +
'\n' +
' -1F 8B 08 00 00 00 00 00 00 03 4B CB CF 07 00 21 │..........K....!│\n' +
' -65 73 8C 03 00 00 00 │es.....│\n' +
' +03 4B CB CF 4F 4A 2C │.K..OJ,│'
' -Zm9v\n' +
' +blah'
));
});

Expand All @@ -419,41 +315,9 @@ describe('unexpected-stream', () => {
Buffer.from('quux\n', 'utf-8')
],
'when piped through',
zlib.createGzip(),
'to yield output satisfying',
Buffer.from([
0x1f,
0x8b,
0x08,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x03,
0x4b,
0xcb,
0xcf,
0x4f,
0x4a,
0x2c,
0x2a,
0x2c,
0x2d,
0xad,
0xe0,
0x02,
0x00,
0xc8,
0x99,
0x6f,
0x44,
0x0b,
0x00,
0x00,
0x00
])
new Base64Encode(),
'to yield output satisfying to equal',
'Zm9vYmFycXV1eAo='
));
});

Expand Down

0 comments on commit 38c9fdd

Please sign in to comment.