@scalar/mock-server 0.1.61 → 0.1.62
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/CHANGELOG.md +488 -0
- package/dist/index.cjs +59 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +41 -127
- package/dist/index.js.map +1 -0
- package/package.json +13 -14
- package/dist/package.json +0 -58
- package/dist/src/createMockServer.d.ts +0 -12
- package/dist/src/createMockServer.js +0 -97
- package/dist/src/createMockServer.test.d.ts +0 -1
- package/dist/src/createMockServer.test.js +0 -299
- package/dist/src/index.d.ts +0 -2
- package/dist/src/index.js +0 -2
- package/dist/src/utils/index.d.ts +0 -2
- package/dist/src/utils/index.js +0 -2
- package/dist/src/utils/normalize.d.ts +0 -4
- package/dist/src/utils/normalize.js +0 -9
- package/dist/src/utils/normalize.test.d.ts +0 -1
- package/dist/src/utils/normalize.test.js +0 -12
- package/dist/src/utils/routeFromPath.d.ts +0 -5
- package/dist/src/utils/routeFromPath.js +0 -7
- package/dist/src/utils/routeFromPath.test.d.ts +0 -1
- package/dist/src/utils/routeFromPath.test.js +0 -10
- package/dist/tests/galaxy.test.d.ts +0 -1
- package/dist/tests/galaxy.test.js +0 -83
- package/dist/tests/onRequest.test.d.ts +0 -1
- package/dist/tests/onRequest.test.js +0 -82
- package/dist/tests/openapi.test.d.ts +0 -1
- package/dist/tests/openapi.test.js +0 -220
- package/dist/tsconfig.tsbuildinfo +0 -1
|
@@ -1,299 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
-
function step(op) {
|
|
15
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
-
switch (op[0]) {
|
|
20
|
-
case 0: case 1: t = op; break;
|
|
21
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
-
default:
|
|
25
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
-
if (t[2]) _.ops.pop();
|
|
30
|
-
_.trys.pop(); continue;
|
|
31
|
-
}
|
|
32
|
-
op = body.call(thisArg, _);
|
|
33
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
import { describe, expect, it } from 'vitest';
|
|
38
|
-
import { createMockServer } from './createMockServer';
|
|
39
|
-
describe('createMockServer', function () {
|
|
40
|
-
it('GET /foobar -> example JSON', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
41
|
-
var specification, server, response, _a;
|
|
42
|
-
return __generator(this, function (_b) {
|
|
43
|
-
switch (_b.label) {
|
|
44
|
-
case 0:
|
|
45
|
-
specification = {
|
|
46
|
-
openapi: '3.1.0',
|
|
47
|
-
info: {
|
|
48
|
-
title: 'Hello World',
|
|
49
|
-
version: '1.0.0',
|
|
50
|
-
},
|
|
51
|
-
paths: {
|
|
52
|
-
'/foobar': {
|
|
53
|
-
get: {
|
|
54
|
-
responses: {
|
|
55
|
-
'200': {
|
|
56
|
-
description: 'OK',
|
|
57
|
-
content: {
|
|
58
|
-
'application/json': {
|
|
59
|
-
example: {
|
|
60
|
-
foo: 'bar',
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
};
|
|
70
|
-
return [4 /*yield*/, createMockServer({
|
|
71
|
-
specification: specification,
|
|
72
|
-
})];
|
|
73
|
-
case 1:
|
|
74
|
-
server = _b.sent();
|
|
75
|
-
return [4 /*yield*/, server.request('/foobar')];
|
|
76
|
-
case 2:
|
|
77
|
-
response = _b.sent();
|
|
78
|
-
expect(response.status).toBe(200);
|
|
79
|
-
_a = expect;
|
|
80
|
-
return [4 /*yield*/, response.json()];
|
|
81
|
-
case 3:
|
|
82
|
-
_a.apply(void 0, [_b.sent()]).toMatchObject({
|
|
83
|
-
foo: 'bar',
|
|
84
|
-
});
|
|
85
|
-
return [2 /*return*/];
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
}); });
|
|
89
|
-
it('POST /foobar -> example JSON', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
90
|
-
var specification, server, response, _a;
|
|
91
|
-
return __generator(this, function (_b) {
|
|
92
|
-
switch (_b.label) {
|
|
93
|
-
case 0:
|
|
94
|
-
specification = {
|
|
95
|
-
openapi: '3.1.0',
|
|
96
|
-
info: {
|
|
97
|
-
title: 'Hello World',
|
|
98
|
-
version: '1.0.0',
|
|
99
|
-
},
|
|
100
|
-
paths: {
|
|
101
|
-
'/foobar': {
|
|
102
|
-
post: {
|
|
103
|
-
responses: {
|
|
104
|
-
'200': {
|
|
105
|
-
description: 'OK',
|
|
106
|
-
content: {
|
|
107
|
-
'application/json': {
|
|
108
|
-
example: {
|
|
109
|
-
foo: 'bar',
|
|
110
|
-
},
|
|
111
|
-
},
|
|
112
|
-
},
|
|
113
|
-
},
|
|
114
|
-
},
|
|
115
|
-
},
|
|
116
|
-
},
|
|
117
|
-
},
|
|
118
|
-
};
|
|
119
|
-
return [4 /*yield*/, createMockServer({
|
|
120
|
-
specification: specification,
|
|
121
|
-
})];
|
|
122
|
-
case 1:
|
|
123
|
-
server = _b.sent();
|
|
124
|
-
return [4 /*yield*/, server.request('/foobar', {
|
|
125
|
-
method: 'POST',
|
|
126
|
-
})];
|
|
127
|
-
case 2:
|
|
128
|
-
response = _b.sent();
|
|
129
|
-
expect(response.status).toBe(200);
|
|
130
|
-
_a = expect;
|
|
131
|
-
return [4 /*yield*/, response.json()];
|
|
132
|
-
case 3:
|
|
133
|
-
_a.apply(void 0, [_b.sent()]).toMatchObject({
|
|
134
|
-
foo: 'bar',
|
|
135
|
-
});
|
|
136
|
-
return [2 /*return*/];
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
}); });
|
|
140
|
-
it('POST /foobar/{id} -> example JSON', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
141
|
-
var specification, server, response, _a;
|
|
142
|
-
return __generator(this, function (_b) {
|
|
143
|
-
switch (_b.label) {
|
|
144
|
-
case 0:
|
|
145
|
-
specification = {
|
|
146
|
-
openapi: '3.1.0',
|
|
147
|
-
info: {
|
|
148
|
-
title: 'Hello World',
|
|
149
|
-
version: '1.0.0',
|
|
150
|
-
},
|
|
151
|
-
paths: {
|
|
152
|
-
'/foobar/{id}': {
|
|
153
|
-
get: {
|
|
154
|
-
responses: {
|
|
155
|
-
'200': {
|
|
156
|
-
description: 'OK',
|
|
157
|
-
content: {
|
|
158
|
-
'application/json': {
|
|
159
|
-
example: {
|
|
160
|
-
foo: 'bar',
|
|
161
|
-
},
|
|
162
|
-
},
|
|
163
|
-
},
|
|
164
|
-
},
|
|
165
|
-
},
|
|
166
|
-
},
|
|
167
|
-
},
|
|
168
|
-
},
|
|
169
|
-
};
|
|
170
|
-
return [4 /*yield*/, createMockServer({
|
|
171
|
-
specification: specification,
|
|
172
|
-
})];
|
|
173
|
-
case 1:
|
|
174
|
-
server = _b.sent();
|
|
175
|
-
return [4 /*yield*/, server.request('/foobar/123')];
|
|
176
|
-
case 2:
|
|
177
|
-
response = _b.sent();
|
|
178
|
-
expect(response.status).toBe(200);
|
|
179
|
-
_a = expect;
|
|
180
|
-
return [4 /*yield*/, response.json()];
|
|
181
|
-
case 3:
|
|
182
|
-
_a.apply(void 0, [_b.sent()]).toMatchObject({
|
|
183
|
-
foo: 'bar',
|
|
184
|
-
});
|
|
185
|
-
return [2 /*return*/];
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
}); });
|
|
189
|
-
it('GET /foobar -> example from schema', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
190
|
-
var specification, server, response, _a;
|
|
191
|
-
return __generator(this, function (_b) {
|
|
192
|
-
switch (_b.label) {
|
|
193
|
-
case 0:
|
|
194
|
-
specification = {
|
|
195
|
-
openapi: '3.1.0',
|
|
196
|
-
info: {
|
|
197
|
-
title: 'Hello World',
|
|
198
|
-
version: '1.0.0',
|
|
199
|
-
},
|
|
200
|
-
paths: {
|
|
201
|
-
'/foobar': {
|
|
202
|
-
get: {
|
|
203
|
-
responses: {
|
|
204
|
-
'200': {
|
|
205
|
-
description: 'OK',
|
|
206
|
-
content: {
|
|
207
|
-
'application/json': {
|
|
208
|
-
schema: {
|
|
209
|
-
type: 'object',
|
|
210
|
-
properties: {
|
|
211
|
-
foo: {
|
|
212
|
-
type: 'string',
|
|
213
|
-
example: 'bar',
|
|
214
|
-
},
|
|
215
|
-
},
|
|
216
|
-
},
|
|
217
|
-
},
|
|
218
|
-
},
|
|
219
|
-
},
|
|
220
|
-
},
|
|
221
|
-
},
|
|
222
|
-
},
|
|
223
|
-
},
|
|
224
|
-
};
|
|
225
|
-
return [4 /*yield*/, createMockServer({
|
|
226
|
-
specification: specification,
|
|
227
|
-
})];
|
|
228
|
-
case 1:
|
|
229
|
-
server = _b.sent();
|
|
230
|
-
return [4 /*yield*/, server.request('/foobar')];
|
|
231
|
-
case 2:
|
|
232
|
-
response = _b.sent();
|
|
233
|
-
expect(response.status).toBe(200);
|
|
234
|
-
_a = expect;
|
|
235
|
-
return [4 /*yield*/, response.json()];
|
|
236
|
-
case 3:
|
|
237
|
-
_a.apply(void 0, [_b.sent()]).toMatchObject({
|
|
238
|
-
foo: 'bar',
|
|
239
|
-
});
|
|
240
|
-
return [2 /*return*/];
|
|
241
|
-
}
|
|
242
|
-
});
|
|
243
|
-
}); });
|
|
244
|
-
it('GET /foobar/{id} -> example from schema', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
245
|
-
var specification, server, response, _a;
|
|
246
|
-
return __generator(this, function (_b) {
|
|
247
|
-
switch (_b.label) {
|
|
248
|
-
case 0:
|
|
249
|
-
specification = {
|
|
250
|
-
openapi: '3.1.0',
|
|
251
|
-
info: {
|
|
252
|
-
title: 'Hello World',
|
|
253
|
-
version: '1.0.0',
|
|
254
|
-
},
|
|
255
|
-
paths: {
|
|
256
|
-
'/foobar/{id}': {
|
|
257
|
-
get: {
|
|
258
|
-
responses: {
|
|
259
|
-
'200': {
|
|
260
|
-
description: 'OK',
|
|
261
|
-
content: {
|
|
262
|
-
'application/json': {
|
|
263
|
-
schema: {
|
|
264
|
-
type: 'object',
|
|
265
|
-
properties: {
|
|
266
|
-
foo: {
|
|
267
|
-
type: 'string',
|
|
268
|
-
example: 'bar',
|
|
269
|
-
},
|
|
270
|
-
},
|
|
271
|
-
},
|
|
272
|
-
},
|
|
273
|
-
},
|
|
274
|
-
},
|
|
275
|
-
},
|
|
276
|
-
},
|
|
277
|
-
},
|
|
278
|
-
},
|
|
279
|
-
};
|
|
280
|
-
return [4 /*yield*/, createMockServer({
|
|
281
|
-
specification: specification,
|
|
282
|
-
})];
|
|
283
|
-
case 1:
|
|
284
|
-
server = _b.sent();
|
|
285
|
-
return [4 /*yield*/, server.request('/foobar/123')];
|
|
286
|
-
case 2:
|
|
287
|
-
response = _b.sent();
|
|
288
|
-
expect(response.status).toBe(200);
|
|
289
|
-
_a = expect;
|
|
290
|
-
return [4 /*yield*/, response.json()];
|
|
291
|
-
case 3:
|
|
292
|
-
_a.apply(void 0, [_b.sent()]).toMatchObject({
|
|
293
|
-
foo: 'bar',
|
|
294
|
-
});
|
|
295
|
-
return [2 /*return*/];
|
|
296
|
-
}
|
|
297
|
-
});
|
|
298
|
-
}); });
|
|
299
|
-
});
|
package/dist/src/index.d.ts
DELETED
package/dist/src/index.js
DELETED
package/dist/src/utils/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { normalize } from './normalize';
|
|
3
|
-
describe('normalize', function () {
|
|
4
|
-
it('returns object when given an object', function () {
|
|
5
|
-
expect(normalize({ foo: 'bar ' })).toMatchObject({ foo: 'bar ' });
|
|
6
|
-
});
|
|
7
|
-
it('returns object when given a string', function () {
|
|
8
|
-
expect(normalize(JSON.stringify({ foo: 'bar ' }))).toMatchObject({
|
|
9
|
-
foo: 'bar ',
|
|
10
|
-
});
|
|
11
|
-
});
|
|
12
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { routeFromPath } from './routeFromPath';
|
|
3
|
-
describe('routeFromPath', function () {
|
|
4
|
-
it('returns correct route for a simple path', function () {
|
|
5
|
-
expect(routeFromPath('/foobar')).toBe('/foobar');
|
|
6
|
-
});
|
|
7
|
-
it('returns correct route for a path with an ID', function () {
|
|
8
|
-
expect(routeFromPath('/foobar/{id}')).toBe('/foobar/:id');
|
|
9
|
-
});
|
|
10
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
-
function step(op) {
|
|
15
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
-
switch (op[0]) {
|
|
20
|
-
case 0: case 1: t = op; break;
|
|
21
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
-
default:
|
|
25
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
-
if (t[2]) _.ops.pop();
|
|
30
|
-
_.trys.pop(); continue;
|
|
31
|
-
}
|
|
32
|
-
op = body.call(thisArg, _);
|
|
33
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
// @ts-ignore
|
|
38
|
-
import galaxy from '@scalar/galaxy/3.1.yaml?raw';
|
|
39
|
-
import { describe, expect, it } from 'vitest';
|
|
40
|
-
import { createMockServer } from '../src/createMockServer';
|
|
41
|
-
describe('createMockServer', function () {
|
|
42
|
-
it('GET /planets -> example JSON', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
43
|
-
var server, response, _a;
|
|
44
|
-
return __generator(this, function (_b) {
|
|
45
|
-
switch (_b.label) {
|
|
46
|
-
case 0: return [4 /*yield*/, createMockServer({
|
|
47
|
-
specification: galaxy,
|
|
48
|
-
})];
|
|
49
|
-
case 1:
|
|
50
|
-
server = _b.sent();
|
|
51
|
-
return [4 /*yield*/, server.request('/planets')];
|
|
52
|
-
case 2:
|
|
53
|
-
response = _b.sent();
|
|
54
|
-
expect(response.status).toBe(200);
|
|
55
|
-
_a = expect;
|
|
56
|
-
return [4 /*yield*/, response.json()];
|
|
57
|
-
case 3:
|
|
58
|
-
_a.apply(void 0, [_b.sent()]).toMatchObject({
|
|
59
|
-
data: [
|
|
60
|
-
{
|
|
61
|
-
creator: {
|
|
62
|
-
email: 'marc@scalar.com',
|
|
63
|
-
id: 1,
|
|
64
|
-
name: 'Marc',
|
|
65
|
-
},
|
|
66
|
-
description: 'The red planet',
|
|
67
|
-
id: 1,
|
|
68
|
-
image: 'https://cdn.scalar.com/photos/mars.jpg',
|
|
69
|
-
name: 'Mars',
|
|
70
|
-
},
|
|
71
|
-
],
|
|
72
|
-
meta: {
|
|
73
|
-
limit: 10,
|
|
74
|
-
next: '/planets?limit=10&offset=10',
|
|
75
|
-
offset: 0,
|
|
76
|
-
total: 100,
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
return [2 /*return*/];
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
}); });
|
|
83
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
-
function step(op) {
|
|
15
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
-
switch (op[0]) {
|
|
20
|
-
case 0: case 1: t = op; break;
|
|
21
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
-
default:
|
|
25
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
-
if (t[2]) _.ops.pop();
|
|
30
|
-
_.trys.pop(); continue;
|
|
31
|
-
}
|
|
32
|
-
op = body.call(thisArg, _);
|
|
33
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
import { describe, expect, it } from 'vitest';
|
|
38
|
-
import { createMockServer } from '../src/createMockServer';
|
|
39
|
-
describe('onRequest', function () {
|
|
40
|
-
it('call custom onRequest hook', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
41
|
-
return __generator(this, function (_a) {
|
|
42
|
-
return [2 /*return*/, new Promise(function (resolve) { return __awaiter(void 0, void 0, void 0, function () {
|
|
43
|
-
var specification, server;
|
|
44
|
-
return __generator(this, function (_a) {
|
|
45
|
-
switch (_a.label) {
|
|
46
|
-
case 0:
|
|
47
|
-
specification = {
|
|
48
|
-
openapi: '3.1.0',
|
|
49
|
-
info: {
|
|
50
|
-
title: 'Hello World',
|
|
51
|
-
version: '1.0.0',
|
|
52
|
-
},
|
|
53
|
-
paths: {
|
|
54
|
-
'/foobar': {
|
|
55
|
-
get: {
|
|
56
|
-
operationId: 'foobar',
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
};
|
|
61
|
-
return [4 /*yield*/, createMockServer({
|
|
62
|
-
specification: specification,
|
|
63
|
-
onRequest: function (_a) {
|
|
64
|
-
var context = _a.context, operation = _a.operation;
|
|
65
|
-
expect(context.req.method).toBe('GET');
|
|
66
|
-
expect(context.req.path).toBe('/foobar');
|
|
67
|
-
expect(operation.operationId).toBe('foobar');
|
|
68
|
-
resolve(null);
|
|
69
|
-
},
|
|
70
|
-
})];
|
|
71
|
-
case 1:
|
|
72
|
-
server = _a.sent();
|
|
73
|
-
return [4 /*yield*/, server.request('/foobar')];
|
|
74
|
-
case 2:
|
|
75
|
-
_a.sent();
|
|
76
|
-
return [2 /*return*/];
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
}); })];
|
|
80
|
-
});
|
|
81
|
-
}); });
|
|
82
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|