-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathreport-to-gql.unit.test.ts
More file actions
223 lines (217 loc) · 6.16 KB
/
Copy pathreport-to-gql.unit.test.ts
File metadata and controls
223 lines (217 loc) · 6.16 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
import { type AuditReportTree, TreeType } from '@code-pushup/portal-client';
import { issueToGQL, tableToGQL, treeToGQL } from './report-to-gql.js';
describe('issueToGQL', () => {
it('should transform issue with file source to GraphQL input type', () => {
expect(
issueToGQL({
message: 'No let, use const instead.',
severity: 'error',
source: {
file: 'cli.ts',
position: { startLine: 5, startColumn: 10, endColumn: 25 },
},
}),
).toStrictEqual({
message: 'No let, use const instead.',
severity: 'Error',
sourceType: 'SourceCode',
sourceFilePath: 'cli.ts',
sourceStartLine: 5,
sourceStartColumn: 10,
sourceEndLine: undefined,
sourceEndColumn: 25,
});
});
it('should transform issue with URL source to GraphQL input type', () => {
expect(
issueToGQL({
message: 'Fix any of the following: Unable to determine contrast ratio',
severity: 'error',
source: {
url: 'https://code-pushup.dev/',
snippet: '<span>measure development KPIs</span>',
selector: '.text-box > span:nth-child(3)',
},
}),
).toStrictEqual({
message: 'Fix any of the following: Unable to determine contrast ratio',
severity: 'Error',
sourceSelector: '.text-box > span:nth-child(3)',
sourceSnippet: '<span>measure development KPIs</span>',
sourceType: 'Url',
sourceUrl: 'https://code-pushup.dev/',
});
});
});
describe('tableToGQL', () => {
it('should transform primitive table to GraphQL input type', () => {
expect(
tableToGQL({
columns: ['left', 'right'],
rows: [
['Script Evaluation', '3,167 ms'],
['Style & Layout', '1,422 ms'],
['Other', '712 ms'],
],
}),
).toStrictEqual({
columns: [{ alignment: 'Left' }, { alignment: 'Right' }],
rows: [
[{ content: 'Script Evaluation' }, { content: '3,167 ms' }],
[{ content: 'Style & Layout' }, { content: '1,422 ms' }],
[{ content: 'Other' }, { content: '712 ms' }],
],
});
});
it('should transform object table to GraphQL input type', () => {
expect(
tableToGQL({
columns: [
{ key: 'category', label: 'Category', align: 'left' },
{ key: 'timeSpent', label: 'Time Spent', align: 'right' },
],
rows: [
{ category: 'Script Evaluation', timeSpent: '3,167 ms' },
{ category: 'Style & Layout', timeSpent: '1,422 ms' },
{ category: 'Other', timeSpent: '712 ms' },
],
}),
).toStrictEqual({
columns: [
{ key: 'category', label: 'Category', alignment: 'Left' },
{ key: 'timeSpent', label: 'Time Spent', alignment: 'Right' },
],
rows: [
[
{ key: 'category', content: 'Script Evaluation' },
{ key: 'timeSpent', content: '3,167 ms' },
],
[
{ key: 'category', content: 'Style & Layout' },
{ key: 'timeSpent', content: '1,422 ms' },
],
[
{ key: 'category', content: 'Other' },
{ key: 'timeSpent', content: '712 ms' },
],
],
});
});
});
describe('treeToGQL', () => {
it('should transform basic tree', () => {
expect(
treeToGQL({
title: 'Critical request chain',
root: {
name: 'https://example.com',
children: [
{
name: 'https://example.com/styles/base.css',
values: { size: '2 kB', duration: 20 },
},
{
name: 'https://example.com/styles/theme.css',
values: { size: '10 kB', duration: 100 },
},
],
},
}),
).toStrictEqual<AuditReportTree>({
type: TreeType.Basic,
title: 'Critical request chain',
root: {
name: 'https://example.com',
children: [
{
name: 'https://example.com/styles/base.css',
values: [
{ key: 'size', value: '2 kB' },
{ key: 'duration', value: '20' },
],
},
{
name: 'https://example.com/styles/theme.css',
values: [
{ key: 'size', value: '10 kB' },
{ key: 'duration', value: '100' },
],
},
],
},
});
});
it('should transform coverage tree', () => {
expect(
treeToGQL({
type: 'coverage',
title: 'Function coverage',
root: {
name: '.',
values: { coverage: 0.7 },
children: [
{
name: 'src',
values: { coverage: 0.7 },
children: [
{
name: 'App.tsx',
values: {
coverage: 0.8,
missing: [
{
startLine: 42,
endLine: 50,
name: 'login',
kind: 'function',
},
],
},
},
{
name: 'index.ts',
values: {
coverage: 0,
missing: [{ startLine: 1, endLine: 10 }],
},
},
],
},
],
},
}),
).toStrictEqual<AuditReportTree>({
type: TreeType.Coverage,
title: 'Function coverage',
root: {
name: '.',
coverage: 0.7,
children: [
{
name: 'src',
coverage: 0.7,
children: [
{
name: 'App.tsx',
coverage: 0.8,
missing: [
{
startLine: 42,
endLine: 50,
name: 'login',
kind: 'function',
},
],
},
{
name: 'index.ts',
coverage: 0,
missing: [{ startLine: 1, endLine: 10 }],
},
],
},
],
},
});
});
});