@usebruno/js 0.45.1 → 0.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -3
- package/src/bru.js +110 -18
- package/src/bruno-request.js +21 -19
- package/src/index.js +4 -1
- package/src/runtime/script-runtime.js +107 -62
- package/src/runtime/test-runtime.js +8 -3
- package/src/sandbox/node-vm/console.js +102 -0
- package/src/sandbox/node-vm/index.js +68 -8
- package/src/sandbox/node-vm/utils.js +15 -0
- package/src/sandbox/quickjs/index.js +6 -21
- package/src/sandbox/quickjs/shims/bru.js +108 -3
- package/src/sandbox/quickjs/shims/bruno-request.js +12 -0
- package/src/sandbox/quickjs/shims/console.js +97 -5
- package/src/sandbox/quickjs/shims/lib/axios.js +26 -16
- package/src/sandbox/quickjs/shims/lib/axios.spec.js +495 -0
- package/src/test.js +6 -4
- package/src/utils/error-formatter.js +426 -0
- package/src/utils/error-formatter.spec.js +388 -0
- package/src/utils/sandbox.js +64 -0
- package/src/utils.js +27 -6
|
@@ -0,0 +1,495 @@
|
|
|
1
|
+
const { describe, it, expect, beforeAll, beforeEach, afterEach, afterAll } = require('@jest/globals');
|
|
2
|
+
const { newQuickJSWASMModule } = require('quickjs-emscripten');
|
|
3
|
+
const addAxiosShimToContext = require('./axios');
|
|
4
|
+
|
|
5
|
+
// Mock axios
|
|
6
|
+
jest.mock('axios');
|
|
7
|
+
const axios = require('axios');
|
|
8
|
+
|
|
9
|
+
describe('axios shim tests', () => {
|
|
10
|
+
let vm, module;
|
|
11
|
+
|
|
12
|
+
beforeAll(async () => {
|
|
13
|
+
module = await newQuickJSWASMModule();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
beforeEach(async () => {
|
|
17
|
+
vm = module.newContext();
|
|
18
|
+
await addAxiosShimToContext(vm);
|
|
19
|
+
jest.clearAllMocks();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
afterEach(() => {
|
|
23
|
+
if (vm) {
|
|
24
|
+
try {
|
|
25
|
+
vm.dispose();
|
|
26
|
+
} catch (err) {
|
|
27
|
+
console.error('Error disposing vm', err);
|
|
28
|
+
}
|
|
29
|
+
vm = null;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
afterAll(() => {
|
|
34
|
+
if (module) {
|
|
35
|
+
try {
|
|
36
|
+
module.dispose();
|
|
37
|
+
} catch (err) {
|
|
38
|
+
console.error('Error disposing module', err);
|
|
39
|
+
}
|
|
40
|
+
module = null;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe('successful requests', () => {
|
|
45
|
+
it('should resolve axios.get with response data', async () => {
|
|
46
|
+
const mockResponse = {
|
|
47
|
+
status: 200,
|
|
48
|
+
headers: { 'content-type': 'application/json' },
|
|
49
|
+
data: { message: 'success' }
|
|
50
|
+
};
|
|
51
|
+
axios.get.mockResolvedValue(mockResponse);
|
|
52
|
+
|
|
53
|
+
const result = vm.evalCode(`
|
|
54
|
+
(async () => {
|
|
55
|
+
const response = await axios.get('https://api.example.com/data');
|
|
56
|
+
return response;
|
|
57
|
+
})()
|
|
58
|
+
`);
|
|
59
|
+
const promiseHandle = vm.unwrapResult(result);
|
|
60
|
+
const resolvedResult = await vm.resolvePromise(promiseHandle);
|
|
61
|
+
const resolvedHandle = vm.unwrapResult(resolvedResult);
|
|
62
|
+
const responseData = vm.dump(resolvedHandle);
|
|
63
|
+
|
|
64
|
+
resolvedHandle.dispose();
|
|
65
|
+
promiseHandle.dispose();
|
|
66
|
+
|
|
67
|
+
expect(responseData).toEqual({
|
|
68
|
+
status: 200,
|
|
69
|
+
headers: { 'content-type': 'application/json' },
|
|
70
|
+
data: { message: 'success' }
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('should resolve axios.post with response data', async () => {
|
|
75
|
+
const mockResponse = {
|
|
76
|
+
status: 201,
|
|
77
|
+
headers: { 'content-type': 'application/json' },
|
|
78
|
+
data: { id: 123, created: true }
|
|
79
|
+
};
|
|
80
|
+
axios.post.mockResolvedValue(mockResponse);
|
|
81
|
+
|
|
82
|
+
const result = vm.evalCode(`
|
|
83
|
+
(async () => {
|
|
84
|
+
const response = await axios.post('https://api.example.com/users', { name: 'test' });
|
|
85
|
+
return response;
|
|
86
|
+
})()
|
|
87
|
+
`);
|
|
88
|
+
const promiseHandle = vm.unwrapResult(result);
|
|
89
|
+
const resolvedResult = await vm.resolvePromise(promiseHandle);
|
|
90
|
+
const resolvedHandle = vm.unwrapResult(resolvedResult);
|
|
91
|
+
const responseData = vm.dump(resolvedHandle);
|
|
92
|
+
|
|
93
|
+
resolvedHandle.dispose();
|
|
94
|
+
promiseHandle.dispose();
|
|
95
|
+
|
|
96
|
+
expect(responseData.status).toBe(201);
|
|
97
|
+
expect(responseData.data).toEqual({ id: 123, created: true });
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('should resolve all HTTP methods', async () => {
|
|
101
|
+
const mockResponse = {
|
|
102
|
+
status: 200,
|
|
103
|
+
headers: {},
|
|
104
|
+
data: { success: true }
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const methods = ['get', 'post', 'put', 'patch', 'delete'];
|
|
108
|
+
|
|
109
|
+
for (const method of methods) {
|
|
110
|
+
axios[method].mockResolvedValue(mockResponse);
|
|
111
|
+
|
|
112
|
+
const result = vm.evalCode(`
|
|
113
|
+
(async () => {
|
|
114
|
+
const response = await axios.${method}('https://api.example.com/endpoint');
|
|
115
|
+
return response.status;
|
|
116
|
+
})()
|
|
117
|
+
`);
|
|
118
|
+
const promiseHandle = vm.unwrapResult(result);
|
|
119
|
+
const resolvedResult = await vm.resolvePromise(promiseHandle);
|
|
120
|
+
const resolvedHandle = vm.unwrapResult(resolvedResult);
|
|
121
|
+
const status = vm.dump(resolvedHandle);
|
|
122
|
+
|
|
123
|
+
resolvedHandle.dispose();
|
|
124
|
+
promiseHandle.dispose();
|
|
125
|
+
|
|
126
|
+
expect(status).toBe(200);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
describe('error handling - 4xx/5xx responses', () => {
|
|
132
|
+
it('should reject on 404 error with full error information', async () => {
|
|
133
|
+
const mockError = {
|
|
134
|
+
message: 'Request failed with status code 404',
|
|
135
|
+
response: {
|
|
136
|
+
status: 404,
|
|
137
|
+
statusText: 'Not Found',
|
|
138
|
+
headers: { 'content-type': 'application/json' },
|
|
139
|
+
data: { error: 'Resource not found' }
|
|
140
|
+
},
|
|
141
|
+
config: {
|
|
142
|
+
url: 'https://api.example.com/users/999',
|
|
143
|
+
method: 'get',
|
|
144
|
+
headers: { Accept: 'application/json' },
|
|
145
|
+
data: undefined
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
axios.get.mockRejectedValue(mockError);
|
|
149
|
+
|
|
150
|
+
const result = vm.evalCode(`
|
|
151
|
+
(async () => {
|
|
152
|
+
try {
|
|
153
|
+
await axios.get('https://api.example.com/users/999');
|
|
154
|
+
return { caught: false };
|
|
155
|
+
} catch (error) {
|
|
156
|
+
return {
|
|
157
|
+
caught: true,
|
|
158
|
+
message: error.message,
|
|
159
|
+
status: error.response?.status,
|
|
160
|
+
statusText: error.response?.statusText,
|
|
161
|
+
responseData: error.response?.data,
|
|
162
|
+
configUrl: error.config?.url,
|
|
163
|
+
configMethod: error.config?.method
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
})()
|
|
167
|
+
`);
|
|
168
|
+
const promiseHandle = vm.unwrapResult(result);
|
|
169
|
+
const resolvedResult = await vm.resolvePromise(promiseHandle);
|
|
170
|
+
const resolvedHandle = vm.unwrapResult(resolvedResult);
|
|
171
|
+
const errorData = vm.dump(resolvedHandle);
|
|
172
|
+
|
|
173
|
+
resolvedHandle.dispose();
|
|
174
|
+
promiseHandle.dispose();
|
|
175
|
+
|
|
176
|
+
expect(errorData.caught).toBe(true);
|
|
177
|
+
expect(errorData.message).toBe('Request failed with status code 404');
|
|
178
|
+
expect(errorData.status).toBe(404);
|
|
179
|
+
expect(errorData.statusText).toBe('Not Found');
|
|
180
|
+
expect(errorData.responseData).toEqual({ error: 'Resource not found' });
|
|
181
|
+
expect(errorData.configUrl).toBe('https://api.example.com/users/999');
|
|
182
|
+
expect(errorData.configMethod).toBe('get');
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('should reject on 500 error', async () => {
|
|
186
|
+
const mockError = {
|
|
187
|
+
message: 'Request failed with status code 500',
|
|
188
|
+
response: {
|
|
189
|
+
status: 500,
|
|
190
|
+
statusText: 'Internal Server Error',
|
|
191
|
+
headers: {},
|
|
192
|
+
data: { error: 'Server error' }
|
|
193
|
+
},
|
|
194
|
+
config: {
|
|
195
|
+
url: 'https://api.example.com/endpoint',
|
|
196
|
+
method: 'post',
|
|
197
|
+
headers: {},
|
|
198
|
+
data: { test: 'data' }
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
axios.post.mockRejectedValue(mockError);
|
|
202
|
+
|
|
203
|
+
const result = vm.evalCode(`
|
|
204
|
+
(async () => {
|
|
205
|
+
try {
|
|
206
|
+
await axios.post('https://api.example.com/endpoint', { test: 'data' });
|
|
207
|
+
return { caught: false };
|
|
208
|
+
} catch (error) {
|
|
209
|
+
return {
|
|
210
|
+
caught: true,
|
|
211
|
+
status: error.response?.status,
|
|
212
|
+
message: error.message
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
})()
|
|
216
|
+
`);
|
|
217
|
+
const promiseHandle = vm.unwrapResult(result);
|
|
218
|
+
const resolvedResult = await vm.resolvePromise(promiseHandle);
|
|
219
|
+
const resolvedHandle = vm.unwrapResult(resolvedResult);
|
|
220
|
+
const errorData = vm.dump(resolvedHandle);
|
|
221
|
+
|
|
222
|
+
resolvedHandle.dispose();
|
|
223
|
+
promiseHandle.dispose();
|
|
224
|
+
|
|
225
|
+
expect(errorData.caught).toBe(true);
|
|
226
|
+
expect(errorData.status).toBe(500);
|
|
227
|
+
expect(errorData.message).toBe('Request failed with status code 500');
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
it('should reject on 401 unauthorized error', async () => {
|
|
231
|
+
const mockError = {
|
|
232
|
+
message: 'Request failed with status code 401',
|
|
233
|
+
response: {
|
|
234
|
+
status: 401,
|
|
235
|
+
statusText: 'Unauthorized',
|
|
236
|
+
headers: { 'www-authenticate': 'Bearer' },
|
|
237
|
+
data: { error: 'Invalid token' }
|
|
238
|
+
},
|
|
239
|
+
config: {
|
|
240
|
+
url: 'https://api.example.com/protected',
|
|
241
|
+
method: 'get',
|
|
242
|
+
headers: { Authorization: 'Bearer invalid' },
|
|
243
|
+
data: undefined
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
axios.get.mockRejectedValue(mockError);
|
|
247
|
+
|
|
248
|
+
const result = vm.evalCode(`
|
|
249
|
+
(async () => {
|
|
250
|
+
try {
|
|
251
|
+
await axios.get('https://api.example.com/protected');
|
|
252
|
+
return { caught: false };
|
|
253
|
+
} catch (error) {
|
|
254
|
+
return {
|
|
255
|
+
caught: true,
|
|
256
|
+
status: error.response?.status,
|
|
257
|
+
responseData: error.response?.data
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
})()
|
|
261
|
+
`);
|
|
262
|
+
const promiseHandle = vm.unwrapResult(result);
|
|
263
|
+
const resolvedResult = await vm.resolvePromise(promiseHandle);
|
|
264
|
+
const resolvedHandle = vm.unwrapResult(resolvedResult);
|
|
265
|
+
const errorData = vm.dump(resolvedHandle);
|
|
266
|
+
|
|
267
|
+
resolvedHandle.dispose();
|
|
268
|
+
promiseHandle.dispose();
|
|
269
|
+
|
|
270
|
+
expect(errorData.caught).toBe(true);
|
|
271
|
+
expect(errorData.status).toBe(401);
|
|
272
|
+
expect(errorData.responseData).toEqual({ error: 'Invalid token' });
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
describe('error handling - network errors', () => {
|
|
277
|
+
it('should reject on network error without response', async () => {
|
|
278
|
+
const mockError = {
|
|
279
|
+
message: 'Network Error',
|
|
280
|
+
config: {
|
|
281
|
+
url: 'https://api.example.com/endpoint',
|
|
282
|
+
method: 'get',
|
|
283
|
+
headers: {},
|
|
284
|
+
data: undefined
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
axios.get.mockRejectedValue(mockError);
|
|
288
|
+
|
|
289
|
+
const result = vm.evalCode(`
|
|
290
|
+
(async () => {
|
|
291
|
+
try {
|
|
292
|
+
await axios.get('https://api.example.com/endpoint');
|
|
293
|
+
return { caught: false };
|
|
294
|
+
} catch (error) {
|
|
295
|
+
return {
|
|
296
|
+
caught: true,
|
|
297
|
+
message: error.message,
|
|
298
|
+
hasResponse: !!error.response,
|
|
299
|
+
configUrl: error.config?.url
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
})()
|
|
303
|
+
`);
|
|
304
|
+
const promiseHandle = vm.unwrapResult(result);
|
|
305
|
+
const resolvedResult = await vm.resolvePromise(promiseHandle);
|
|
306
|
+
const resolvedHandle = vm.unwrapResult(resolvedResult);
|
|
307
|
+
const errorData = vm.dump(resolvedHandle);
|
|
308
|
+
|
|
309
|
+
resolvedHandle.dispose();
|
|
310
|
+
promiseHandle.dispose();
|
|
311
|
+
|
|
312
|
+
expect(errorData.caught).toBe(true);
|
|
313
|
+
expect(errorData.message).toBe('Network Error');
|
|
314
|
+
expect(errorData.hasResponse).toBe(false);
|
|
315
|
+
expect(errorData.configUrl).toBe('https://api.example.com/endpoint');
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
it('should reject on timeout error', async () => {
|
|
319
|
+
const mockError = {
|
|
320
|
+
message: 'timeout of 1000ms exceeded',
|
|
321
|
+
config: {
|
|
322
|
+
url: 'https://api.example.com/slow',
|
|
323
|
+
method: 'get',
|
|
324
|
+
headers: {},
|
|
325
|
+
data: undefined
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
axios.get.mockRejectedValue(mockError);
|
|
329
|
+
|
|
330
|
+
const result = vm.evalCode(`
|
|
331
|
+
(async () => {
|
|
332
|
+
try {
|
|
333
|
+
await axios.get('https://api.example.com/slow');
|
|
334
|
+
return { caught: false };
|
|
335
|
+
} catch (error) {
|
|
336
|
+
return {
|
|
337
|
+
caught: true,
|
|
338
|
+
message: error.message
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
})()
|
|
342
|
+
`);
|
|
343
|
+
const promiseHandle = vm.unwrapResult(result);
|
|
344
|
+
const resolvedResult = await vm.resolvePromise(promiseHandle);
|
|
345
|
+
const resolvedHandle = vm.unwrapResult(resolvedResult);
|
|
346
|
+
const errorData = vm.dump(resolvedHandle);
|
|
347
|
+
|
|
348
|
+
resolvedHandle.dispose();
|
|
349
|
+
promiseHandle.dispose();
|
|
350
|
+
|
|
351
|
+
expect(errorData.caught).toBe(true);
|
|
352
|
+
expect(errorData.message).toBe('timeout of 1000ms exceeded');
|
|
353
|
+
});
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
describe('base axios function', () => {
|
|
357
|
+
it('should work with axios() base function', async () => {
|
|
358
|
+
const mockResponse = {
|
|
359
|
+
status: 200,
|
|
360
|
+
headers: {},
|
|
361
|
+
data: { success: true }
|
|
362
|
+
};
|
|
363
|
+
axios.mockResolvedValue(mockResponse);
|
|
364
|
+
|
|
365
|
+
const result = vm.evalCode(`
|
|
366
|
+
(async () => {
|
|
367
|
+
const response = await axios({
|
|
368
|
+
method: 'GET',
|
|
369
|
+
url: 'https://api.example.com/data'
|
|
370
|
+
});
|
|
371
|
+
return response;
|
|
372
|
+
})()
|
|
373
|
+
`);
|
|
374
|
+
const promiseHandle = vm.unwrapResult(result);
|
|
375
|
+
const resolvedResult = await vm.resolvePromise(promiseHandle);
|
|
376
|
+
const resolvedHandle = vm.unwrapResult(resolvedResult);
|
|
377
|
+
const responseData = vm.dump(resolvedHandle);
|
|
378
|
+
|
|
379
|
+
resolvedHandle.dispose();
|
|
380
|
+
promiseHandle.dispose();
|
|
381
|
+
|
|
382
|
+
expect(responseData.status).toBe(200);
|
|
383
|
+
expect(responseData.data).toEqual({ success: true });
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
it('should reject on error with axios() base function', async () => {
|
|
387
|
+
const mockError = {
|
|
388
|
+
message: 'Request failed with status code 403',
|
|
389
|
+
response: {
|
|
390
|
+
status: 403,
|
|
391
|
+
statusText: 'Forbidden',
|
|
392
|
+
headers: {},
|
|
393
|
+
data: { error: 'Access denied' }
|
|
394
|
+
},
|
|
395
|
+
config: {
|
|
396
|
+
url: 'https://api.example.com/forbidden',
|
|
397
|
+
method: 'get',
|
|
398
|
+
headers: {},
|
|
399
|
+
data: undefined
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
axios.mockRejectedValue(mockError);
|
|
403
|
+
|
|
404
|
+
const result = vm.evalCode(`
|
|
405
|
+
(async () => {
|
|
406
|
+
try {
|
|
407
|
+
await axios({
|
|
408
|
+
method: 'GET',
|
|
409
|
+
url: 'https://api.example.com/forbidden'
|
|
410
|
+
});
|
|
411
|
+
return { caught: false };
|
|
412
|
+
} catch (error) {
|
|
413
|
+
return {
|
|
414
|
+
caught: true,
|
|
415
|
+
status: error.response?.status,
|
|
416
|
+
message: error.message
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
})()
|
|
420
|
+
`);
|
|
421
|
+
const promiseHandle = vm.unwrapResult(result);
|
|
422
|
+
const resolvedResult = await vm.resolvePromise(promiseHandle);
|
|
423
|
+
const resolvedHandle = vm.unwrapResult(resolvedResult);
|
|
424
|
+
const errorData = vm.dump(resolvedHandle);
|
|
425
|
+
|
|
426
|
+
resolvedHandle.dispose();
|
|
427
|
+
promiseHandle.dispose();
|
|
428
|
+
|
|
429
|
+
expect(errorData.caught).toBe(true);
|
|
430
|
+
expect(errorData.status).toBe(403);
|
|
431
|
+
expect(errorData.message).toBe('Request failed with status code 403');
|
|
432
|
+
});
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
describe('real-world use case from issue #6342', () => {
|
|
436
|
+
it('should properly handle token refresh error with full error info', async () => {
|
|
437
|
+
const mockError = {
|
|
438
|
+
message: 'Request failed with status code 404',
|
|
439
|
+
response: {
|
|
440
|
+
status: 404,
|
|
441
|
+
statusText: 'Not Found',
|
|
442
|
+
headers: { 'content-type': 'application/json' },
|
|
443
|
+
data: { error: 'Realm not found' }
|
|
444
|
+
},
|
|
445
|
+
config: {
|
|
446
|
+
url: 'https://keycloak.example.com/auth/realms/test/protocol/openid-connect/token',
|
|
447
|
+
method: 'post',
|
|
448
|
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
449
|
+
data: 'grant_type=password&client_id=test&username=user&password=pass&scope=openid'
|
|
450
|
+
}
|
|
451
|
+
};
|
|
452
|
+
axios.post.mockRejectedValue(mockError);
|
|
453
|
+
|
|
454
|
+
const result = vm.evalCode(`
|
|
455
|
+
(async () => {
|
|
456
|
+
const url = 'https://keycloak.example.com/auth/realms/test/protocol/openid-connect/token';
|
|
457
|
+
const data = 'grant_type=password&client_id=test&username=user&password=pass&scope=openid';
|
|
458
|
+
|
|
459
|
+
try {
|
|
460
|
+
const response = await axios.post(url, data, {
|
|
461
|
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
|
|
462
|
+
});
|
|
463
|
+
return { success: true, token: response.data?.access_token };
|
|
464
|
+
} catch (error) {
|
|
465
|
+
return {
|
|
466
|
+
success: false,
|
|
467
|
+
errorMessage: error.message,
|
|
468
|
+
hasConfig: !!error.config,
|
|
469
|
+
configUrl: error.config?.url,
|
|
470
|
+
configMethod: error.config?.method,
|
|
471
|
+
configData: error.config?.data,
|
|
472
|
+
responseStatus: error.response?.status,
|
|
473
|
+
responseData: error.response?.data
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
})()
|
|
477
|
+
`);
|
|
478
|
+
const promiseHandle = vm.unwrapResult(result);
|
|
479
|
+
const resolvedResult = await vm.resolvePromise(promiseHandle);
|
|
480
|
+
const resolvedHandle = vm.unwrapResult(resolvedResult);
|
|
481
|
+
const result_data = vm.dump(resolvedHandle);
|
|
482
|
+
|
|
483
|
+
resolvedHandle.dispose();
|
|
484
|
+
promiseHandle.dispose();
|
|
485
|
+
|
|
486
|
+
expect(result_data.success).toBe(false);
|
|
487
|
+
expect(result_data.errorMessage).toBe('Request failed with status code 404');
|
|
488
|
+
expect(result_data.hasConfig).toBe(true);
|
|
489
|
+
expect(result_data.configUrl).toBe('https://keycloak.example.com/auth/realms/test/protocol/openid-connect/token');
|
|
490
|
+
expect(result_data.configMethod).toBe('post');
|
|
491
|
+
expect(result_data.responseStatus).toBe(404);
|
|
492
|
+
expect(result_data.responseData).toEqual({ error: 'Realm not found' });
|
|
493
|
+
});
|
|
494
|
+
});
|
|
495
|
+
});
|
package/src/test.js
CHANGED
|
@@ -3,7 +3,6 @@ const Test = (__brunoTestResults, chai) => async (description, callback) => {
|
|
|
3
3
|
await callback();
|
|
4
4
|
__brunoTestResults.addResult({ description, status: 'pass' });
|
|
5
5
|
} catch (error) {
|
|
6
|
-
console.log(chai.AssertionError);
|
|
7
6
|
if (error instanceof chai.AssertionError) {
|
|
8
7
|
const { message, actual, expected } = error;
|
|
9
8
|
__brunoTestResults.addResult({
|
|
@@ -11,16 +10,19 @@ const Test = (__brunoTestResults, chai) => async (description, callback) => {
|
|
|
11
10
|
status: 'fail',
|
|
12
11
|
error: message,
|
|
13
12
|
actual,
|
|
14
|
-
expected
|
|
13
|
+
expected,
|
|
14
|
+
stack: error.stack || null,
|
|
15
|
+
errorName: error.name || 'AssertionError'
|
|
15
16
|
});
|
|
16
17
|
} else {
|
|
17
18
|
__brunoTestResults.addResult({
|
|
18
19
|
description,
|
|
19
20
|
status: 'fail',
|
|
20
|
-
error: error.message || 'An unexpected error occurred.'
|
|
21
|
+
error: error.message || 'An unexpected error occurred.',
|
|
22
|
+
stack: error.stack || null,
|
|
23
|
+
errorName: error.name || 'Error'
|
|
21
24
|
});
|
|
22
25
|
}
|
|
23
|
-
console.log(error);
|
|
24
26
|
}
|
|
25
27
|
};
|
|
26
28
|
|