|
| 1 | +import fs from 'node:fs/promises'; |
| 2 | +import path from 'node:path'; |
| 3 | +import plugin from '../src'; |
| 4 | + |
| 5 | +function isSourceFile(value: string): boolean { |
| 6 | + const ext = path.extname(value); |
| 7 | + return ext === '.ts' && !value.endsWith('.d.ts'); |
| 8 | +} |
| 9 | + |
| 10 | +describe('package', () => { |
| 11 | + const pkg = path.resolve('src'); |
| 12 | + |
| 13 | + it('exists', () => { |
| 14 | + expect(plugin).toBeDefined(); |
| 15 | + }); |
| 16 | + |
| 17 | + it('has every rule', async () => { |
| 18 | + const files = await fs.readdir(path.resolve(pkg, 'rules')); |
| 19 | + for (const file of files.filter(isSourceFile)) { |
| 20 | + const ruleName = path.basename(file, path.extname(file)); |
| 21 | + expect(plugin.rules).toHaveProperty(ruleName); |
| 22 | + } |
| 23 | + }); |
| 24 | + |
| 25 | + it('exports all configs', async () => { |
| 26 | + const files = await fs.readdir(path.resolve(pkg, 'configs')); |
| 27 | + for (const file of files.filter(isSourceFile)) { |
| 28 | + const configName = path.basename(file, path.extname(file)); |
| 29 | + expect(plugin.configs).toHaveProperty(configName); |
| 30 | + } |
| 31 | + }); |
| 32 | + |
| 33 | + it('has configs only for rules included in the plugin', () => { |
| 34 | + if (!plugin.configs) { |
| 35 | + expect.fail('No configs found.'); |
| 36 | + } |
| 37 | + |
| 38 | + const namespace = 'rxjs-x'; |
| 39 | + for (const config of Object.values(plugin.configs)) { |
| 40 | + if (!config.rules) { |
| 41 | + continue; |
| 42 | + } |
| 43 | + for (const ruleName of Object.keys(config.rules)) { |
| 44 | + expect(plugin.rules).toHaveProperty(ruleName.slice(namespace.length + 1)); |
| 45 | + } |
| 46 | + } |
| 47 | + }); |
| 48 | +}); |
0 commit comments