Skip to content

Commit

Permalink
Fix the ignoreStream tests for Node.js v14.
Browse files Browse the repository at this point in the history
  • Loading branch information
krasivyy3954 committed May 25, 2020
1 parent 0847ecb commit 2733ecb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.md
Expand Up @@ -14,6 +14,7 @@
- Configured Prettier option `semi` to the default, `true`.
- Ensure GitHub Actions run on pull request.
- Also run GitHub Actions with Node.js v14.
- Fixed the `ignoreStream` function tests for Node.js v14 with a new `CountReadableStream` test helper, fixing [#209](https://github.com/jaydenseric/graphql-upload/issues/209).
- Minor JSDoc wording tweak for consistency.

## 10.0.0
Expand Down
23 changes: 23 additions & 0 deletions test/CountReadableStream.js
@@ -0,0 +1,23 @@
'use strict';

const { Readable } = require('stream');

/**
* A count readable stream, for testing purposes.
* @kind class
* @name CountReadableStream
* @see [Example counting stream in the Node.js docs](https://nodejs.org/api/stream.html#stream_an_example_counting_stream).
* @ignore
*/
module.exports = class CountReadableStream extends Readable {
constructor(options) {
super(options);
this._max = 1000000;
this._index = 1;
}

_read() {
const i = this._index++;
this.push(i > this._max ? null : Buffer.from(String(i), 'ascii'));
}
};
6 changes: 3 additions & 3 deletions test/lib/ignoreStream.test.js
@@ -1,20 +1,20 @@
'use strict';

const { doesNotThrow, strictEqual } = require('assert');
const { Readable } = require('stream');
const ignoreStream = require('../../lib/ignoreStream');
const CountReadableStream = require('../CountReadableStream');

module.exports = (tests) => {
tests.add('`ignoreStream` ignores errors.', () => {
doesNotThrow(() => {
const stream = new Readable();
const stream = new CountReadableStream();
ignoreStream(stream);
stream.emit('error', new Error('Message.'));
});
});

tests.add('`ignoreStream` resumes a paused stream.', () => {
const stream = new Readable();
const stream = new CountReadableStream();
stream.pause();
ignoreStream(stream);
strictEqual(stream.isPaused(), false);
Expand Down

0 comments on commit 2733ecb

Please sign in to comment.