Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add high-level tests #76

Merged
merged 1 commit into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -139,6 +142,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