|
1 | 1 | import fs from 'fs'; |
2 | | - |
3 | 2 | import { createRequire } from 'module'; |
| 3 | +import process from 'process'; |
| 4 | +import path from 'path'; |
| 5 | +import { fileURLToPath } from 'url'; |
4 | 6 |
|
| 7 | +import eslint9 from 'eslint9'; |
| 8 | +import esmock from 'esmock'; |
5 | 9 | import test from 'ava'; |
6 | 10 | import nodeResolve from '@rollup/plugin-node-resolve'; |
7 | 11 | import { rollup } from 'rollup'; |
@@ -241,3 +245,36 @@ test('works with flat config', async (t) => { |
241 | 245 |
|
242 | 246 | t.is(count, 1); |
243 | 247 | }); |
| 248 | + |
| 249 | +test.serial('works with ESLint v9', async (t) => { |
| 250 | + // Load the plugin with an override to route 'eslint' imports to ESLint v9 |
| 251 | + const eslint = await esmock('current-package', { |
| 252 | + eslint: eslint9 |
| 253 | + }); |
| 254 | + |
| 255 | + // ESLint v9 needs to be invoked with a flat config file in the current dir |
| 256 | + const cwd = process.cwd(); |
| 257 | + const testDir = path.dirname(fileURLToPath(import.meta.url)); |
| 258 | + process.chdir(path.join(testDir, 'fixtures', 'flat-config')); |
| 259 | + |
| 260 | + let count = 0; |
| 261 | + try { |
| 262 | + await rollup({ |
| 263 | + input: './undeclared.js', |
| 264 | + plugins: [ |
| 265 | + eslint({ |
| 266 | + formatter: (results) => { |
| 267 | + count += results[0].messages.length; |
| 268 | + // eslint-disable-next-line prefer-destructuring |
| 269 | + const { message } = results[0].messages[0]; |
| 270 | + t.is(message, "'x' is not defined."); |
| 271 | + } |
| 272 | + }) |
| 273 | + ] |
| 274 | + }); |
| 275 | + } finally { |
| 276 | + process.chdir(cwd); |
| 277 | + } |
| 278 | + |
| 279 | + t.is(count, 1); |
| 280 | +}); |
0 commit comments