@@ -4,11 +4,12 @@ import { Architect } from '@angular-devkit/architect';
4
4
import { TestingArchitectHost } from '@angular-devkit/architect/testing' ;
5
5
import { schema } from '@angular-devkit/core' ;
6
6
import { Logger } from '@angular-devkit/core/src/logger' ;
7
+ import { exec } from 'child_process' ;
7
8
8
9
describe ( 'Lint' , ( ) => {
9
10
let architect : Architect ;
10
11
let architectHost : TestingArchitectHost ;
11
- const logger = new Logger ( 'test' ) ;
12
+ let logger : Logger ;
12
13
13
14
beforeEach ( async ( ) => {
14
15
const registry = new schema . CoreSchemaRegistry ( ) ;
@@ -18,6 +19,7 @@ describe('Lint', () => {
18
19
// Since we don't use those, both are the same in this case.
19
20
architectHost = new TestingArchitectHost ( './test' , './test' ) ;
20
21
architect = new Architect ( architectHost , registry ) ;
22
+ logger = new Logger ( 'test' ) ;
21
23
22
24
// This will either take a Node package name, or a path to the directory
23
25
// for the package.json file.
@@ -26,6 +28,10 @@ describe('Lint', () => {
26
28
console . info ( '#' , Array . from ( architectHost . _builderMap . keys ( ) ) ) ;
27
29
} ) ;
28
30
31
+ afterEach ( async ( ) => {
32
+ exec ( 'git restore test/src/' ) ;
33
+ } ) ;
34
+
29
35
it ( 'has created the correct linting results' , async ( ) => {
30
36
// A "run" can have multiple outputs, and contains progress information.
31
37
const run = await architect . scheduleBuilder (
@@ -94,4 +100,66 @@ describe('Lint', () => {
94
100
} ,
95
101
] ) ;
96
102
} ) ;
103
+
104
+ it ( 'autofix lint issues when using fix option' , async ( ) => {
105
+ // A "run" can have multiple outputs, and contains progress information.
106
+ const run = await architect . scheduleBuilder (
107
+ '@krema/angular-eslint-stylelint-builder:lint' ,
108
+ {
109
+ eslintFilePatterns : [ 'src/**/*.ts' ] ,
110
+ stylelintFilePatterns : [ 'src/**/*.css' ] ,
111
+ fix : true ,
112
+ } ,
113
+ { logger }
114
+ ) ;
115
+ const loggerPromise = logger
116
+ . pipe (
117
+ toArray ( ) ,
118
+ map ( messages =>
119
+ messages . map ( y => {
120
+ console . log ( '>>' , y . message ) ;
121
+ return { level : y . level , message : y . message } ;
122
+ } )
123
+ )
124
+ )
125
+ . toPromise ( ) ;
126
+
127
+ // The "result" member (of type BuilderOutput) is the next output.
128
+ await run . result ;
129
+
130
+ // Stop the builder from running. This stops Architect from keeping
131
+ // the builder-associated states in memory, since builders keep waiting
132
+ // to be scheduled.
133
+ await run . stop ( ) ;
134
+ logger . complete ( ) ;
135
+
136
+ expect ( loggerPromise ) . resolves . toEqual ( [
137
+ {
138
+ level : 'info' ,
139
+ message : '\nLinting "<???>"...' ,
140
+ } ,
141
+ {
142
+ level : 'debug' ,
143
+ message : 'Running eslint...' ,
144
+ } ,
145
+ {
146
+ level : 'debug' ,
147
+ message : 'Running stylelint...' ,
148
+ } ,
149
+ {
150
+ level : 'info' ,
151
+ // @ts -ignore
152
+ message : expect . toIncludeMultiple ( [
153
+ //file.ts
154
+ 'file.ts\n' + " 3:3 error Unexpected 'debugger' statement eslint\tno-debugger\n" ,
155
+ // info messages
156
+ '✖ 1 problem (1 error, 0 warnings)\n' ,
157
+ ] ) ,
158
+ } ,
159
+ {
160
+ level : 'error' ,
161
+ message : 'Lint errors found in the listed files.\n' ,
162
+ } ,
163
+ ] ) ;
164
+ } ) ;
97
165
} ) ;
0 commit comments