11import chalk from 'chalk' ;
22import { afterEach , beforeEach , describe , expect , it , vi } from 'vitest' ;
3- import { mockConsole , unmockConsole } from '../../test' ;
43import { FileResult } from './file-system' ;
54import { logMultipleResults , logPromiseResults } from './log-results' ;
65import { formatBytes } from './report' ;
76
87const succeededCallback = ( result : PromiseFulfilledResult < FileResult > ) => {
98 const [ fileName , size ] = result . value ;
10- console . log (
9+ console . info (
1110 `- ${ chalk . bold ( fileName ) } ` +
1211 ( size ? ` (${ chalk . gray ( formatBytes ( size ) ) } )` : '' ) ,
1312 ) ;
1413} ;
1514
1615const failedCallback = ( result : PromiseRejectedResult ) => {
17- console . log ( `- ${ chalk . bold ( result . reason ) } ` ) ;
16+ console . warn ( `- ${ chalk . bold ( result . reason ) } ` ) ;
1817} ;
1918
2019describe ( 'logMultipleResults' , ( ) => {
@@ -79,25 +78,6 @@ describe('logMultipleResults', () => {
7978} ) ;
8079
8180describe ( 'logPromiseResults' , ( ) => {
82- let logs : string [ ] ;
83- const setupConsole = async ( ) => {
84- logs = [ ] ;
85- mockConsole ( msg => logs . push ( msg ) ) ;
86- } ;
87- const teardownConsole = async ( ) => {
88- logs = [ ] ;
89- unmockConsole ( ) ;
90- } ;
91-
92- beforeEach ( async ( ) => {
93- logs = [ ] ;
94- setupConsole ( ) ;
95- } ) ;
96-
97- afterEach ( ( ) => {
98- teardownConsole ( ) ;
99- } ) ;
100-
10181 it ( 'should log on success' , async ( ) => {
10282 logPromiseResults (
10383 [
@@ -110,9 +90,12 @@ describe('logPromiseResults', () => {
11090 succeededCallback ,
11191 ) ;
11292
113- expect ( logs ) . toHaveLength ( 2 ) ;
114- expect ( logs [ 0 ] ) . toContain ( 'Uploaded reports successfully: ' ) ;
115- expect ( logs [ 1 ] ) . toContain ( '- [1mout.json[22m' ) ;
93+ expect ( console . info ) . toHaveBeenCalledWith (
94+ expect . stringContaining ( 'Uploaded reports successfully: ' ) ,
95+ ) ;
96+ expect ( console . info ) . toHaveBeenCalledWith (
97+ expect . stringContaining ( '- [1mout.json[22m' ) ,
98+ ) ;
11699 } ) ;
117100
118101 it ( 'should log on fail' , async ( ) => {
@@ -122,8 +105,11 @@ describe('logPromiseResults', () => {
122105 failedCallback ,
123106 ) ;
124107
125- expect ( logs ) . toHaveLength ( 2 ) ;
126- expect ( logs [ 0 ] ) . toContain ( 'Generated reports failed: ' ) ;
127- expect ( logs [ 1 ] ) . toContain ( '- [1mfail[22m' ) ;
108+ expect ( console . warn ) . toHaveBeenCalledWith (
109+ expect . stringContaining ( 'Generated reports failed: ' ) ,
110+ ) ;
111+ expect ( console . warn ) . toHaveBeenCalledWith (
112+ expect . stringContaining ( '- [1mfail[22m' ) ,
113+ ) ;
128114 } ) ;
129115} ) ;
0 commit comments