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