11import { describe , test } from 'node:test' ;
22import assert from 'node:assert/strict' ;
33import { spawnSync } from 'node:child_process' ;
4- import { resolve , dirname } from 'node:path' ;
4+ import { resolve , sep , dirname } from 'node:path' ;
55import { fileURLToPath } from 'node:url' ;
6- import stripAnsi from 'strip-ansi' ;
76
87const __dirname = dirname ( fileURLToPath ( import . meta. url ) ) ;
98
@@ -18,10 +17,7 @@ describe('E2E Tests', () => {
1817 const result = runStylelint ( '*.css' ) ;
1918
2019 const expectedResult = `
21- check.invalid.css
22- 2:25 ✖ Replace ""x"" with "'x'" prettier/prettier
23-
24- 1 problem (1 error, 0 warnings)
20+ ::error file=check.invalid.css,line=2,col=25,endLine=2,endColumn=28,title=Stylelint problem::Replace ""x"" with "'x'" (prettier/prettier)
2521` . trim ( ) ;
2622
2723 assert . strictEqual ( result . output , '' ) ;
@@ -33,11 +29,8 @@ check.invalid.css
3329 const result = runStylelint ( '*.scss' ) ;
3430
3531 const expectedResult = `
36- check.invalid.scss
37- 2:25 ✖ Replace ""x"" with "'x'" prettier/prettier
38- 8:14 ✖ Insert "," prettier/prettier
39-
40- 2 problems (2 errors, 0 warnings)
32+ ::error file=check.invalid.scss,line=2,col=25,endLine=2,endColumn=28,title=Stylelint problem::Replace ""x"" with "'x'" (prettier/prettier)
33+ ::error file=check.invalid.scss,line=8,col=14,endLine=8,endColumn=15,title=Stylelint problem::Insert "," (prettier/prettier)
4134` . trim ( ) ;
4235
4336 assert . strictEqual ( result . output , '' ) ;
@@ -76,14 +69,19 @@ check.invalid.scss
7669
7770function runStylelint ( pattern ) {
7871 const stylelintCmd = resolve ( `${ __dirname } /../node_modules/.bin/stylelint` ) ;
72+ const cwd = `${ __dirname } /fixtures` ;
7973
80- const result = spawnSync ( stylelintCmd , [ pattern ] , {
81- cwd : `${ __dirname } /fixtures` ,
74+ // Use github formatter as it is less likely to change across releases
75+ const result = spawnSync ( stylelintCmd , [ '--formatter=github' , pattern ] , {
76+ cwd,
8277 } ) ;
8378
8479 return {
8580 status : result . status ,
86- output : stripAnsi ( result . stdout . toString ( ) . trim ( ) ) ,
87- error : stripAnsi ( result . stderr . toString ( ) . trim ( ) ) ,
81+ output : result . stdout . toString ( ) . trim ( ) ,
82+ error : result . stderr
83+ . toString ( )
84+ . trim ( )
85+ . replaceAll ( `file=${ cwd } ${ sep } ` , 'file=' ) ,
8886 } ;
8987}
0 commit comments