21 lines
437 B
JavaScript
21 lines
437 B
JavaScript
import test from 'node:test';
|
|
import { Readable } from 'node:stream';
|
|
|
|
test('planning with streams', (t, done) => {
|
|
function* generate() {
|
|
yield 'a';
|
|
yield 'b';
|
|
yield 'c';
|
|
}
|
|
const expected = ['a', 'b', 'c'];
|
|
t.plan(expected.length);
|
|
const stream = Readable.from(generate());
|
|
stream.on('data', (chunk) => {
|
|
t.assert.strictEqual(chunk, expected.shift());
|
|
});
|
|
|
|
stream.on('end', () => {
|
|
done();
|
|
});
|
|
});
|