11import { describe , it , expect , vi , beforeEach , afterEach } from 'vitest' ;
2- import chalk from 'chalk' ;
32import { printMissing } from '../../../../src/ui/scan/printMissing.js' ;
43import type { EnvUsage } from '../../../../src/config/types.js' ;
54
@@ -21,6 +20,7 @@ describe('printMissing', () => {
2120
2221 it ( 'returns false when no missing variables' , ( ) => {
2322 const result = printMissing ( [ ] , [ ] , '.env' ) ;
23+
2424 expect ( result ) . toBe ( false ) ;
2525 expect ( logSpy ) . not . toHaveBeenCalled ( ) ;
2626 } ) ;
@@ -29,6 +29,70 @@ describe('printMissing', () => {
2929 const used : EnvUsage [ ] = [ ] ;
3030
3131 const result = printMissing ( [ 'UNKNOWN' ] , used , '.env' ) ;
32+
33+ expect ( result ) . toBe ( true ) ;
34+ expect ( logSpy ) . toHaveBeenCalledTimes ( 4 ) ;
35+ expect ( logSpy ) . toHaveBeenNthCalledWith (
36+ 2 ,
37+ expect . stringContaining ( 'Missing in .env' ) ,
38+ ) ;
39+ } ) ;
40+
41+ it ( 'prints grouped missing usages and falls back to environment file label' , ( ) => {
42+ const used : EnvUsage [ ] = [
43+ {
44+ variable : 'API_KEY' ,
45+ file : 'src/a.ts' ,
46+ line : 10 ,
47+ column : 1 ,
48+ pattern : 'process.env' ,
49+ context : 'process.env.API_KEY' ,
50+ } ,
51+ {
52+ variable : 'API_KEY' ,
53+ file : 'src/a.ts' ,
54+ line : 12 ,
55+ column : 1 ,
56+ pattern : 'process.env' ,
57+ context : 'process.env.API_KEY' ,
58+ } ,
59+ {
60+ variable : 'JWT_SECRET' ,
61+ file : 'src/b.ts' ,
62+ line : 7 ,
63+ column : 1 ,
64+ pattern : 'process.env' ,
65+ context : 'process.env.JWT_SECRET' ,
66+ } ,
67+ {
68+ variable : 'UNUSED' ,
69+ file : 'src/c.ts' ,
70+ line : 1 ,
71+ column : 1 ,
72+ pattern : 'process.env' ,
73+ context : 'process.env.UNUSED' ,
74+ } ,
75+ ] ;
76+
77+ const result = printMissing ( [ 'API_KEY' , 'JWT_SECRET' ] , used , '' ) ;
78+
3279 expect ( result ) . toBe ( true ) ;
80+ expect ( logSpy ) . toHaveBeenCalledTimes ( 7 ) ;
81+ expect ( logSpy ) . toHaveBeenNthCalledWith (
82+ 2 ,
83+ expect . stringContaining ( 'Missing in environment file' ) ,
84+ ) ;
85+ expect ( logSpy ) . toHaveBeenNthCalledWith (
86+ 4 ,
87+ expect . stringContaining ( 'normalized:src/a.ts:10' ) ,
88+ ) ;
89+ expect ( logSpy ) . toHaveBeenNthCalledWith (
90+ 5 ,
91+ expect . stringContaining ( 'normalized:src/a.ts:12' ) ,
92+ ) ;
93+ expect ( logSpy ) . toHaveBeenNthCalledWith (
94+ 6 ,
95+ expect . stringContaining ( 'normalized:src/b.ts:7' ) ,
96+ ) ;
3397 } ) ;
3498} ) ;
0 commit comments