|
1 | | -import { describe, it, expect } from 'vitest' |
2 | | -// Import from built version to test the actual export |
3 | | -// In a real scenario, users would import from 'eslint-plugin-test-a11y-js' |
4 | | -import eslintPlugin from '../../../../dist/linter/eslint-plugin/index.js' |
| 1 | +import { describe, it, expect, beforeAll } from 'vitest' |
| 2 | +import { resolve, dirname } from 'path' |
| 3 | +import { fileURLToPath } from 'url' |
| 4 | +import { existsSync } from 'fs' |
| 5 | +import { createRequire } from 'module' |
| 6 | + |
| 7 | +const require = createRequire(import.meta.url) |
| 8 | + |
| 9 | +function getProjectRoot(): string { |
| 10 | + const fromCwd = process.cwd() |
| 11 | + const pluginFromCwd = resolve(fromCwd, 'dist/linter/eslint-plugin/index.js') |
| 12 | + if (existsSync(pluginFromCwd)) return fromCwd |
| 13 | + const fromFile = resolve(dirname(fileURLToPath(import.meta.url)), '..', '..', '..', '..') |
| 14 | + const pluginFromFile = resolve(fromFile, 'dist/linter/eslint-plugin/index.js') |
| 15 | + if (existsSync(pluginFromFile)) return fromFile |
| 16 | + throw new Error( |
| 17 | + 'dist/linter/eslint-plugin/index.js not found. Ensure npm run build ran first.' |
| 18 | + ) |
| 19 | +} |
| 20 | + |
| 21 | +let eslintPlugin: { meta?: { name?: string; version?: string }; rules?: Record<string, unknown>; configs?: Record<string, unknown> } |
5 | 22 |
|
6 | 23 | const ALL_RULE_NAMES = [ |
7 | 24 | 'accessible-emoji', |
@@ -50,6 +67,11 @@ const ALL_RULE_NAMES = [ |
50 | 67 | ] |
51 | 68 |
|
52 | 69 | describe('ESLint Plugin Structure', () => { |
| 70 | + beforeAll(() => { |
| 71 | + const root = getProjectRoot() |
| 72 | + eslintPlugin = require(resolve(root, 'dist/linter/eslint-plugin/index.js')).default |
| 73 | + }) |
| 74 | + |
53 | 75 | it('should export a plugin object', () => { |
54 | 76 | expect(eslintPlugin).toBeDefined() |
55 | 77 | expect(typeof eslintPlugin).toBe('object') |
|
0 commit comments