-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathjsdocs-plugin.unit.test.ts
More file actions
101 lines (89 loc) · 2.64 KB
/
jsdocs-plugin.unit.test.ts
File metadata and controls
101 lines (89 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import { describe, expect, it, vi } from 'vitest';
import { pluginConfigSchema } from '@code-pushup/models';
import {
GROUPS,
PLUGIN_DESCRIPTION,
PLUGIN_DOCS_URL,
PLUGIN_SLUG,
PLUGIN_TITLE,
} from './constants.js';
import { jsDocsPlugin } from './jsdocs-plugin.js';
import { createRunnerFunction } from './runner/runner.js';
import {
filterAuditsByPluginConfig,
filterGroupsByOnlyAudits,
} from './utils.js';
vi.mock('./utils.js', async () => ({
...(await vi.importActual('./utils.js')),
filterAuditsByPluginConfig: vi.fn().mockReturnValue([
{
slug: 'mock-audit',
title: 'Mock Audit',
},
]),
filterGroupsByOnlyAudits: vi.fn().mockReturnValue([
{
slug: 'mock-group',
title: 'Mock Group',
refs: [
{
slug: 'mock-audit',
weight: 1,
},
],
},
]),
}));
vi.mock('./runner/runner.js', () => ({
createRunnerFunction: vi.fn().mockReturnValue(() => Promise.resolve([])),
}));
describe('jsDocsPlugin', () => {
it('should create a valid plugin config', () => {
expect(
jsDocsPlugin({
patterns: ['src/**/*.ts', '!**/*.spec.ts', '!**/*.test.ts'],
}),
).toStrictEqual(
expect.objectContaining({
slug: PLUGIN_SLUG,
title: PLUGIN_TITLE,
icon: 'folder-docs',
description: PLUGIN_DESCRIPTION,
docsUrl: PLUGIN_DOCS_URL,
groups: expect.any(Array),
audits: expect.any(Array),
runner: expect.any(Function),
}),
);
});
it('should throw for invalid plugin options', () => {
expect(() =>
// @ts-expect-error testing invalid config
jsDocsPlugin({ patterns: 123 }),
).toThrow('Invalid input');
});
it('should filter groups', () => {
const config = { patterns: ['src/**/*.ts'] };
jsDocsPlugin(config);
expect(filterGroupsByOnlyAudits).toHaveBeenCalledWith(GROUPS, config);
});
it('should filter audits', async () => {
const config = { patterns: ['src/**/*.ts'] };
jsDocsPlugin(config);
expect(filterAuditsByPluginConfig).toHaveBeenCalledWith(config);
});
it('should forward options to runner function', async () => {
const config = { patterns: ['src/**/*.ts'] };
jsDocsPlugin(config);
expect(createRunnerFunction).toHaveBeenCalledWith(config);
});
it('should pass scoreTargets to PluginConfig when provided', () => {
const scoreTargets = { 'functions-coverage': 0.9 };
const pluginConfig = jsDocsPlugin({
patterns: ['src/**/*.ts'],
scoreTargets,
});
expect(() => pluginConfigSchema.parse(pluginConfig)).not.toThrow();
expect(pluginConfig.scoreTargets).toStrictEqual(scoreTargets);
});
});