File: test-buffer.js

package info (click to toggle)
node-get-stdin 8.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 164 kB
  • sloc: javascript: 136; makefile: 2
file content (22 lines) | stat: -rw-r--r-- 580 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import {serial as test} from 'ava';
import delay from 'delay';
import getStdin from '.';

test('get stdin', async t => {
	process.stdin.isTTY = false;

	const promise = getStdin.buffer();
	process.stdin.push(Buffer.from('uni'));
	process.stdin.push(Buffer.from('corns'));
	await delay(1);
	process.stdin.emit('end');

	const data = await promise;
	t.true(data.equals(Buffer.from('unicorns')));
	t.is(data.toString(), 'unicorns');
});

test('get empty buffer when no stdin', async t => {
	process.stdin.isTTY = true;
	t.true((await getStdin.buffer()).equals(Buffer.from('')));
});