wrangler 0.0.0-e3e3243 → 0.0.0-e41c7e41
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 +47 -14
- package/bin/wrangler.js +154 -31
- package/kv-asset-handler.js +1 -0
- package/miniflare-dist/index.mjs +6258 -21
- package/package.json +191 -141
- package/src/__tests__/access.test.ts +25 -0
- 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 +3971 -2810
- package/src/__tests__/d1.test.ts +80 -0
- package/src/__tests__/delete.test.ts +230 -0
- package/src/__tests__/deployments.test.ts +91 -0
- package/src/__tests__/dev.test.tsx +1521 -526
- 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 +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 +219 -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 +27 -27
- 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/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 +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 +248 -967
- package/src/__tests__/init.test.ts +2900 -0
- package/src/__tests__/jest.setup.ts +167 -34
- package/src/__tests__/kv.test.ts +1661 -1366
- 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-deployment-tail.test.ts +820 -0
- package/src/__tests__/pages.test.ts +2437 -77
- package/src/__tests__/parse.test.ts +253 -245
- package/src/__tests__/paths.test.ts +39 -0
- package/src/__tests__/publish.test.ts +7569 -3445
- package/src/__tests__/pubsub.test.ts +370 -0
- package/src/__tests__/queues.test.ts +371 -0
- package/src/__tests__/r2.test.ts +388 -193
- package/src/__tests__/route.test.ts +22 -22
- package/src/__tests__/secret.test.ts +626 -407
- package/src/__tests__/tail.test.ts +680 -442
- package/src/__tests__/test-old-node-version.js +31 -0
- package/src/__tests__/type-generation.test.ts +226 -0
- package/src/__tests__/user.test.ts +155 -0
- 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 +266 -88
- package/src/__tests__/worker-namespace.test.ts +326 -0
- package/src/abort.d.ts +3 -0
- package/src/api/dev.ts +210 -0
- package/src/api/index.ts +2 -0
- package/src/bundle-reporter.tsx +68 -0
- package/src/bundle.ts +791 -123
- package/src/cfetch/index.ts +123 -67
- package/src/cfetch/internal.ts +216 -92
- package/src/cli.ts +23 -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 +506 -316
- package/src/config/index.ts +310 -38
- package/src/config/validation-helpers.ts +385 -342
- package/src/config/validation.ts +1970 -1099
- package/src/config-cache.ts +85 -0
- package/src/create-worker-preview.ts +240 -124
- package/src/create-worker-upload-form.ts +300 -201
- package/src/d1/backups.tsx +218 -0
- package/src/d1/constants.ts +2 -0
- package/src/d1/create.tsx +63 -0
- package/src/d1/delete.tsx +56 -0
- package/src/d1/execute.tsx +352 -0
- package/src/d1/formatTimeAgo.ts +14 -0
- package/src/d1/index.ts +99 -0
- package/src/d1/list.tsx +48 -0
- package/src/d1/migrations.tsx +446 -0
- package/src/d1/options.ts +22 -0
- package/src/d1/types.tsx +24 -0
- package/src/d1/utils.ts +48 -0
- package/src/delete.ts +108 -0
- package/src/deployments.ts +77 -0
- package/src/deprecated/index.ts +438 -0
- package/src/dev/dev-vars.ts +39 -0
- package/src/dev/dev.tsx +526 -328
- package/src/dev/get-local-persistence-path.tsx +31 -0
- package/src/dev/local.tsx +867 -213
- package/src/dev/remote.tsx +592 -192
- package/src/dev/start-server.ts +538 -0
- package/src/dev/use-esbuild.ts +184 -84
- package/src/dev/validate-dev-props.ts +31 -0
- package/src/dev-registry.tsx +201 -0
- package/src/dev.tsx +905 -0
- package/src/dialogs.tsx +150 -59
- package/src/dispatch-namespace.ts +207 -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/git-client.ts +124 -0
- package/src/global-wrangler-config-path.ts +26 -0
- package/src/https-options.ts +85 -80
- package/src/index.tsx +634 -2341
- package/src/init.ts +970 -0
- package/src/inspect.ts +707 -557
- 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 +92 -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 +96 -0
- package/src/miniflare-cli/assets.ts +215 -0
- package/src/miniflare-cli/index.ts +206 -30
- package/src/miniflare-cli/request-context.ts +40 -0
- package/src/module-collection.ts +222 -213
- package/src/open-in-browser.ts +8 -16
- package/src/package-manager.ts +183 -90
- package/src/pages/build.tsx +270 -0
- package/src/pages/constants.ts +18 -0
- package/src/pages/deployment-tails.tsx +284 -0
- package/src/pages/deployments.tsx +84 -0
- package/src/pages/dev.tsx +708 -0
- package/src/pages/errors.ts +66 -0
- package/src/pages/functions/buildPlugin.ts +107 -0
- package/src/pages/functions/buildWorker.ts +166 -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 +102 -0
- package/src/pages/projects.tsx +169 -0
- package/src/pages/prompt-select-project.tsx +31 -0
- package/src/pages/publish.tsx +451 -0
- package/src/pages/types.ts +41 -0
- package/src/pages/upload.tsx +426 -0
- package/src/pages/utils.ts +23 -0
- package/src/parse.ts +224 -121
- package/src/paths.ts +53 -8
- package/src/proxy.ts +624 -375
- 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/constants.ts +4 -0
- package/src/r2/helpers.ts +131 -0
- package/src/r2/index.ts +289 -0
- package/src/routes.ts +140 -0
- package/src/secret/index.ts +378 -0
- package/src/selfsigned.d.ts +23 -23
- package/src/sites.tsx +283 -191
- package/src/tail/createTail.ts +379 -0
- package/src/tail/filters.ts +108 -110
- package/src/tail/index.ts +211 -296
- package/src/tail/printing.ts +92 -47
- package/src/type-generation.ts +173 -0
- package/src/update-check.ts +19 -0
- 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 +142 -42
- package/src/worker.ts +182 -100
- package/src/yargs-types.ts +24 -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 +205 -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 +227 -0
- package/templates/middleware/middleware-miniflare3-json-error.ts +20 -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 +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 +893 -0
- package/wrangler-dist/cli.js +116238 -94482
- 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/kv.ts +0 -319
- package/src/miniflare-cli/enum-keys.ts +0 -17
- package/src/pages.tsx +0 -1061
- package/src/publish.ts +0 -350
- package/src/r2.ts +0 -50
- 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,295 +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";
|
|
7
|
+
import { useMockIsTTY } from "./helpers/mock-istty";
|
|
8
|
+
import { mockCollectKnownRoutesRequest } from "./helpers/mock-known-routes";
|
|
9
|
+
import { msw, mswSucessScriptHandlers } from "./helpers/msw";
|
|
6
10
|
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
7
11
|
import { runWrangler } from "./helpers/run-wrangler";
|
|
8
|
-
import type {
|
|
12
|
+
import type {
|
|
13
|
+
TailEventMessage,
|
|
14
|
+
RequestEvent,
|
|
15
|
+
ScheduledEvent,
|
|
16
|
+
AlarmEvent,
|
|
17
|
+
} from "../tail/createTail";
|
|
18
|
+
import type { RequestInit } from "undici";
|
|
9
19
|
import type WebSocket from "ws";
|
|
10
|
-
|
|
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
|
-
|
|
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
|
+
});
|
|
295
506
|
});
|
|
296
507
|
|
|
297
508
|
/* helpers */
|
|
@@ -306,44 +517,45 @@ describe("tail", () => {
|
|
|
306
517
|
* @returns the same type we expect when deserializing in wrangler
|
|
307
518
|
*/
|
|
308
519
|
function serialize(message: TailEventMessage): WebSocket.RawData {
|
|
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
|
-
|
|
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
|
+
}
|
|
335
547
|
}
|
|
336
548
|
|
|
337
549
|
/**
|
|
338
550
|
* Small helper to disambiguate the event types possible in a `TailEventMessage`
|
|
339
551
|
*
|
|
340
552
|
* @param event A TailEvent
|
|
341
|
-
* @returns
|
|
553
|
+
* @returns true if `event` is a RequestEvent
|
|
342
554
|
*/
|
|
343
|
-
function
|
|
344
|
-
|
|
345
|
-
): event is
|
|
346
|
-
|
|
555
|
+
function isRequest(
|
|
556
|
+
event: ScheduledEvent | RequestEvent | AlarmEvent | undefined | null
|
|
557
|
+
): event is RequestEvent {
|
|
558
|
+
return Boolean(event && "request" in event);
|
|
347
559
|
}
|
|
348
560
|
|
|
349
561
|
/**
|
|
@@ -355,7 +567,7 @@ function isScheduled(
|
|
|
355
567
|
* @returns a string ready to be printed to the terminal or compared against
|
|
356
568
|
*/
|
|
357
569
|
function deserializeToJson(message: WebSocket.RawData): string {
|
|
358
|
-
|
|
570
|
+
return JSON.stringify(JSON.parse(message.toString()), null, 2);
|
|
359
571
|
}
|
|
360
572
|
|
|
361
573
|
/**
|
|
@@ -363,12 +575,12 @@ function deserializeToJson(message: WebSocket.RawData): string {
|
|
|
363
575
|
* when running `wrangler tail`
|
|
364
576
|
*/
|
|
365
577
|
type MockAPI = {
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
578
|
+
requests: {
|
|
579
|
+
creation: RequestInit[];
|
|
580
|
+
deletion: RequestCounter;
|
|
581
|
+
};
|
|
582
|
+
ws: MockWebSocket;
|
|
583
|
+
nextMessageJson(): Promise<unknown>;
|
|
372
584
|
};
|
|
373
585
|
|
|
374
586
|
/**
|
|
@@ -377,7 +589,7 @@ type MockAPI = {
|
|
|
377
589
|
* the correct API calls without actually sending any web traffic
|
|
378
590
|
*/
|
|
379
591
|
type RequestCounter = {
|
|
380
|
-
|
|
592
|
+
count: number;
|
|
381
593
|
};
|
|
382
594
|
|
|
383
595
|
/**
|
|
@@ -387,34 +599,33 @@ type RequestCounter = {
|
|
|
387
599
|
* @returns a `RequestCounter` for counting how many times the API is hit
|
|
388
600
|
*/
|
|
389
601
|
function mockCreateTailRequest(
|
|
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
|
-
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;
|
|
418
629
|
}
|
|
419
630
|
|
|
420
631
|
/**
|
|
@@ -427,43 +638,47 @@ const mockTailExpiration = new Date(3005, 1);
|
|
|
427
638
|
*/
|
|
428
639
|
const mockEventTimestamp = 1645454470467;
|
|
429
640
|
|
|
641
|
+
/**
|
|
642
|
+
* Default value for event time ISO strings
|
|
643
|
+
*/
|
|
644
|
+
const mockEventScheduledTime = new Date(mockEventTimestamp).toISOString();
|
|
645
|
+
|
|
430
646
|
/**
|
|
431
647
|
* Mock out the API hit during Tail deletion
|
|
432
648
|
*
|
|
433
649
|
* @returns a `RequestCounter` for counting how many times the API is hit
|
|
434
650
|
*/
|
|
435
651
|
function mockDeleteTailRequest(
|
|
436
|
-
|
|
437
|
-
|
|
652
|
+
env?: string,
|
|
653
|
+
legacyEnv = false,
|
|
654
|
+
expectedScriptName = legacyEnv && env ? `test-worker-${env}` : "test-worker"
|
|
438
655
|
): RequestCounter {
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
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;
|
|
467
682
|
}
|
|
468
683
|
|
|
469
684
|
const mockWebSockets: MockWebSocket[] = [];
|
|
@@ -475,31 +690,44 @@ const mockWebSockets: MockWebSocket[] = [];
|
|
|
475
690
|
* @param websocketURL a fake websocket URL for wrangler to connect to
|
|
476
691
|
* @returns a mocked-out version of the API
|
|
477
692
|
*/
|
|
478
|
-
function mockWebsocketAPIs(
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
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;
|
|
503
731
|
}
|
|
504
732
|
|
|
505
733
|
/**
|
|
@@ -509,16 +737,20 @@ function mockWebsocketAPIs(env?: string, legacyEnv = false): MockAPI {
|
|
|
509
737
|
* @param opts Any specific parts of the message to use instead of defaults
|
|
510
738
|
* @returns a `TailEventMessage` that wrangler can process and display
|
|
511
739
|
*/
|
|
512
|
-
function generateMockEventMessage(
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
740
|
+
function generateMockEventMessage({
|
|
741
|
+
outcome = "ok",
|
|
742
|
+
exceptions = [],
|
|
743
|
+
logs = [],
|
|
744
|
+
eventTimestamp = mockEventTimestamp,
|
|
745
|
+
event = generateMockRequestEvent(),
|
|
746
|
+
}: Partial<TailEventMessage>): TailEventMessage {
|
|
747
|
+
return {
|
|
748
|
+
outcome,
|
|
749
|
+
exceptions,
|
|
750
|
+
logs,
|
|
751
|
+
eventTimestamp,
|
|
752
|
+
event,
|
|
753
|
+
};
|
|
522
754
|
}
|
|
523
755
|
|
|
524
756
|
/**
|
|
@@ -529,34 +761,40 @@ function generateMockEventMessage(
|
|
|
529
761
|
* @returns a `RequestEvent` that can be used within an `EventMessage`
|
|
530
762
|
*/
|
|
531
763
|
function generateMockRequestEvent(
|
|
532
|
-
|
|
764
|
+
opts?: Partial<RequestEvent["request"]>
|
|
533
765
|
): RequestEvent {
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
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
|
+
};
|
|
553
785
|
}
|
|
554
786
|
|
|
555
787
|
function generateMockScheduledEvent(
|
|
556
|
-
|
|
788
|
+
opts?: Partial<ScheduledEvent>
|
|
557
789
|
): ScheduledEvent {
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
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
|
+
};
|
|
562
800
|
}
|