1+ import { describe , it , beforeEach , afterEach } from 'node:test' ;
12import assert from 'node:assert' ;
23
34import CLI from '../../lib/cli.js' ;
@@ -40,6 +41,8 @@ describe('cli', () => {
4041
4142 describe ( 'spinners' , ( ) => {
4243 beforeEach ( ( ) => {
44+ stream = new LogStream ( ) ;
45+ cli = new CLI ( stream ) ;
4346 cli . startSpinner ( 'foo' ) ;
4447 } ) ;
4548
@@ -58,20 +61,34 @@ describe('cli', () => {
5861 } ) ;
5962
6063 describe ( 'write' , ( ) => {
64+ beforeEach ( ( ) => {
65+ stream = new LogStream ( ) ;
66+ cli = new CLI ( stream ) ;
67+ } ) ;
6168 it ( 'should write in stream' , ( ) => {
69+ const stream = new LogStream ( ) ;
70+ const cli = new CLI ( stream ) ;
6271 cli . write ( 'Getting commits...' ) ;
63- assert . strictEqual ( logResult ( ) , 'Getting commits...' ) ;
72+ assert . strictEqual ( strip ( stream . toString ( ) ) , 'Getting commits...' ) ;
6473 } ) ;
6574 } ) ;
6675
6776 describe ( 'log' , ( ) => {
77+ beforeEach ( ( ) => {
78+ stream = new LogStream ( ) ;
79+ cli = new CLI ( stream ) ;
80+ } ) ;
6881 it ( 'should write in stream' , ( ) => {
6982 cli . log ( 'Getting commits...' ) ;
7083 assert . strictEqual ( logResult ( ) , 'Getting commits...\n' ) ;
7184 } ) ;
7285 } ) ;
7386
7487 describe ( 'table' , ( ) => {
88+ beforeEach ( ( ) => {
89+ stream = new LogStream ( ) ;
90+ cli = new CLI ( stream ) ;
91+ } ) ;
7592 it ( 'should print the first element with bold style and padding' , ( ) => {
7693 cli . table ( 'Title' , 'description' ) ;
7794 assert . strictEqual ( logResult ( ) ,
@@ -80,6 +97,10 @@ describe('cli', () => {
8097 } ) ;
8198
8299 describe ( 'separator' , ( ) => {
100+ beforeEach ( ( ) => {
101+ stream = new LogStream ( ) ;
102+ cli = new CLI ( stream ) ;
103+ } ) ;
83104 it ( 'should print a separator line with the specified text' , ( ) => {
84105 cli . separator ( 'Separator' ) ;
85106 assert . strictEqual (
@@ -105,6 +126,10 @@ describe('cli', () => {
105126 } ) ;
106127
107128 describe ( 'ok' , ( ) => {
129+ beforeEach ( ( ) => {
130+ stream = new LogStream ( ) ;
131+ cli = new CLI ( stream ) ;
132+ } ) ;
108133 it ( 'should print a success message' , ( ) => {
109134 cli . ok ( 'Perfect!' ) ;
110135 assert . strictEqual ( logResult ( ) , ` ${ success } Perfect!\n` ) ;
@@ -118,6 +143,10 @@ describe('cli', () => {
118143 } ) ;
119144
120145 describe ( 'warn' , ( ) => {
146+ beforeEach ( ( ) => {
147+ stream = new LogStream ( ) ;
148+ cli = new CLI ( stream ) ;
149+ } ) ;
121150 it ( 'should print a warning message' , ( ) => {
122151 cli . warn ( 'Warning!' ) ;
123152 assert . strictEqual ( logResult ( ) , ` ${ warning } Warning!\n` ) ;
@@ -131,6 +160,10 @@ describe('cli', () => {
131160 } ) ;
132161
133162 describe ( 'info' , ( ) => {
163+ beforeEach ( ( ) => {
164+ stream = new LogStream ( ) ;
165+ cli = new CLI ( stream ) ;
166+ } ) ;
134167 it ( 'should print an info message' , ( ) => {
135168 cli . info ( 'Info!' ) ;
136169 assert . strictEqual ( logResult ( ) , ` ${ info } Info!\n` ) ;
@@ -143,6 +176,10 @@ describe('cli', () => {
143176 } ) ;
144177
145178 describe ( 'error' , ( ) => {
179+ beforeEach ( ( ) => {
180+ stream = new LogStream ( ) ;
181+ cli = new CLI ( stream ) ;
182+ } ) ;
146183 it ( 'should print an error message' , ( ) => {
147184 cli . error ( 'Error!' ) ;
148185 assert . strictEqual ( logResult ( ) , ` ${ error } Error!\n` ) ;
@@ -183,6 +220,7 @@ describe('cli', () => {
183220 questionType : cli . QUESTION_TYPE . INPUT
184221 } ) ;
185222 assert . strictEqual ( cli . spinner . isSpinning , true ) ;
223+ cli . stopSpinner ( 'foo' ) ;
186224 } ) ;
187225 } ) ;
188226
0 commit comments