|
1 | 1 | import { describe, expect, it } from 'vitest'; |
2 | | -import { reportMock } from '../../test'; |
3 | | -import { auditOutputsSchema } from './audit-output'; |
4 | | -import { pluginConfigSchema } from './plugin-config'; |
| 2 | +import { Audit, auditSchema, pluginAuditsSchema } from './audit'; |
5 | 3 |
|
6 | | -describe('auditOutputsSchema', () => { |
7 | | - it('should pass if output audits are valid', () => { |
8 | | - const auditOutputs = reportMock().plugins[0].audits; |
9 | | - expect(() => auditOutputsSchema.parse(auditOutputs)).not.toThrow(); |
| 4 | +describe('auditSchema', () => { |
| 5 | + it('should accept a valid audit with all information', () => { |
| 6 | + expect(() => |
| 7 | + auditSchema.parse({ |
| 8 | + slug: 'no-conditionals-in-tests', |
| 9 | + title: 'No conditional logic is used in tests.', |
| 10 | + description: 'Conditional logic does not produce stable results.', |
| 11 | + docsUrl: |
| 12 | + 'https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/no-conditional-in-test.md', |
| 13 | + } satisfies Audit), |
| 14 | + ).not.toThrow(); |
10 | 15 | }); |
11 | 16 |
|
12 | | - it('should throw if slugs of audits are invalid', () => { |
13 | | - const auditOutputs = reportMock().plugins[0].audits; |
14 | | - auditOutputs[0].slug = '-invalid-audit-slug'; |
15 | | - |
16 | | - expect(() => auditOutputsSchema.parse(auditOutputs)).toThrow( |
17 | | - 'slug has to follow the pattern', |
18 | | - ); |
| 17 | + it('should accept a valid audit with minimum information', () => { |
| 18 | + expect(() => |
| 19 | + auditSchema.parse({ |
| 20 | + slug: 'jest-unit-test-results', |
| 21 | + title: 'Jest unit tests results.', |
| 22 | + } satisfies Audit), |
| 23 | + ).not.toThrow(); |
19 | 24 | }); |
20 | 25 |
|
21 | | - it('should throw if slugs of audits are duplicated', () => { |
22 | | - const audits = reportMock().plugins[0].audits; |
23 | | - const auditOutputs = [...audits, audits[0]]; |
24 | | - expect(() => auditOutputsSchema.parse(auditOutputs)).toThrow( |
25 | | - 'In plugin audits the slugs are not unique', |
26 | | - ); |
| 26 | + it('should throw for an invalid URL', () => { |
| 27 | + expect(() => |
| 28 | + auditSchema.parse({ |
| 29 | + slug: 'consistent-test-it', |
| 30 | + title: 'Use a consistent test function.', |
| 31 | + docsUrl: 'invalid-url', |
| 32 | + } satisfies Audit), |
| 33 | + ).toThrow('Invalid url'); |
27 | 34 | }); |
| 35 | +}); |
28 | 36 |
|
29 | | - it('should throw if plugin groups refs contain invalid slugs', () => { |
30 | | - const invalidAuditRef = '-invalid-audit-ref'; |
31 | | - const pluginConfig = reportMock().plugins[1]; |
32 | | - const groups = pluginConfig.groups; |
33 | | - groups[0].refs[0].slug = invalidAuditRef; |
34 | | - pluginConfig.groups = groups; |
| 37 | +describe('pluginAuditsSchema', () => { |
| 38 | + it('should parse a valid audit array', () => { |
| 39 | + expect(() => |
| 40 | + pluginAuditsSchema.parse([ |
| 41 | + { |
| 42 | + slug: 'consistent-test-it', |
| 43 | + title: 'Use a consistent test function.', |
| 44 | + }, |
| 45 | + { |
| 46 | + slug: 'jest-unit-test-results', |
| 47 | + title: 'Jest unit tests results.', |
| 48 | + }, |
| 49 | + ] satisfies Audit[]), |
| 50 | + ).not.toThrow(); |
| 51 | + }); |
35 | 52 |
|
36 | | - expect(() => pluginConfigSchema.parse(pluginConfig)).toThrow( |
37 | | - `slug has to follow the patter`, |
38 | | - ); |
| 53 | + it('should throw for duplicate audits', () => { |
| 54 | + expect(() => |
| 55 | + pluginAuditsSchema.parse([ |
| 56 | + { |
| 57 | + slug: 'consistent-test-it', |
| 58 | + title: 'Use a consistent test function.', |
| 59 | + }, |
| 60 | + { |
| 61 | + slug: 'jest-unit-test-results', |
| 62 | + title: 'Jest unit tests results.', |
| 63 | + }, |
| 64 | + { |
| 65 | + slug: 'jest-unit-test-results', |
| 66 | + title: 'Jest unit tests results.', |
| 67 | + }, |
| 68 | + ] satisfies Audit[]), |
| 69 | + ).toThrow('slugs are not unique: jest-unit-test-results'); |
39 | 70 | }); |
40 | 71 | }); |
0 commit comments