@@ -38,7 +38,30 @@ describe('no-flag autoscan', () => {
3838 const res = runCli ( cwd , [ '--compare' ] ) ;
3939 expect ( res . status ) . toBe ( 1 ) ;
4040 expect ( res . stdout ) . toContain ( 'Comparing .env ↔ .env.example' ) ;
41- expect ( res . stdout ) . toContain ( 'Comparing .env.staging ↔ .env.example.staging' ) ;
41+ expect ( res . stdout ) . toContain (
42+ 'Comparing .env.staging ↔ .env.example.staging' ,
43+ ) ;
4244 expect ( res . stdout ) . toContain ( 'Missing keys' ) ;
4345 } ) ;
46+ it ( 'will warn about .env not ignored by .gitignore' , ( ) => {
47+ const cwd = tmpDir ( ) ;
48+
49+ fs . mkdirSync ( path . join ( cwd , '.git' ) ) ;
50+ fs . writeFileSync ( path . join ( cwd , '.env' ) , 'API_KEY=test\n' ) ;
51+
52+ fs . writeFileSync ( path . join ( cwd , '.gitignore' ) , 'node_modules\n' ) ;
53+
54+ fs . mkdirSync ( path . join ( cwd , 'src' ) , { recursive : true } ) ;
55+ fs . writeFileSync (
56+ path . join ( cwd , 'src' , 'index.ts' ) ,
57+ `const apiKey = process.env.API_KEY;` . trimStart ( ) ,
58+ ) ;
59+
60+ const res = runCli ( cwd , [ ] ) ;
61+ console . log ( 'stdout:' , res . stdout ) ;
62+ console . log ( 'stderr:' , res . stderr ) ;
63+
64+ expect ( res . status ) . toBe ( 0 ) ;
65+ expect ( res . stdout ) . toContain ( '.env is not ignored by Git' ) ;
66+ } ) ;
4467} ) ;
0 commit comments