wrangler 2.4.4 → 2.6.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/bin/wrangler.js +20 -8
- package/miniflare-dist/index.mjs +90 -41
- package/package.json +3 -3
- package/src/__tests__/configuration.test.ts +211 -0
- package/src/__tests__/delete.test.ts +81 -48
- package/src/__tests__/dev.test.tsx +25 -8
- package/src/__tests__/helpers/mock-oauth-flow.ts +5 -1
- package/src/__tests__/helpers/msw/handlers/oauth.ts +13 -18
- package/src/__tests__/init.test.ts +18 -3
- package/src/__tests__/logout.test.ts +47 -0
- package/src/__tests__/metrics.test.ts +88 -43
- package/src/__tests__/pages-deployment-tail.test.ts +165 -101
- package/src/__tests__/publish.test.ts +94 -7
- package/src/__tests__/pubsub.test.ts +208 -88
- package/src/__tests__/queues.test.ts +155 -67
- package/src/__tests__/tail.test.ts +207 -108
- package/src/__tests__/type-generation.test.ts +7 -0
- package/src/__tests__/user.test.ts +43 -69
- package/src/config/environment.ts +16 -0
- package/src/config/index.ts +31 -8
- package/src/config/validation.ts +49 -0
- package/src/create-worker-upload-form.ts +9 -0
- package/src/d1/backups.tsx +7 -2
- package/src/d1/delete.tsx +4 -4
- package/src/d1/index.ts +2 -0
- package/src/d1/migrations/apply.tsx +6 -5
- package/src/d1/migrations/helpers.ts +4 -2
- package/src/d1/migrations/list.tsx +2 -2
- package/src/d1/migrations/options.ts +18 -0
- package/src/dev/dev.tsx +46 -22
- package/src/dev/local.tsx +63 -29
- package/src/dev/start-server.ts +18 -21
- package/src/dev.tsx +33 -13
- package/src/git-client.ts +15 -4
- package/src/index.tsx +1 -0
- package/src/init.ts +8 -0
- package/src/miniflare-cli/assets.ts +55 -28
- package/src/miniflare-cli/index.ts +2 -1
- package/src/pages/dev.tsx +7 -0
- package/src/proxy.ts +5 -0
- package/src/publish/publish.ts +1 -0
- package/src/secret/index.ts +1 -0
- package/src/type-generation.ts +10 -2
- package/src/worker.ts +6 -0
- package/wrangler-dist/cli.d.ts +15 -0
- package/wrangler-dist/cli.js +2045 -636
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import MockWebSocket from "jest-websocket-mock";
|
|
2
|
+
import { rest } from "msw";
|
|
2
3
|
import { Headers, Request } from "undici";
|
|
3
4
|
import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
|
|
4
|
-
import { setMockResponse, unsetAllMocks } from "./helpers/mock-cfetch";
|
|
5
5
|
import { mockConsoleMethods } from "./helpers/mock-console";
|
|
6
|
-
import { mockGetZoneFromHostRequest } from "./helpers/mock-get-zone-from-host";
|
|
7
6
|
import { useMockIsTTY } from "./helpers/mock-istty";
|
|
8
|
-
import { mockCollectKnownRoutesRequest } from "./helpers/mock-known-routes";
|
|
9
7
|
import { msw, mswSucessScriptHandlers } from "./helpers/msw";
|
|
10
8
|
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
11
9
|
import { runWrangler } from "./helpers/run-wrangler";
|
|
@@ -17,6 +15,7 @@ import type {
|
|
|
17
15
|
} from "../tail/createTail";
|
|
18
16
|
import type { RequestInit } from "undici";
|
|
19
17
|
import type WebSocket from "ws";
|
|
18
|
+
|
|
20
19
|
describe("tail", () => {
|
|
21
20
|
beforeEach(() => msw.use(...mswSucessScriptHandlers));
|
|
22
21
|
runInTempDir();
|
|
@@ -28,7 +27,6 @@ describe("tail", () => {
|
|
|
28
27
|
afterEach(() => {
|
|
29
28
|
mockWebSockets.forEach((ws) => ws.close());
|
|
30
29
|
mockWebSockets.splice(0);
|
|
31
|
-
unsetAllMocks();
|
|
32
30
|
});
|
|
33
31
|
|
|
34
32
|
/**
|
|
@@ -67,38 +65,101 @@ describe("tail", () => {
|
|
|
67
65
|
expect(api.requests.creation.length).toStrictEqual(1);
|
|
68
66
|
expect(api.requests.deletion.count).toStrictEqual(0);
|
|
69
67
|
|
|
70
|
-
api.
|
|
68
|
+
await api.closeHelper();
|
|
71
69
|
expect(api.requests.deletion.count).toStrictEqual(1);
|
|
72
70
|
});
|
|
73
71
|
it("should connect to the worker assigned to a given route", async () => {
|
|
74
72
|
const api = mockWebsocketAPIs();
|
|
75
73
|
expect(api.requests.creation.length).toStrictEqual(0);
|
|
76
74
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
75
|
+
msw.use(
|
|
76
|
+
rest.get(`*/zones`, (req, res, ctx) => {
|
|
77
|
+
expect(req.url.searchParams.get("name")).toBe("example.com");
|
|
78
|
+
return res.once(
|
|
79
|
+
ctx.status(200),
|
|
80
|
+
ctx.json({
|
|
81
|
+
success: true,
|
|
82
|
+
errors: [],
|
|
83
|
+
messages: [],
|
|
84
|
+
result: [{ id: "test-zone" }],
|
|
85
|
+
})
|
|
86
|
+
);
|
|
87
|
+
})
|
|
88
|
+
);
|
|
89
|
+
msw.use(
|
|
90
|
+
rest.get(`*/zones/:zoneId/workers/routes`, (req, res, ctx) => {
|
|
91
|
+
return res.once(
|
|
92
|
+
ctx.status(200),
|
|
93
|
+
ctx.json({
|
|
94
|
+
success: true,
|
|
95
|
+
errors: [],
|
|
96
|
+
messages: [],
|
|
97
|
+
result: [
|
|
98
|
+
{
|
|
99
|
+
pattern: "example.com/*",
|
|
100
|
+
script: "test-worker",
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
})
|
|
104
|
+
);
|
|
105
|
+
})
|
|
106
|
+
);
|
|
84
107
|
await runWrangler("tail example.com/*");
|
|
85
108
|
|
|
86
109
|
await expect(api.ws.connected).resolves.toBeTruthy();
|
|
87
110
|
expect(api.requests.creation.length).toStrictEqual(1);
|
|
88
111
|
expect(api.requests.deletion.count).toStrictEqual(0);
|
|
89
112
|
|
|
90
|
-
api.
|
|
113
|
+
await api.closeHelper();
|
|
91
114
|
expect(api.requests.deletion.count).toStrictEqual(1);
|
|
92
115
|
});
|
|
93
116
|
|
|
94
117
|
it("should error if a given route is not assigned to the user's zone", async () => {
|
|
95
|
-
|
|
96
|
-
|
|
118
|
+
msw.use(
|
|
119
|
+
rest.get(`*/zones`, (req, res, ctx) => {
|
|
120
|
+
expect(req.url.searchParams.get("name")).toBe("example.com");
|
|
121
|
+
return res.once(
|
|
122
|
+
ctx.status(200),
|
|
123
|
+
ctx.json({
|
|
124
|
+
success: true,
|
|
125
|
+
errors: [],
|
|
126
|
+
messages: [],
|
|
127
|
+
result: [{ id: "test-zone" }],
|
|
128
|
+
})
|
|
129
|
+
);
|
|
130
|
+
})
|
|
131
|
+
);
|
|
132
|
+
msw.use(
|
|
133
|
+
rest.get(`*/zones/:zoneId/workers/routes`, (req, res, ctx) => {
|
|
134
|
+
return res.once(
|
|
135
|
+
ctx.status(200),
|
|
136
|
+
ctx.json({
|
|
137
|
+
success: true,
|
|
138
|
+
errors: [],
|
|
139
|
+
messages: [],
|
|
140
|
+
result: [],
|
|
141
|
+
})
|
|
142
|
+
);
|
|
143
|
+
})
|
|
144
|
+
);
|
|
97
145
|
|
|
98
146
|
await expect(runWrangler("tail example.com/*")).rejects.toThrow();
|
|
99
147
|
});
|
|
100
148
|
it("should error if a given route is not within the user's zone", async () => {
|
|
101
|
-
|
|
149
|
+
msw.use(
|
|
150
|
+
rest.get(`*/zones`, (req, res, ctx) => {
|
|
151
|
+
expect(req.url.searchParams.get("name")).toBe("example.com");
|
|
152
|
+
return res.once(
|
|
153
|
+
ctx.status(200),
|
|
154
|
+
ctx.json({
|
|
155
|
+
success: true,
|
|
156
|
+
errors: [],
|
|
157
|
+
messages: [],
|
|
158
|
+
result: [],
|
|
159
|
+
})
|
|
160
|
+
);
|
|
161
|
+
})
|
|
162
|
+
);
|
|
102
163
|
|
|
103
164
|
await expect(runWrangler("tail example.com/*")).rejects.toThrow();
|
|
104
165
|
});
|
|
@@ -113,7 +174,7 @@ describe("tail", () => {
|
|
|
113
174
|
expect(api.requests.creation.length).toStrictEqual(1);
|
|
114
175
|
expect(api.requests.deletion.count).toStrictEqual(0);
|
|
115
176
|
|
|
116
|
-
api.
|
|
177
|
+
await api.closeHelper();
|
|
117
178
|
expect(api.requests.deletion.count).toStrictEqual(1);
|
|
118
179
|
});
|
|
119
180
|
|
|
@@ -127,13 +188,13 @@ describe("tail", () => {
|
|
|
127
188
|
expect(api.requests.creation.length).toStrictEqual(1);
|
|
128
189
|
expect(api.requests.deletion.count).toStrictEqual(0);
|
|
129
190
|
|
|
130
|
-
api.
|
|
191
|
+
await api.closeHelper();
|
|
131
192
|
expect(api.requests.deletion.count).toStrictEqual(1);
|
|
132
193
|
});
|
|
133
194
|
|
|
134
195
|
it("errors when the websocket closes unexpectedly", async () => {
|
|
135
196
|
const api = mockWebsocketAPIs();
|
|
136
|
-
api.
|
|
197
|
+
await api.closeHelper();
|
|
137
198
|
|
|
138
199
|
await expect(runWrangler("tail test-worker")).rejects.toThrow();
|
|
139
200
|
});
|
|
@@ -158,57 +219,72 @@ describe("tail", () => {
|
|
|
158
219
|
await expect(tooLow).rejects.toThrow();
|
|
159
220
|
|
|
160
221
|
await runWrangler("tail test-worker --sampling-rate 0.25");
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
222
|
+
|
|
223
|
+
expect(api.requests.creation[0]).toEqual({
|
|
224
|
+
filters: [{ sampling_rate: 0.25 }],
|
|
225
|
+
});
|
|
164
226
|
});
|
|
165
227
|
|
|
166
228
|
it("sends single status filters", async () => {
|
|
167
229
|
const api = mockWebsocketAPIs();
|
|
168
230
|
await runWrangler("tail test-worker --status error");
|
|
169
|
-
expect(api.requests.creation[0]
|
|
170
|
-
|
|
171
|
-
|
|
231
|
+
expect(api.requests.creation[0]).toEqual({
|
|
232
|
+
filters: [
|
|
233
|
+
{
|
|
234
|
+
outcome: ["exception", "exceededCpu", "exceededMemory", "unknown"],
|
|
235
|
+
},
|
|
236
|
+
],
|
|
237
|
+
});
|
|
172
238
|
});
|
|
173
239
|
|
|
174
240
|
it("sends multiple status filters", async () => {
|
|
175
241
|
const api = mockWebsocketAPIs();
|
|
176
242
|
await runWrangler("tail test-worker --status error --status canceled");
|
|
177
|
-
expect(api.requests.creation[0]
|
|
178
|
-
|
|
179
|
-
|
|
243
|
+
expect(api.requests.creation[0]).toEqual({
|
|
244
|
+
filters: [
|
|
245
|
+
{
|
|
246
|
+
outcome: [
|
|
247
|
+
"exception",
|
|
248
|
+
"exceededCpu",
|
|
249
|
+
"exceededMemory",
|
|
250
|
+
"unknown",
|
|
251
|
+
"canceled",
|
|
252
|
+
],
|
|
253
|
+
},
|
|
254
|
+
],
|
|
255
|
+
});
|
|
180
256
|
});
|
|
181
257
|
|
|
182
258
|
it("sends single HTTP method filters", async () => {
|
|
183
259
|
const api = mockWebsocketAPIs();
|
|
184
260
|
await runWrangler("tail test-worker --method POST");
|
|
185
|
-
expect(api.requests.creation[0]
|
|
186
|
-
|
|
187
|
-
);
|
|
261
|
+
expect(api.requests.creation[0]).toEqual({
|
|
262
|
+
filters: [{ method: ["POST"] }],
|
|
263
|
+
});
|
|
188
264
|
});
|
|
189
265
|
|
|
190
266
|
it("sends multiple HTTP method filters", async () => {
|
|
191
267
|
const api = mockWebsocketAPIs();
|
|
192
268
|
await runWrangler("tail test-worker --method POST --method GET");
|
|
193
|
-
expect(api.requests.creation[0]
|
|
194
|
-
|
|
195
|
-
);
|
|
269
|
+
expect(api.requests.creation[0]).toEqual({
|
|
270
|
+
filters: [{ method: ["POST", "GET"] }],
|
|
271
|
+
});
|
|
196
272
|
});
|
|
197
273
|
|
|
198
274
|
it("sends header filters without a query", async () => {
|
|
199
275
|
const api = mockWebsocketAPIs();
|
|
200
276
|
await runWrangler("tail test-worker --header X-CUSTOM-HEADER");
|
|
201
|
-
expect(api.requests.creation[0]
|
|
202
|
-
|
|
203
|
-
);
|
|
277
|
+
expect(api.requests.creation[0]).toEqual({
|
|
278
|
+
filters: [{ header: { key: "X-CUSTOM-HEADER" } }],
|
|
279
|
+
});
|
|
204
280
|
});
|
|
205
281
|
|
|
206
282
|
it("sends header filters with a query", async () => {
|
|
207
283
|
const api = mockWebsocketAPIs();
|
|
208
284
|
await runWrangler("tail test-worker --header X-CUSTOM-HEADER:some-value");
|
|
209
|
-
expect(api.requests.creation[0]
|
|
210
|
-
|
|
211
|
-
);
|
|
285
|
+
expect(api.requests.creation[0]).toEqual({
|
|
286
|
+
filters: [{ header: { key: "X-CUSTOM-HEADER", query: "some-value" } }],
|
|
287
|
+
});
|
|
212
288
|
});
|
|
213
289
|
|
|
214
290
|
it("sends single IP filters", async () => {
|
|
@@ -216,9 +292,9 @@ describe("tail", () => {
|
|
|
216
292
|
const fakeIp = "192.0.2.1";
|
|
217
293
|
|
|
218
294
|
await runWrangler(`tail test-worker --ip ${fakeIp}`);
|
|
219
|
-
expect(api.requests.creation[0]
|
|
220
|
-
|
|
221
|
-
);
|
|
295
|
+
expect(api.requests.creation[0]).toEqual({
|
|
296
|
+
filters: [{ client_ip: [fakeIp] }],
|
|
297
|
+
});
|
|
222
298
|
});
|
|
223
299
|
|
|
224
300
|
it("sends multiple IP filters", async () => {
|
|
@@ -226,9 +302,9 @@ describe("tail", () => {
|
|
|
226
302
|
const fakeIp = "192.0.2.1";
|
|
227
303
|
|
|
228
304
|
await runWrangler(`tail test-worker --ip ${fakeIp} --ip self`);
|
|
229
|
-
expect(api.requests.creation[0]
|
|
230
|
-
|
|
231
|
-
);
|
|
305
|
+
expect(api.requests.creation[0]).toEqual({
|
|
306
|
+
filters: [{ client_ip: [fakeIp, "self"] }],
|
|
307
|
+
});
|
|
232
308
|
});
|
|
233
309
|
|
|
234
310
|
it("sends search filters", async () => {
|
|
@@ -236,9 +312,9 @@ describe("tail", () => {
|
|
|
236
312
|
const search = "filterMe";
|
|
237
313
|
|
|
238
314
|
await runWrangler(`tail test-worker --search ${search}`);
|
|
239
|
-
expect(api.requests.creation[0]
|
|
240
|
-
|
|
241
|
-
);
|
|
315
|
+
expect(api.requests.creation[0]).toEqual({
|
|
316
|
+
filters: [{ query: search }],
|
|
317
|
+
});
|
|
242
318
|
});
|
|
243
319
|
|
|
244
320
|
it("sends everything but the kitchen sink", async () => {
|
|
@@ -259,10 +335,27 @@ describe("tail", () => {
|
|
|
259
335
|
`--search ${query} ` +
|
|
260
336
|
`--debug`;
|
|
261
337
|
|
|
262
|
-
const expectedWebsocketMessage =
|
|
338
|
+
const expectedWebsocketMessage = {
|
|
339
|
+
filters: [
|
|
340
|
+
{ sampling_rate: 0.69 },
|
|
341
|
+
{
|
|
342
|
+
outcome: [
|
|
343
|
+
"ok",
|
|
344
|
+
"exception",
|
|
345
|
+
"exceededCpu",
|
|
346
|
+
"exceededMemory",
|
|
347
|
+
"unknown",
|
|
348
|
+
],
|
|
349
|
+
},
|
|
350
|
+
{ method: ["GET", "POST", "PUT"] },
|
|
351
|
+
{ header: { key: "X-HELLO", query: "world" } },
|
|
352
|
+
{ client_ip: ["192.0.2.1", "self"] },
|
|
353
|
+
{ query: "onlyTheseMessagesPlease" },
|
|
354
|
+
],
|
|
355
|
+
};
|
|
263
356
|
|
|
264
357
|
await runWrangler(`tail test-worker ${cliFilters}`);
|
|
265
|
-
expect(api.requests.creation[0]
|
|
358
|
+
expect(api.requests.creation[0]).toEqual(expectedWebsocketMessage);
|
|
266
359
|
});
|
|
267
360
|
});
|
|
268
361
|
|
|
@@ -320,10 +413,7 @@ describe("tail", () => {
|
|
|
320
413
|
new Date(mockEventTimestamp).toLocaleString(),
|
|
321
414
|
"[mock event timestamp]"
|
|
322
415
|
)
|
|
323
|
-
.replace(
|
|
324
|
-
mockTailExpiration.toLocaleString(),
|
|
325
|
-
"[mock expiration date]"
|
|
326
|
-
)
|
|
416
|
+
.replace(mockTailExpiration.toISOString(), "[mock expiration date]")
|
|
327
417
|
).toMatchInlineSnapshot(`
|
|
328
418
|
"Successfully created tail, expires at [mock expiration date]
|
|
329
419
|
Connected to test-worker, waiting for logs...
|
|
@@ -346,10 +436,7 @@ describe("tail", () => {
|
|
|
346
436
|
new Date(mockEventTimestamp).toLocaleString(),
|
|
347
437
|
"[mock timestamp string]"
|
|
348
438
|
)
|
|
349
|
-
.replace(
|
|
350
|
-
mockTailExpiration.toLocaleString(),
|
|
351
|
-
"[mock expiration date]"
|
|
352
|
-
)
|
|
439
|
+
.replace(mockTailExpiration.toISOString(), "[mock expiration date]")
|
|
353
440
|
).toMatchInlineSnapshot(`
|
|
354
441
|
"Successfully created tail, expires at [mock expiration date]
|
|
355
442
|
Connected to test-worker, waiting for logs...
|
|
@@ -372,10 +459,7 @@ describe("tail", () => {
|
|
|
372
459
|
new Date(mockEventScheduledTime).toLocaleString(),
|
|
373
460
|
"[mock scheduled time]"
|
|
374
461
|
)
|
|
375
|
-
.replace(
|
|
376
|
-
mockTailExpiration.toLocaleString(),
|
|
377
|
-
"[mock expiration date]"
|
|
378
|
-
)
|
|
462
|
+
.replace(mockTailExpiration.toISOString(), "[mock expiration date]")
|
|
379
463
|
).toMatchInlineSnapshot(`
|
|
380
464
|
"Successfully created tail, expires at [mock expiration date]
|
|
381
465
|
Connected to test-worker, waiting for logs...
|
|
@@ -393,14 +477,11 @@ describe("tail", () => {
|
|
|
393
477
|
api.ws.send(serializedMessage);
|
|
394
478
|
expect(
|
|
395
479
|
std.out
|
|
396
|
-
.replace(
|
|
397
|
-
mockTailExpiration.toLocaleString(),
|
|
398
|
-
"[mock expiration date]"
|
|
399
|
-
)
|
|
400
480
|
.replace(
|
|
401
481
|
new Date(mockEventTimestamp).toLocaleString(),
|
|
402
482
|
"[mock timestamp string]"
|
|
403
483
|
)
|
|
484
|
+
.replace(mockTailExpiration.toISOString(), "[mock expiration date]")
|
|
404
485
|
).toMatchInlineSnapshot(`
|
|
405
486
|
"Successfully created tail, expires at [mock expiration date]
|
|
406
487
|
Connected to test-worker, waiting for logs...
|
|
@@ -424,10 +505,7 @@ describe("tail", () => {
|
|
|
424
505
|
new Date(mockEventTimestamp).toLocaleString(),
|
|
425
506
|
"[mock event timestamp]"
|
|
426
507
|
)
|
|
427
|
-
.replace(
|
|
428
|
-
mockTailExpiration.toLocaleString(),
|
|
429
|
-
"[mock expiration date]"
|
|
430
|
-
)
|
|
508
|
+
.replace(mockTailExpiration.toISOString(), "[mock expiration date]")
|
|
431
509
|
).toMatchInlineSnapshot(`
|
|
432
510
|
"Successfully created tail, expires at [mock expiration date]
|
|
433
511
|
Connected to test-worker, waiting for logs...
|
|
@@ -480,10 +558,7 @@ describe("tail", () => {
|
|
|
480
558
|
new Date(mockEventTimestamp).toLocaleString(),
|
|
481
559
|
"[mock event timestamp]"
|
|
482
560
|
)
|
|
483
|
-
.replace(
|
|
484
|
-
mockTailExpiration.toLocaleString(),
|
|
485
|
-
"[mock expiration date]"
|
|
486
|
-
)
|
|
561
|
+
.replace(mockTailExpiration.toISOString(), "[mock expiration date]")
|
|
487
562
|
).toMatchInlineSnapshot(`
|
|
488
563
|
"Successfully created tail, expires at [mock expiration date]
|
|
489
564
|
Connected to test-worker, waiting for logs...
|
|
@@ -581,6 +656,7 @@ type MockAPI = {
|
|
|
581
656
|
};
|
|
582
657
|
ws: MockWebSocket;
|
|
583
658
|
nextMessageJson(): Promise<unknown>;
|
|
659
|
+
closeHelper: () => Promise<void>;
|
|
584
660
|
};
|
|
585
661
|
|
|
586
662
|
/**
|
|
@@ -607,22 +683,32 @@ function mockCreateTailRequest(
|
|
|
607
683
|
const requests: RequestInit[] = [];
|
|
608
684
|
const servicesOrScripts = env && !legacyEnv ? "services" : "scripts";
|
|
609
685
|
const environment = env && !legacyEnv ? "/environments/:envName" : "";
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
686
|
+
msw.use(
|
|
687
|
+
rest.post(
|
|
688
|
+
`*/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/tails`,
|
|
689
|
+
async (req, res, ctx) => {
|
|
690
|
+
const request = await req.json();
|
|
691
|
+
requests.push(request);
|
|
692
|
+
expect(req.params.accountId).toEqual("some-account-id");
|
|
693
|
+
expect(req.params.scriptName).toEqual(expectedScriptName);
|
|
694
|
+
if (!legacyEnv) {
|
|
695
|
+
expect(req.params.envName).toEqual(env);
|
|
696
|
+
}
|
|
697
|
+
return res.once(
|
|
698
|
+
ctx.status(200),
|
|
699
|
+
ctx.json({
|
|
700
|
+
success: true,
|
|
701
|
+
errors: [],
|
|
702
|
+
messages: [],
|
|
703
|
+
result: {
|
|
704
|
+
url: websocketURL,
|
|
705
|
+
id: "tail-id",
|
|
706
|
+
expires_at: mockTailExpiration,
|
|
707
|
+
},
|
|
708
|
+
})
|
|
709
|
+
);
|
|
619
710
|
}
|
|
620
|
-
|
|
621
|
-
id: "tail-id",
|
|
622
|
-
url: websocketURL,
|
|
623
|
-
expires_at: mockTailExpiration,
|
|
624
|
-
};
|
|
625
|
-
}
|
|
711
|
+
)
|
|
626
712
|
);
|
|
627
713
|
|
|
628
714
|
return requests;
|
|
@@ -656,26 +742,30 @@ function mockDeleteTailRequest(
|
|
|
656
742
|
const requests = { count: 0 };
|
|
657
743
|
const servicesOrScripts = env && !legacyEnv ? "services" : "scripts";
|
|
658
744
|
const environment = env && !legacyEnv ? "/environments/:envName" : "";
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
expect(tailId).toEqual("tail-id");
|
|
671
|
-
} else {
|
|
672
|
-
expect(envNameOrTailId).toEqual("tail-id");
|
|
745
|
+
msw.use(
|
|
746
|
+
rest.delete(
|
|
747
|
+
`*/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/tails/:tailId`,
|
|
748
|
+
async (req, res, ctx) => {
|
|
749
|
+
requests.count++;
|
|
750
|
+
expect(req.params.accountId).toEqual("some-account-id");
|
|
751
|
+
expect(req.params.scriptName).toEqual(expectedScriptName);
|
|
752
|
+
if (!legacyEnv) {
|
|
753
|
+
if (env) {
|
|
754
|
+
expect(req.params.tailId).toEqual("tail-id");
|
|
755
|
+
}
|
|
673
756
|
}
|
|
674
|
-
|
|
675
|
-
|
|
757
|
+
expect(req.params.tailId).toEqual("tail-id");
|
|
758
|
+
return res(
|
|
759
|
+
ctx.status(200),
|
|
760
|
+
ctx.json({
|
|
761
|
+
success: true,
|
|
762
|
+
errors: [],
|
|
763
|
+
messages: [],
|
|
764
|
+
result: null,
|
|
765
|
+
})
|
|
766
|
+
);
|
|
676
767
|
}
|
|
677
|
-
|
|
678
|
-
}
|
|
768
|
+
)
|
|
679
769
|
);
|
|
680
770
|
|
|
681
771
|
return requests;
|
|
@@ -712,6 +802,15 @@ function mockWebsocketAPIs(
|
|
|
712
802
|
const message = await api.ws.nextMessage;
|
|
713
803
|
return JSON.parse(message as string);
|
|
714
804
|
},
|
|
805
|
+
/**
|
|
806
|
+
* Close the mock websocket and clean up the API.
|
|
807
|
+
* The setTimeout forces a cycle to allow for closing and cleanup
|
|
808
|
+
* @returns a Promise that resolves when the websocket is closed
|
|
809
|
+
*/
|
|
810
|
+
async closeHelper() {
|
|
811
|
+
api.ws.close();
|
|
812
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
813
|
+
},
|
|
715
814
|
};
|
|
716
815
|
api.requests.creation = mockCreateTailRequest(
|
|
717
816
|
websocketURL,
|
|
@@ -52,6 +52,12 @@ const bindingsConfigMock: Partial<Config> = {
|
|
|
52
52
|
},
|
|
53
53
|
],
|
|
54
54
|
services: [{ binding: "SERVICE_BINDING", service: "SERVICE_NAME" }],
|
|
55
|
+
analytics_engine_datasets: [
|
|
56
|
+
{
|
|
57
|
+
binding: "AE_DATASET_BINDING",
|
|
58
|
+
dataset: "AE_DATASET_TEST",
|
|
59
|
+
},
|
|
60
|
+
],
|
|
55
61
|
dispatch_namespaces: [
|
|
56
62
|
{ binding: "NAMESPACE_BINDING", namespace: "NAMESPACE_ID" },
|
|
57
63
|
],
|
|
@@ -116,6 +122,7 @@ describe("generateTypes()", () => {
|
|
|
116
122
|
R2_BUCKET_BINDING: R2Bucket;
|
|
117
123
|
D1_TESTING_SOMETHING: D1Database;
|
|
118
124
|
SERVICE_BINDING: Fetcher;
|
|
125
|
+
AE_DATASET_BINDING: AnalyticsEngineDataset;
|
|
119
126
|
NAMESPACE_BINDING: any;
|
|
120
127
|
LOGFWDR_SCHEMA: any;
|
|
121
128
|
SOME_DATA_BLOB1: ArrayBuffer;
|