|
| 1 | +import { describe, expect, it } from 'vitest'; |
| 2 | +import { CoveragePluginConfig, coveragePluginConfigSchema } from './config'; |
| 3 | + |
| 4 | +describe('coveragePluginConfigSchema', () => { |
| 5 | + it('accepts a code coverage configuration with all entities', () => { |
| 6 | + expect(() => |
| 7 | + coveragePluginConfigSchema.parse({ |
| 8 | + coverageType: ['branch', 'function'], |
| 9 | + reports: ['coverage/cli/lcov.info'], |
| 10 | + coverageToolCommand: { |
| 11 | + command: 'npx nx run-many', |
| 12 | + args: ['-t', 'test', '--coverage'], |
| 13 | + }, |
| 14 | + perfectScoreThreshold: 85, |
| 15 | + } satisfies CoveragePluginConfig), |
| 16 | + ).not.toThrow(); |
| 17 | + }); |
| 18 | + |
| 19 | + it('accepts a minimal code coverage configuration', () => { |
| 20 | + expect(() => |
| 21 | + coveragePluginConfigSchema.parse({ |
| 22 | + coverageType: ['line'], |
| 23 | + reports: ['coverage/cli/lcov.info'], |
| 24 | + } satisfies CoveragePluginConfig), |
| 25 | + ).not.toThrow(); |
| 26 | + }); |
| 27 | + |
| 28 | + it('throws for no coverage type', () => { |
| 29 | + expect(() => |
| 30 | + coveragePluginConfigSchema.parse({ |
| 31 | + coverageType: [], |
| 32 | + reports: ['coverage/cli/lcov.info'], |
| 33 | + } satisfies CoveragePluginConfig), |
| 34 | + ).toThrow('too_small'); |
| 35 | + }); |
| 36 | + |
| 37 | + it('throws for no report', () => { |
| 38 | + expect(() => |
| 39 | + coveragePluginConfigSchema.parse({ |
| 40 | + coverageType: ['branch'], |
| 41 | + reports: [], |
| 42 | + } satisfies CoveragePluginConfig), |
| 43 | + ).toThrow('too_small'); |
| 44 | + }); |
| 45 | + |
| 46 | + it('throws for unsupported report format', () => { |
| 47 | + expect(() => |
| 48 | + coveragePluginConfigSchema.parse({ |
| 49 | + coverageType: ['line'], |
| 50 | + reports: ['coverage/cli/coverage-final.json'], |
| 51 | + }), |
| 52 | + ).toThrow(/Invalid input: must include.+lcov/); |
| 53 | + }); |
| 54 | + |
| 55 | + it('throws for missing command', () => { |
| 56 | + expect(() => |
| 57 | + coveragePluginConfigSchema.parse({ |
| 58 | + coverageType: ['line'], |
| 59 | + reports: ['coverage/cli/lcov.info'], |
| 60 | + coverageToolCommand: { |
| 61 | + args: ['npx', 'nx', 'run-many', '-t', 'test', '--coverage'], |
| 62 | + }, |
| 63 | + }), |
| 64 | + ).toThrow('invalid_type'); |
| 65 | + }); |
| 66 | + |
| 67 | + it('throws for invalid score threshold', () => { |
| 68 | + expect(() => |
| 69 | + coveragePluginConfigSchema.parse({ |
| 70 | + coverageType: ['line'], |
| 71 | + reports: ['coverage/cli/lcov.info'], |
| 72 | + perfectScoreThreshold: 110, |
| 73 | + } satisfies CoveragePluginConfig), |
| 74 | + ).toThrow('too_big'); |
| 75 | + }); |
| 76 | +}); |
0 commit comments