|
1 | 1 | 'use strict' |
2 | 2 |
|
3 | 3 | const { strict: assert } = require('node:assert') |
4 | | -const cp = require('node:child_process') |
| 4 | +const { execSync } = require('node:child_process') |
5 | 5 | const path = require('node:path') |
6 | 6 | const semver = require('semver') |
7 | 7 |
|
8 | 8 | const TARGET_DIR = path.join(__dirname, 'flat-config') |
9 | | -const ESLINT = `.${path.sep}node_modules${path.sep}.bin${path.sep}eslint` |
| 9 | +const ESLINT = path.join(TARGET_DIR, 'node_modules', '.bin', 'eslint') |
| 10 | + |
| 11 | +let eslintNodeVersion = '' |
10 | 12 |
|
11 | 13 | describe('Integration with flat config', () => { |
12 | 14 | beforeAll(() => { |
13 | | - cp.execSync('npm i -f', { cwd: TARGET_DIR, stdio: 'inherit' }) |
| 15 | + execSync('npm i -f', { cwd: TARGET_DIR, stdio: 'inherit' }) |
| 16 | + eslintNodeVersion = require( |
| 17 | + path.join(TARGET_DIR, 'node_modules/eslint/package.json') |
| 18 | + ).engines.node |
14 | 19 | }) |
15 | 20 |
|
16 | | - it('should lint without errors', () => { |
17 | | - if ( |
18 | | - !semver.satisfies( |
19 | | - process.version, |
20 | | - require( |
21 | | - path.join(__dirname, 'flat-config/node_modules/eslint/package.json') |
22 | | - ).engines.node |
| 21 | + it.skipIf(!semver.satisfies(process.version, eslintNodeVersion))( |
| 22 | + 'should lint without errors', |
| 23 | + () => { |
| 24 | + const result = JSON.parse( |
| 25 | + execSync(`${ESLINT} a.vue --format=json`, { |
| 26 | + cwd: TARGET_DIR, |
| 27 | + encoding: 'utf8' |
| 28 | + }) |
23 | 29 | ) |
24 | | - ) { |
25 | | - return |
| 30 | + assert.strictEqual(result.length, 1) |
| 31 | + assert.deepStrictEqual(result[0].messages, []) |
26 | 32 | } |
27 | | - |
28 | | - const result = JSON.parse( |
29 | | - cp.execSync(`${ESLINT} a.vue --format=json`, { |
30 | | - cwd: TARGET_DIR, |
31 | | - encoding: 'utf8' |
32 | | - }) |
33 | | - ) |
34 | | - assert.strictEqual(result.length, 1) |
35 | | - assert.deepStrictEqual(result[0].messages, []) |
36 | | - }) |
| 33 | + ) |
37 | 34 | }) |
0 commit comments