|
1 | 1 | import chalk from 'chalk' |
2 | 2 |
|
3 | | -export default { |
4 | | - info(messages) { |
5 | | - if (process.env.JEST_WORKER_ID !== undefined) return |
| 3 | +let alreadyShown = new Set() |
6 | 4 |
|
7 | | - console.warn('') |
8 | | - messages.forEach((message) => { |
9 | | - console.warn(chalk.bold.cyan('info'), '-', message) |
10 | | - }) |
11 | | - }, |
12 | | - warn(messages) { |
13 | | - if (process.env.JEST_WORKER_ID !== undefined) return |
| 5 | +function log(chalk, messages, key) { |
| 6 | + if (process.env.JEST_WORKER_ID !== undefined) return |
14 | 7 |
|
15 | | - console.warn('') |
16 | | - messages.forEach((message) => { |
17 | | - console.warn(chalk.bold.yellow('warn'), '-', message) |
18 | | - }) |
19 | | - }, |
20 | | - risk(messages) { |
21 | | - if (process.env.JEST_WORKER_ID !== undefined) return |
| 8 | + if (key && alreadyShown.has(key)) return |
| 9 | + if (key) alreadyShown.add(key) |
| 10 | + |
| 11 | + console.warn('') |
| 12 | + messages.forEach((message) => console.warn(chalk, '-', message)) |
| 13 | +} |
22 | 14 |
|
23 | | - console.warn('') |
24 | | - messages.forEach((message) => { |
25 | | - console.warn(chalk.bold.magenta('risk'), '-', message) |
26 | | - }) |
| 15 | +export default { |
| 16 | + info(key, messages) { |
| 17 | + log(chalk.bold.cyan('info'), ...(Array.isArray(key) ? [key] : [messages, key])) |
| 18 | + }, |
| 19 | + warn(key, messages) { |
| 20 | + log(chalk.bold.yellow('warn'), ...(Array.isArray(key) ? [key] : [messages, key])) |
| 21 | + }, |
| 22 | + risk(key, messages) { |
| 23 | + log(chalk.bold.magenta('risk'), ...(Array.isArray(key) ? [key] : [messages, key])) |
27 | 24 | }, |
28 | 25 | } |
0 commit comments