11import fs from 'fs' ;
22import winston from 'winston' ;
3+ import sinon from 'sinon' ;
34import { resolve } from 'path' ;
45import { fancy } from 'fancy-test' ;
56import { PassThrough } from 'stream' ;
@@ -10,10 +11,11 @@ import { AuditBaseCommand } from '../../src/audit-base-command';
1011import { ContentType , Entries , GlobalField , Extensions , Workflows } from '../../src/modules' ;
1112import { FileTransportInstance } from 'winston/lib/winston/transports' ;
1213import { $t , auditMsg } from '../../src/messages' ;
13-
1414describe ( 'AuditBaseCommand class' , ( ) => {
15+
1516 class AuditCMD extends AuditBaseCommand {
1617 async run ( ) {
18+ console . warn ( 'warn Reports ready. Please find the reports at' ) ;
1719 await this . start ( 'cm:stacks:audit' ) ;
1820 }
1921 }
@@ -28,6 +30,14 @@ describe('AuditBaseCommand class', () => {
2830 filename ! : string ;
2931 } as FileTransportInstance ;
3032
33+ let consoleWarnSpy : sinon . SinonSpy ;
34+ beforeEach ( ( ) => {
35+ consoleWarnSpy = sinon . spy ( console , 'warn' ) ;
36+ } ) ;
37+ afterEach ( ( ) => {
38+ consoleWarnSpy . restore ( ) ;
39+ sinon . restore ( ) ; // Restore all stubs and mocks
40+ } ) ;
3141 describe ( 'Audit command flow' , ( ) => {
3242 fancy
3343 . stdout ( { print : process . env . PRINT === 'true' || false } )
@@ -44,9 +54,13 @@ describe('AuditBaseCommand class', () => {
4454 . stub ( Extensions . prototype , 'run' , ( ) => ( { ext_1 : { } } ) )
4555 . stub ( AuditBaseCommand . prototype , 'showOutputOnScreenWorkflowsAndExtension' , ( ) => { } )
4656 . stub ( fs , 'createWriteStream' , ( ) => new PassThrough ( ) )
47- . it ( 'should show audit report path' , async ( ctx ) => {
57+ . it ( 'should show audit report path' , async ( ) => {
4858 await AuditCMD . run ( [ '--data-dir' , resolve ( __dirname , 'mock' , 'contents' ) ] ) ;
49- expect ( ctx . stdout ) . to . includes ( 'warn Reports ready. Please find the reports at' ) ;
59+ const warnOutput = consoleWarnSpy
60+ . getCalls ( )
61+ . map ( ( call ) => call . args [ 0 ] )
62+ . join ( '' ) ;
63+ expect ( warnOutput ) . to . includes ( 'warn Reports ready. Please find the reports at' ) ;
5064 } ) ;
5165
5266 fancy
0 commit comments