forked from DevExpress/testcafe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.js
43 lines (34 loc) · 1.17 KB
/
log.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import tty from 'tty';
import elegantSpinner from 'elegant-spinner';
import logUpdate from 'log-update-async-hook';
import chalk from 'chalk';
import isCI from 'is-ci';
// NOTE: To support piping, we use stderr as the log output
// stream, while stdout is used for the report output.
export default {
animation: null,
isAnimated: tty.isatty(1) && !isCI,
showSpinner () {
// NOTE: we can use the spinner only if stderr is a TTY and we are not in CI environment (e.g. TravisCI),
// otherwise we can't repaint animation frames. Thanks https://github.com/sindresorhus/ora for insight.
if (this.isAnimated) {
const spinnerFrame = elegantSpinner();
this.animation = setInterval(() => {
const frame = chalk.cyan(spinnerFrame());
logUpdate.stderr(frame);
}, 50);
}
},
hideSpinner (isExit) {
if (this.animation) {
clearInterval(this.animation);
logUpdate.stderr.clear();
if (isExit)
logUpdate.stderr.done();
this.animation = null;
}
},
write (text) {
console.error(text);
}
};