Skip to content

Commit f460633

Browse files
test: coverage on plugin and recommended config (#1)
1 parent 25fe704 commit f460633

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

tests/configs/recommended.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { createRecommendedConfig } from '../../src/configs/recommended';
2+
3+
describe('recommended', () => {
4+
const mockPlugin = {};
5+
const config = createRecommendedConfig(mockPlugin);
6+
7+
it('should add the rxjs-x plugin', () => {
8+
expect(config.plugins).toEqual({ 'rxjs-x': mockPlugin });
9+
});
10+
11+
it('should default no-sharereplay to allowConfig: true', () => {
12+
expect(config.rules).instanceOf(Object);
13+
expect(config.rules['rxjs-x/no-sharereplay']).toEqual(['error', { allowConfig: true }]);
14+
});
15+
});

tests/package.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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

Comments
 (0)