Skip to content
Open
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
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class VerboseRenderer {
constructor(tasks, options) {
this._tasks = tasks;
this._options = Object.assign({
dateFormat: 'HH:mm:ss'
dateFormat: 'HH:mm:ss',
stream: process.stdout
}, options);
}

Expand All @@ -52,12 +53,12 @@ class VerboseRenderer {
}

render() {
cliCursor.hide();
cliCursor.hide(this._options.stream);
render(this._tasks, this._options);
}

end() {
cliCursor.show();
cliCursor.show(this._options.stream);
}
}

Expand Down
5 changes: 3 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ const chalk = require('chalk');
const format = require('date-fns/format');

exports.log = (options, output) => {
const logger = new console.Console(options.stream, options.stream);
if (options.dateFormat === false) {
console.log(output);
logger.log(`${output}`);
return;
}

const timestamp = format(new Date(), options.dateFormat);

console.log(chalk.dim(`[${timestamp}]`) + ` ${output}`);
logger.log(chalk.dim(`[${timestamp}]`) + ` ${output}`);
};
6 changes: 6 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ Default: `HH:mm:ss`

Format of the rendered timestamp. Use the [date-fns string format](https://date-fns.org/docs/format). If `false` is passed in, the timestamp will be hidden.

### stream

Type: `stream.Writable` <br>
Default: `process.stdout`

The stream to render to.

## Related

Expand Down
11 changes: 7 additions & 4 deletions test/fixtures/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ exports.testOutput = (t, expected) => {
t.plan(t._test.planCount || expected.length);
let i = 0;

const promise = hookStd(actual => {
t.is(stripAnsi(actual), `${expected[i++]}`);
const promise = hookStd.stdout(actual => {
const stripped = stripAnsi(actual);
if (stripped !== '') {
t.is(stripped, `${expected[i++]}`);

if (i === expected.length) {
promise.unhook();
if (i === expected.length) {
promise.unhook();
}
}
});
};
2 changes: 1 addition & 1 deletion test/test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {serial as test} from 'ava';
import Listr from 'listr';
import format from 'date-fns/format';
import {testOutput} from './fixtures/utils';
import renderer from '..';
import {testOutput} from './fixtures/utils';

const date = format(new Date(), 'dd/MM/yyyy');

Expand Down