-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathapi-check.spec.ts
More file actions
361 lines (330 loc) · 10.3 KB
/
Copy pathapi-check.spec.ts
File metadata and controls
361 lines (330 loc) · 10.3 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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
import fs from 'node:fs'
import path from 'node:path'
import { describe, it, expect, afterAll, beforeAll } from 'vitest'
import { FixtureSandbox } from '../../testing/fixture-sandbox.js'
import { ParseProjectOutput } from '../../commands/debug/parse-project.js'
async function parseProject (fixt: FixtureSandbox, ...args: string[]): Promise<ParseProjectOutput> {
const result = await fixt.run('pnpm', [
'checkly',
'debug',
'parse-project',
...args,
])
if (result.exitCode !== 0) {
// eslint-disable-next-line no-console
console.error('stderr', result.stderr)
// eslint-disable-next-line no-console
console.error('stdout', result.stdout)
}
expect(result.exitCode).toBe(0)
const output: ParseProjectOutput = JSON.parse(result.stdout)
return output
}
const DEFAULT_TEST_TIMEOUT = 30_000
describe('ApiCheck', () => {
let fixt: FixtureSandbox
beforeAll(async () => {
fixt = await FixtureSandbox.create({
source: path.join(__dirname, 'fixtures', 'api-check'),
})
}, 180_000)
afterAll(async () => {
await fixt?.destroy()
})
it('should correctly load file script dependencies', async () => {
const output = await parseProject(
fixt,
'--config',
fixt.abspath('test-cases/test-script-dependencies/checkly.config.js'),
)
expect(output).toEqual(expect.objectContaining({
diagnostics: expect.objectContaining({
fatal: false,
}),
payload: expect.objectContaining({
sharedFiles: [
expect.objectContaining({
path: 'test-cases/test-script-dependencies/dep1.js',
content: fs.readFileSync(fixt.abspath('test-cases/test-script-dependencies/dep1.js'), 'utf8'),
}),
expect.objectContaining({
path: 'test-cases/test-script-dependencies/dep2.js',
content: fs.readFileSync(fixt.abspath('test-cases/test-script-dependencies/dep2.js'), 'utf8'),
}),
],
resources: expect.arrayContaining([
expect.objectContaining({
logicalId: 'check-setupScript',
type: 'check',
member: true,
payload: expect.objectContaining({
setupScriptPath: 'test-cases/test-script-dependencies/entrypoint.js',
setupScriptDependencies: [
0,
1,
],
}),
}),
expect.objectContaining({
logicalId: 'check-tearDownScript',
type: 'check',
member: true,
payload: expect.objectContaining({
tearDownScriptPath: 'test-cases/test-script-dependencies/entrypoint.js',
tearDownScriptDependencies: [
0,
1,
],
}),
}),
]),
}),
}))
}, DEFAULT_TEST_TIMEOUT)
it('should fail to bundle if runtime is not supported even if default runtime is set', async () => {
const output = await parseProject(
fixt,
'--config',
fixt.abspath('test-cases/test-invalid-runtime/checkly.config.js'),
)
expect(output).toEqual(expect.objectContaining({
diagnostics: expect.objectContaining({
fatal: true,
benign: false,
observations: expect.arrayContaining([
expect.objectContaining({
message: expect.stringContaining('is not a known runtime.'),
}),
]),
}),
}))
}, DEFAULT_TEST_TIMEOUT)
it('should synthesize runtime if specified', async () => {
const output = await parseProject(
fixt,
'--config',
fixt.abspath('test-cases/test-runtime/checkly.config.js'),
)
expect(output).toEqual(expect.objectContaining({
diagnostics: expect.objectContaining({
fatal: false,
}),
payload: expect.objectContaining({
resources: expect.arrayContaining([
expect.objectContaining({
logicalId: 'check-with-runtime',
type: 'check',
member: true,
payload: expect.objectContaining({
runtimeId: '2025.04',
}),
}),
]),
}),
}))
}, DEFAULT_TEST_TIMEOUT)
it('should not synthesize default runtime', async () => {
const output = await parseProject(
fixt,
'--config',
fixt.abspath('test-cases/test-runtime/checkly.config.js'),
'--default-runtime',
'2024.09',
)
expect(output).toEqual(expect.objectContaining({
diagnostics: expect.objectContaining({
fatal: false,
}),
payload: expect.objectContaining({
resources: expect.arrayContaining([
expect.objectContaining({
logicalId: 'check-without-runtime',
type: 'check',
member: true,
// The default runtime is used for sanity checks but is not
// serialized. This is done so that all checks can be changed
// at once by changing the account default runtime.
payload: expect.not.objectContaining({
runtimeId: expect.anything(),
}),
}),
]),
}),
}))
}, DEFAULT_TEST_TIMEOUT)
it('should apply default check settings', async () => {
const output = await parseProject(
fixt,
'--config',
fixt.abspath('test-cases/test-check-defaults/checkly.config.js'),
)
expect(output).toEqual(expect.objectContaining({
diagnostics: expect.objectContaining({
fatal: false,
}),
payload: expect.objectContaining({
resources: expect.arrayContaining([
expect.objectContaining({
logicalId: 'check-should-have-defaults',
type: 'check',
member: true,
payload: expect.objectContaining({
tags: ['default tags'],
}),
}),
expect.objectContaining({
logicalId: 'check-should-not-have-defaults',
type: 'check',
member: true,
payload: expect.objectContaining({
tags: ['not default tags'],
}),
}),
]),
}),
}))
}, DEFAULT_TEST_TIMEOUT)
it('should support setting groups with `groupId`', async () => {
const output = await parseProject(
fixt,
'--config',
fixt.abspath('test-cases/test-groupId-mapping/checkly.config.js'),
)
expect(output).toEqual(expect.objectContaining({
diagnostics: expect.objectContaining({
fatal: false,
}),
payload: expect.objectContaining({
resources: expect.arrayContaining([
expect.objectContaining({
logicalId: 'test-group',
type: 'check-group',
member: true,
}),
expect.objectContaining({
logicalId: 'check',
type: 'check',
member: true,
payload: expect.objectContaining({
groupId: {
ref: 'test-group',
},
}),
}),
]),
}),
}))
}, DEFAULT_TEST_TIMEOUT)
it('should support setting groups with `group`', async () => {
const output = await parseProject(
fixt,
'--config',
fixt.abspath('test-cases/test-group-mapping/checkly.config.js'),
)
expect(output).toEqual(expect.objectContaining({
diagnostics: expect.objectContaining({
fatal: false,
}),
payload: expect.objectContaining({
resources: expect.arrayContaining([
expect.objectContaining({
logicalId: 'test-group',
type: 'check-group',
member: true,
}),
expect.objectContaining({
logicalId: 'check',
type: 'check',
member: true,
payload: expect.objectContaining({
groupId: {
ref: 'test-group',
},
}),
}),
]),
}),
}))
}, DEFAULT_TEST_TIMEOUT)
it('should synthesize skipSSL requests', async () => {
const output = await parseProject(
fixt,
'--config',
fixt.abspath('test-cases/test-skip-ssl/checkly.config.js'),
)
expect(output).toEqual(expect.objectContaining({
diagnostics: expect.objectContaining({
fatal: false,
}),
payload: expect.objectContaining({
resources: expect.arrayContaining([
expect.objectContaining({
logicalId: 'check',
type: 'check',
member: true,
payload: expect.objectContaining({
request: expect.objectContaining({
skipSSL: true,
}),
}),
}),
]),
}),
}))
}, DEFAULT_TEST_TIMEOUT)
it('should synthesize requests that treat binary-labelled responses as text', async () => {
const output = await parseProject(
fixt,
'--config',
fixt.abspath('test-cases/test-treat-response-body-as-text/checkly.config.js'),
)
expect(output).toEqual(expect.objectContaining({
diagnostics: expect.objectContaining({
fatal: false,
}),
payload: expect.objectContaining({
resources: expect.arrayContaining([
expect.objectContaining({
logicalId: 'check',
type: 'check',
member: true,
payload: expect.objectContaining({
request: expect.objectContaining({
treatResponseBodyAsText: true,
}),
}),
}),
]),
}),
}))
}, DEFAULT_TEST_TIMEOUT)
describe('retryStrategy', () => {
it('should synthesize `onlyOn`', async () => {
const output = await parseProject(
fixt,
'--config',
fixt.abspath('test-cases/test-retryStrategy-onlyOn/checkly.config.js'),
)
expect(output).toEqual(expect.objectContaining({
diagnostics: expect.objectContaining({
fatal: false,
}),
payload: expect.objectContaining({
resources: expect.arrayContaining([
expect.objectContaining({
logicalId: 'check',
type: 'check',
member: true,
payload: expect.objectContaining({
retryStrategy: expect.objectContaining({
type: 'LINEAR',
onlyOn: 'NETWORK_ERROR',
}),
}),
}),
]),
}),
}))
}, DEFAULT_TEST_TIMEOUT)
})
})