-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathlighthouse-plugin.unit.test.ts
More file actions
123 lines (111 loc) · 3.98 KB
/
Copy pathlighthouse-plugin.unit.test.ts
File metadata and controls
123 lines (111 loc) · 3.98 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import { expect } from 'vitest';
import { pluginConfigSchema } from '@code-pushup/models';
import { lighthousePlugin } from './lighthouse-plugin.js';
import type { LighthouseOptions } from './types.js';
describe('lighthousePlugin-config-object', () => {
it('should create valid plugin config', () => {
const pluginConfig = lighthousePlugin('https://code-pushup-portal.com');
expect(() => pluginConfigSchema.parse(pluginConfig)).not.toThrow();
const { audits, groups } = pluginConfig;
expect(audits.length).toBeGreaterThan(100);
expect(groups).toStrictEqual([
expect.objectContaining({ slug: 'performance' }),
expect.objectContaining({ slug: 'accessibility' }),
expect.objectContaining({ slug: 'best-practices' }),
expect.objectContaining({ slug: 'seo' }),
]);
});
it('should create valid plugin config with multiple URLs', () => {
const pluginConfig = lighthousePlugin([
'https://code-pushup-portal.com',
'https://code-pushup-portal.com/about',
]);
expect(() => pluginConfigSchema.parse(pluginConfig)).not.toThrow();
const { audits, groups } = pluginConfig;
expect(audits.length).toBeGreaterThan(100);
expect(groups).toStrictEqual([
expect.objectContaining({ slug: 'performance-1' }),
expect.objectContaining({ slug: 'accessibility-1' }),
expect.objectContaining({ slug: 'best-practices-1' }),
expect.objectContaining({ slug: 'seo-1' }),
expect.objectContaining({ slug: 'performance-2' }),
expect.objectContaining({ slug: 'accessibility-2' }),
expect.objectContaining({ slug: 'best-practices-2' }),
expect.objectContaining({ slug: 'seo-2' }),
]);
});
it('should generate context for multiple URLs', () => {
const pluginConfig = lighthousePlugin({
'https://code-pushup-portal.com': 2,
'https://code-pushup-portal.com/about': 1,
});
expect(pluginConfig.context).toStrictEqual({
urlCount: 2,
weights: { 1: 2, 2: 1 },
});
});
it.each([
[
{ onlyAudits: ['first-contentful-paint'] },
'first-contentful-paint',
false,
],
[
{ onlyAudits: ['first-contentful-paint'] },
'largest-contentful-paint',
true,
],
[
{ skipAudits: ['first-contentful-paint'] },
'first-contentful-paint',
true,
],
[
{ skipAudits: ['first-contentful-paint'] },
'largest-contentful-paint',
false,
],
])(
'should apply option %o and set the "%s" audit skipped status to %s',
(option, audit, isSkipped) => {
const pluginConfig = lighthousePlugin(
'https://code-pushup-portal.com',
option as LighthouseOptions,
);
expect(() => pluginConfigSchema.parse(pluginConfig)).not.toThrow();
expect(pluginConfig.audits.find(({ slug }) => audit === slug)).toEqual(
expect.objectContaining({ isSkipped }),
);
},
);
it.each([
[{ onlyGroups: ['performance'] }, 'performance', false],
[{ onlyGroups: ['performance'] }, 'accessibility', true],
])(
'should apply option %o and set the "%s" group skipped status to %s',
(option, group, isSkipped) => {
const pluginConfig = lighthousePlugin(
'https://code-pushup-portal.com',
option as LighthouseOptions,
);
expect(() => pluginConfigSchema.parse(pluginConfig)).not.toThrow();
expect(pluginConfig.groups?.find(({ slug }) => group === slug)).toEqual(
expect.objectContaining({ isSkipped }),
);
},
);
it('should mark groups referencing audits in onlyAudits as not skipped', () => {
const pluginConfig = lighthousePlugin('https://code-pushup-portal.com', {
onlyAudits: ['first-contentful-paint'],
});
expect(() => pluginConfigSchema.parse(pluginConfig)).not.toThrow();
const group = pluginConfig.groups?.find(({ refs }) =>
refs.some(ref => ref.slug === 'first-contentful-paint'),
);
expect(group).toEqual(
expect.objectContaining({
isSkipped: false,
}),
);
});
});