55import type { Linter } from 'eslint'
66
77import { ESLint } from 'eslint'
8+ import { existsSync } from 'fs'
9+ import { readFile } from 'fs/promises'
810import { join , resolve } from 'path'
911import { expect , test } from 'vitest'
1012import * as eslintConfig from '../lib/index.js'
@@ -21,9 +23,18 @@ const eslint = new ESLint({
2123 * @param file - File path to lint
2224 * @return Lint result
2325 */
24- async function lintFile ( file ) {
25- const real = resolve ( join ( __dirname , file ) )
26- return await eslint . lintFiles ( real )
26+ async function lintTestCase ( testCase : string ) {
27+ let file = `fixtures/codestyle/input/${ testCase } .`
28+ if ( existsSync ( join ( __dirname , file ) + 'js' ) ) {
29+ file += 'js'
30+ } else {
31+ file += 'ts'
32+ }
33+
34+ const path = resolve ( join ( __dirname , file ) )
35+ const content = await readFile ( path )
36+ const results = await eslint . lintText ( content . toString ( ) , { filePath : `src/${ file } ` } )
37+ return { results, path }
2738}
2839
2940test . for ( [
@@ -37,7 +48,7 @@ test.for([
3748 'quotes' ,
3849 'semicolons' ,
3950] ) ( 'Code style' , async ( testCase : string ) => {
40- const results = await lintFile ( `fixtures/codestyle/input/ ${ testCase } .{t,j}s` )
51+ const { results, path } = await lintTestCase ( testCase )
4152 expect ( results ) . toHaveLength ( 1 )
42- await expect ( results [ 0 ] . output ) . toMatchFileSnapshot ( results [ 0 ] . filePath . replace ( 'input' , 'output' ) )
53+ await expect ( results [ 0 ] . output ) . toMatchFileSnapshot ( path . replace ( 'input' , 'output' ) )
4354} )
0 commit comments