Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions tests/configs/recommended.test.ts
Original file line number Diff line number Diff line change
@@ -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 }]);
});
});
48 changes: 48 additions & 0 deletions tests/package.test.ts
Original file line number Diff line number Diff line change
@@ -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));
}
}
});
});