11import assert from "node:assert/strict"
22import { describe , it } from "node:test"
3+ import { fileURLToPath , URL } from "node:url"
34
4- import { Linter } from "eslint"
5+ import { ESLint , Linter } from "eslint"
56import typescriptEslint from "typescript-eslint"
67
78import { apiProviderHygieneConfig , apiProviderTestSelectors , apiSpecTsIgnoreConfig } from "./api-provider-hygiene.js"
@@ -174,7 +175,13 @@ describe("api provider hygiene: spec loops", () => {
174175 } )
175176 }
176177
177- for ( const code of [ 'await expect(p).rejects.toThrow("aborted")' , "expect(() => f()).toThrow('abort')" ] ) {
178+ for ( const code of [
179+ 'await expect(p).rejects.toThrow("aborted")' ,
180+ "expect(() => f()).toThrow('abort')" ,
181+ 'await expect(p).rejects.toThrowError("aborted")' ,
182+ "expect(() => f()).toThrow(/abort/i)" ,
183+ "await expect(p).rejects.toThrowError(/aborted/i)" ,
184+ ] ) {
178185 it ( `flags a bare abort substring: ${ code } ` , ( ) => {
179186 assert . equal ( lintSpec ( code ) . length , 1 )
180187 } )
@@ -184,6 +191,11 @@ describe("api provider hygiene: spec loops", () => {
184191 'await expect(p).rejects.toThrow("The Requesty request was aborted")' ,
185192 'await expect(p).rejects.toMatchObject({ name: "AbortError" })' ,
186193 'await expect(p).rejects.toThrow("API Error")' ,
194+ 'expect(() => f()).not.toThrow("aborted")' ,
195+ 'await expect(p).rejects.not.toThrow("aborted")' ,
196+ "expect(() => f()).not.toThrowError(/abort/i)" ,
197+ "await expect(p).rejects.not.toThrowError(/aborted/i)" ,
198+ "await expect(p).rejects.toThrow(/^The Requesty request was aborted$/)" ,
187199 ] ) {
188200 it ( `allows: ${ code } ` , ( ) => {
189201 assert . deepEqual ( lintSpec ( code ) , [ ] )
@@ -261,3 +273,39 @@ describe("api provider hygiene: @ts-ignore in specs", () => {
261273 assert . deepEqual ( lintSpecFile ( "// @ts-ignore x\nhandler.client" , "services/__tests__/example.spec.ts" ) , [ ] )
262274 } )
263275} )
276+
277+ // Resolve each lane through the extension's real config before exercising its syntax rules.
278+ // Isolating syntax rules avoids requiring fixture files in the TypeScript project.
279+ describe ( "abort assertions in the extension ESLint config" , ( ) => {
280+ const srcRoot = fileURLToPath ( new URL ( "../../src/" , import . meta. url ) )
281+ const eslint = new ESLint ( { cwd : srcRoot } )
282+
283+ for ( const filename of [ "core/task/__tests__/example.spec.ts" , "core/config/__tests__/example.spec.ts" ] ) {
284+ it ( `checks rejected and accepted assertions in ${ filename } ` , async ( ) => {
285+ const resolved = await eslint . calculateConfigForFile ( filename )
286+ const syntaxConfig = [
287+ {
288+ files : [ "**/*.ts" ] ,
289+ languageOptions : { parser : typescriptEslint . parser } ,
290+ rules : { "no-restricted-syntax" : resolved . rules [ "no-restricted-syntax" ] } ,
291+ } ,
292+ ]
293+ for ( const [ code , expectedCount ] of [
294+ [ 'await expect(p).rejects.toThrow("aborted")' , 1 ] ,
295+ [ "await expect(p).rejects.toThrowError(/abort/i)" , 1 ] ,
296+ [ 'await expect(p).rejects.not.toThrow("aborted")' , 0 ] ,
297+ [
298+ 'await expect(p).rejects.toMatchObject({ name: "AbortError", message: "The Requesty request was aborted" })' ,
299+ 0 ,
300+ ] ,
301+ ] ) {
302+ const messages = linter . verify ( code , syntaxConfig , { filename } )
303+ assert . equal ( messages . length , expectedCount , code )
304+ if ( expectedCount ) {
305+ assert . equal ( messages [ 0 ] . ruleId , "no-restricted-syntax" )
306+ assert . match ( messages [ 0 ] . message , / b a r e ' a b o r t ' s u b s t r i n g / )
307+ }
308+ }
309+ } )
310+ }
311+ } )
0 commit comments