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