wrangler 0.0.0-e64812e → 0.0.0-e8e684c7
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/README.md +27 -3
- package/bin/wrangler.js +150 -62
- package/kv-asset-handler.js +1 -0
- package/miniflare-dist/index.mjs +663 -7
- package/package.json +173 -152
- package/src/__tests__/config-cache-without-cache-dir.test.ts +38 -0
- package/src/__tests__/config-cache.test.ts +30 -24
- package/src/__tests__/configuration.test.ts +4015 -3363
- package/src/__tests__/dev.test.tsx +1290 -952
- package/src/__tests__/generate.test.ts +91 -0
- package/src/__tests__/guess-worker-format.test.ts +68 -68
- package/src/__tests__/helpers/cmd-shim.d.ts +6 -6
- package/src/__tests__/helpers/mock-account-id.ts +24 -24
- package/src/__tests__/helpers/mock-bin.ts +20 -20
- package/src/__tests__/helpers/mock-cfetch.ts +179 -94
- package/src/__tests__/helpers/mock-console.ts +49 -39
- package/src/__tests__/helpers/mock-dialogs.ts +94 -71
- package/src/__tests__/helpers/mock-get-zone-from-host.ts +8 -0
- package/src/__tests__/helpers/mock-http-server.ts +30 -30
- package/src/__tests__/helpers/mock-istty.ts +65 -18
- package/src/__tests__/helpers/mock-known-routes.ts +7 -0
- package/src/__tests__/helpers/mock-kv.ts +26 -26
- package/src/__tests__/helpers/mock-oauth-flow.ts +223 -228
- package/src/__tests__/helpers/mock-process.ts +39 -0
- package/src/__tests__/helpers/mock-stdin.ts +82 -77
- package/src/__tests__/helpers/mock-web-socket.ts +21 -21
- package/src/__tests__/helpers/run-in-tmp.ts +27 -28
- package/src/__tests__/helpers/run-wrangler.ts +8 -8
- package/src/__tests__/helpers/write-worker-source.ts +16 -16
- package/src/__tests__/helpers/write-wrangler-toml.ts +9 -9
- package/src/__tests__/https-options.test.ts +142 -109
- package/src/__tests__/index.test.ts +222 -233
- package/src/__tests__/init.test.ts +2139 -1603
- package/src/__tests__/jest.setup.ts +114 -34
- package/src/__tests__/kv.test.ts +1222 -1032
- package/src/__tests__/logger.test.ts +100 -74
- package/src/__tests__/metrics.test.ts +450 -0
- package/src/__tests__/package-manager.test.ts +303 -303
- package/src/__tests__/pages.test.ts +1173 -652
- package/src/__tests__/parse.test.ts +252 -252
- package/src/__tests__/publish.test.ts +6788 -5301
- package/src/__tests__/pubsub.test.ts +367 -0
- package/src/__tests__/r2.test.ts +328 -225
- package/src/__tests__/route.test.ts +18 -18
- package/src/__tests__/secret.test.ts +470 -459
- package/src/__tests__/tail.test.ts +676 -564
- package/src/__tests__/test-old-node-version.js +31 -0
- package/src/__tests__/user.test.ts +136 -112
- package/src/__tests__/validate-dev-props.test.ts +56 -0
- package/src/__tests__/version.test.ts +35 -0
- package/src/__tests__/whoami.test.tsx +267 -83
- package/src/__tests__/worker-namespace.test.ts +329 -0
- package/src/abort.d.ts +1 -1
- package/src/api/dev.ts +93 -0
- package/src/api/index.ts +1 -0
- package/src/bundle-reporter.tsx +29 -0
- package/src/bundle.ts +430 -157
- package/src/cfetch/index.ts +80 -80
- package/src/cfetch/internal.ts +244 -91
- package/src/cli.ts +21 -7
- package/src/config/config.ts +224 -195
- package/src/config/diagnostics.ts +61 -61
- package/src/config/environment.ts +422 -357
- package/src/config/index.ts +219 -193
- package/src/config/validation-helpers.ts +379 -357
- package/src/config/validation.ts +1690 -1367
- package/src/config-cache.ts +81 -41
- package/src/create-worker-preview.ts +208 -136
- package/src/create-worker-upload-form.ts +275 -238
- package/src/dev/dev-vars.ts +13 -13
- package/src/dev/dev.tsx +477 -351
- package/src/dev/local.tsx +426 -295
- package/src/dev/remote.tsx +406 -211
- package/src/dev/use-esbuild.ts +154 -94
- package/src/dev/validate-dev-props.ts +31 -0
- package/src/dev-registry.tsx +160 -0
- package/src/dev.tsx +696 -0
- package/src/dialogs.tsx +97 -97
- package/src/dispatch-namespace.ts +206 -0
- package/src/durable.ts +87 -87
- package/src/entry.ts +234 -228
- package/src/environment-variables.ts +23 -23
- package/src/errors.ts +6 -6
- package/src/faye-websocket.d.ts +6 -0
- package/src/generate.ts +131 -0
- package/src/git-client.ts +42 -0
- package/src/global-wrangler-config-path.ts +26 -0
- package/src/https-options.ts +84 -80
- package/src/index.tsx +2164 -2768
- package/src/init.ts +622 -0
- package/src/inspect.ts +678 -593
- package/src/intl-polyfill.d.ts +123 -123
- package/src/is-ci.ts +14 -0
- package/src/is-interactive.ts +12 -0
- package/src/kv.ts +299 -277
- package/src/logger.ts +46 -39
- package/src/metrics/index.ts +5 -0
- package/src/metrics/metrics-config.ts +239 -0
- package/src/metrics/metrics-dispatcher.ts +96 -0
- package/src/metrics/metrics-usage-headers.ts +24 -0
- package/src/metrics/send-event.ts +92 -0
- package/src/miniflare-cli/assets.ts +554 -0
- package/src/miniflare-cli/enum-keys.ts +8 -8
- package/src/miniflare-cli/index.ts +198 -32
- package/src/miniflare-cli/request-context.ts +18 -18
- package/src/module-collection.ts +212 -212
- package/src/open-in-browser.ts +4 -6
- package/src/package-manager.ts +173 -128
- package/src/pages/build.tsx +238 -0
- package/src/pages/constants.ts +12 -0
- package/src/pages/deployments.tsx +106 -0
- package/src/pages/dev.tsx +528 -0
- package/src/pages/errors.ts +22 -0
- package/src/pages/functions/buildPlugin.ts +109 -0
- package/src/pages/functions/buildWorker.ts +155 -0
- package/{pages → src/pages}/functions/filepath-routing.test.ts +113 -113
- package/src/pages/functions/filepath-routing.ts +189 -0
- package/src/pages/functions/identifiers.ts +78 -0
- package/src/pages/functions/routes-consolidation.test.ts +250 -0
- package/src/pages/functions/routes-consolidation.ts +73 -0
- package/src/pages/functions/routes-transformation.test.ts +271 -0
- package/src/pages/functions/routes-transformation.ts +122 -0
- package/src/pages/functions/routes.ts +151 -0
- package/src/pages/functions.tsx +96 -0
- package/src/pages/index.tsx +94 -0
- package/src/pages/projects.tsx +169 -0
- package/src/pages/publish.tsx +391 -0
- package/src/pages/types.ts +49 -0
- package/src/pages/upload.tsx +413 -0
- package/src/pages/utils.ts +12 -0
- package/src/parse.ts +209 -125
- package/src/paths.ts +6 -6
- package/src/preview.ts +31 -0
- package/src/proxy.ts +410 -389
- package/src/publish.ts +773 -534
- package/src/pubsub/index.ts +286 -0
- package/src/pubsub/pubsub-commands.tsx +623 -0
- package/src/r2.ts +100 -19
- package/src/selfsigned.d.ts +23 -23
- package/src/sites.tsx +278 -201
- package/src/tail/filters.ts +111 -109
- package/src/tail/index.ts +230 -217
- package/src/tail/printing.ts +86 -46
- package/src/update-check.ts +11 -11
- package/src/user/choose-account.tsx +69 -0
- package/src/user/env-vars.ts +46 -0
- package/src/user/generate-auth-url.ts +33 -0
- package/src/user/generate-random-state.ts +16 -0
- package/src/user/index.ts +3 -0
- package/src/user/user.tsx +1191 -0
- package/src/whoami.tsx +141 -42
- package/src/worker.ts +123 -99
- package/src/zones.ts +167 -0
- package/templates/checked-fetch.js +17 -0
- package/templates/first-party-worker-module-facade.ts +18 -0
- package/templates/format-dev-errors.ts +32 -0
- package/templates/new-worker-scheduled.js +3 -3
- package/templates/new-worker-scheduled.ts +15 -15
- package/templates/new-worker.js +3 -3
- package/templates/new-worker.ts +15 -15
- package/templates/no-op-worker.js +10 -0
- package/templates/pages-shim.ts +9 -0
- package/templates/pages-template-plugin.ts +167 -0
- package/templates/pages-template-worker.ts +172 -0
- package/templates/serve-static-assets.ts +63 -0
- package/templates/service-bindings-module-facade.js +54 -0
- package/templates/service-bindings-sw-facade.js +42 -0
- package/templates/tsconfig.json +95 -95
- package/wrangler-dist/cli.d.ts +338 -0
- package/wrangler-dist/cli.js +95449 -67524
- package/pages/functions/buildPlugin.ts +0 -105
- package/pages/functions/buildWorker.ts +0 -151
- package/pages/functions/filepath-routing.ts +0 -189
- package/pages/functions/identifiers.ts +0 -78
- package/pages/functions/routes.ts +0 -156
- package/pages/functions/template-plugin.ts +0 -147
- package/pages/functions/template-worker.ts +0 -143
- package/src/__tests__/helpers/faye-websocket.d.ts +0 -6
- package/src/pages.tsx +0 -2038
- package/src/user.tsx +0 -1203
- package/templates/static-asset-facade.js +0 -47
- package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
- package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
- package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
- package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
- package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
- package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
- package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
- package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
- package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
- package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
- package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
- package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
- package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
- package/vendor/wrangler-mime/CHANGELOG.md +0 -289
- package/vendor/wrangler-mime/LICENSE +0 -21
- package/vendor/wrangler-mime/Mime.js +0 -97
- package/vendor/wrangler-mime/README.md +0 -187
- package/vendor/wrangler-mime/cli.js +0 -46
- package/vendor/wrangler-mime/index.js +0 -4
- package/vendor/wrangler-mime/lite.js +0 -4
- package/vendor/wrangler-mime/package.json +0 -52
- package/vendor/wrangler-mime/types/other.js +0 -1
- package/vendor/wrangler-mime/types/standard.js +0 -1
|
@@ -3,418 +3,519 @@ import { Headers, Request } from "undici";
|
|
|
3
3
|
import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
|
|
4
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";
|
|
6
7
|
import { useMockIsTTY } from "./helpers/mock-istty";
|
|
8
|
+
import { mockCollectKnownRoutesRequest } from "./helpers/mock-known-routes";
|
|
7
9
|
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
8
10
|
import { runWrangler } from "./helpers/run-wrangler";
|
|
9
|
-
import type {
|
|
11
|
+
import type {
|
|
12
|
+
TailEventMessage,
|
|
13
|
+
RequestEvent,
|
|
14
|
+
ScheduledEvent,
|
|
15
|
+
AlarmEvent,
|
|
16
|
+
} from "../tail";
|
|
10
17
|
import type WebSocket from "ws";
|
|
11
18
|
|
|
12
19
|
describe("tail", () => {
|
|
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
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
20
|
+
runInTempDir();
|
|
21
|
+
mockAccountId();
|
|
22
|
+
mockApiToken();
|
|
23
|
+
|
|
24
|
+
const std = mockConsoleMethods();
|
|
25
|
+
|
|
26
|
+
afterEach(() => {
|
|
27
|
+
mockWebSockets.forEach((ws) => ws.close());
|
|
28
|
+
mockWebSockets.splice(0);
|
|
29
|
+
unsetAllMocks();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Interaction with the tailing API, including tail creation,
|
|
34
|
+
* deletion, and connection.
|
|
35
|
+
*/
|
|
36
|
+
describe("API interaction", () => {
|
|
37
|
+
it("should throw an error if name isn't provided", async () => {
|
|
38
|
+
await expect(
|
|
39
|
+
runWrangler("tail")
|
|
40
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
41
|
+
`"Required Worker name missing. Please specify the Worker name in wrangler.toml, or pass it as an argument with \`wrangler tail <worker-name>\`"`
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("creates and then delete tails", async () => {
|
|
46
|
+
const api = mockWebsocketAPIs();
|
|
47
|
+
expect(api.requests.creation.count).toStrictEqual(0);
|
|
48
|
+
|
|
49
|
+
await runWrangler("tail test-worker");
|
|
50
|
+
|
|
51
|
+
await expect(api.ws.connected).resolves.toBeTruthy();
|
|
52
|
+
expect(api.requests.creation.count).toStrictEqual(1);
|
|
53
|
+
expect(api.requests.deletion.count).toStrictEqual(0);
|
|
54
|
+
|
|
55
|
+
api.ws.close();
|
|
56
|
+
expect(api.requests.deletion.count).toStrictEqual(1);
|
|
57
|
+
});
|
|
58
|
+
it("should connect to the worker assigned to a given route", async () => {
|
|
59
|
+
const api = mockWebsocketAPIs();
|
|
60
|
+
expect(api.requests.creation.count).toStrictEqual(0);
|
|
61
|
+
|
|
62
|
+
mockGetZoneFromHostRequest("example.com", "test-zone");
|
|
63
|
+
mockCollectKnownRoutesRequest([
|
|
64
|
+
{
|
|
65
|
+
pattern: "example.com/*",
|
|
66
|
+
script: "test-worker",
|
|
67
|
+
},
|
|
68
|
+
]);
|
|
69
|
+
await runWrangler("tail example.com/*");
|
|
70
|
+
|
|
71
|
+
await expect(api.ws.connected).resolves.toBeTruthy();
|
|
72
|
+
expect(api.requests.creation.count).toStrictEqual(1);
|
|
73
|
+
expect(api.requests.deletion.count).toStrictEqual(0);
|
|
74
|
+
|
|
75
|
+
api.ws.close();
|
|
76
|
+
expect(api.requests.deletion.count).toStrictEqual(1);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("should error if a given route is not assigned to the user's zone", async () => {
|
|
80
|
+
mockGetZoneFromHostRequest("example.com", "test-zone");
|
|
81
|
+
mockCollectKnownRoutesRequest([]);
|
|
82
|
+
|
|
83
|
+
await expect(runWrangler("tail example.com/*")).rejects.toThrow();
|
|
84
|
+
});
|
|
85
|
+
it("should error if a given route is not within the user's zone", async () => {
|
|
86
|
+
mockGetZoneFromHostRequest("example.com");
|
|
87
|
+
|
|
88
|
+
await expect(runWrangler("tail example.com/*")).rejects.toThrow();
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("creates and then delete tails: legacy envs", async () => {
|
|
92
|
+
const api = mockWebsocketAPIs("some-env", true);
|
|
93
|
+
expect(api.requests.creation.count).toStrictEqual(0);
|
|
94
|
+
|
|
95
|
+
await runWrangler("tail test-worker --env some-env --legacy-env true");
|
|
96
|
+
|
|
97
|
+
await expect(api.ws.connected).resolves.toBeTruthy();
|
|
98
|
+
expect(api.requests.creation.count).toStrictEqual(1);
|
|
99
|
+
expect(api.requests.deletion.count).toStrictEqual(0);
|
|
100
|
+
|
|
101
|
+
api.ws.close();
|
|
102
|
+
expect(api.requests.deletion.count).toStrictEqual(1);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("creates and then delete tails: service envs", async () => {
|
|
106
|
+
const api = mockWebsocketAPIs("some-env");
|
|
107
|
+
expect(api.requests.creation.count).toStrictEqual(0);
|
|
108
|
+
|
|
109
|
+
await runWrangler("tail test-worker --env some-env --legacy-env false");
|
|
110
|
+
|
|
111
|
+
await expect(api.ws.connected).resolves.toBeTruthy();
|
|
112
|
+
expect(api.requests.creation.count).toStrictEqual(1);
|
|
113
|
+
expect(api.requests.deletion.count).toStrictEqual(0);
|
|
114
|
+
|
|
115
|
+
api.ws.close();
|
|
116
|
+
expect(api.requests.deletion.count).toStrictEqual(1);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("errors when the websocket closes unexpectedly", async () => {
|
|
120
|
+
const api = mockWebsocketAPIs();
|
|
121
|
+
api.ws.close();
|
|
122
|
+
|
|
123
|
+
await expect(runWrangler("tail test-worker")).rejects.toThrow();
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("activates debug mode when the cli arg is passed in", async () => {
|
|
127
|
+
const api = mockWebsocketAPIs();
|
|
128
|
+
await runWrangler("tail test-worker --debug");
|
|
129
|
+
await expect(api.nextMessageJson()).resolves.toHaveProperty(
|
|
130
|
+
"debug",
|
|
131
|
+
true
|
|
132
|
+
);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
describe("filtering", () => {
|
|
137
|
+
it("sends sampling rate filters", async () => {
|
|
138
|
+
const api = mockWebsocketAPIs();
|
|
139
|
+
const tooHigh = runWrangler("tail test-worker --sampling-rate 10");
|
|
140
|
+
await expect(tooHigh).rejects.toThrow();
|
|
141
|
+
|
|
142
|
+
const tooLow = runWrangler("tail test-worker --sampling-rate -5");
|
|
143
|
+
await expect(tooLow).rejects.toThrow();
|
|
144
|
+
|
|
145
|
+
await runWrangler("tail test-worker --sampling-rate 0.25");
|
|
146
|
+
await expect(api.nextMessageJson()).resolves.toHaveProperty("filters", [
|
|
147
|
+
{ sampling_rate: 0.25 },
|
|
148
|
+
]);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("sends single status filters", async () => {
|
|
152
|
+
const api = mockWebsocketAPIs();
|
|
153
|
+
await runWrangler("tail test-worker --status error");
|
|
154
|
+
await expect(api.nextMessageJson()).resolves.toHaveProperty("filters", [
|
|
155
|
+
{ outcome: ["exception", "exceededCpu", "exceededMemory", "unknown"] },
|
|
156
|
+
]);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("sends multiple status filters", async () => {
|
|
160
|
+
const api = mockWebsocketAPIs();
|
|
161
|
+
await runWrangler("tail test-worker --status error --status canceled");
|
|
162
|
+
await expect(api.nextMessageJson()).resolves.toHaveProperty("filters", [
|
|
163
|
+
{
|
|
164
|
+
outcome: [
|
|
165
|
+
"exception",
|
|
166
|
+
"exceededCpu",
|
|
167
|
+
"exceededMemory",
|
|
168
|
+
"unknown",
|
|
169
|
+
"canceled",
|
|
170
|
+
],
|
|
171
|
+
},
|
|
172
|
+
]);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it("sends single HTTP method filters", async () => {
|
|
176
|
+
const api = mockWebsocketAPIs();
|
|
177
|
+
await runWrangler("tail test-worker --method POST");
|
|
178
|
+
await expect(api.nextMessageJson()).resolves.toHaveProperty("filters", [
|
|
179
|
+
{ method: ["POST"] },
|
|
180
|
+
]);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it("sends multiple HTTP method filters", async () => {
|
|
184
|
+
const api = mockWebsocketAPIs();
|
|
185
|
+
await runWrangler("tail test-worker --method POST --method GET");
|
|
186
|
+
await expect(api.nextMessageJson()).resolves.toHaveProperty("filters", [
|
|
187
|
+
{ method: ["POST", "GET"] },
|
|
188
|
+
]);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it("sends header filters without a query", async () => {
|
|
192
|
+
const api = mockWebsocketAPIs();
|
|
193
|
+
await runWrangler("tail test-worker --header X-CUSTOM-HEADER");
|
|
194
|
+
await expect(api.nextMessageJson()).resolves.toHaveProperty("filters", [
|
|
195
|
+
{ header: { key: "X-CUSTOM-HEADER" } },
|
|
196
|
+
]);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it("sends header filters with a query", async () => {
|
|
200
|
+
const api = mockWebsocketAPIs();
|
|
201
|
+
await runWrangler("tail test-worker --header X-CUSTOM-HEADER:some-value");
|
|
202
|
+
await expect(api.nextMessageJson()).resolves.toHaveProperty("filters", [
|
|
203
|
+
{ header: { key: "X-CUSTOM-HEADER", query: "some-value" } },
|
|
204
|
+
]);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it("sends single IP filters", async () => {
|
|
208
|
+
const api = mockWebsocketAPIs();
|
|
209
|
+
const fakeIp = "192.0.2.1";
|
|
210
|
+
|
|
211
|
+
await runWrangler(`tail test-worker --ip ${fakeIp}`);
|
|
212
|
+
await expect(api.nextMessageJson()).resolves.toHaveProperty("filters", [
|
|
213
|
+
{ client_ip: [fakeIp] },
|
|
214
|
+
]);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it("sends multiple IP filters", async () => {
|
|
218
|
+
const api = mockWebsocketAPIs();
|
|
219
|
+
const fakeIp = "192.0.2.1";
|
|
220
|
+
|
|
221
|
+
await runWrangler(`tail test-worker --ip ${fakeIp} --ip self`);
|
|
222
|
+
await expect(api.nextMessageJson()).resolves.toHaveProperty("filters", [
|
|
223
|
+
{ client_ip: [fakeIp, "self"] },
|
|
224
|
+
]);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it("sends search filters", async () => {
|
|
228
|
+
const api = mockWebsocketAPIs();
|
|
229
|
+
const search = "filterMe";
|
|
230
|
+
|
|
231
|
+
await runWrangler(`tail test-worker --search ${search}`);
|
|
232
|
+
await expect(api.nextMessageJson()).resolves.toHaveProperty("filters", [
|
|
233
|
+
{ query: search },
|
|
234
|
+
]);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it("sends everything but the kitchen sink", async () => {
|
|
238
|
+
const api = mockWebsocketAPIs();
|
|
239
|
+
const sampling_rate = 0.69;
|
|
240
|
+
const status = ["ok", "error"];
|
|
241
|
+
const method = ["GET", "POST", "PUT"];
|
|
242
|
+
const header = "X-HELLO:world";
|
|
243
|
+
const client_ip = ["192.0.2.1", "self"];
|
|
244
|
+
const query = "onlyTheseMessagesPlease";
|
|
245
|
+
|
|
246
|
+
const cliFilters =
|
|
247
|
+
`--sampling-rate ${sampling_rate} ` +
|
|
248
|
+
status.map((s) => `--status ${s} `).join("") +
|
|
249
|
+
method.map((m) => `--method ${m} `).join("") +
|
|
250
|
+
`--header ${header} ` +
|
|
251
|
+
client_ip.map((c) => `--ip ${c} `).join("") +
|
|
252
|
+
`--search ${query} ` +
|
|
253
|
+
`--debug`;
|
|
254
|
+
|
|
255
|
+
const expectedWebsocketMessage = {
|
|
256
|
+
filters: [
|
|
257
|
+
{ sampling_rate },
|
|
258
|
+
{
|
|
259
|
+
outcome: [
|
|
260
|
+
"ok",
|
|
261
|
+
"exception",
|
|
262
|
+
"exceededCpu",
|
|
263
|
+
"exceededMemory",
|
|
264
|
+
"unknown",
|
|
265
|
+
],
|
|
266
|
+
},
|
|
267
|
+
{ method },
|
|
268
|
+
{ header: { key: "X-HELLO", query: "world" } },
|
|
269
|
+
{ client_ip },
|
|
270
|
+
{ query },
|
|
271
|
+
],
|
|
272
|
+
debug: true,
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
await runWrangler(`tail test-worker ${cliFilters}`);
|
|
276
|
+
await expect(api.nextMessageJson()).resolves.toEqual(
|
|
277
|
+
expectedWebsocketMessage
|
|
278
|
+
);
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
describe("printing", () => {
|
|
283
|
+
const { setIsTTY } = useMockIsTTY();
|
|
284
|
+
|
|
285
|
+
it("logs request messages in JSON format", async () => {
|
|
286
|
+
const api = mockWebsocketAPIs();
|
|
287
|
+
await runWrangler("tail test-worker --format json");
|
|
288
|
+
|
|
289
|
+
const event = generateMockRequestEvent();
|
|
290
|
+
const message = generateMockEventMessage({ event });
|
|
291
|
+
const serializedMessage = serialize(message);
|
|
292
|
+
|
|
293
|
+
api.ws.send(serializedMessage);
|
|
294
|
+
expect(std.out).toMatch(deserializeToJson(serializedMessage));
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
it("logs scheduled messages in JSON format", async () => {
|
|
298
|
+
const api = mockWebsocketAPIs();
|
|
299
|
+
await runWrangler("tail test-worker --format json");
|
|
300
|
+
|
|
301
|
+
const event = generateMockScheduledEvent();
|
|
302
|
+
const message = generateMockEventMessage({ event });
|
|
303
|
+
const serializedMessage = serialize(message);
|
|
304
|
+
|
|
305
|
+
api.ws.send(serializedMessage);
|
|
306
|
+
expect(std.out).toMatch(deserializeToJson(serializedMessage));
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
it("logs alarm messages in json format", async () => {
|
|
310
|
+
const api = mockWebsocketAPIs();
|
|
311
|
+
await runWrangler("tail test-worker --format json");
|
|
312
|
+
|
|
313
|
+
const event = generateMockAlarmEvent();
|
|
314
|
+
const message = generateMockEventMessage({ event });
|
|
315
|
+
const serializedMessage = serialize(message);
|
|
316
|
+
|
|
317
|
+
api.ws.send(serializedMessage);
|
|
318
|
+
expect(std.out).toMatch(deserializeToJson(serializedMessage));
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it("logs request messages in pretty format", async () => {
|
|
322
|
+
const api = mockWebsocketAPIs();
|
|
323
|
+
await runWrangler("tail test-worker --format pretty");
|
|
324
|
+
|
|
325
|
+
const event = generateMockRequestEvent();
|
|
326
|
+
const message = generateMockEventMessage({ event });
|
|
327
|
+
const serializedMessage = serialize(message);
|
|
328
|
+
|
|
329
|
+
api.ws.send(serializedMessage);
|
|
330
|
+
expect(
|
|
331
|
+
std.out
|
|
332
|
+
.replace(
|
|
333
|
+
new Date(mockEventTimestamp).toLocaleString(),
|
|
334
|
+
"[mock event timestamp]"
|
|
335
|
+
)
|
|
336
|
+
.replace(
|
|
337
|
+
mockTailExpiration.toLocaleString(),
|
|
338
|
+
"[mock expiration date]"
|
|
339
|
+
)
|
|
340
|
+
).toMatchInlineSnapshot(`
|
|
341
|
+
"Successfully created tail, expires at [mock expiration date]
|
|
342
|
+
Connected to test-worker, waiting for logs...
|
|
343
|
+
GET https://example.org/ - Ok @ [mock event timestamp]"
|
|
344
|
+
`);
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
it("logs scheduled messages in pretty format", async () => {
|
|
348
|
+
const api = mockWebsocketAPIs();
|
|
349
|
+
await runWrangler("tail test-worker --format pretty");
|
|
350
|
+
|
|
351
|
+
const event = generateMockScheduledEvent();
|
|
352
|
+
const message = generateMockEventMessage({ event });
|
|
353
|
+
const serializedMessage = serialize(message);
|
|
354
|
+
|
|
355
|
+
api.ws.send(serializedMessage);
|
|
356
|
+
expect(
|
|
357
|
+
std.out
|
|
358
|
+
.replace(
|
|
359
|
+
new Date(mockEventTimestamp).toLocaleString(),
|
|
360
|
+
"[mock timestamp string]"
|
|
361
|
+
)
|
|
362
|
+
.replace(
|
|
363
|
+
mockTailExpiration.toLocaleString(),
|
|
364
|
+
"[mock expiration date]"
|
|
365
|
+
)
|
|
366
|
+
).toMatchInlineSnapshot(`
|
|
367
|
+
"Successfully created tail, expires at [mock expiration date]
|
|
368
|
+
Connected to test-worker, waiting for logs...
|
|
369
|
+
\\"* * * * *\\" @ [mock timestamp string] - Ok"
|
|
370
|
+
`);
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
it("logs alarm messages in pretty format", async () => {
|
|
374
|
+
const api = mockWebsocketAPIs();
|
|
375
|
+
await runWrangler("tail test-worker --format pretty");
|
|
376
|
+
|
|
377
|
+
const event = generateMockAlarmEvent();
|
|
378
|
+
const message = generateMockEventMessage({ event });
|
|
379
|
+
const serializedMessage = serialize(message);
|
|
380
|
+
|
|
381
|
+
api.ws.send(serializedMessage);
|
|
382
|
+
expect(
|
|
383
|
+
std.out
|
|
384
|
+
.replace(
|
|
385
|
+
new Date(mockEventScheduledTime).toLocaleString(),
|
|
386
|
+
"[mock scheduled time]"
|
|
387
|
+
)
|
|
388
|
+
.replace(
|
|
389
|
+
mockTailExpiration.toLocaleString(),
|
|
390
|
+
"[mock expiration date]"
|
|
391
|
+
)
|
|
392
|
+
).toMatchInlineSnapshot(`
|
|
393
|
+
"Successfully created tail, expires at [mock expiration date]
|
|
394
|
+
Connected to test-worker, waiting for logs...
|
|
395
|
+
Alarm @ [mock scheduled time] - Ok"
|
|
396
|
+
`);
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
it("should not crash when the tail message has a void event", async () => {
|
|
400
|
+
const api = mockWebsocketAPIs();
|
|
401
|
+
await runWrangler("tail test-worker --format pretty");
|
|
402
|
+
|
|
403
|
+
const message = generateMockEventMessage({ event: null });
|
|
404
|
+
const serializedMessage = serialize(message);
|
|
405
|
+
|
|
406
|
+
api.ws.send(serializedMessage);
|
|
407
|
+
expect(
|
|
408
|
+
std.out
|
|
409
|
+
.replace(
|
|
410
|
+
mockTailExpiration.toLocaleString(),
|
|
411
|
+
"[mock expiration date]"
|
|
412
|
+
)
|
|
413
|
+
.replace(
|
|
414
|
+
new Date(mockEventTimestamp).toLocaleString(),
|
|
415
|
+
"[mock timestamp string]"
|
|
416
|
+
)
|
|
417
|
+
).toMatchInlineSnapshot(`
|
|
418
|
+
"Successfully created tail, expires at [mock expiration date]
|
|
419
|
+
Connected to test-worker, waiting for logs...
|
|
420
|
+
Unknown Event - Ok @ [mock timestamp string]"
|
|
421
|
+
`);
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
it("defaults to logging in pretty format when the output is a TTY", async () => {
|
|
425
|
+
setIsTTY(true);
|
|
426
|
+
const api = mockWebsocketAPIs();
|
|
427
|
+
await runWrangler("tail test-worker");
|
|
428
|
+
|
|
429
|
+
const event = generateMockRequestEvent();
|
|
430
|
+
const message = generateMockEventMessage({ event });
|
|
431
|
+
const serializedMessage = serialize(message);
|
|
432
|
+
|
|
433
|
+
api.ws.send(serializedMessage);
|
|
434
|
+
expect(
|
|
435
|
+
std.out
|
|
436
|
+
.replace(
|
|
437
|
+
new Date(mockEventTimestamp).toLocaleString(),
|
|
438
|
+
"[mock event timestamp]"
|
|
439
|
+
)
|
|
440
|
+
.replace(
|
|
441
|
+
mockTailExpiration.toLocaleString(),
|
|
442
|
+
"[mock expiration date]"
|
|
443
|
+
)
|
|
444
|
+
).toMatchInlineSnapshot(`
|
|
445
|
+
"Successfully created tail, expires at [mock expiration date]
|
|
446
|
+
Connected to test-worker, waiting for logs...
|
|
447
|
+
GET https://example.org/ - Ok @ [mock event timestamp]"
|
|
448
|
+
`);
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
it("defaults to logging in json format when the output is not a TTY", async () => {
|
|
452
|
+
setIsTTY(false);
|
|
453
|
+
|
|
454
|
+
const api = mockWebsocketAPIs();
|
|
455
|
+
await runWrangler("tail test-worker");
|
|
456
|
+
|
|
457
|
+
const event = generateMockRequestEvent();
|
|
458
|
+
const message = generateMockEventMessage({ event });
|
|
459
|
+
const serializedMessage = serialize(message);
|
|
460
|
+
|
|
461
|
+
api.ws.send(serializedMessage);
|
|
462
|
+
expect(std.out).toMatch(deserializeToJson(serializedMessage));
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
it("logs console messages and exceptions", async () => {
|
|
466
|
+
setIsTTY(true);
|
|
467
|
+
const api = mockWebsocketAPIs();
|
|
468
|
+
await runWrangler("tail test-worker");
|
|
469
|
+
|
|
470
|
+
const event = generateMockRequestEvent();
|
|
471
|
+
const message = generateMockEventMessage({
|
|
472
|
+
event,
|
|
473
|
+
logs: [
|
|
474
|
+
{ message: ["some string"], level: "log", timestamp: 1234561 },
|
|
475
|
+
{
|
|
476
|
+
message: [{ complex: "object" }],
|
|
477
|
+
level: "log",
|
|
478
|
+
timestamp: 1234562,
|
|
479
|
+
},
|
|
480
|
+
{ message: [1234], level: "error", timestamp: 1234563 },
|
|
481
|
+
],
|
|
482
|
+
exceptions: [
|
|
483
|
+
{ name: "Error", message: "some error", timestamp: 1234564 },
|
|
484
|
+
{ name: "Error", message: { complex: "error" }, timestamp: 1234564 },
|
|
485
|
+
],
|
|
486
|
+
});
|
|
487
|
+
const serializedMessage = serialize(message);
|
|
488
|
+
|
|
489
|
+
api.ws.send(serializedMessage);
|
|
490
|
+
expect(
|
|
491
|
+
std.out
|
|
492
|
+
.replace(
|
|
493
|
+
new Date(mockEventTimestamp).toLocaleString(),
|
|
494
|
+
"[mock event timestamp]"
|
|
495
|
+
)
|
|
496
|
+
.replace(
|
|
497
|
+
mockTailExpiration.toLocaleString(),
|
|
498
|
+
"[mock expiration date]"
|
|
499
|
+
)
|
|
500
|
+
).toMatchInlineSnapshot(`
|
|
501
|
+
"Successfully created tail, expires at [mock expiration date]
|
|
502
|
+
Connected to test-worker, waiting for logs...
|
|
503
|
+
GET https://example.org/ - Ok @ [mock event timestamp]
|
|
504
|
+
(log) some string
|
|
505
|
+
(log) { complex: 'object' }
|
|
506
|
+
(error) 1234"
|
|
507
|
+
`);
|
|
508
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
509
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1m Error: some error[0m
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
[31mX [41;31m[[41;97mERROR[41;31m][0m [1m Error: { complex: 'error' }[0m
|
|
513
|
+
|
|
514
|
+
"
|
|
515
|
+
`);
|
|
516
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
517
|
+
});
|
|
518
|
+
});
|
|
418
519
|
});
|
|
419
520
|
|
|
420
521
|
/* helpers */
|
|
@@ -429,45 +530,45 @@ describe("tail", () => {
|
|
|
429
530
|
* @returns the same type we expect when deserializing in wrangler
|
|
430
531
|
*/
|
|
431
532
|
function serialize(message: TailEventMessage): WebSocket.RawData {
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
533
|
+
if (!isRequest(message.event)) {
|
|
534
|
+
// `ScheduledEvent`s and `TailEvent`s work just fine
|
|
535
|
+
const stringified = JSON.stringify(message);
|
|
536
|
+
return Buffer.from(stringified, "utf-8");
|
|
537
|
+
} else {
|
|
538
|
+
// Since the "properties" of an `undici.Request` are actually getters,
|
|
539
|
+
// which don't serialize properly, we need to hydrate them manually.
|
|
540
|
+
// This isn't a problem outside of testing since deserialization
|
|
541
|
+
// works just fine and wrangler never _sends_ any event messages,
|
|
542
|
+
// it only receives them.
|
|
543
|
+
const request = ((message.event as RequestEvent | undefined | null) || {})
|
|
544
|
+
.request;
|
|
545
|
+
const stringified = JSON.stringify(message, (key, value) => {
|
|
546
|
+
if (key !== "request") {
|
|
547
|
+
return value;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
return {
|
|
551
|
+
...request,
|
|
552
|
+
url: request?.url,
|
|
553
|
+
headers: request?.headers,
|
|
554
|
+
method: request?.method,
|
|
555
|
+
};
|
|
556
|
+
});
|
|
557
|
+
|
|
558
|
+
return Buffer.from(stringified, "utf-8");
|
|
559
|
+
}
|
|
459
560
|
}
|
|
460
561
|
|
|
461
562
|
/**
|
|
462
563
|
* Small helper to disambiguate the event types possible in a `TailEventMessage`
|
|
463
564
|
*
|
|
464
565
|
* @param event A TailEvent
|
|
465
|
-
* @returns
|
|
566
|
+
* @returns true if `event` is a RequestEvent
|
|
466
567
|
*/
|
|
467
|
-
function
|
|
468
|
-
|
|
469
|
-
): event is
|
|
470
|
-
|
|
568
|
+
function isRequest(
|
|
569
|
+
event: ScheduledEvent | RequestEvent | AlarmEvent | undefined | null
|
|
570
|
+
): event is RequestEvent {
|
|
571
|
+
return Boolean(event && "request" in event);
|
|
471
572
|
}
|
|
472
573
|
|
|
473
574
|
/**
|
|
@@ -479,7 +580,7 @@ function isScheduled(
|
|
|
479
580
|
* @returns a string ready to be printed to the terminal or compared against
|
|
480
581
|
*/
|
|
481
582
|
function deserializeToJson(message: WebSocket.RawData): string {
|
|
482
|
-
|
|
583
|
+
return JSON.stringify(JSON.parse(message.toString()), null, 2);
|
|
483
584
|
}
|
|
484
585
|
|
|
485
586
|
/**
|
|
@@ -487,12 +588,12 @@ function deserializeToJson(message: WebSocket.RawData): string {
|
|
|
487
588
|
* when running `wrangler tail`
|
|
488
589
|
*/
|
|
489
590
|
type MockAPI = {
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
591
|
+
requests: {
|
|
592
|
+
creation: RequestCounter;
|
|
593
|
+
deletion: RequestCounter;
|
|
594
|
+
};
|
|
595
|
+
ws: MockWebSocket;
|
|
596
|
+
nextMessageJson(): Promise<unknown>;
|
|
496
597
|
};
|
|
497
598
|
|
|
498
599
|
/**
|
|
@@ -501,7 +602,7 @@ type MockAPI = {
|
|
|
501
602
|
* the correct API calls without actually sending any web traffic
|
|
502
603
|
*/
|
|
503
604
|
type RequestCounter = {
|
|
504
|
-
|
|
605
|
+
count: number;
|
|
505
606
|
};
|
|
506
607
|
|
|
507
608
|
/**
|
|
@@ -511,34 +612,34 @@ type RequestCounter = {
|
|
|
511
612
|
* @returns a `RequestCounter` for counting how many times the API is hit
|
|
512
613
|
*/
|
|
513
614
|
function mockCreateTailRequest(
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
615
|
+
websocketURL: string,
|
|
616
|
+
env?: string,
|
|
617
|
+
legacyEnv = false
|
|
517
618
|
): RequestCounter {
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
619
|
+
const requests = { count: 0 };
|
|
620
|
+
const servicesOrScripts = env && !legacyEnv ? "services" : "scripts";
|
|
621
|
+
const environment = env && !legacyEnv ? "/environments/:envName" : "";
|
|
622
|
+
setMockResponse(
|
|
623
|
+
`/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/tails`,
|
|
624
|
+
"POST",
|
|
625
|
+
([_url, accountId, scriptName, envName]) => {
|
|
626
|
+
requests.count++;
|
|
627
|
+
expect(accountId).toEqual("some-account-id");
|
|
628
|
+
expect(scriptName).toEqual(
|
|
629
|
+
legacyEnv && env ? `test-worker-${env}` : "test-worker"
|
|
630
|
+
);
|
|
631
|
+
if (!legacyEnv) {
|
|
632
|
+
expect(envName).toEqual(env);
|
|
633
|
+
}
|
|
634
|
+
return {
|
|
635
|
+
id: "tail-id",
|
|
636
|
+
url: websocketURL,
|
|
637
|
+
expires_at: mockTailExpiration,
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
);
|
|
641
|
+
|
|
642
|
+
return requests;
|
|
542
643
|
}
|
|
543
644
|
|
|
544
645
|
/**
|
|
@@ -551,43 +652,48 @@ const mockTailExpiration = new Date(3005, 1);
|
|
|
551
652
|
*/
|
|
552
653
|
const mockEventTimestamp = 1645454470467;
|
|
553
654
|
|
|
655
|
+
/**
|
|
656
|
+
* Default value for event time ISO strings
|
|
657
|
+
*/
|
|
658
|
+
const mockEventScheduledTime = new Date(mockEventTimestamp).toISOString();
|
|
659
|
+
|
|
554
660
|
/**
|
|
555
661
|
* Mock out the API hit during Tail deletion
|
|
556
662
|
*
|
|
557
663
|
* @returns a `RequestCounter` for counting how many times the API is hit
|
|
558
664
|
*/
|
|
559
665
|
function mockDeleteTailRequest(
|
|
560
|
-
|
|
561
|
-
|
|
666
|
+
env?: string,
|
|
667
|
+
legacyEnv = false
|
|
562
668
|
): RequestCounter {
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
669
|
+
const requests = { count: 0 };
|
|
670
|
+
const servicesOrScripts = env && !legacyEnv ? "services" : "scripts";
|
|
671
|
+
const environment = env && !legacyEnv ? "/environments/:envName" : "";
|
|
672
|
+
setMockResponse(
|
|
673
|
+
// "/accounts/:accountId/workers/scripts/:worker/tails",
|
|
674
|
+
`/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/tails/:tailId`,
|
|
675
|
+
"DELETE",
|
|
676
|
+
([_url, accountId, scriptName, envNameOrTailId, tailId]) => {
|
|
677
|
+
requests.count++;
|
|
678
|
+
expect(accountId).toEqual("some-account-id");
|
|
679
|
+
expect(scriptName).toEqual(
|
|
680
|
+
legacyEnv && env ? `test-worker-${env}` : "test-worker"
|
|
681
|
+
);
|
|
682
|
+
if (!legacyEnv) {
|
|
683
|
+
if (env) {
|
|
684
|
+
expect(envNameOrTailId).toEqual(env);
|
|
685
|
+
expect(tailId).toEqual("tail-id");
|
|
686
|
+
} else {
|
|
687
|
+
expect(envNameOrTailId).toEqual("tail-id");
|
|
688
|
+
}
|
|
689
|
+
} else {
|
|
690
|
+
expect(envNameOrTailId).toEqual("tail-id");
|
|
691
|
+
}
|
|
692
|
+
return null;
|
|
693
|
+
}
|
|
694
|
+
);
|
|
695
|
+
|
|
696
|
+
return requests;
|
|
591
697
|
}
|
|
592
698
|
|
|
593
699
|
const mockWebSockets: MockWebSocket[] = [];
|
|
@@ -600,30 +706,30 @@ const mockWebSockets: MockWebSocket[] = [];
|
|
|
600
706
|
* @returns a mocked-out version of the API
|
|
601
707
|
*/
|
|
602
708
|
function mockWebsocketAPIs(env?: string, legacyEnv = false): MockAPI {
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
709
|
+
const websocketURL = "ws://localhost:1234";
|
|
710
|
+
const api: MockAPI = {
|
|
711
|
+
requests: {
|
|
712
|
+
deletion: { count: 0 },
|
|
713
|
+
creation: { count: 0 },
|
|
714
|
+
},
|
|
715
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
716
|
+
ws: null!, // will be set in the `beforeEach()` below.
|
|
717
|
+
|
|
718
|
+
/**
|
|
719
|
+
* Parse the next message received by the mock websocket as JSON
|
|
720
|
+
* @returns JSON.parse of the next message received by the websocket
|
|
721
|
+
*/
|
|
722
|
+
async nextMessageJson() {
|
|
723
|
+
const message = await api.ws.nextMessage;
|
|
724
|
+
return JSON.parse(message as string);
|
|
725
|
+
},
|
|
726
|
+
};
|
|
727
|
+
api.requests.creation = mockCreateTailRequest(websocketURL, env, legacyEnv);
|
|
728
|
+
api.requests.deletion = mockDeleteTailRequest(env, legacyEnv);
|
|
729
|
+
api.ws = new MockWebSocket(websocketURL);
|
|
730
|
+
mockWebSockets.push(api.ws);
|
|
731
|
+
|
|
732
|
+
return api;
|
|
627
733
|
}
|
|
628
734
|
|
|
629
735
|
/**
|
|
@@ -634,19 +740,19 @@ function mockWebsocketAPIs(env?: string, legacyEnv = false): MockAPI {
|
|
|
634
740
|
* @returns a `TailEventMessage` that wrangler can process and display
|
|
635
741
|
*/
|
|
636
742
|
function generateMockEventMessage({
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
743
|
+
outcome = "ok",
|
|
744
|
+
exceptions = [],
|
|
745
|
+
logs = [],
|
|
746
|
+
eventTimestamp = mockEventTimestamp,
|
|
747
|
+
event = generateMockRequestEvent(),
|
|
642
748
|
}: Partial<TailEventMessage>): TailEventMessage {
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
749
|
+
return {
|
|
750
|
+
outcome,
|
|
751
|
+
exceptions,
|
|
752
|
+
logs,
|
|
753
|
+
eventTimestamp,
|
|
754
|
+
event,
|
|
755
|
+
};
|
|
650
756
|
}
|
|
651
757
|
|
|
652
758
|
/**
|
|
@@ -657,34 +763,40 @@ function generateMockEventMessage({
|
|
|
657
763
|
* @returns a `RequestEvent` that can be used within an `EventMessage`
|
|
658
764
|
*/
|
|
659
765
|
function generateMockRequestEvent(
|
|
660
|
-
|
|
766
|
+
opts?: Partial<RequestEvent["request"]>
|
|
661
767
|
): RequestEvent {
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
768
|
+
return {
|
|
769
|
+
request: Object.assign(
|
|
770
|
+
new Request(opts?.url || "https://example.org/", {
|
|
771
|
+
method: opts?.method || "GET",
|
|
772
|
+
headers:
|
|
773
|
+
opts?.headers || new Headers({ "X-EXAMPLE-HEADER": "some_value" }),
|
|
774
|
+
}),
|
|
775
|
+
{
|
|
776
|
+
cf: opts?.cf || {
|
|
777
|
+
tlsCipher: "AEAD-ENCRYPT-O-MATIC-SHA",
|
|
778
|
+
tlsVersion: "TLSv2.0",
|
|
779
|
+
asn: 42069,
|
|
780
|
+
colo: "ATL",
|
|
781
|
+
httpProtocol: "HTTP/4",
|
|
782
|
+
asOrganization: "Cloudflare",
|
|
783
|
+
},
|
|
784
|
+
}
|
|
785
|
+
),
|
|
786
|
+
};
|
|
681
787
|
}
|
|
682
788
|
|
|
683
789
|
function generateMockScheduledEvent(
|
|
684
|
-
|
|
790
|
+
opts?: Partial<ScheduledEvent>
|
|
685
791
|
): ScheduledEvent {
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
792
|
+
return {
|
|
793
|
+
cron: opts?.cron || "* * * * *",
|
|
794
|
+
scheduledTime: opts?.scheduledTime || mockEventTimestamp,
|
|
795
|
+
};
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
function generateMockAlarmEvent(opts?: Partial<AlarmEvent>): AlarmEvent {
|
|
799
|
+
return {
|
|
800
|
+
scheduledTime: opts?.scheduledTime || mockEventScheduledTime,
|
|
801
|
+
};
|
|
690
802
|
}
|