@@ -6,6 +6,7 @@ import { describe, expect, it } from 'vitest';
66import { execa } from 'execa' ;
77
88const PACKAGE_ROOT_PATH = dirname ( import . meta. dirname ) ;
9+ const ROOT_PATH = pathJoin ( PACKAGE_ROOT_PATH , '../../../' ) ;
910const CLI_PATH = pathJoin ( PACKAGE_ROOT_PATH , 'dist/cli.js' ) ;
1011const ROOT_URL = new URL ( '../../../' , import . meta. url ) . href ;
1112const FIXTURES_URL = new URL ( './fixtures/' , import . meta. url ) . href ;
@@ -37,12 +38,19 @@ function normalizeOutput(output: string): string {
3738 // Remove lines from stack traces which are outside `fixtures` directory.
3839 // Replace path to repo root in stack traces with `<root>`.
3940 lines = lines . flatMap ( ( line ) => {
40- // e.g. ` | at file:///path/to/oxc/apps/oxlint/test/fixtures/foor /bar.js:1:1`
41- // e.g. ` | at whatever (file:///path/to/oxc/apps/oxlint/test/fixtures/foor /bar.js:1:1)`
42- const match = line . match ( / ^ ( \s * \| \s + a t (?: .+ ?\( ) ? ) ( .+ ) $ / ) ;
41+ // e.g. ` | at file:///path/to/oxc/apps/oxlint/test/fixtures/foo /bar.js:1:1`
42+ // e.g. ` | at whatever (file:///path/to/oxc/apps/oxlint/test/fixtures/foo /bar.js:1:1)`
43+ let match = line . match ( / ^ ( \s * \| \s + a t (?: .+ ?\( ) ? ) ( .+ ) $ / ) ;
4344 if ( match ) {
4445 const [ , premable , at ] = match ;
4546 return at . startsWith ( FIXTURES_URL ) ? [ `${ premable } <root>/${ at . slice ( ROOT_URL . length ) } ` ] : [ ] ;
47+ } else {
48+ // e.g. ` | File path: /path/to/oxc/apps/oxlint/test/fixtures/foo/bar.js`
49+ match = line . match ( / ^ ( \s * \| \s + F i l e p a t h : ) ( .+ ) $ / ) ;
50+ if ( match ) {
51+ const [ , premable , path ] = match ;
52+ if ( path . startsWith ( ROOT_PATH ) ) return [ `${ premable } <root>/${ path . slice ( ROOT_PATH . length ) } ` ] ;
53+ }
4654 }
4755 return [ line ] ;
4856 } ) ;
@@ -129,6 +137,44 @@ describe('oxlint CLI', () => {
129137 expect ( normalizeOutput ( stdout ) ) . toMatchSnapshot ( ) ;
130138 } ) ;
131139
140+ describe ( 'should report an error if a custom plugin throws an error during linting' , ( ) => {
141+ it ( 'in `create` method' , async ( ) => {
142+ const { stdout, exitCode } = await runOxlint ( 'test/fixtures/custom_plugin_lint_create_error' ) ;
143+ expect ( exitCode ) . toBe ( 1 ) ;
144+ expect ( normalizeOutput ( stdout ) ) . toMatchSnapshot ( ) ;
145+ } ) ;
146+
147+ it ( 'in `createOnce` method' , async ( ) => {
148+ const { stdout, exitCode } = await runOxlint ( 'test/fixtures/custom_plugin_lint_createOnce_error' ) ;
149+ expect ( exitCode ) . toBe ( 1 ) ;
150+ expect ( normalizeOutput ( stdout ) ) . toMatchSnapshot ( ) ;
151+ } ) ;
152+
153+ it ( 'in visit function' , async ( ) => {
154+ const { stdout, exitCode } = await runOxlint ( 'test/fixtures/custom_plugin_lint_visit_error' ) ;
155+ expect ( exitCode ) . toBe ( 1 ) ;
156+ expect ( normalizeOutput ( stdout ) ) . toMatchSnapshot ( ) ;
157+ } ) ;
158+
159+ it ( 'in `before` hook' , async ( ) => {
160+ const { stdout, exitCode } = await runOxlint ( 'test/fixtures/custom_plugin_lint_before_hook_error' ) ;
161+ expect ( exitCode ) . toBe ( 1 ) ;
162+ expect ( normalizeOutput ( stdout ) ) . toMatchSnapshot ( ) ;
163+ } ) ;
164+
165+ it ( 'in `after` hook' , async ( ) => {
166+ const { stdout, exitCode } = await runOxlint ( 'test/fixtures/custom_plugin_lint_after_hook_error' ) ;
167+ expect ( exitCode ) . toBe ( 1 ) ;
168+ expect ( normalizeOutput ( stdout ) ) . toMatchSnapshot ( ) ;
169+ } ) ;
170+
171+ it ( 'in `fix` function' , async ( ) => {
172+ const { stdout, exitCode } = await runOxlint ( 'test/fixtures/custom_plugin_lint_fix_error' ) ;
173+ expect ( exitCode ) . toBe ( 1 ) ;
174+ expect ( normalizeOutput ( stdout ) ) . toMatchSnapshot ( ) ;
175+ } ) ;
176+ } ) ;
177+
132178 it ( 'should report the correct severity when using a custom plugin' , async ( ) => {
133179 const { stdout, exitCode } = await runOxlint ( 'test/fixtures/basic_custom_plugin_warn_severity' ) ;
134180 expect ( exitCode ) . toBe ( 0 ) ;
0 commit comments