1
1
import cp from 'child_process'
2
2
import path from 'path'
3
3
import assert from 'assert'
4
- import semver from 'semver'
5
- import { readPackageJson } from './helper'
6
4
7
5
const TEST_CWD = path . join ( __dirname , 'flat-config' )
8
- const ESLINT = `.${ path . sep } node_modules${ path . sep } .bin${ path . sep } eslint`
9
6
10
- describe ( 'Integration with flat config' , ( ) => {
7
+ describe ( 'Integration with Flat config' , ( ) => {
11
8
let originalCwd : string
12
9
13
10
before ( ( ) => {
14
- originalCwd = process . cwd ( ) ;
15
- process . chdir ( TEST_CWD ) ;
16
- try {
17
- cp . execSync ( 'yarn' , { stdio : 'inherit' } ) ;
18
- } catch ( error ) {
19
- console . error ( 'Error running yarn:' , error ) ;
20
- throw error ;
21
- }
22
- } ) ;
11
+ originalCwd = process . cwd ( )
12
+ process . chdir ( TEST_CWD )
13
+ cp . execSync ( 'yarn' , { stdio : 'inherit' } )
14
+ } )
23
15
after ( ( ) => {
24
- originalCwd && process . chdir ( originalCwd )
16
+ process . chdir ( originalCwd )
25
17
} )
26
18
27
- it ( 'should work with flat config' , async ( ) => {
28
- if (
29
- ! semver . satisfies (
30
- process . version ,
31
- readPackageJson (
32
- path . resolve ( __dirname , './flat-config/node_modules/eslint' )
33
- ) . engines . node
34
- )
35
- ) {
36
- return
37
- }
38
- const cliResult = cp . execSync ( `${ ESLINT } src/* --format=json` , {
39
- encoding : 'utf-8'
19
+ it ( 'should work with Flat config' , async ( ) => {
20
+ const ESLint = require ( './flat-config/node_modules/eslint' ) . ESLint
21
+ const engine = new ESLint ( {
22
+ cwd : TEST_CWD
40
23
} )
41
24
42
- const result = JSON . parse ( cliResult )
25
+ try {
26
+ const results = await engine . lintFiles ( [ './src' ] )
43
27
44
- const aSvelte = result . find (
45
- ( r : { filePath : string } ) => path . basename ( r . filePath ) === 'a.svelte'
46
- )
47
- assert . strictEqual ( aSvelte . messages . length , 1 )
48
- assert . strictEqual (
49
- aSvelte . messages [ 0 ] . ruleId ,
50
- '@intlify/svelte/no-raw-text'
51
- )
28
+ const aSvelte = results . find (
29
+ ( r : { filePath : string } ) => path . basename ( r . filePath ) === 'a.svelte'
30
+ )
31
+
32
+ if ( ! aSvelte ) {
33
+ throw new Error ( 'a.svelte file not found in lint results' )
34
+ }
35
+
36
+ assert . strictEqual ( aSvelte . messages . length , 1 )
37
+ assert . strictEqual (
38
+ aSvelte . messages [ 0 ] . ruleId ,
39
+ '@intlify/svelte/no-raw-text'
40
+ )
41
+ } catch ( error ) {
42
+ console . error ( 'Error during linting:' , error )
43
+ throw error
44
+ }
52
45
} )
53
46
} )
0 commit comments