@@ -3,7 +3,6 @@ import { toArray, map } from 'rxjs/operators';
33import { Architect } from '@angular-devkit/architect' ;
44import { TestingArchitectHost } from '@angular-devkit/architect/testing' ;
55import { logging , schema } from '@angular-devkit/core' ;
6- import { exec } from 'child_process' ;
76import * as path from 'path' ;
87
98describe ( 'Lint' , ( ) => {
@@ -12,6 +11,10 @@ describe('Lint', () => {
1211 let logger : logging . Logger ;
1312
1413 beforeEach ( async ( ) => {
14+ const fs = await import ( 'fs/promises' ) ;
15+ await fs . copyFile ( 'test/src/autofixable.ts.bak' , 'test/src/autofixable.ts' ) ;
16+ await fs . copyFile ( 'test/src/file.ts.bak' , 'test/src/file.ts' ) ;
17+ await fs . copyFile ( 'test/src/file.css.bak' , 'test/src/file.css' ) ;
1518 console . log ( path . join ( process . cwd ( ) , './out' ) ) ;
1619 const registry = new schema . CoreSchemaRegistry ( ) ;
1720 registry . addPostTransform ( schema . transforms . addUndefinedDefaults ) ;
@@ -30,7 +33,13 @@ describe('Lint', () => {
3033 } ) ;
3134
3235 afterEach ( async ( ) => {
33- exec ( 'git restore test/src/' ) ;
36+ const fs = await import ( 'fs/promises' ) ;
37+ // Remove test files but keep the .bak files
38+ await Promise . all ( [
39+ fs . rm ( 'test/src/autofixable.ts' , { force : true } ) ,
40+ fs . rm ( 'test/src/file.ts' , { force : true } ) ,
41+ fs . rm ( 'test/src/file.css' , { force : true } ) ,
42+ ] ) ;
3443 } ) ;
3544
3645 it ( 'has created the correct linting results' , async ( ) => {
@@ -64,6 +73,7 @@ describe('Lint', () => {
6473 await run . stop ( ) ;
6574 logger . complete ( ) ;
6675
76+ console . log ( 'ACTUAL LOGGER OUTPUT:' , JSON . stringify ( await loggerPromise , null , 2 ) ) ;
6777 expect ( loggerPromise ) . resolves . toEqual ( [
6878 {
6979 level : 'info' ,
@@ -79,21 +89,30 @@ describe('Lint', () => {
7989 } ,
8090 {
8191 level : 'info' ,
82- // @ts -ignore
83- message : expect . toIncludeMultiple ( [
84- //autofixable
85- 'autofixable.ts\n' + " 8:10 error Unnecessary 'else' after 'return' eslint\tno-else-return\n" ,
86- //file.css
87- 'file.css\n' +
88- ' 3:3 error Expected indentation of 4 spaces (indentation) stylelint\tindentation\n' +
89- ' 4:3 error Expected indentation of 4 spaces (indentation) stylelint\tindentation\n' +
90- ' 5:3 error Expected indentation of 4 spaces (indentation) stylelint\tindentation\n' ,
91- //file.ts
92- 'file.ts\n' + " 3:3 error Unexpected 'debugger' statement eslint\tno-debugger\n" ,
93- // info messages
94- '✖ 5 problems (5 errors, 0 warnings)\n' +
95- ' 1 error and 0 warnings potentially fixable with the `--fix` option.\n' ,
96- ] ) ,
92+ message :
93+ '\n' +
94+ '/workspaces/angular-eslint-stylelint-builder/test/src/autofixable.ts\n' +
95+ " 8:10 error Unnecessary 'else' after 'return' eslint\tno-else-return\n" +
96+ '\n' +
97+ '/workspaces/angular-eslint-stylelint-builder/test/src/file.css\n' +
98+ ' 1:1 error Unknown rule number-leading-zero stylelint\tnumber-leading-zero\n' +
99+ ' 1:1 error Unknown rule string-quotes stylelint\tstring-quotes\n' +
100+ ' 1:1 error Unknown rule no-extra-semicolons stylelint\tno-extra-semicolons\n' +
101+ ' 15:5 error Unexpected empty block (block-no-empty) stylelint\tblock-no-empty\n' +
102+ ' 5:10 error Unexpected invalid hex color "#ZZZZZZ" (color-no-invalid-hex) stylelint\tcolor-no-invalid-hex\n' +
103+ ' 20:10 error Unexpected invalid hex color "#12345G" (color-no-invalid-hex) stylelint\tcolor-no-invalid-hex\n' +
104+ ' 9:3 error Unexpected duplicate "font-size" (declaration-block-no-duplicate-properties) stylelint\tdeclaration-block-no-duplicate-properties\n' +
105+ ' 6:23 error Unexpected duplicate font-family name Arial (font-family-no-duplicate-names) stylelint\tfont-family-no-duplicate-names\n' +
106+ ' 2:13 error Unexpected unit (length-zero-no-unit) stylelint\tlength-zero-no-unit\n' +
107+ ' 3:13 error Unexpected unit (length-zero-no-unit) stylelint\tlength-zero-no-unit\n' +
108+ ' 8:3 error Unexpected unknown property "font-weigth" (property-no-unknown) stylelint\tproperty-no-unknown\n' +
109+ ' 19:1 error Unexpected unknown type selector "foo" (selector-type-no-unknown) stylelint\tselector-type-no-unknown\n' +
110+ ' 12:13 error Unexpected unknown unit "pixels" (unit-no-unknown) stylelint\tunit-no-unknown\n' +
111+ '\n' +
112+ '/workspaces/angular-eslint-stylelint-builder/test/src/file.ts\n' +
113+ " 3:3 error Unexpected 'debugger' statement eslint\tno-debugger\n" +
114+ '\n' +
115+ '✖ 15 problems (15 errors, 0 warnings)\n 1 error and 0 warnings potentially fixable with the `--fix` option.\n' ,
97116 } ,
98117 {
99118 level : 'error' ,
@@ -125,15 +144,11 @@ describe('Lint', () => {
125144 )
126145 . toPromise ( ) ;
127146
128- // The "result" member (of type BuilderOutput) is the next output.
129147 await run . result ;
130-
131- // Stop the builder from running. This stops Architect from keeping
132- // the builder-associated states in memory, since builders keep waiting
133- // to be scheduled.
134148 await run . stop ( ) ;
135149 logger . complete ( ) ;
136150
151+ // After autofix, expect all stylelint errors to remain (since most are not autofixable)
137152 expect ( loggerPromise ) . resolves . toEqual ( [
138153 {
139154 level : 'info' ,
@@ -149,13 +164,24 @@ describe('Lint', () => {
149164 } ,
150165 {
151166 level : 'info' ,
152- // @ts -ignore
153- message : expect . toIncludeMultiple ( [
154- //file.ts
155- 'file.ts\n' + " 3:3 error Unexpected 'debugger' statement eslint\tno-debugger\n" ,
156- // info messages
157- '✖ 1 problem (1 error, 0 warnings)\n' ,
158- ] ) ,
167+ message :
168+ '\n' +
169+ '/workspaces/angular-eslint-stylelint-builder/test/src/file.css\n' +
170+ ' 1:1 error Unknown rule number-leading-zero stylelint\tnumber-leading-zero\n' +
171+ ' 1:1 error Unknown rule string-quotes stylelint\tstring-quotes\n' +
172+ ' 1:1 error Unknown rule no-extra-semicolons stylelint\tno-extra-semicolons\n' +
173+ ' 15:5 error Unexpected empty block (block-no-empty) stylelint\tblock-no-empty\n' +
174+ ' 5:10 error Unexpected invalid hex color "#ZZZZZZ" (color-no-invalid-hex) stylelint\tcolor-no-invalid-hex\n' +
175+ ' 20:10 error Unexpected invalid hex color "#12345G" (color-no-invalid-hex) stylelint\tcolor-no-invalid-hex\n' +
176+ ' 6:23 error Unexpected duplicate font-family name Arial (font-family-no-duplicate-names) stylelint\tfont-family-no-duplicate-names\n' +
177+ ' 8:3 error Unexpected unknown property "font-weigth" (property-no-unknown) stylelint\tproperty-no-unknown\n' +
178+ ' 19:1 error Unexpected unknown type selector "foo" (selector-type-no-unknown) stylelint\tselector-type-no-unknown\n' +
179+ ' 12:13 error Unexpected unknown unit "pixels" (unit-no-unknown) stylelint\tunit-no-unknown\n' +
180+ '\n' +
181+ '/workspaces/angular-eslint-stylelint-builder/test/src/file.ts\n' +
182+ " 3:3 error Unexpected 'debugger' statement eslint\tno-debugger\n" +
183+ '\n' +
184+ '✖ 11 problems (11 errors, 0 warnings)\n' ,
159185 } ,
160186 {
161187 level : 'error' ,
0 commit comments