@@ -5,14 +5,14 @@ import { Architect } from '@angular-devkit/architect';
55import { TestingArchitectHost } from '@angular-devkit/architect/testing' ;
66import { logging , schema } from '@angular-devkit/core' ;
77import * as path from 'path' ;
8+ import * as fs from 'fs/promises' ;
89
910describe ( 'Lint' , ( ) => {
1011 let architect : Architect ;
1112 let architectHost : TestingArchitectHost ;
1213 let logger : logging . Logger ;
1314
1415 beforeEach ( async ( ) => {
15- const fs = await import ( 'fs/promises' ) ;
1616 await fs . copyFile ( 'test/src/autofixable.ts.bak' , 'test/src/autofixable.ts' ) ;
1717 await fs . copyFile ( 'test/src/file.ts.bak' , 'test/src/file.ts' ) ;
1818 await fs . copyFile ( 'test/src/file.css.bak' , 'test/src/file.css' ) ;
@@ -34,12 +34,12 @@ describe('Lint', () => {
3434 } ) ;
3535
3636 afterEach ( async ( ) => {
37- const fs = await import ( 'fs/promises' ) ;
3837 // Remove test files but keep the .bak files
3938 await Promise . all ( [
4039 fs . rm ( 'test/src/autofixable.ts' , { force : true } ) ,
4140 fs . rm ( 'test/src/file.ts' , { force : true } ) ,
4241 fs . rm ( 'test/src/file.css' , { force : true } ) ,
42+ fs . rm ( 'test/lint-report.txt' , { force : true } ) ,
4343 ] ) ;
4444 } ) ;
4545
@@ -243,4 +243,39 @@ describe('Lint', () => {
243243 expect ( output ) . not . toContain ( 'file.ts' ) ;
244244 expect ( output ) . not . toContain ( 'file.css' ) ;
245245 } ) ;
246+
247+ it ( 'writes JSON output to file with fix enabled' , async ( ) => {
248+ const outputFile = 'lint-report.txt' ;
249+
250+ const run = await architect . scheduleBuilder (
251+ '@krema/angular-eslint-stylelint-builder:lint' ,
252+ {
253+ eslintFilePatterns : [ 'src/**/*.ts' ] ,
254+ stylelintFilePatterns : [ 'src/**/*.css' ] ,
255+ fix : true ,
256+ outputFile,
257+ format : 'json' ,
258+ eslintConfig : 'eslint.config.js' ,
259+ stylelintConfig : 'stylelint.config.js' ,
260+ } ,
261+ { logger }
262+ ) ;
263+ await run . result ;
264+ await run . stop ( ) ;
265+ logger . complete ( ) ;
266+
267+ // Check that the output file exists and contains valid JSON
268+ let exists = false ;
269+ try {
270+ await fs . access ( path . join ( 'test' , outputFile ) ) ;
271+ exists = true ;
272+ } catch {
273+ exists = false ;
274+ }
275+ expect ( exists ) . toBe ( true ) ;
276+ if ( exists ) {
277+ const content = await fs . readFile ( path . join ( 'test' , outputFile ) , 'utf8' ) ;
278+ expect ( ( ) => JSON . parse ( content ) ) . not . toThrow ( ) ;
279+ }
280+ } ) ;
246281} ) ;
0 commit comments