wrangler 0.0.0-e2b7352 → 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 +51 -14
- package/bin/wrangler.js +154 -31
- package/kv-asset-handler.js +1 -0
- package/miniflare-dist/index.mjs +6244 -21
- package/package.json +185 -141
- 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 +42 -0
- package/src/__tests__/configuration.test.ts +4122 -2810
- package/src/__tests__/dev.test.tsx +1341 -527
- package/src/__tests__/dialogs.test.tsx +40 -0
- package/src/__tests__/generate.test.ts +91 -0
- package/src/__tests__/guess-worker-format.test.ts +74 -57
- 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 +202 -93
- package/src/__tests__/helpers/mock-console.ts +68 -32
- package/src/__tests__/helpers/mock-dialogs.ts +121 -33
- package/src/__tests__/helpers/mock-get-zone-from-host.ts +8 -0
- package/src/__tests__/helpers/mock-http-server.ts +46 -0
- package/src/__tests__/helpers/mock-istty.ts +74 -0
- 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 +252 -0
- 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 +28 -22
- 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 +31 -0
- package/src/__tests__/helpers/write-wrangler-toml.ts +9 -9
- package/src/__tests__/https-options.test.ts +144 -108
- package/src/__tests__/index.test.ts +233 -967
- package/src/__tests__/init.test.ts +2717 -0
- package/src/__tests__/jest.setup.ts +151 -34
- package/src/__tests__/kv.test.ts +1376 -1085
- package/src/__tests__/logger.test.ts +141 -0
- 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 +1990 -77
- package/src/__tests__/parse.test.ts +253 -245
- package/src/__tests__/paths.test.ts +39 -0
- package/src/__tests__/publish.test.ts +6989 -3411
- package/src/__tests__/pubsub.test.ts +367 -0
- package/src/__tests__/r2.test.ts +363 -190
- package/src/__tests__/route.test.ts +22 -22
- package/src/__tests__/secret.test.ts +626 -407
- package/src/__tests__/tail.test.ts +653 -516
- package/src/__tests__/test-old-node-version.js +31 -0
- package/src/__tests__/user.test.ts +155 -0
- package/src/__tests__/validate-dev-props.test.ts +56 -0
- package/src/__tests__/version.test.ts +35 -0
- package/src/__tests__/whoami.test.tsx +261 -88
- 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 +723 -122
- package/src/cfetch/index.ts +83 -66
- package/src/cfetch/internal.ts +267 -92
- package/src/cli.ts +24 -14
- package/src/config/README.md +1 -1
- package/src/config/config.ts +236 -179
- package/src/config/diagnostics.ts +61 -61
- package/src/config/environment.ts +450 -316
- package/src/config/index.ts +259 -38
- package/src/config/validation-helpers.ts +385 -342
- package/src/config/validation.ts +1797 -1099
- package/src/config-cache.ts +85 -0
- package/src/create-worker-preview.ts +233 -124
- package/src/create-worker-upload-form.ts +285 -201
- 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 +36 -0
- package/src/dev/dev.tsx +501 -328
- package/src/dev/get-local-persistence-path.tsx +31 -0
- package/src/dev/local.tsx +629 -211
- package/src/dev/remote.tsx +398 -188
- package/src/dev/start-server.ts +443 -0
- package/src/dev/use-esbuild.ts +175 -82
- 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 +138 -57
- package/src/dispatch-namespace.ts +206 -0
- package/src/durable.ts +102 -0
- package/src/entry.ts +260 -171
- package/src/environment-variables.ts +40 -23
- package/src/errors.ts +11 -0
- 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 +85 -80
- package/src/index.tsx +2295 -2315
- package/src/init.ts +967 -0
- package/src/inspect.ts +687 -557
- 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 +80 -0
- 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 +201 -30
- package/src/miniflare-cli/request-context.ts +40 -0
- package/src/module-collection.ts +213 -213
- package/src/open-in-browser.ts +8 -16
- package/src/package-manager.ts +183 -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/src/pages/functions/filepath-routing.test.ts +234 -0
- 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 +224 -121
- package/src/paths.ts +53 -8
- package/src/preview.ts +31 -0
- package/src/proxy.ts +436 -370
- package/src/publish.ts +839 -324
- 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 +281 -189
- package/src/tail/filters.ts +108 -110
- package/src/tail/index.ts +234 -218
- package/src/tail/printing.ts +92 -47
- package/src/update-check.ts +19 -0
- 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 +142 -42
- package/src/worker.ts +171 -100
- 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/gitignore +171 -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 +129492 -108210
- package/miniflare-dist/index.mjs.map +0 -7
- package/pages/functions/buildWorker.ts +0 -62
- package/pages/functions/filepath-routing.test.ts +0 -223
- package/pages/functions/filepath-routing.ts +0 -181
- package/pages/functions/identifiers.ts +0 -78
- package/pages/functions/routes.ts +0 -151
- package/pages/functions/template-worker.ts +0 -130
- package/src/__tests__/helpers/faye-websocket.d.ts +0 -6
- package/src/__tests__/logout.test.ts +0 -52
- package/src/__tests__/sentry.test.ts +0 -146
- package/src/miniflare-cli/enum-keys.ts +0 -17
- package/src/pages.tsx +0 -1061
- package/src/reporting.ts +0 -131
- package/src/user.tsx +0 -1127
- 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
- package/wrangler-dist/cli.js.map +0 -7
|
@@ -3,371 +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";
|
|
7
|
+
import { useMockIsTTY } from "./helpers/mock-istty";
|
|
8
|
+
import { mockCollectKnownRoutesRequest } from "./helpers/mock-known-routes";
|
|
6
9
|
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
7
10
|
import { runWrangler } from "./helpers/run-wrangler";
|
|
8
|
-
import type {
|
|
11
|
+
import type {
|
|
12
|
+
TailEventMessage,
|
|
13
|
+
RequestEvent,
|
|
14
|
+
ScheduledEvent,
|
|
15
|
+
AlarmEvent,
|
|
16
|
+
} from "../tail";
|
|
17
|
+
import type { RequestInit } from "undici";
|
|
9
18
|
import type WebSocket from "ws";
|
|
10
19
|
|
|
11
20
|
describe("tail", () => {
|
|
12
|
-
|
|
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
|
-
|
|
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
|
+
});
|
|
371
492
|
});
|
|
372
493
|
|
|
373
494
|
/* helpers */
|
|
@@ -382,44 +503,45 @@ describe("tail", () => {
|
|
|
382
503
|
* @returns the same type we expect when deserializing in wrangler
|
|
383
504
|
*/
|
|
384
505
|
function serialize(message: TailEventMessage): WebSocket.RawData {
|
|
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
|
-
|
|
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
|
+
}
|
|
411
533
|
}
|
|
412
534
|
|
|
413
535
|
/**
|
|
414
536
|
* Small helper to disambiguate the event types possible in a `TailEventMessage`
|
|
415
537
|
*
|
|
416
538
|
* @param event A TailEvent
|
|
417
|
-
* @returns
|
|
539
|
+
* @returns true if `event` is a RequestEvent
|
|
418
540
|
*/
|
|
419
|
-
function
|
|
420
|
-
|
|
421
|
-
): event is
|
|
422
|
-
|
|
541
|
+
function isRequest(
|
|
542
|
+
event: ScheduledEvent | RequestEvent | AlarmEvent | undefined | null
|
|
543
|
+
): event is RequestEvent {
|
|
544
|
+
return Boolean(event && "request" in event);
|
|
423
545
|
}
|
|
424
546
|
|
|
425
547
|
/**
|
|
@@ -431,7 +553,7 @@ function isScheduled(
|
|
|
431
553
|
* @returns a string ready to be printed to the terminal or compared against
|
|
432
554
|
*/
|
|
433
555
|
function deserializeToJson(message: WebSocket.RawData): string {
|
|
434
|
-
|
|
556
|
+
return JSON.stringify(JSON.parse(message.toString()), null, 2);
|
|
435
557
|
}
|
|
436
558
|
|
|
437
559
|
/**
|
|
@@ -439,12 +561,12 @@ function deserializeToJson(message: WebSocket.RawData): string {
|
|
|
439
561
|
* when running `wrangler tail`
|
|
440
562
|
*/
|
|
441
563
|
type MockAPI = {
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
564
|
+
requests: {
|
|
565
|
+
creation: RequestInit[];
|
|
566
|
+
deletion: RequestCounter;
|
|
567
|
+
};
|
|
568
|
+
ws: MockWebSocket;
|
|
569
|
+
nextMessageJson(): Promise<unknown>;
|
|
448
570
|
};
|
|
449
571
|
|
|
450
572
|
/**
|
|
@@ -453,7 +575,7 @@ type MockAPI = {
|
|
|
453
575
|
* the correct API calls without actually sending any web traffic
|
|
454
576
|
*/
|
|
455
577
|
type RequestCounter = {
|
|
456
|
-
|
|
578
|
+
count: number;
|
|
457
579
|
};
|
|
458
580
|
|
|
459
581
|
/**
|
|
@@ -463,34 +585,34 @@ type RequestCounter = {
|
|
|
463
585
|
* @returns a `RequestCounter` for counting how many times the API is hit
|
|
464
586
|
*/
|
|
465
587
|
function mockCreateTailRequest(
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
):
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
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;
|
|
494
616
|
}
|
|
495
617
|
|
|
496
618
|
/**
|
|
@@ -503,43 +625,48 @@ const mockTailExpiration = new Date(3005, 1);
|
|
|
503
625
|
*/
|
|
504
626
|
const mockEventTimestamp = 1645454470467;
|
|
505
627
|
|
|
628
|
+
/**
|
|
629
|
+
* Default value for event time ISO strings
|
|
630
|
+
*/
|
|
631
|
+
const mockEventScheduledTime = new Date(mockEventTimestamp).toISOString();
|
|
632
|
+
|
|
506
633
|
/**
|
|
507
634
|
* Mock out the API hit during Tail deletion
|
|
508
635
|
*
|
|
509
636
|
* @returns a `RequestCounter` for counting how many times the API is hit
|
|
510
637
|
*/
|
|
511
638
|
function mockDeleteTailRequest(
|
|
512
|
-
|
|
513
|
-
|
|
639
|
+
env?: string,
|
|
640
|
+
legacyEnv = false
|
|
514
641
|
): RequestCounter {
|
|
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
|
-
|
|
542
|
-
|
|
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;
|
|
543
670
|
}
|
|
544
671
|
|
|
545
672
|
const mockWebSockets: MockWebSocket[] = [];
|
|
@@ -552,30 +679,30 @@ const mockWebSockets: MockWebSocket[] = [];
|
|
|
552
679
|
* @returns a mocked-out version of the API
|
|
553
680
|
*/
|
|
554
681
|
function mockWebsocketAPIs(env?: string, legacyEnv = false): MockAPI {
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
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;
|
|
579
706
|
}
|
|
580
707
|
|
|
581
708
|
/**
|
|
@@ -585,16 +712,20 @@ function mockWebsocketAPIs(env?: string, legacyEnv = false): MockAPI {
|
|
|
585
712
|
* @param opts Any specific parts of the message to use instead of defaults
|
|
586
713
|
* @returns a `TailEventMessage` that wrangler can process and display
|
|
587
714
|
*/
|
|
588
|
-
function generateMockEventMessage(
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
715
|
+
function generateMockEventMessage({
|
|
716
|
+
outcome = "ok",
|
|
717
|
+
exceptions = [],
|
|
718
|
+
logs = [],
|
|
719
|
+
eventTimestamp = mockEventTimestamp,
|
|
720
|
+
event = generateMockRequestEvent(),
|
|
721
|
+
}: Partial<TailEventMessage>): TailEventMessage {
|
|
722
|
+
return {
|
|
723
|
+
outcome,
|
|
724
|
+
exceptions,
|
|
725
|
+
logs,
|
|
726
|
+
eventTimestamp,
|
|
727
|
+
event,
|
|
728
|
+
};
|
|
598
729
|
}
|
|
599
730
|
|
|
600
731
|
/**
|
|
@@ -605,34 +736,40 @@ function generateMockEventMessage(
|
|
|
605
736
|
* @returns a `RequestEvent` that can be used within an `EventMessage`
|
|
606
737
|
*/
|
|
607
738
|
function generateMockRequestEvent(
|
|
608
|
-
|
|
739
|
+
opts?: Partial<RequestEvent["request"]>
|
|
609
740
|
): RequestEvent {
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
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
|
+
};
|
|
629
760
|
}
|
|
630
761
|
|
|
631
762
|
function generateMockScheduledEvent(
|
|
632
|
-
|
|
763
|
+
opts?: Partial<ScheduledEvent>
|
|
633
764
|
): ScheduledEvent {
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
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
|
+
};
|
|
638
775
|
}
|