@@ -6,6 +6,8 @@ import { execa } from 'execa';
66
77const PACKAGE_ROOT_PATH = dirname ( import . meta. dirname ) ;
88const CLI_PATH = pathJoin ( PACKAGE_ROOT_PATH , 'dist/cli.js' ) ;
9+ const ROOT_URL = new URL ( '../../../' , import . meta. url ) . href ;
10+ const FIXTURES_URL = new URL ( './fixtures/' , import . meta. url ) . href ;
911
1012async function runOxlintWithoutPlugins ( cwd : string , args : string [ ] = [ ] ) {
1113 return await execa ( 'node' , [ CLI_PATH , ...args ] , {
@@ -19,9 +21,28 @@ async function runOxlint(cwd: string, args: string[] = []) {
1921}
2022
2123function normalizeOutput ( output : string ) : string {
22- return output
23- . replace ( / F i n i s h e d i n \d + ( \. \d + ) ? ( s | m s | u s | n s ) / , 'Finished in Xms' )
24- . replace ( / u s i n g \d + t h r e a d s ./ , 'using X threads.' ) ;
24+ let lines = output . split ( '\n' ) ;
25+
26+ // Remove timing and thread count info which can vary between runs
27+ lines [ lines . length - 1 ] = lines [ lines . length - 1 ] . replace (
28+ / ^ F i n i s h e d i n \d + (?: \. \d + ) ? (?: s | m s | u s | n s ) o n ( \d + ) f i l e ( s ? ) u s i n g \d + t h r e a d s .$ / ,
29+ 'Finished in Xms on $1 file$2 using X threads.' ,
30+ ) ;
31+
32+ // Remove lines from stack traces which are outside `fixtures` directory.
33+ // Replace path to repo root in stack traces with `<root>`.
34+ lines = lines . flatMap ( ( line ) => {
35+ // e.g. ` | at file:///path/to/oxc/apps/oxlint/test/fixtures/foor/bar.js:1:1`
36+ // e.g. ` | at whatever (file:///path/to/oxc/apps/oxlint/test/fixtures/foor/bar.js:1:1)`
37+ const match = line . match ( / ^ ( \s * \| \s + a t (?: .+ ?\( ) ? ) ( .+ ) $ / ) ;
38+ if ( match ) {
39+ const [ , premable , at ] = match ;
40+ return at . startsWith ( FIXTURES_URL ) ? [ `${ premable } <root>/${ at . slice ( ROOT_URL . length ) } ` ] : [ ] ;
41+ }
42+ return [ line ] ;
43+ } ) ;
44+
45+ return lines . join ( '\n' ) ;
2546}
2647
2748describe ( 'oxlint CLI' , ( ) => {
@@ -73,12 +94,18 @@ describe('oxlint CLI', () => {
7394 expect ( normalizeOutput ( stdout ) ) . toMatchSnapshot ( ) ;
7495 } ) ;
7596
76- it ( 'should report an error if a custom plugin cannot be loaded ' , async ( ) => {
97+ it ( 'should report an error if a custom plugin is missing ' , async ( ) => {
7798 const { stdout, exitCode } = await runOxlint ( 'test/fixtures/missing_custom_plugin' ) ;
7899 expect ( exitCode ) . toBe ( 1 ) ;
79100 expect ( normalizeOutput ( stdout ) ) . toMatchSnapshot ( ) ;
80101 } ) ;
81102
103+ it ( 'should report an error if a custom plugin throws an error during import' , async ( ) => {
104+ const { stdout, exitCode } = await runOxlint ( 'test/fixtures/custom_plugin_import_error' ) ;
105+ expect ( exitCode ) . toBe ( 1 ) ;
106+ expect ( normalizeOutput ( stdout ) ) . toMatchSnapshot ( ) ;
107+ } ) ;
108+
82109 it ( 'should report an error if a rule is not found within a custom plugin' , async ( ) => {
83110 const { stdout, exitCode } = await runOxlint ( 'test/fixtures/custom_plugin_missing_rule' ) ;
84111 expect ( exitCode ) . toBe ( 1 ) ;
0 commit comments