wrangler 0.0.0-e98613f8 → 0.0.0-e9a45766c
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 +10 -4
- package/bin/wrangler.js +10 -2
- package/miniflare-dist/index.mjs +257 -132
- package/package.json +26 -19
- package/src/__tests__/api-dev.test.ts +65 -36
- package/src/__tests__/api-devregistry.test.ts +121 -0
- package/src/__tests__/api.test.ts +27 -5
- package/src/__tests__/configuration.test.ts +575 -39
- package/src/__tests__/constellation.test.ts +371 -0
- package/src/__tests__/d1/d1.test.ts +82 -0
- package/src/__tests__/d1/execute.test.ts +66 -0
- package/src/__tests__/d1/migrate.test.ts +257 -0
- package/src/__tests__/d1/splitter.test.ts +255 -0
- package/src/__tests__/delete.test.ts +11 -2
- package/src/__tests__/deployments.test.ts +330 -52
- package/src/__tests__/dev.test.tsx +146 -82
- package/src/__tests__/generate.test.ts +10 -8
- package/src/__tests__/guess-worker-format.test.ts +35 -0
- package/src/__tests__/helpers/end-event-loop.ts +6 -0
- package/src/__tests__/helpers/mock-auth-domain.ts +20 -0
- package/src/__tests__/helpers/mock-console.ts +6 -0
- package/src/__tests__/helpers/mock-dialogs.ts +71 -85
- package/src/__tests__/helpers/mock-get-pages-upload-token.ts +25 -0
- package/src/__tests__/helpers/mock-get-zone-from-host.ts +8 -5
- package/src/__tests__/helpers/mock-known-routes.ts +7 -2
- package/src/__tests__/helpers/mock-kv.ts +29 -16
- package/src/__tests__/helpers/mock-oauth-flow.ts +99 -92
- package/src/__tests__/helpers/mock-process.ts +8 -13
- package/src/__tests__/helpers/mock-set-timeout.ts +16 -0
- package/src/__tests__/helpers/msw/blob-worker.cjs +19 -0
- package/src/__tests__/helpers/msw/handlers/deployments.ts +127 -26
- package/src/__tests__/helpers/msw/handlers/namespaces.ts +18 -41
- package/src/__tests__/helpers/msw/handlers/r2.ts +14 -34
- package/src/__tests__/helpers/msw/handlers/script.ts +9 -28
- package/src/__tests__/helpers/msw/handlers/user.ts +13 -24
- package/src/__tests__/helpers/msw/handlers/zones.ts +6 -8
- package/src/__tests__/helpers/msw/index.ts +32 -1
- package/src/__tests__/helpers/msw/read-file-sync.js +61 -0
- package/src/__tests__/helpers/string-dynamic-values-matcher.ts +28 -0
- package/src/__tests__/helpers/worker-scripts/parent-worker.js +4 -1
- package/src/__tests__/index.test.ts +92 -74
- package/src/__tests__/init.test.ts +909 -628
- package/src/__tests__/jest.setup.ts +19 -42
- package/src/__tests__/kv.test.ts +355 -231
- package/src/__tests__/logger.test.ts +68 -2
- package/src/__tests__/logout.test.ts +1 -1
- package/src/__tests__/metrics.test.ts +93 -50
- package/src/__tests__/middleware.scheduled.test.ts +42 -32
- package/src/__tests__/middleware.test.ts +212 -122
- package/src/__tests__/mtls-certificates.test.ts +589 -0
- package/src/__tests__/pages/deployment-list.test.ts +80 -0
- package/src/__tests__/pages/functions-build.test.ts +528 -0
- package/src/__tests__/pages/pages.test.ts +81 -0
- package/src/__tests__/pages/project-create.test.ts +63 -0
- package/src/__tests__/pages/project-list.test.ts +110 -0
- package/src/__tests__/pages/project-upload.test.ts +500 -0
- package/src/__tests__/pages/publish.test.ts +2864 -0
- package/src/__tests__/pages-deployment-tail.test.ts +239 -102
- package/src/__tests__/parse.test.ts +106 -0
- package/src/__tests__/publish.test.ts +2218 -1002
- package/src/__tests__/pubsub.test.ts +226 -100
- package/src/__tests__/queues.test.ts +42 -32
- package/src/__tests__/r2.test.ts +37 -56
- package/src/__tests__/secret.test.ts +179 -130
- package/src/__tests__/tail.test.ts +113 -23
- package/src/__tests__/test-old-node-version.js +3 -3
- package/src/__tests__/traverse-module-graph.test.ts +220 -0
- package/src/__tests__/tsconfig-sanity.ts +12 -0
- package/src/__tests__/tsconfig.json +8 -0
- package/src/__tests__/tsconfig.tsbuildinfo +1 -0
- package/src/__tests__/type-generation.test.ts +8 -0
- package/src/__tests__/user.test.ts +7 -18
- package/src/__tests__/whoami.test.tsx +8 -114
- package/src/__tests__/worker-namespace.test.ts +83 -69
- package/src/api/dev.ts +172 -61
- package/src/api/index.ts +10 -1
- package/src/api/mtls-certificate.ts +148 -0
- package/src/api/pages/create-worker-bundle-contents.ts +77 -0
- package/src/api/pages/index.ts +5 -0
- package/src/api/pages/publish.tsx +371 -0
- package/src/bundle.ts +139 -33
- package/src/cfetch/index.ts +0 -2
- package/src/cfetch/internal.ts +16 -21
- package/src/cli.ts +4 -4
- package/src/config/config.ts +14 -7
- package/src/config/environment.ts +80 -16
- package/src/config/index.ts +99 -30
- package/src/config/validation-helpers.ts +1 -1
- package/src/config/validation.ts +275 -9
- package/src/constellation/createProject.tsx +51 -0
- package/src/constellation/deleteProject.ts +51 -0
- package/src/constellation/deleteProjectModel.ts +68 -0
- package/src/constellation/index.ts +75 -0
- package/src/constellation/listCatalog.tsx +35 -0
- package/src/constellation/listModel.tsx +41 -0
- package/src/constellation/listProject.tsx +28 -0
- package/src/constellation/listRuntime.tsx +28 -0
- package/src/constellation/options.ts +17 -0
- package/src/constellation/types.ts +17 -0
- package/src/constellation/uploadModel.tsx +64 -0
- package/src/constellation/utils.ts +90 -0
- package/src/create-worker-preview.ts +19 -8
- package/src/create-worker-upload-form.ts +52 -5
- package/src/d1/backups.tsx +40 -44
- package/src/d1/create.tsx +50 -43
- package/src/d1/{delete.tsx → delete.ts} +8 -11
- package/src/d1/execute.tsx +171 -166
- package/src/d1/index.ts +5 -6
- package/src/d1/list.tsx +27 -13
- package/src/d1/migrations/apply.tsx +92 -64
- package/src/d1/migrations/create.tsx +31 -29
- package/src/d1/migrations/helpers.ts +66 -44
- package/src/d1/migrations/list.tsx +47 -31
- package/src/d1/migrations/options.ts +7 -2
- package/src/d1/options.ts +3 -3
- package/src/d1/splitter.ts +161 -0
- package/src/d1/{types.tsx → types.ts} +1 -0
- package/src/d1/utils.ts +2 -1
- package/src/delete.ts +8 -16
- package/src/deployments.ts +333 -42
- package/src/deprecated/index.ts +8 -302
- package/src/dev/dev.tsx +13 -22
- package/src/dev/local.tsx +131 -69
- package/src/dev/remote.tsx +35 -3
- package/src/dev/start-server.ts +83 -77
- package/src/dev/use-esbuild.ts +63 -52
- package/src/dev/validate-dev-props.ts +9 -0
- package/src/{dev-registry.tsx → dev-registry.ts} +9 -8
- package/src/dev.tsx +131 -110
- package/src/dialogs.ts +136 -0
- package/src/dispatch-namespace.ts +21 -17
- package/src/docs/helpers.ts +50 -0
- package/src/docs/index.ts +54 -0
- package/src/entry.ts +26 -11
- package/src/environment-variables/factory.ts +89 -0
- package/src/environment-variables/misc-variables.ts +30 -0
- package/src/generate/index.ts +298 -0
- package/src/{index.tsx → index.ts} +137 -56
- package/src/init.ts +254 -187
- package/src/inspect.ts +170 -9
- package/src/jest.d.ts +4 -0
- package/src/kv/helpers.ts +7 -4
- package/src/kv/index.ts +15 -17
- package/src/logger.ts +36 -5
- package/src/metrics/metrics-config.ts +1 -1
- package/src/metrics/send-event.ts +4 -1
- package/src/miniflare-cli/assets.ts +66 -31
- package/src/miniflare-cli/index.ts +5 -8
- package/src/miniflare-cli/tsconfig.json +9 -0
- package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -0
- package/src/miniflare-cli/types.ts +11 -0
- package/src/module-collection.ts +92 -26
- package/src/mtls-certificate/cli.ts +155 -0
- package/src/pages/build.ts +423 -0
- package/src/pages/buildFunctions.ts +140 -0
- package/src/pages/{deployment-tails.tsx → deployment-tails.ts} +7 -10
- package/src/pages/deployments.tsx +9 -9
- package/src/pages/{dev.tsx → dev.ts} +167 -139
- package/src/pages/errors.ts +1 -0
- package/src/pages/functions/buildPlugin.ts +61 -54
- package/src/pages/functions/buildWorker.ts +217 -33
- package/src/pages/functions/tsconfig.json +8 -0
- package/src/pages/functions/tsconfig.tsbuildinfo +1 -0
- package/src/pages/{functions.tsx → functions.ts} +8 -4
- package/src/pages/{index.tsx → index.ts} +3 -3
- package/src/pages/projects.tsx +12 -22
- package/src/pages/publish.tsx +43 -227
- package/src/pages/types.ts +5 -0
- package/src/pages/upload.tsx +57 -14
- package/src/pages/utils.ts +1 -1
- package/src/parse.ts +23 -1
- package/src/paths.ts +1 -1
- package/src/publish/index.ts +20 -16
- package/src/publish/publish.ts +76 -46
- package/src/pubsub/{pubsub-commands.tsx → pubsub-commands.ts} +19 -20
- package/src/queues/cli/commands/consumer/add.ts +24 -24
- package/src/queues/cli/commands/consumer/index.ts +3 -6
- package/src/queues/cli/commands/consumer/remove.ts +11 -18
- package/src/queues/cli/commands/create.ts +8 -8
- package/src/queues/cli/commands/delete.ts +8 -8
- package/src/queues/cli/commands/index.ts +3 -4
- package/src/queues/cli/commands/list.ts +8 -8
- package/src/queues/client.ts +1 -0
- package/src/r2/helpers.ts +1 -0
- package/src/r2/index.ts +28 -28
- package/src/secret/index.ts +15 -16
- package/src/{sites.tsx → sites.ts} +165 -53
- package/src/tail/createTail.ts +37 -1
- package/src/tail/filters.ts +1 -1
- package/src/tail/index.ts +8 -11
- package/src/tail/printing.ts +25 -0
- package/src/traverse-module-graph.ts +54 -0
- package/src/tsconfig-sanity.ts +16 -0
- package/src/type-generation.ts +11 -3
- package/src/user/access.ts +0 -1
- package/src/user/auth-variables.ts +113 -0
- package/src/user/choose-account.tsx +1 -31
- package/src/user/index.ts +0 -1
- package/src/user/{user.tsx → user.ts} +114 -77
- package/src/utils/render.ts +93 -0
- package/src/{whoami.tsx → whoami.ts} +37 -71
- package/src/worker.ts +35 -1
- package/src/yargs-types.ts +18 -5
- package/templates/__tests__/tsconfig-sanity.ts +12 -0
- package/templates/__tests__/tsconfig.json +8 -0
- package/templates/__tests__/tsconfig.tsbuildinfo +1 -0
- package/templates/checked-fetch.js +9 -3
- package/templates/d1-beta-facade.js +42 -3
- package/templates/facade.d.ts +14 -0
- package/templates/first-party-worker-module-facade.ts +4 -3
- package/templates/format-dev-errors.ts +8 -6
- package/templates/gitignore +1 -0
- package/templates/init-tests/test-jest-new-worker.js +3 -5
- package/templates/init-tests/test-vitest-new-worker.js +3 -5
- package/templates/init-tests/test-vitest-new-worker.ts +25 -0
- package/templates/middleware/loader-modules.ts +2 -2
- package/templates/middleware/loader-sw.ts +6 -0
- package/templates/middleware/middleware-miniflare3-json-error.ts +17 -5
- package/templates/new-worker.ts +3 -0
- package/templates/pages-dev-pipeline.ts +4 -1
- package/templates/pages-shim.ts +4 -1
- package/templates/pages-template-plugin.ts +19 -10
- package/templates/serve-static-assets.ts +17 -14
- package/templates/service-bindings-module-facade.js +1 -0
- package/templates/tsconfig-sanity.ts +11 -0
- package/templates/tsconfig.init.json +105 -0
- package/templates/tsconfig.json +5 -103
- package/templates/tsconfig.tsbuildinfo +1 -0
- package/wrangler-dist/cli.d.ts +871 -73
- package/wrangler-dist/cli.js +80512 -90686
- package/wrangler-dist/wasm-sync.wasm +0 -0
- package/src/__tests__/api-devregistry.test.js +0 -56
- package/src/__tests__/d1.test.ts +0 -80
- package/src/__tests__/dialogs.test.tsx +0 -40
- package/src/__tests__/helpers/mock-cfetch.ts +0 -333
- package/src/__tests__/pages.test.ts +0 -2442
- package/src/dialogs.tsx +0 -168
- package/src/environment-variables.ts +0 -50
- package/src/pages/build.tsx +0 -270
- package/src/user/env-vars.ts +0 -46
- /package/src/{bundle-reporter.tsx → bundle-reporter.ts} +0 -0
- /package/src/d1/migrations/{index.tsx → index.ts} +0 -0
- /package/src/dev/{get-local-persistence-path.tsx → get-local-persistence-path.ts} +0 -0
- /package/src/pages/{hash.tsx → hash.ts} +0 -0
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import MockWebSocket from "jest-websocket-mock";
|
|
2
|
+
import { rest } from "msw";
|
|
2
3
|
import { Headers, Request } from "undici";
|
|
3
4
|
import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
|
|
4
|
-
import { setMockResponse, unsetAllMocks } from "./helpers/mock-cfetch";
|
|
5
5
|
import { mockConsoleMethods } from "./helpers/mock-console";
|
|
6
6
|
import { useMockIsTTY } from "./helpers/mock-istty";
|
|
7
|
+
import { msw } from "./helpers/msw";
|
|
7
8
|
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
8
9
|
import { runWrangler } from "./helpers/run-wrangler";
|
|
9
10
|
import type {
|
|
@@ -11,11 +12,18 @@ import type {
|
|
|
11
12
|
RequestEvent,
|
|
12
13
|
ScheduledEvent,
|
|
13
14
|
AlarmEvent,
|
|
15
|
+
EmailEvent,
|
|
16
|
+
TailInfo,
|
|
14
17
|
} from "../tail/createTail";
|
|
15
18
|
import type { RequestInit } from "undici";
|
|
16
19
|
import type WebSocket from "ws";
|
|
17
20
|
|
|
18
21
|
describe("pages deployment tail", () => {
|
|
22
|
+
runInTempDir();
|
|
23
|
+
mockAccountId();
|
|
24
|
+
mockApiToken();
|
|
25
|
+
const std = mockConsoleMethods();
|
|
26
|
+
|
|
19
27
|
beforeAll(() => {
|
|
20
28
|
// Force the CLI to be "non-interactive" in test env
|
|
21
29
|
process.env.CF_PAGES = "1";
|
|
@@ -25,16 +33,9 @@ describe("pages deployment tail", () => {
|
|
|
25
33
|
delete process.env.CF_PAGES;
|
|
26
34
|
});
|
|
27
35
|
|
|
28
|
-
runInTempDir();
|
|
29
|
-
mockAccountId();
|
|
30
|
-
mockApiToken();
|
|
31
|
-
|
|
32
|
-
const std = mockConsoleMethods();
|
|
33
|
-
|
|
34
36
|
afterEach(() => {
|
|
35
37
|
mockWebSockets.forEach((ws) => ws.close());
|
|
36
38
|
mockWebSockets.splice(0);
|
|
37
|
-
unsetAllMocks();
|
|
38
39
|
});
|
|
39
40
|
|
|
40
41
|
/**
|
|
@@ -64,7 +65,7 @@ describe("pages deployment tail", () => {
|
|
|
64
65
|
expect(api.requests.creation.length).toStrictEqual(1);
|
|
65
66
|
expect(api.requests.deletion.count).toStrictEqual(0);
|
|
66
67
|
|
|
67
|
-
api.
|
|
68
|
+
await api.closeHelper();
|
|
68
69
|
expect(api.requests.deletion.count).toStrictEqual(1);
|
|
69
70
|
});
|
|
70
71
|
|
|
@@ -80,7 +81,7 @@ describe("pages deployment tail", () => {
|
|
|
80
81
|
expect(api.requests.creation.length).toStrictEqual(1);
|
|
81
82
|
expect(api.requests.deletion.count).toStrictEqual(0);
|
|
82
83
|
|
|
83
|
-
api.
|
|
84
|
+
await api.closeHelper();
|
|
84
85
|
expect(api.requests.deletion.count).toStrictEqual(1);
|
|
85
86
|
});
|
|
86
87
|
|
|
@@ -104,13 +105,13 @@ describe("pages deployment tail", () => {
|
|
|
104
105
|
expect(api.requests.creation.length).toStrictEqual(1);
|
|
105
106
|
expect(api.requests.deletion.count).toStrictEqual(0);
|
|
106
107
|
|
|
107
|
-
api.
|
|
108
|
+
await api.closeHelper();
|
|
108
109
|
expect(api.requests.deletion.count).toStrictEqual(1);
|
|
109
110
|
});
|
|
110
111
|
|
|
111
112
|
it("errors when the websocket closes unexpectedly", async () => {
|
|
112
113
|
const api = mockTailAPIs();
|
|
113
|
-
api.
|
|
114
|
+
await api.closeHelper();
|
|
114
115
|
|
|
115
116
|
await expect(
|
|
116
117
|
runWrangler(
|
|
@@ -134,24 +135,27 @@ describe("pages deployment tail", () => {
|
|
|
134
135
|
});
|
|
135
136
|
|
|
136
137
|
describe("filtering", () => {
|
|
137
|
-
it("
|
|
138
|
-
const api = mockTailAPIs();
|
|
138
|
+
it("should throw for bad sampling rate filters ranges", async () => {
|
|
139
139
|
const tooHigh = runWrangler(
|
|
140
140
|
"pages deployment tail mock-deployment-id --project-name mock-project --sampling-rate 10"
|
|
141
141
|
);
|
|
142
|
+
|
|
142
143
|
await expect(tooHigh).rejects.toThrow();
|
|
143
144
|
|
|
144
145
|
const tooLow = runWrangler(
|
|
145
146
|
"pages deployment tail mock-deployment-id --project-name mock-project --sampling-rate -5"
|
|
146
147
|
);
|
|
147
148
|
await expect(tooLow).rejects.toThrow();
|
|
149
|
+
});
|
|
148
150
|
|
|
151
|
+
it("should send sampling rate filter", async () => {
|
|
152
|
+
const api = mockTailAPIs();
|
|
149
153
|
await runWrangler(
|
|
150
154
|
"pages deployment tail mock-deployment-id --project-name mock-project --sampling-rate 0.25"
|
|
151
155
|
);
|
|
152
|
-
expect(api.requests.creation[0]
|
|
153
|
-
|
|
154
|
-
);
|
|
156
|
+
expect(api.requests.creation[0]).toEqual({
|
|
157
|
+
filters: [{ sampling_rate: 0.25 }],
|
|
158
|
+
});
|
|
155
159
|
});
|
|
156
160
|
|
|
157
161
|
it("sends single status filters", async () => {
|
|
@@ -159,9 +163,13 @@ describe("pages deployment tail", () => {
|
|
|
159
163
|
await runWrangler(
|
|
160
164
|
"pages deployment tail mock-deployment-id --project-name mock-project --status error"
|
|
161
165
|
);
|
|
162
|
-
expect(api.requests.creation[0]
|
|
163
|
-
|
|
164
|
-
|
|
166
|
+
expect(api.requests.creation[0]).toEqual({
|
|
167
|
+
filters: [
|
|
168
|
+
{
|
|
169
|
+
outcome: ["exception", "exceededCpu", "exceededMemory", "unknown"],
|
|
170
|
+
},
|
|
171
|
+
],
|
|
172
|
+
});
|
|
165
173
|
});
|
|
166
174
|
|
|
167
175
|
it("sends multiple status filters", async () => {
|
|
@@ -169,9 +177,19 @@ describe("pages deployment tail", () => {
|
|
|
169
177
|
await runWrangler(
|
|
170
178
|
"pages deployment tail mock-deployment-id --project-name mock-project --status error --status canceled"
|
|
171
179
|
);
|
|
172
|
-
expect(api.requests.creation[0]
|
|
173
|
-
|
|
174
|
-
|
|
180
|
+
expect(api.requests.creation[0]).toEqual({
|
|
181
|
+
filters: [
|
|
182
|
+
{
|
|
183
|
+
outcome: [
|
|
184
|
+
"exception",
|
|
185
|
+
"exceededCpu",
|
|
186
|
+
"exceededMemory",
|
|
187
|
+
"unknown",
|
|
188
|
+
"canceled",
|
|
189
|
+
],
|
|
190
|
+
},
|
|
191
|
+
],
|
|
192
|
+
});
|
|
175
193
|
});
|
|
176
194
|
|
|
177
195
|
it("sends single HTTP method filters", async () => {
|
|
@@ -179,9 +197,9 @@ describe("pages deployment tail", () => {
|
|
|
179
197
|
await runWrangler(
|
|
180
198
|
"pages deployment tail mock-deployment-id --project-name mock-project --method POST"
|
|
181
199
|
);
|
|
182
|
-
expect(api.requests.creation[0]
|
|
183
|
-
|
|
184
|
-
);
|
|
200
|
+
expect(api.requests.creation[0]).toEqual({
|
|
201
|
+
filters: [{ method: ["POST"] }],
|
|
202
|
+
});
|
|
185
203
|
});
|
|
186
204
|
|
|
187
205
|
it("sends multiple HTTP method filters", async () => {
|
|
@@ -189,9 +207,9 @@ describe("pages deployment tail", () => {
|
|
|
189
207
|
await runWrangler(
|
|
190
208
|
"pages deployment tail mock-deployment-id --project-name mock-project --method POST --method GET"
|
|
191
209
|
);
|
|
192
|
-
expect(api.requests.creation[0]
|
|
193
|
-
|
|
194
|
-
);
|
|
210
|
+
expect(api.requests.creation[0]).toEqual({
|
|
211
|
+
filters: [{ method: ["POST", "GET"] }],
|
|
212
|
+
});
|
|
195
213
|
});
|
|
196
214
|
|
|
197
215
|
it("sends header filters without a query", async () => {
|
|
@@ -199,9 +217,9 @@ describe("pages deployment tail", () => {
|
|
|
199
217
|
await runWrangler(
|
|
200
218
|
"pages deployment tail mock-deployment-id --project-name mock-project --header X-CUSTOM-HEADER"
|
|
201
219
|
);
|
|
202
|
-
expect(api.requests.creation[0]
|
|
203
|
-
|
|
204
|
-
);
|
|
220
|
+
expect(api.requests.creation[0]).toEqual({
|
|
221
|
+
filters: [{ header: { key: "X-CUSTOM-HEADER" } }],
|
|
222
|
+
});
|
|
205
223
|
});
|
|
206
224
|
|
|
207
225
|
it("sends header filters with a query", async () => {
|
|
@@ -209,9 +227,9 @@ describe("pages deployment tail", () => {
|
|
|
209
227
|
await runWrangler(
|
|
210
228
|
"pages deployment tail mock-deployment-id --project-name mock-project --header X-CUSTOM-HEADER:some-value"
|
|
211
229
|
);
|
|
212
|
-
expect(api.requests.creation[0]
|
|
213
|
-
|
|
214
|
-
);
|
|
230
|
+
expect(api.requests.creation[0]).toEqual({
|
|
231
|
+
filters: [{ header: { key: "X-CUSTOM-HEADER", query: "some-value" } }],
|
|
232
|
+
});
|
|
215
233
|
});
|
|
216
234
|
|
|
217
235
|
it("sends single IP filters", async () => {
|
|
@@ -221,9 +239,9 @@ describe("pages deployment tail", () => {
|
|
|
221
239
|
await runWrangler(
|
|
222
240
|
`pages deployment tail mock-deployment-id --project-name mock-project --ip ${fakeIp}`
|
|
223
241
|
);
|
|
224
|
-
expect(api.requests.creation[0]
|
|
225
|
-
|
|
226
|
-
);
|
|
242
|
+
expect(api.requests.creation[0]).toEqual({
|
|
243
|
+
filters: [{ client_ip: [`${fakeIp}`] }],
|
|
244
|
+
});
|
|
227
245
|
});
|
|
228
246
|
|
|
229
247
|
it("sends multiple IP filters", async () => {
|
|
@@ -233,9 +251,9 @@ describe("pages deployment tail", () => {
|
|
|
233
251
|
await runWrangler(
|
|
234
252
|
`pages deployment tail mock-deployment-id --project-name mock-project --ip ${fakeIp} --ip self`
|
|
235
253
|
);
|
|
236
|
-
expect(api.requests.creation[0]
|
|
237
|
-
|
|
238
|
-
);
|
|
254
|
+
expect(api.requests.creation[0]).toEqual({
|
|
255
|
+
filters: [{ client_ip: [`${fakeIp}`, "self"] }],
|
|
256
|
+
});
|
|
239
257
|
});
|
|
240
258
|
|
|
241
259
|
it("sends search filters", async () => {
|
|
@@ -245,9 +263,9 @@ describe("pages deployment tail", () => {
|
|
|
245
263
|
await runWrangler(
|
|
246
264
|
`pages deployment tail mock-deployment-id --project-name mock-project --search ${search}`
|
|
247
265
|
);
|
|
248
|
-
expect(api.requests.creation[0]
|
|
249
|
-
|
|
250
|
-
);
|
|
266
|
+
expect(api.requests.creation[0]).toEqual({
|
|
267
|
+
filters: [{ query: `${search}` }],
|
|
268
|
+
});
|
|
251
269
|
});
|
|
252
270
|
|
|
253
271
|
it("sends everything but the kitchen sink", async () => {
|
|
@@ -268,12 +286,29 @@ describe("pages deployment tail", () => {
|
|
|
268
286
|
`--search ${query} ` +
|
|
269
287
|
`--debug`;
|
|
270
288
|
|
|
271
|
-
const expectedWebsocketMessage =
|
|
289
|
+
const expectedWebsocketMessage = {
|
|
290
|
+
filters: [
|
|
291
|
+
{ sampling_rate: 0.69 },
|
|
292
|
+
{
|
|
293
|
+
outcome: [
|
|
294
|
+
"ok",
|
|
295
|
+
"exception",
|
|
296
|
+
"exceededCpu",
|
|
297
|
+
"exceededMemory",
|
|
298
|
+
"unknown",
|
|
299
|
+
],
|
|
300
|
+
},
|
|
301
|
+
{ method: ["GET", "POST", "PUT"] },
|
|
302
|
+
{ header: { key: "X-HELLO", query: "world" } },
|
|
303
|
+
{ client_ip: ["192.0.2.1", "self"] },
|
|
304
|
+
{ query: "onlyTheseMessagesPlease" },
|
|
305
|
+
],
|
|
306
|
+
};
|
|
272
307
|
|
|
273
308
|
await runWrangler(
|
|
274
309
|
`pages deployment tail mock-deployment-id --project-name mock-project ${cliFilters}`
|
|
275
310
|
);
|
|
276
|
-
expect(api.requests.creation[0]
|
|
311
|
+
expect(api.requests.creation[0]).toEqual(expectedWebsocketMessage);
|
|
277
312
|
});
|
|
278
313
|
});
|
|
279
314
|
|
|
@@ -322,6 +357,20 @@ describe("pages deployment tail", () => {
|
|
|
322
357
|
expect(std.out).toMatch(deserializeToJson(serializedMessage));
|
|
323
358
|
});
|
|
324
359
|
|
|
360
|
+
it("logs email messages in json format", async () => {
|
|
361
|
+
const api = mockTailAPIs();
|
|
362
|
+
await runWrangler(
|
|
363
|
+
"pages deployment tail mock-deployment-id --project-name mock-project --format json"
|
|
364
|
+
);
|
|
365
|
+
|
|
366
|
+
const event = generateMockEmailEvent();
|
|
367
|
+
const message = generateMockEventMessage({ event });
|
|
368
|
+
const serializedMessage = serialize(message);
|
|
369
|
+
|
|
370
|
+
api.ws.send(serializedMessage);
|
|
371
|
+
expect(std.out).toMatch(deserializeToJson(serializedMessage));
|
|
372
|
+
});
|
|
373
|
+
|
|
325
374
|
it("logs request messages in pretty format", async () => {
|
|
326
375
|
const api = mockTailAPIs();
|
|
327
376
|
await runWrangler(
|
|
@@ -403,6 +452,33 @@ describe("pages deployment tail", () => {
|
|
|
403
452
|
`);
|
|
404
453
|
});
|
|
405
454
|
|
|
455
|
+
it("logs email messages in pretty format", async () => {
|
|
456
|
+
const api = mockTailAPIs();
|
|
457
|
+
await runWrangler(
|
|
458
|
+
"pages deployment tail mock-deployment-id --project-name mock-project --format pretty"
|
|
459
|
+
);
|
|
460
|
+
|
|
461
|
+
const event = generateMockEmailEvent();
|
|
462
|
+
const message = generateMockEventMessage({ event });
|
|
463
|
+
const serializedMessage = serialize(message);
|
|
464
|
+
|
|
465
|
+
api.ws.send(serializedMessage);
|
|
466
|
+
expect(
|
|
467
|
+
std.out
|
|
468
|
+
.replace(
|
|
469
|
+
new Date(mockEventTimestamp).toLocaleString(),
|
|
470
|
+
"[mock event timestamp]"
|
|
471
|
+
)
|
|
472
|
+
.replace(
|
|
473
|
+
mockTailExpiration.toLocaleString(),
|
|
474
|
+
"[mock expiration date]"
|
|
475
|
+
)
|
|
476
|
+
).toMatchInlineSnapshot(`
|
|
477
|
+
"Connected to deployment mock-deployment-id, waiting for logs...
|
|
478
|
+
Email from:${mockEmailEventFrom} to:${mockEmailEventTo} size:${mockEmailEventSize} @ [mock event timestamp] - Ok"
|
|
479
|
+
`);
|
|
480
|
+
});
|
|
481
|
+
|
|
406
482
|
it("should not crash when the tail message has a void event", async () => {
|
|
407
483
|
const api = mockTailAPIs();
|
|
408
484
|
await runWrangler(
|
|
@@ -476,6 +552,7 @@ describe("pages deployment tail", () => {
|
|
|
476
552
|
it("logs console messages and exceptions", async () => {
|
|
477
553
|
setIsTTY(true);
|
|
478
554
|
const api = mockTailAPIs();
|
|
555
|
+
|
|
479
556
|
await runWrangler(
|
|
480
557
|
"pages deployment tail mock-deployment-id --project-name mock-project"
|
|
481
558
|
);
|
|
@@ -500,16 +577,12 @@ describe("pages deployment tail", () => {
|
|
|
500
577
|
const serializedMessage = serialize(message);
|
|
501
578
|
|
|
502
579
|
api.ws.send(serializedMessage);
|
|
580
|
+
|
|
503
581
|
expect(
|
|
504
|
-
std.out
|
|
505
|
-
.
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
)
|
|
509
|
-
.replace(
|
|
510
|
-
mockTailExpiration.toLocaleString(),
|
|
511
|
-
"[mock expiration date]"
|
|
512
|
-
)
|
|
582
|
+
std.out.replace(
|
|
583
|
+
new Date(mockEventTimestamp).toLocaleString(),
|
|
584
|
+
"[mock event timestamp]"
|
|
585
|
+
)
|
|
513
586
|
).toMatchInlineSnapshot(`
|
|
514
587
|
"Connected to deployment mock-deployment-id, waiting for logs...
|
|
515
588
|
GET https://example.org/ - Ok @ [mock event timestamp]
|
|
@@ -578,7 +651,14 @@ function serialize(message: TailEventMessage): WebSocket.RawData {
|
|
|
578
651
|
* @returns true if `event` is a RequestEvent
|
|
579
652
|
*/
|
|
580
653
|
function isRequest(
|
|
581
|
-
event:
|
|
654
|
+
event:
|
|
655
|
+
| ScheduledEvent
|
|
656
|
+
| RequestEvent
|
|
657
|
+
| AlarmEvent
|
|
658
|
+
| EmailEvent
|
|
659
|
+
| TailInfo
|
|
660
|
+
| undefined
|
|
661
|
+
| null
|
|
582
662
|
): event is RequestEvent {
|
|
583
663
|
return Boolean(event && "request" in event);
|
|
584
664
|
}
|
|
@@ -607,6 +687,7 @@ type MockAPI = {
|
|
|
607
687
|
};
|
|
608
688
|
ws: MockWebSocket;
|
|
609
689
|
nextMessageJson(): Promise<unknown>;
|
|
690
|
+
closeHelper: () => Promise<void>;
|
|
610
691
|
};
|
|
611
692
|
|
|
612
693
|
/**
|
|
@@ -616,31 +697,40 @@ type MockAPI = {
|
|
|
616
697
|
*/
|
|
617
698
|
function mockListDeployments(): RequestCounter {
|
|
618
699
|
const requests: RequestCounter = { count: 0 };
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
700
|
+
msw.use(
|
|
701
|
+
rest.get(
|
|
702
|
+
`*/accounts/:accountId/pages/projects/:projectName/deployments`,
|
|
703
|
+
(_, res, ctx) => {
|
|
704
|
+
requests.count++;
|
|
705
|
+
return res.once(
|
|
706
|
+
ctx.status(200),
|
|
707
|
+
ctx.json({
|
|
708
|
+
success: true,
|
|
709
|
+
errors: [],
|
|
710
|
+
messages: [],
|
|
711
|
+
result: [
|
|
712
|
+
{
|
|
713
|
+
id: "mock-deployment-id",
|
|
714
|
+
url: "https://87bbc8fe.mock.pages.dev",
|
|
715
|
+
environment: "production",
|
|
716
|
+
created_on: "2021-11-17T14:52:26.133835Z",
|
|
717
|
+
latest_stage: {
|
|
718
|
+
ended_on: "2021-11-17T14:52:26.133835Z",
|
|
719
|
+
status: "success",
|
|
720
|
+
},
|
|
721
|
+
deployment_trigger: {
|
|
722
|
+
metadata: {
|
|
723
|
+
branch: "main",
|
|
724
|
+
commit_hash: "c7649364c4cb32ad4f65b530b9424e8be5bec9d6",
|
|
725
|
+
},
|
|
726
|
+
},
|
|
727
|
+
project_name: "mock-project",
|
|
728
|
+
},
|
|
729
|
+
],
|
|
730
|
+
})
|
|
731
|
+
);
|
|
732
|
+
}
|
|
733
|
+
)
|
|
644
734
|
);
|
|
645
735
|
|
|
646
736
|
return requests;
|
|
@@ -662,17 +752,26 @@ type RequestCounter = {
|
|
|
662
752
|
*/
|
|
663
753
|
function mockCreateTailRequest(): RequestInit[] {
|
|
664
754
|
const requests: RequestInit[] = [];
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
755
|
+
msw.use(
|
|
756
|
+
rest.post(
|
|
757
|
+
`*/accounts/:accountId/pages/projects/:projectName/deployments/:deploymentId/tails`,
|
|
758
|
+
async (req, res, ctx) => {
|
|
759
|
+
requests.push(await req.json());
|
|
760
|
+
return res.once(
|
|
761
|
+
ctx.status(200),
|
|
762
|
+
ctx.json({
|
|
763
|
+
success: true,
|
|
764
|
+
errors: [],
|
|
765
|
+
messages: [],
|
|
766
|
+
result: {
|
|
767
|
+
id: "tail-id",
|
|
768
|
+
url: websocketURL,
|
|
769
|
+
expires_at: mockTailExpiration,
|
|
770
|
+
},
|
|
771
|
+
})
|
|
772
|
+
);
|
|
773
|
+
}
|
|
774
|
+
)
|
|
676
775
|
);
|
|
677
776
|
|
|
678
777
|
return requests;
|
|
@@ -693,6 +792,21 @@ const mockEventTimestamp = 1645454470467;
|
|
|
693
792
|
*/
|
|
694
793
|
const mockEventScheduledTime = new Date(mockEventTimestamp).toISOString();
|
|
695
794
|
|
|
795
|
+
/**
|
|
796
|
+
* Default value for email event from
|
|
797
|
+
*/
|
|
798
|
+
const mockEmailEventFrom = "from@example.com";
|
|
799
|
+
|
|
800
|
+
/**
|
|
801
|
+
* Default value for email event to
|
|
802
|
+
*/
|
|
803
|
+
const mockEmailEventTo = "to@example.com";
|
|
804
|
+
|
|
805
|
+
/**
|
|
806
|
+
* Default value for email event mail size
|
|
807
|
+
*/
|
|
808
|
+
const mockEmailEventSize = 45416;
|
|
809
|
+
|
|
696
810
|
/**
|
|
697
811
|
* Mock out the API hit during Tail deletion
|
|
698
812
|
*
|
|
@@ -700,13 +814,17 @@ const mockEventScheduledTime = new Date(mockEventTimestamp).toISOString();
|
|
|
700
814
|
*/
|
|
701
815
|
function mockDeleteTailRequest(): RequestCounter {
|
|
702
816
|
const requests = { count: 0 };
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
817
|
+
msw.use(
|
|
818
|
+
rest.delete(
|
|
819
|
+
`*/accounts/:accountId/pages/projects/:projectName/deployments/:deploymentId/tails/:tailId`,
|
|
820
|
+
(_, res, ctx) => {
|
|
821
|
+
requests.count++;
|
|
822
|
+
return res.once(
|
|
823
|
+
ctx.status(200),
|
|
824
|
+
ctx.json({ success: true, errors: [], messages: [], result: null })
|
|
825
|
+
);
|
|
826
|
+
}
|
|
827
|
+
)
|
|
710
828
|
);
|
|
711
829
|
|
|
712
830
|
return requests;
|
|
@@ -730,7 +848,7 @@ function mockTailAPIs(): MockAPI {
|
|
|
730
848
|
deployments: { count: 0 },
|
|
731
849
|
},
|
|
732
850
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
733
|
-
ws: null!, // will be set in the `beforeEach()
|
|
851
|
+
ws: null!, // will be set in the `beforeEach()`.
|
|
734
852
|
|
|
735
853
|
/**
|
|
736
854
|
* Parse the next message received by the mock websocket as JSON
|
|
@@ -740,12 +858,23 @@ function mockTailAPIs(): MockAPI {
|
|
|
740
858
|
const message = await api.ws.nextMessage;
|
|
741
859
|
return JSON.parse(message as string);
|
|
742
860
|
},
|
|
861
|
+
/**
|
|
862
|
+
* Close the mock websocket and clean up the API.
|
|
863
|
+
* The setTimeout forces a cycle to allow for closing and cleanup
|
|
864
|
+
* @returns a Promise that resolves when the websocket is closed
|
|
865
|
+
*/
|
|
866
|
+
async closeHelper() {
|
|
867
|
+
api.ws.close();
|
|
868
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
869
|
+
},
|
|
743
870
|
};
|
|
871
|
+
|
|
872
|
+
api.ws = new MockWebSocket(websocketURL);
|
|
873
|
+
mockWebSockets.push(api.ws);
|
|
874
|
+
|
|
744
875
|
api.requests.creation = mockCreateTailRequest();
|
|
745
876
|
api.requests.deletion = mockDeleteTailRequest();
|
|
746
877
|
api.requests.deployments = mockListDeployments();
|
|
747
|
-
api.ws = new MockWebSocket(websocketURL);
|
|
748
|
-
mockWebSockets.push(api.ws);
|
|
749
878
|
|
|
750
879
|
return api;
|
|
751
880
|
}
|
|
@@ -818,3 +947,11 @@ function generateMockAlarmEvent(opts?: Partial<AlarmEvent>): AlarmEvent {
|
|
|
818
947
|
scheduledTime: opts?.scheduledTime || mockEventScheduledTime,
|
|
819
948
|
};
|
|
820
949
|
}
|
|
950
|
+
|
|
951
|
+
function generateMockEmailEvent(opts?: Partial<EmailEvent>): EmailEvent {
|
|
952
|
+
return {
|
|
953
|
+
mailFrom: opts?.mailFrom || mockEmailEventFrom,
|
|
954
|
+
rcptTo: opts?.rcptTo || mockEmailEventTo,
|
|
955
|
+
rawSize: opts?.rawSize || mockEmailEventSize,
|
|
956
|
+
};
|
|
957
|
+
}
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
indexLocation,
|
|
5
5
|
parseJSON,
|
|
6
6
|
parseTOML,
|
|
7
|
+
parseJSONC,
|
|
7
8
|
} from "../parse";
|
|
8
9
|
import type { Message } from "../parse";
|
|
9
10
|
|
|
@@ -257,7 +258,112 @@ describe("parseJSON", () => {
|
|
|
257
258
|
}
|
|
258
259
|
});
|
|
259
260
|
});
|
|
261
|
+
describe("parseJSONC", () => {
|
|
262
|
+
it("should parse jsonc that is empty", () => {
|
|
263
|
+
expect(parseJSONC("{}")).toStrictEqual({});
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
it("should parse jsonc with basic values", () => {
|
|
267
|
+
expect(
|
|
268
|
+
parseJSONC(`
|
|
269
|
+
{
|
|
270
|
+
"name" : "basic",
|
|
271
|
+
"version": 1
|
|
272
|
+
}`)
|
|
273
|
+
).toStrictEqual({
|
|
274
|
+
name: "basic",
|
|
275
|
+
version: 1,
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it("should parse jsonc with complex values", () => {
|
|
280
|
+
expect(
|
|
281
|
+
parseJSONC(
|
|
282
|
+
`{
|
|
283
|
+
"name":"complex",
|
|
284
|
+
"spec":{
|
|
285
|
+
"uptime":[1,2.5,3],
|
|
286
|
+
"ok":true
|
|
287
|
+
}
|
|
288
|
+
}`
|
|
289
|
+
)
|
|
290
|
+
).toStrictEqual({
|
|
291
|
+
name: "complex",
|
|
292
|
+
spec: {
|
|
293
|
+
uptime: [1, 2.5, 3],
|
|
294
|
+
ok: true,
|
|
295
|
+
},
|
|
296
|
+
});
|
|
297
|
+
});
|
|
260
298
|
|
|
299
|
+
it("should parse jsonc with comments", () => {
|
|
300
|
+
expect(
|
|
301
|
+
parseJSONC(
|
|
302
|
+
`{
|
|
303
|
+
// Comment A
|
|
304
|
+
"name":"complex",
|
|
305
|
+
"spec":{
|
|
306
|
+
// Nested comment
|
|
307
|
+
"uptime":[1,2.5,3],
|
|
308
|
+
"ok":true
|
|
309
|
+
}
|
|
310
|
+
}`
|
|
311
|
+
)
|
|
312
|
+
).toStrictEqual({
|
|
313
|
+
name: "complex",
|
|
314
|
+
spec: {
|
|
315
|
+
uptime: [1, 2.5, 3],
|
|
316
|
+
ok: true,
|
|
317
|
+
},
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it("should fail to parse jsonc with invalid string", () => {
|
|
322
|
+
try {
|
|
323
|
+
parseJSONC(`\n{\n"version" "1\n}\n`);
|
|
324
|
+
fail("parseJSONC did not throw");
|
|
325
|
+
} catch (err) {
|
|
326
|
+
expect({ ...(err as Error) }).toStrictEqual({
|
|
327
|
+
name: "ParseError",
|
|
328
|
+
text: "UnexpectedEndOfString",
|
|
329
|
+
kind: "error",
|
|
330
|
+
location: {
|
|
331
|
+
length: 2,
|
|
332
|
+
line: 3,
|
|
333
|
+
column: 10,
|
|
334
|
+
lineText: '"version" "1',
|
|
335
|
+
file: undefined,
|
|
336
|
+
fileText: `\n{\n"version" "1\n}\n`,
|
|
337
|
+
},
|
|
338
|
+
notes: [],
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
it("should fail to parse jsonc with invalid number", () => {
|
|
344
|
+
const file = "config.json",
|
|
345
|
+
fileText = `{\n\t"a":{\n\t\t"b":{\n\t\t\t"c":[012345]\n}\n}\n}`;
|
|
346
|
+
try {
|
|
347
|
+
parseJSONC(fileText, file);
|
|
348
|
+
fail("parseJSONC did not throw");
|
|
349
|
+
} catch (err) {
|
|
350
|
+
expect({ ...(err as Error) }).toStrictEqual({
|
|
351
|
+
name: "ParseError",
|
|
352
|
+
text: "CommaExpected",
|
|
353
|
+
kind: "error",
|
|
354
|
+
location: {
|
|
355
|
+
file,
|
|
356
|
+
fileText,
|
|
357
|
+
length: 5,
|
|
358
|
+
line: 4,
|
|
359
|
+
column: 9,
|
|
360
|
+
lineText: `\t\t\t"c":[012345]`,
|
|
361
|
+
},
|
|
362
|
+
notes: [],
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
});
|
|
261
367
|
describe("indexLocation", () => {
|
|
262
368
|
it("should calculate location from one-line input", () => {
|
|
263
369
|
const fileText = "";
|