Skip to content

Commit

Permalink
Add high-level tests (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky authored Aug 9, 2023
1 parent 0db94f1 commit bca1b28
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions fixture
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
unicorn
19 changes: 19 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import {Buffer, constants as BufferConstants} from 'node:buffer';
import {setTimeout} from 'node:timers/promises';
import {spawn} from 'node:child_process';
import {createReadStream} from 'node:fs';
import {version as nodeVersion} from 'node:process';
import {Duplex} from 'node:stream';
import {text, buffer} from 'node:stream/consumers';
import test from 'ava';
Expand Down Expand Up @@ -158,6 +161,22 @@ test('Throws if the first argument is null', firstArgumentCheck, null);
test('Throws if the first argument is a string', firstArgumentCheck, '');
test('Throws if the first argument is an array', firstArgumentCheck, []);

test('works with createReadStream() and buffers', async t => {
const result = await getStreamAsBuffer(createReadStream('fixture'));
t.true(result.equals(fixtureBuffer));
});

test('works with createReadStream() and utf8', async t => {
const result = await getStream(createReadStream('fixture', 'utf8'));
t.is(result, fixtureString);
});

test('works with child_process.spawn()', async t => {
const {stdout} = spawn('node', ['--version'], {stdio: ['ignore', 'pipe', 'ignore']});
const result = await getStream(stdout);
t.is(result.trim(), nodeVersion);
});

test('native string', async t => {
const result = await text(createStream(fixtureString));
t.is(result, fixtureString);
Expand Down

0 comments on commit bca1b28

Please sign in to comment.