/
handleDeprecationWarnings.ts
42 lines (38 loc) · 1.19 KB
/
handleDeprecationWarnings.ts
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
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import chalk = require('chalk');
import {KEYS} from 'jest-watcher';
export default function handleDeprecationWarnings(
pipe: NodeJS.WriteStream,
stdin: NodeJS.ReadStream = process.stdin,
): Promise<void> {
return new Promise((resolve, reject) => {
if (typeof stdin.setRawMode === 'function') {
const messages = [
chalk.red('There are deprecation warnings.\n'),
chalk.dim(' \u203A Press ') + 'Enter' + chalk.dim(' to continue.'),
chalk.dim(' \u203A Press ') + 'Esc' + chalk.dim(' to exit.'),
];
pipe.write(messages.join('\n'));
stdin.setRawMode(true);
stdin.resume();
stdin.setEncoding('utf8');
// this is a string since we set encoding above
stdin.on('data', (key: string) => {
if (key === KEYS.ENTER) {
resolve();
} else if (
[KEYS.ESCAPE, KEYS.CONTROL_C, KEYS.CONTROL_D].indexOf(key) !== -1
) {
reject();
}
});
} else {
resolve();
}
});
}