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