diff --git a/tests/configs/recommended.test.ts b/tests/configs/recommended.test.ts new file mode 100644 index 00000000..3ba4581c --- /dev/null +++ b/tests/configs/recommended.test.ts @@ -0,0 +1,15 @@ +import { createRecommendedConfig } from '../../src/configs/recommended'; + +describe('recommended', () => { + const mockPlugin = {}; + const config = createRecommendedConfig(mockPlugin); + + it('should add the rxjs-x plugin', () => { + expect(config.plugins).toEqual({ 'rxjs-x': mockPlugin }); + }); + + it('should default no-sharereplay to allowConfig: true', () => { + expect(config.rules).instanceOf(Object); + expect(config.rules['rxjs-x/no-sharereplay']).toEqual(['error', { allowConfig: true }]); + }); +}); diff --git a/tests/package.test.ts b/tests/package.test.ts new file mode 100644 index 00000000..11d39154 --- /dev/null +++ b/tests/package.test.ts @@ -0,0 +1,48 @@ +import fs from 'node:fs/promises'; +import path from 'node:path'; +import plugin from '../src'; + +function isSourceFile(value: string): boolean { + const ext = path.extname(value); + return ext === '.ts' && !value.endsWith('.d.ts'); +} + +describe('package', () => { + const pkg = path.resolve('src'); + + it('exists', () => { + expect(plugin).toBeDefined(); + }); + + it('has every rule', async () => { + const files = await fs.readdir(path.resolve(pkg, 'rules')); + for (const file of files.filter(isSourceFile)) { + const ruleName = path.basename(file, path.extname(file)); + expect(plugin.rules).toHaveProperty(ruleName); + } + }); + + it('exports all configs', async () => { + const files = await fs.readdir(path.resolve(pkg, 'configs')); + for (const file of files.filter(isSourceFile)) { + const configName = path.basename(file, path.extname(file)); + expect(plugin.configs).toHaveProperty(configName); + } + }); + + it('has configs only for rules included in the plugin', () => { + if (!plugin.configs) { + expect.fail('No configs found.'); + } + + const namespace = 'rxjs-x'; + for (const config of Object.values(plugin.configs)) { + if (!config.rules) { + continue; + } + for (const ruleName of Object.keys(config.rules)) { + expect(plugin.rules).toHaveProperty(ruleName.slice(namespace.length + 1)); + } + } + }); +});