env.test.ts27 lines · main
1import assert from 'node:assert/strict';
2import { Readable } from 'node:stream';
3import { describe, test } from 'node:test';
4
5import { readPipedLine } from './env.js';
6
7describe('readPipedLine (piped, non-TTY stdin)', () => {
8 test('resolves the piped value — `echo secret | briven env set KEY`', async () => {
9 // Stream ends right after the line, which synchronously triggers the
10 // readline "close". Before the fix this rejected "cancelled"; now the
11 // value must come through.
12 const input = Readable.from(['my-secret-value\n']);
13 const value = await readPipedLine(input);
14 assert.equal(value, 'my-secret-value');
15 });
16
17 test('resolves even when there is no trailing newline before EOF', async () => {
18 const input = Readable.from(['no-newline']);
19 const value = await readPipedLine(input);
20 assert.equal(value, 'no-newline');
21 });
22
23 test('rejects "cancelled" only when no line ever arrives (empty stdin)', async () => {
24 const input = Readable.from([]);
25 await assert.rejects(readPipedLine(input), /cancelled/);
26 });
27});