Skip to content

Commit

Permalink
Fix stream to observable mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
SamVerschueren committed Oct 24, 2017
1 parent 5c3392e commit 33bae7c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -53,7 +53,7 @@
"ora": "^0.2.3",
"p-map": "^1.1.1",
"rxjs": "^5.4.2",
"stream-to-observable": "^0.1.0",
"stream-to-observable": "^0.2.0",
"strip-ansi": "^3.0.1"
},
"devDependencies": {
Expand All @@ -65,6 +65,7 @@
"lint-staged": "^3.3.1",
"nyc": "^8.3.2",
"pre-commit": "^1.2.2",
"split": "^1.0.1",
"xo": "*",
"zen-observable": "^0.3.0"
},
Expand Down
14 changes: 13 additions & 1 deletion readme.md
Expand Up @@ -146,8 +146,20 @@ const tasks = new Listr([

### Streams

It's also possible to return a `stream`. The stream will be converted to an `Observable` and handled as such.
It's also possible to return a [`ReadableStream`](https://nodejs.org/api/stream.html#stream_class_stream_readable). The stream will be converted to an `Observable` and handled as such.

```js
const fs = require('fs');
const split = require('split');

const list = new Listr([
{
title: 'File',
task: () => fs.createReadStream('data.txt', 'utf8')
.pipe(split(/\r?\n/, null, {trailing: false}))
}
]);
```

### Skipping tasks

Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/data.txt
@@ -0,0 +1,2 @@
foo
bar
35 changes: 35 additions & 0 deletions test/stream.js
@@ -0,0 +1,35 @@
import * as fs from 'fs';
import * as path from 'path';
import test from 'ava';
import split from 'split';
import Listr from '../';
import SimpleRenderer from './fixtures/simple-renderer';
import {testOutput} from './fixtures/utils';

test('output', async t => {
const list = new Listr([
{
title: 'foo',
task: () => {
return new Listr([
{
title: 'bar',
task: () => fs.createReadStream(path.join(__dirname, 'fixtures/data.txt'), 'utf8').pipe(split(/\r?\n/, null, {trailing: false}))
}
]);
}
}
], {renderer: SimpleRenderer});

testOutput(t, [
'foo [started]',
'bar [started]',
'> foo',
'> bar',
'bar [completed]',
'foo [completed]',
'done'
]);

await list.run();
});

0 comments on commit 33bae7c

Please sign in to comment.