wrangler 0.0.0-e928f94 → 0.0.0-e95bea2
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/bin/wrangler.js +2 -2
- package/package.json +46 -18
- package/pages/functions/buildWorker.ts +62 -0
- package/pages/functions/filepath-routing.test.ts +123 -0
- package/pages/functions/filepath-routing.ts +178 -0
- package/pages/functions/identifiers.ts +78 -0
- package/pages/functions/routes.ts +151 -0
- package/pages/functions/template-worker.ts +130 -0
- package/src/__tests__/configuration.test.ts +2217 -0
- package/src/__tests__/dev.test.tsx +405 -0
- package/src/__tests__/dev2.test.tsx +152 -0
- package/src/__tests__/guess-worker-format.test.ts +58 -0
- package/src/__tests__/{clipboardy-mock.js → helpers/clipboardy-mock.js} +0 -0
- package/src/__tests__/helpers/cmd-shim.d.ts +11 -0
- package/src/__tests__/helpers/faye-websocket.d.ts +6 -0
- package/src/__tests__/helpers/mock-account-id.ts +44 -0
- package/src/__tests__/helpers/mock-bin.ts +36 -0
- package/src/__tests__/helpers/mock-cfetch.ts +207 -0
- package/src/__tests__/helpers/mock-console.ts +70 -0
- package/src/__tests__/helpers/mock-dialogs.ts +65 -0
- package/src/__tests__/helpers/mock-kv.ts +40 -0
- package/src/__tests__/helpers/mock-stdin.ts +103 -0
- package/src/__tests__/helpers/mock-user.ts +27 -0
- package/src/__tests__/helpers/mock-web-socket.ts +29 -0
- package/src/__tests__/helpers/run-in-tmp.ts +29 -0
- package/src/__tests__/helpers/run-wrangler.ts +16 -0
- package/src/__tests__/helpers/write-wrangler-toml.ts +17 -0
- package/src/__tests__/https-options.test.ts +127 -0
- package/src/__tests__/index.test.ts +957 -119
- package/src/__tests__/jest.setup.ts +69 -0
- package/src/__tests__/kv.test.ts +1408 -0
- package/src/__tests__/logout.test.ts +50 -0
- package/src/__tests__/package-manager.test.ts +206 -0
- package/src/__tests__/pages.test.ts +44 -0
- package/src/__tests__/parse.test.ts +322 -0
- package/src/__tests__/publish.test.ts +2453 -0
- package/src/__tests__/r2.test.ts +198 -0
- package/src/__tests__/route.test.ts +45 -0
- package/src/__tests__/secret.test.ts +425 -0
- package/src/__tests__/sentry.test.ts +146 -0
- package/src/__tests__/tail.test.ts +564 -0
- package/src/__tests__/whoami.test.tsx +86 -0
- package/src/bundle.ts +142 -0
- package/src/cfetch/index.ts +104 -0
- package/src/cfetch/internal.ts +135 -0
- package/src/cli.ts +16 -7
- package/src/config/README.md +107 -0
- package/src/config/config.ts +279 -0
- package/src/config/diagnostics.ts +80 -0
- package/src/config/environment.ts +305 -0
- package/src/config/index.ts +52 -0
- package/src/config/validation-helpers.ts +388 -0
- package/src/config/validation.ts +1027 -0
- package/src/{api/preview.ts → create-worker-preview.ts} +63 -25
- package/src/create-worker-upload-form.ts +217 -0
- package/src/dev/dev.tsx +357 -0
- package/src/dev/local.tsx +241 -0
- package/src/dev/remote.tsx +201 -0
- package/src/dev/use-esbuild.ts +100 -0
- package/src/dialogs.tsx +5 -13
- package/src/entry.ts +159 -0
- package/src/environment-variables.ts +33 -0
- package/src/https-options.ts +122 -0
- package/src/index.tsx +1374 -903
- package/src/inspect.ts +617 -0
- package/src/kv/index.tsx +339 -0
- package/src/module-collection.ts +215 -26
- package/src/open-in-browser.ts +25 -0
- package/src/package-manager.ts +126 -0
- package/src/pages.tsx +452 -250
- package/src/parse.ts +183 -0
- package/src/paths.ts +26 -0
- package/src/proxy.ts +438 -0
- package/src/publish.ts +300 -292
- package/src/r2.ts +50 -0
- package/src/reporting.ts +131 -0
- package/src/selfsigned.d.ts +29 -0
- package/src/sites.tsx +181 -58
- package/src/tail/filters.ts +279 -0
- package/src/tail/index.ts +299 -0
- package/src/tail/printing.ts +62 -0
- package/src/user.tsx +166 -130
- package/src/whoami.tsx +69 -0
- package/src/worker.ts +163 -0
- package/templates/new-worker.js +15 -0
- package/templates/new-worker.ts +15 -0
- package/{static-asset-facade.js → templates/static-asset-facade.js} +0 -0
- package/templates/tsconfig.json +105 -0
- package/wrangler-dist/cli.js +131958 -115793
- package/wrangler-dist/cli.js.map +3 -3
- package/src/__tests__/fixtures/init/.gitkeep +0 -0
- package/src/__tests__/mock-cfetch.js +0 -46
- package/src/api/form_data.ts +0 -141
- package/src/api/inspect.ts +0 -441
- package/src/api/worker.ts +0 -161
- package/src/cfetch.ts +0 -72
- package/src/config.ts +0 -122
- package/src/dev.tsx +0 -724
- package/src/kv.tsx +0 -211
- package/src/tail.tsx +0 -71
|
@@ -0,0 +1,2217 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { normalizeAndValidateConfig } from "../config/validation";
|
|
3
|
+
import type { RawConfig, RawEnvironment } from "../config";
|
|
4
|
+
|
|
5
|
+
describe("normalizeAndValidateConfig()", () => {
|
|
6
|
+
it("should use defaults for empty configuration", () => {
|
|
7
|
+
const { config, diagnostics } = normalizeAndValidateConfig({}, undefined);
|
|
8
|
+
|
|
9
|
+
expect(config).toEqual({
|
|
10
|
+
account_id: undefined,
|
|
11
|
+
build: {
|
|
12
|
+
command: undefined,
|
|
13
|
+
cwd: undefined,
|
|
14
|
+
watch_dir: undefined,
|
|
15
|
+
},
|
|
16
|
+
compatibility_date: undefined,
|
|
17
|
+
compatibility_flags: [],
|
|
18
|
+
configPath: undefined,
|
|
19
|
+
dev: {
|
|
20
|
+
ip: "127.0.0.1",
|
|
21
|
+
local_protocol: "http",
|
|
22
|
+
port: 8787,
|
|
23
|
+
upstream_protocol: "https",
|
|
24
|
+
host: undefined,
|
|
25
|
+
},
|
|
26
|
+
durable_objects: {
|
|
27
|
+
bindings: [],
|
|
28
|
+
},
|
|
29
|
+
env: {},
|
|
30
|
+
jsx_factory: "React.createElement",
|
|
31
|
+
jsx_fragment: "React.Fragment",
|
|
32
|
+
kv_namespaces: [],
|
|
33
|
+
legacy_env: true,
|
|
34
|
+
main: undefined,
|
|
35
|
+
migrations: [],
|
|
36
|
+
name: undefined,
|
|
37
|
+
r2_buckets: [],
|
|
38
|
+
route: undefined,
|
|
39
|
+
routes: undefined,
|
|
40
|
+
rules: [],
|
|
41
|
+
site: undefined,
|
|
42
|
+
text_blobs: undefined,
|
|
43
|
+
triggers: {
|
|
44
|
+
crons: [],
|
|
45
|
+
},
|
|
46
|
+
unsafe: {
|
|
47
|
+
bindings: [],
|
|
48
|
+
},
|
|
49
|
+
usage_model: undefined,
|
|
50
|
+
vars: {},
|
|
51
|
+
wasm_modules: undefined,
|
|
52
|
+
workers_dev: true,
|
|
53
|
+
zone_id: undefined,
|
|
54
|
+
});
|
|
55
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
56
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
describe("top-level non-environment configuration", () => {
|
|
60
|
+
it("should override config defaults with provided values", () => {
|
|
61
|
+
const main = "src/index.ts";
|
|
62
|
+
const expectedConfig: RawConfig = {
|
|
63
|
+
main,
|
|
64
|
+
legacy_env: true,
|
|
65
|
+
dev: {
|
|
66
|
+
ip: "255.255.255.255",
|
|
67
|
+
port: 9999,
|
|
68
|
+
local_protocol: "https",
|
|
69
|
+
upstream_protocol: "http",
|
|
70
|
+
},
|
|
71
|
+
build: {
|
|
72
|
+
command: "COMMAND",
|
|
73
|
+
cwd: "CWD",
|
|
74
|
+
watch_dir: "WATCH_DIR",
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
79
|
+
expectedConfig,
|
|
80
|
+
undefined
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
const resolvedMain = path.resolve(process.cwd(), main);
|
|
84
|
+
expect(config).toEqual(
|
|
85
|
+
expect.objectContaining({ ...expectedConfig, main: resolvedMain })
|
|
86
|
+
);
|
|
87
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
88
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("should error on invalid top level fields", () => {
|
|
92
|
+
const expectedConfig = {
|
|
93
|
+
main: 111,
|
|
94
|
+
legacy_env: "FOO",
|
|
95
|
+
dev: {
|
|
96
|
+
ip: 222,
|
|
97
|
+
port: "FOO",
|
|
98
|
+
local_protocol: "wss",
|
|
99
|
+
upstream_protocol: "ws",
|
|
100
|
+
},
|
|
101
|
+
build: {
|
|
102
|
+
command: 555,
|
|
103
|
+
cwd: 666,
|
|
104
|
+
watch_dir: 777,
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
109
|
+
expectedConfig as unknown as RawConfig,
|
|
110
|
+
undefined
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
expect(config).toEqual(
|
|
114
|
+
expect.objectContaining({ ...expectedConfig, main: undefined })
|
|
115
|
+
);
|
|
116
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
117
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
118
|
+
"Processing wrangler configuration:
|
|
119
|
+
- Expected \\"build.command\\" to be of type string but got 555.
|
|
120
|
+
- Expected \\"build.cwd\\" to be of type string but got 666.
|
|
121
|
+
- Expected \\"build.watch_dir\\" to be of type string but got 777.
|
|
122
|
+
- Expected \\"legacy_env\\" to be of type boolean but got \\"FOO\\".
|
|
123
|
+
- Expected \\"main\\" to be a string but got 111
|
|
124
|
+
- Expected \\"dev.ip\\" to be of type string but got 222.
|
|
125
|
+
- Expected \\"dev.port\\" to be of type number but got \\"FOO\\".
|
|
126
|
+
- Expected \\"dev.local_protocol\\" field to be one of [\\"http\\",\\"https\\"] but got \\"wss\\".
|
|
127
|
+
- Expected \\"dev.upstream_protocol\\" field to be one of [\\"http\\",\\"https\\"] but got \\"ws\\"."
|
|
128
|
+
`);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("should warn on and remove unexpected top level fields", () => {
|
|
132
|
+
const expectedConfig = {
|
|
133
|
+
miniflare: {
|
|
134
|
+
host: "127.0.0.1",
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
139
|
+
expectedConfig as unknown as RawConfig,
|
|
140
|
+
undefined
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
expect("miniflare" in config).toBe(false);
|
|
144
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
145
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
146
|
+
"Processing wrangler configuration:
|
|
147
|
+
- Unexpected fields found in top-level field: \\"miniflare\\""
|
|
148
|
+
`);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("should override build.upload config defaults with provided values and warn about deprecations", () => {
|
|
152
|
+
const expectedConfig: RawConfig = {
|
|
153
|
+
build: {
|
|
154
|
+
upload: {
|
|
155
|
+
dir: "src",
|
|
156
|
+
format: "modules",
|
|
157
|
+
main: "index.ts",
|
|
158
|
+
rules: [{ type: "Text", globs: ["GLOB"], fallthrough: true }],
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
164
|
+
expectedConfig,
|
|
165
|
+
path.resolve("project/wrangler.toml")
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
expect(config.main).toEqual(path.resolve("project/src/index.ts"));
|
|
169
|
+
expect(config.build.upload).toBeUndefined();
|
|
170
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
171
|
+
expect(diagnostics.hasWarnings()).toBe(true);
|
|
172
|
+
expect(normalizePath(diagnostics.renderWarnings()))
|
|
173
|
+
.toMatchInlineSnapshot(`
|
|
174
|
+
"Processing project/wrangler.toml configuration:
|
|
175
|
+
- DEPRECATION: \\"build.upload.format\\":
|
|
176
|
+
The format is inferred automatically from the code.
|
|
177
|
+
- DEPRECATION: \\"build.upload.main\\":
|
|
178
|
+
Delete the \`build.upload.main\` and \`build.upload.dir\` fields.
|
|
179
|
+
Then add the top level \`main\` field to your configuration file:
|
|
180
|
+
\`\`\`
|
|
181
|
+
main = \\"src/index.ts\\"
|
|
182
|
+
\`\`\`
|
|
183
|
+
- DEPRECATION: \\"build.upload.dir\\":
|
|
184
|
+
Use the top level \\"main\\" field or a command-line argument to specify the entry-point for the Worker.
|
|
185
|
+
- DEPRECATION: The \`build.upload.rules\` config field is no longer used, the rules should be specified via the \`rules\` config field. Delete the \`build.upload\` field from the configuration file, and add this:
|
|
186
|
+
\`\`\`
|
|
187
|
+
[[rules]]
|
|
188
|
+
type = \\"Text\\"
|
|
189
|
+
globs = [ \\"GLOB\\" ]
|
|
190
|
+
fallthrough = true
|
|
191
|
+
\`\`\`"
|
|
192
|
+
`);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it("should override `migrations` config defaults with provided values", () => {
|
|
196
|
+
const expectedConfig: RawConfig = {
|
|
197
|
+
migrations: [
|
|
198
|
+
{
|
|
199
|
+
tag: "TAG",
|
|
200
|
+
new_classes: ["CLASS_1", "CLASS_2"],
|
|
201
|
+
renamed_classes: [
|
|
202
|
+
{
|
|
203
|
+
from: "FROM_CLASS",
|
|
204
|
+
to: "TO_CLASS",
|
|
205
|
+
},
|
|
206
|
+
],
|
|
207
|
+
deleted_classes: ["CLASS_3", "CLASS_4"],
|
|
208
|
+
},
|
|
209
|
+
],
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
213
|
+
expectedConfig,
|
|
214
|
+
undefined
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
expect(config).toEqual(expect.objectContaining(expectedConfig));
|
|
218
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
219
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it("should error on invalid `migrations` values", () => {
|
|
223
|
+
const expectedConfig = {
|
|
224
|
+
migrations: [
|
|
225
|
+
{
|
|
226
|
+
tag: 111,
|
|
227
|
+
new_classes: [222, 333],
|
|
228
|
+
renamed_classes: [
|
|
229
|
+
{
|
|
230
|
+
from: 444,
|
|
231
|
+
to: 555,
|
|
232
|
+
},
|
|
233
|
+
],
|
|
234
|
+
deleted_classes: [666, 777],
|
|
235
|
+
},
|
|
236
|
+
],
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
240
|
+
expectedConfig as unknown as RawConfig,
|
|
241
|
+
undefined
|
|
242
|
+
);
|
|
243
|
+
|
|
244
|
+
expect(config).toEqual(expect.objectContaining(expectedConfig));
|
|
245
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
246
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
247
|
+
"Processing wrangler configuration:
|
|
248
|
+
- Expected \\"migrations[0].tag\\" to be of type string but got 111.
|
|
249
|
+
- Expected \\"migrations[0].new_classes.[0]\\" to be of type string but got 222.
|
|
250
|
+
- Expected \\"migrations[0].new_classes.[1]\\" to be of type string but got 333.
|
|
251
|
+
- Expected \\"migrations[0].renamed_classes\\" to be an array of \\"{from: string, to: string}\\" objects but got [{\\"from\\":444,\\"to\\":555}].
|
|
252
|
+
- Expected \\"migrations[0].deleted_classes.[0]\\" to be of type string but got 666.
|
|
253
|
+
- Expected \\"migrations[0].deleted_classes.[1]\\" to be of type string but got 777."
|
|
254
|
+
`);
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
describe("site", () => {
|
|
258
|
+
it("should override `site` config defaults with provided values", () => {
|
|
259
|
+
const expectedConfig: RawConfig = {
|
|
260
|
+
site: {
|
|
261
|
+
bucket: "BUCKET",
|
|
262
|
+
include: ["INCLUDE_1", "INCLUDE_2"],
|
|
263
|
+
exclude: ["EXCLUDE_1", "EXCLUDE_2"],
|
|
264
|
+
},
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
268
|
+
expectedConfig,
|
|
269
|
+
undefined
|
|
270
|
+
);
|
|
271
|
+
|
|
272
|
+
expect(config).toEqual(expect.objectContaining(expectedConfig));
|
|
273
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
274
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
it("should error if `site` config is missing `bucket`", () => {
|
|
278
|
+
const expectedConfig: RawConfig = {
|
|
279
|
+
// @ts-expect-error we're intentionally passing an invalid configuration here
|
|
280
|
+
site: {
|
|
281
|
+
include: ["INCLUDE_1", "INCLUDE_2"],
|
|
282
|
+
exclude: ["EXCLUDE_1", "EXCLUDE_2"],
|
|
283
|
+
},
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
287
|
+
expectedConfig,
|
|
288
|
+
undefined
|
|
289
|
+
);
|
|
290
|
+
|
|
291
|
+
expect(config).toEqual(expect.objectContaining(expectedConfig));
|
|
292
|
+
expect(diagnostics.hasErrors()).toBe(true);
|
|
293
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
294
|
+
"Processing wrangler configuration:
|
|
295
|
+
- \\"site.bucket\\" is a required field."
|
|
296
|
+
`);
|
|
297
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
it("should error on invalid `site` values", () => {
|
|
301
|
+
const expectedConfig = {
|
|
302
|
+
site: {
|
|
303
|
+
bucket: "BUCKET",
|
|
304
|
+
include: [222, 333],
|
|
305
|
+
exclude: [444, 555],
|
|
306
|
+
},
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
310
|
+
expectedConfig as unknown as RawConfig,
|
|
311
|
+
undefined
|
|
312
|
+
);
|
|
313
|
+
|
|
314
|
+
expect(config).toEqual(expect.objectContaining(expectedConfig));
|
|
315
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
316
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
317
|
+
"Processing wrangler configuration:
|
|
318
|
+
- Expected \\"sites.include.[0]\\" to be of type string but got 222.
|
|
319
|
+
- Expected \\"sites.include.[1]\\" to be of type string but got 333.
|
|
320
|
+
- Expected \\"sites.exclude.[0]\\" to be of type string but got 444.
|
|
321
|
+
- Expected \\"sites.exclude.[1]\\" to be of type string but got 555."
|
|
322
|
+
`);
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
it("should error with a deprecation warning if entry-point is defined", async () => {
|
|
326
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
327
|
+
{
|
|
328
|
+
site: {
|
|
329
|
+
bucket: "some/path",
|
|
330
|
+
"entry-point": "some/other/script.js",
|
|
331
|
+
},
|
|
332
|
+
} as unknown as RawConfig,
|
|
333
|
+
undefined
|
|
334
|
+
);
|
|
335
|
+
|
|
336
|
+
expect(config.site).toMatchInlineSnapshot(`
|
|
337
|
+
Object {
|
|
338
|
+
"bucket": "some/path",
|
|
339
|
+
"exclude": Array [],
|
|
340
|
+
"include": Array [],
|
|
341
|
+
}
|
|
342
|
+
`);
|
|
343
|
+
expect(diagnostics.hasWarnings()).toBe(true);
|
|
344
|
+
expect(diagnostics.hasErrors()).toBe(true);
|
|
345
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
346
|
+
"Processing wrangler configuration:
|
|
347
|
+
- Unexpected fields found in site field: \\"entry-point\\""
|
|
348
|
+
`);
|
|
349
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
350
|
+
"Processing wrangler configuration:
|
|
351
|
+
- DEPRECATION: \\"site.entry-point\\":
|
|
352
|
+
The \`site.entry-point\` config field is no longer used.
|
|
353
|
+
The entry-point should be specified via the command line or the \`main\` config field."
|
|
354
|
+
`);
|
|
355
|
+
});
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
it("should map `wasm_module` paths from relative to the config path to relative to the cwd", () => {
|
|
359
|
+
const expectedConfig: RawConfig = {
|
|
360
|
+
wasm_modules: {
|
|
361
|
+
MODULE_1: "path/to/module_1.mjs",
|
|
362
|
+
MODULE_2: "module_2.mjs",
|
|
363
|
+
},
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
367
|
+
expectedConfig,
|
|
368
|
+
"project/wrangler.toml"
|
|
369
|
+
);
|
|
370
|
+
|
|
371
|
+
expect(config).toEqual(
|
|
372
|
+
expect.objectContaining({
|
|
373
|
+
wasm_modules: {
|
|
374
|
+
MODULE_1: path.normalize("project/path/to/module_1.mjs"),
|
|
375
|
+
MODULE_2: path.normalize("project/module_2.mjs"),
|
|
376
|
+
},
|
|
377
|
+
})
|
|
378
|
+
);
|
|
379
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
380
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
it("should error on invalid `wasm_module` paths", () => {
|
|
384
|
+
const expectedConfig = {
|
|
385
|
+
wasm_modules: {
|
|
386
|
+
MODULE_1: 111,
|
|
387
|
+
MODULE_2: 222,
|
|
388
|
+
},
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
392
|
+
expectedConfig as unknown as RawConfig,
|
|
393
|
+
"project/wrangler.toml"
|
|
394
|
+
);
|
|
395
|
+
|
|
396
|
+
expect(config).toEqual(
|
|
397
|
+
expect.objectContaining({
|
|
398
|
+
wasm_modules: {},
|
|
399
|
+
})
|
|
400
|
+
);
|
|
401
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
402
|
+
expect(normalizePath(diagnostics.renderErrors())).toMatchInlineSnapshot(`
|
|
403
|
+
"Processing project/wrangler.toml configuration:
|
|
404
|
+
- Expected \\"wasm_modules['MODULE_1']\\" field to be a string but got 111.
|
|
405
|
+
- Expected \\"wasm_modules['MODULE_2']\\" field to be a string but got 222."
|
|
406
|
+
`);
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
it("should map `text_blobs` paths from relative to the config path to relative to the cwd", () => {
|
|
410
|
+
const expectedConfig: RawConfig = {
|
|
411
|
+
text_blobs: {
|
|
412
|
+
BLOB_1: "path/to/text1.txt",
|
|
413
|
+
BLOB_2: "text2.md",
|
|
414
|
+
},
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
418
|
+
expectedConfig,
|
|
419
|
+
"project/wrangler.toml"
|
|
420
|
+
);
|
|
421
|
+
|
|
422
|
+
expect(config).toEqual(
|
|
423
|
+
expect.objectContaining({
|
|
424
|
+
text_blobs: {
|
|
425
|
+
BLOB_1: path.normalize("project/path/to/text1.txt"),
|
|
426
|
+
BLOB_2: path.normalize("project/text2.md"),
|
|
427
|
+
},
|
|
428
|
+
})
|
|
429
|
+
);
|
|
430
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
431
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
it("should error on invalid `text_blob` paths", () => {
|
|
435
|
+
const expectedConfig = {
|
|
436
|
+
text_blobs: {
|
|
437
|
+
MODULE_1: 111,
|
|
438
|
+
MODULE_2: 222,
|
|
439
|
+
},
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
443
|
+
expectedConfig as unknown as RawConfig,
|
|
444
|
+
"project/wrangler.toml"
|
|
445
|
+
);
|
|
446
|
+
|
|
447
|
+
expect(config).toEqual(
|
|
448
|
+
expect.objectContaining({
|
|
449
|
+
text_blobs: {},
|
|
450
|
+
})
|
|
451
|
+
);
|
|
452
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
453
|
+
expect(normalizePath(diagnostics.renderErrors())).toMatchInlineSnapshot(`
|
|
454
|
+
"Processing project/wrangler.toml configuration:
|
|
455
|
+
- Expected \\"text_blobs['MODULE_1']\\" field to be a string but got 111.
|
|
456
|
+
- Expected \\"text_blobs['MODULE_2']\\" field to be a string but got 222."
|
|
457
|
+
`);
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
describe("(deprecated)", () => {
|
|
461
|
+
it("should remove and warn about deprecated properties", () => {
|
|
462
|
+
const rawConfig: RawConfig = {
|
|
463
|
+
type: "webpack",
|
|
464
|
+
webpack_config: "CONFIG",
|
|
465
|
+
};
|
|
466
|
+
|
|
467
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
468
|
+
rawConfig,
|
|
469
|
+
undefined
|
|
470
|
+
);
|
|
471
|
+
|
|
472
|
+
// Note the `.not.` here...
|
|
473
|
+
expect(config).toEqual(
|
|
474
|
+
expect.not.objectContaining({
|
|
475
|
+
type: expect.anything(),
|
|
476
|
+
webpack_config: expect.anything(),
|
|
477
|
+
})
|
|
478
|
+
);
|
|
479
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
480
|
+
expect(diagnostics.hasWarnings()).toBe(true);
|
|
481
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
482
|
+
"Processing wrangler configuration:
|
|
483
|
+
- DEPRECATION: \\"type\\":
|
|
484
|
+
DO NOT USE THIS. Most common features now work out of the box with wrangler, including modules, jsx, typescript, etc. If you need anything more, use a custom build.
|
|
485
|
+
- DEPRECATION: \\"webpack_config\\":
|
|
486
|
+
DO NOT USE THIS. Most common features now work out of the box with wrangler, including modules, jsx, typescript, etc. If you need anything more, use a custom build."
|
|
487
|
+
`);
|
|
488
|
+
});
|
|
489
|
+
});
|
|
490
|
+
});
|
|
491
|
+
|
|
492
|
+
describe("top-level environment configuration", () => {
|
|
493
|
+
it("should override config defaults with provided values", () => {
|
|
494
|
+
const expectedConfig: RawConfig = {
|
|
495
|
+
name: "NAME",
|
|
496
|
+
account_id: "ACCOUNT_ID",
|
|
497
|
+
compatibility_date: "2022-01-01",
|
|
498
|
+
compatibility_flags: ["FLAG1", "FLAG2"],
|
|
499
|
+
workers_dev: false,
|
|
500
|
+
routes: ["ROUTE_1", "ROUTE_2"],
|
|
501
|
+
route: "ROUTE_3",
|
|
502
|
+
jsx_factory: "JSX_FACTORY",
|
|
503
|
+
jsx_fragment: "JSX_FRAGMENT",
|
|
504
|
+
triggers: { crons: ["CRON_1", "CRON_2"] },
|
|
505
|
+
usage_model: "bundled",
|
|
506
|
+
vars: {
|
|
507
|
+
VAR1: "VALUE_1",
|
|
508
|
+
VAR2: "VALUE_2",
|
|
509
|
+
},
|
|
510
|
+
durable_objects: {
|
|
511
|
+
bindings: [
|
|
512
|
+
{ name: "DO_BINDING_1", class_name: "CLASS1" },
|
|
513
|
+
{
|
|
514
|
+
name: "DO_BINDING_2",
|
|
515
|
+
class_name: "CLASS2",
|
|
516
|
+
script_name: "SCRIPT2",
|
|
517
|
+
},
|
|
518
|
+
],
|
|
519
|
+
},
|
|
520
|
+
kv_namespaces: [
|
|
521
|
+
{ binding: "KV_BINDING_1", id: "KV_ID_1" },
|
|
522
|
+
{
|
|
523
|
+
binding: "KV_BINDING_2",
|
|
524
|
+
id: "KV_ID_2",
|
|
525
|
+
preview_id: "KV_PREVIEW_1",
|
|
526
|
+
},
|
|
527
|
+
],
|
|
528
|
+
r2_buckets: [
|
|
529
|
+
{ binding: "R2_BINDING_1", bucket_name: "R2_BUCKET_1" },
|
|
530
|
+
{
|
|
531
|
+
binding: "R2_BINDING_2",
|
|
532
|
+
bucket_name: "R2_BUCKET_2",
|
|
533
|
+
preview_bucket_name: "R2_PREVIEW_2",
|
|
534
|
+
},
|
|
535
|
+
],
|
|
536
|
+
unsafe: {
|
|
537
|
+
bindings: [
|
|
538
|
+
{ name: "UNSAFE_BINDING_1", type: "UNSAFE_TYPE_1" },
|
|
539
|
+
{
|
|
540
|
+
name: "UNSAFE_BINDING_2",
|
|
541
|
+
type: "UNSAFE_TYPE_2",
|
|
542
|
+
extra: "UNSAFE_EXTRA_1",
|
|
543
|
+
},
|
|
544
|
+
],
|
|
545
|
+
},
|
|
546
|
+
};
|
|
547
|
+
|
|
548
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
549
|
+
expectedConfig,
|
|
550
|
+
undefined
|
|
551
|
+
);
|
|
552
|
+
|
|
553
|
+
expect(config).toEqual(expect.objectContaining(expectedConfig));
|
|
554
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
555
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
556
|
+
"Processing wrangler configuration:
|
|
557
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
558
|
+
`);
|
|
559
|
+
});
|
|
560
|
+
|
|
561
|
+
it("should error on invalid environment values", () => {
|
|
562
|
+
const expectedConfig: RawConfig = {
|
|
563
|
+
name: 111,
|
|
564
|
+
account_id: 222,
|
|
565
|
+
compatibility_date: 333,
|
|
566
|
+
compatibility_flags: [444, 555],
|
|
567
|
+
workers_dev: "BAD",
|
|
568
|
+
routes: [666, 777],
|
|
569
|
+
route: 888,
|
|
570
|
+
jsx_factory: 999,
|
|
571
|
+
jsx_fragment: 1000,
|
|
572
|
+
triggers: { crons: [1111, 1222] },
|
|
573
|
+
usage_model: "INVALID",
|
|
574
|
+
} as unknown as RawConfig;
|
|
575
|
+
|
|
576
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
577
|
+
expectedConfig,
|
|
578
|
+
undefined
|
|
579
|
+
);
|
|
580
|
+
|
|
581
|
+
expect(config).toEqual(expect.objectContaining(expectedConfig));
|
|
582
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
583
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
584
|
+
"Processing wrangler configuration:
|
|
585
|
+
- Expected \\"route\\" field to be a string but got 888.
|
|
586
|
+
- Expected \\"routes\\" field to be an array of strings but got [666,777].
|
|
587
|
+
- Expected \\"workers_dev\\" field to be a boolean but got \\"BAD\\".
|
|
588
|
+
- Expected \\"account_id\\" field to be a string but got 222.
|
|
589
|
+
- Expected \\"compatibility_date\\" field to be a string but got 333.
|
|
590
|
+
- Expected \\"compatibility_flags\\" field to be an array of strings but got [444,555].
|
|
591
|
+
- Expected \\"jsx_factory\\" field to be a string but got 999.
|
|
592
|
+
- Expected \\"jsx_fragment\\" field to be a string but got 1000.
|
|
593
|
+
- Expected \\"name\\" field to be a string but got 111.
|
|
594
|
+
- Expected \\"usage_model\\" field to be one of [\\"bundled\\",\\"unbound\\"] but got \\"INVALID\\"."
|
|
595
|
+
`);
|
|
596
|
+
});
|
|
597
|
+
|
|
598
|
+
describe("durable_objects field", () => {
|
|
599
|
+
it("should error if durable_objects is an array", () => {
|
|
600
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
601
|
+
{ durable_objects: [] } as unknown as RawConfig,
|
|
602
|
+
undefined
|
|
603
|
+
);
|
|
604
|
+
|
|
605
|
+
expect(config).toEqual(
|
|
606
|
+
expect.not.objectContaining({ durable_objects: expect.anything })
|
|
607
|
+
);
|
|
608
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
609
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
610
|
+
"Processing wrangler configuration:
|
|
611
|
+
- The field \\"durable_objects\\" should be an object but got []."
|
|
612
|
+
`);
|
|
613
|
+
});
|
|
614
|
+
|
|
615
|
+
it("should error if durable_objects is a string", () => {
|
|
616
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
617
|
+
{ durable_objects: "BAD" } as unknown as RawConfig,
|
|
618
|
+
undefined
|
|
619
|
+
);
|
|
620
|
+
|
|
621
|
+
expect(config).toEqual(
|
|
622
|
+
expect.not.objectContaining({ durable_objects: expect.anything })
|
|
623
|
+
);
|
|
624
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
625
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
626
|
+
"Processing wrangler configuration:
|
|
627
|
+
- The field \\"durable_objects\\" should be an object but got \\"BAD\\"."
|
|
628
|
+
`);
|
|
629
|
+
});
|
|
630
|
+
|
|
631
|
+
it("should error if durable_objects is a number", () => {
|
|
632
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
633
|
+
{ durable_objects: 999 } as unknown as RawConfig,
|
|
634
|
+
undefined
|
|
635
|
+
);
|
|
636
|
+
|
|
637
|
+
expect(config).toEqual(
|
|
638
|
+
expect.not.objectContaining({ durable_objects: expect.anything })
|
|
639
|
+
);
|
|
640
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
641
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
642
|
+
"Processing wrangler configuration:
|
|
643
|
+
- The field \\"durable_objects\\" should be an object but got 999."
|
|
644
|
+
`);
|
|
645
|
+
});
|
|
646
|
+
|
|
647
|
+
it("should error if durable_objects is null", () => {
|
|
648
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
649
|
+
{ durable_objects: null } as unknown as RawConfig,
|
|
650
|
+
undefined
|
|
651
|
+
);
|
|
652
|
+
|
|
653
|
+
expect(config).toEqual(
|
|
654
|
+
expect.not.objectContaining({ durable_objects: expect.anything })
|
|
655
|
+
);
|
|
656
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
657
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
658
|
+
"Processing wrangler configuration:
|
|
659
|
+
- The field \\"durable_objects\\" should be an object but got null."
|
|
660
|
+
`);
|
|
661
|
+
});
|
|
662
|
+
|
|
663
|
+
it("should error if durable_objects.bindings is not defined", () => {
|
|
664
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
665
|
+
{ durable_objects: {} } as unknown as RawConfig,
|
|
666
|
+
undefined
|
|
667
|
+
);
|
|
668
|
+
|
|
669
|
+
expect(config).toEqual(
|
|
670
|
+
expect.not.objectContaining({ durable_objects: expect.anything })
|
|
671
|
+
);
|
|
672
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
673
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
674
|
+
"Processing wrangler configuration:
|
|
675
|
+
- The field \\"durable_objects\\" is missing the required \\"bindings\\" property."
|
|
676
|
+
`);
|
|
677
|
+
});
|
|
678
|
+
|
|
679
|
+
it("should error if durable_objects.bindings is an object", () => {
|
|
680
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
681
|
+
{ durable_objects: { bindings: {} } } as unknown as RawConfig,
|
|
682
|
+
undefined
|
|
683
|
+
);
|
|
684
|
+
|
|
685
|
+
expect(config).toEqual(
|
|
686
|
+
expect.not.objectContaining({
|
|
687
|
+
durable_objects: { bindings: expect.anything },
|
|
688
|
+
})
|
|
689
|
+
);
|
|
690
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
691
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
692
|
+
"Processing wrangler configuration:
|
|
693
|
+
- The field \\"durable_objects.bindings\\" should be an array but got {}."
|
|
694
|
+
`);
|
|
695
|
+
});
|
|
696
|
+
|
|
697
|
+
it("should error if durable_objects.bindings is a string", () => {
|
|
698
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
699
|
+
{ durable_objects: { bindings: "BAD" } } as unknown as RawConfig,
|
|
700
|
+
undefined
|
|
701
|
+
);
|
|
702
|
+
|
|
703
|
+
expect(config).toEqual(
|
|
704
|
+
expect.not.objectContaining({
|
|
705
|
+
durable_objects: { bindings: expect.anything },
|
|
706
|
+
})
|
|
707
|
+
);
|
|
708
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
709
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
710
|
+
"Processing wrangler configuration:
|
|
711
|
+
- The field \\"durable_objects.bindings\\" should be an array but got \\"BAD\\"."
|
|
712
|
+
`);
|
|
713
|
+
});
|
|
714
|
+
|
|
715
|
+
it("should error if durable_objects.bindings is a number", () => {
|
|
716
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
717
|
+
{ durable_objects: { bindings: 999 } } as unknown as RawConfig,
|
|
718
|
+
undefined
|
|
719
|
+
);
|
|
720
|
+
|
|
721
|
+
expect(config).toEqual(
|
|
722
|
+
expect.not.objectContaining({
|
|
723
|
+
durable_objects: { bindings: expect.anything },
|
|
724
|
+
})
|
|
725
|
+
);
|
|
726
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
727
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
728
|
+
"Processing wrangler configuration:
|
|
729
|
+
- The field \\"durable_objects.bindings\\" should be an array but got 999."
|
|
730
|
+
`);
|
|
731
|
+
});
|
|
732
|
+
|
|
733
|
+
it("should error if durable_objects.bindings is null", () => {
|
|
734
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
735
|
+
{ durable_objects: { bindings: null } } as unknown as RawConfig,
|
|
736
|
+
undefined
|
|
737
|
+
);
|
|
738
|
+
|
|
739
|
+
expect(config).toEqual(
|
|
740
|
+
expect.not.objectContaining({
|
|
741
|
+
durable_objects: { bindings: expect.anything },
|
|
742
|
+
})
|
|
743
|
+
);
|
|
744
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
745
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
746
|
+
"Processing wrangler configuration:
|
|
747
|
+
- The field \\"durable_objects.bindings\\" should be an array but got null."
|
|
748
|
+
`);
|
|
749
|
+
});
|
|
750
|
+
|
|
751
|
+
it("should error if durable_objects.bindings are not valid", () => {
|
|
752
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
753
|
+
{
|
|
754
|
+
durable_objects: {
|
|
755
|
+
bindings: [
|
|
756
|
+
{},
|
|
757
|
+
{ name: "VALID" },
|
|
758
|
+
{ name: 1555, class_name: 1666 },
|
|
759
|
+
{
|
|
760
|
+
name: 1777,
|
|
761
|
+
class_name: 1888,
|
|
762
|
+
script_name: 1999,
|
|
763
|
+
},
|
|
764
|
+
],
|
|
765
|
+
},
|
|
766
|
+
} as unknown as RawConfig,
|
|
767
|
+
undefined
|
|
768
|
+
);
|
|
769
|
+
|
|
770
|
+
expect(config).toEqual(
|
|
771
|
+
expect.not.objectContaining({
|
|
772
|
+
durable_objects: { bindings: expect.anything },
|
|
773
|
+
})
|
|
774
|
+
);
|
|
775
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
776
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
777
|
+
"Processing wrangler configuration:
|
|
778
|
+
|
|
779
|
+
- \\"durable_objects.bindings[0]\\": {}
|
|
780
|
+
- binding should have a string \\"name\\" field.
|
|
781
|
+
- binding should have a string \\"class_name\\" field.
|
|
782
|
+
|
|
783
|
+
- \\"durable_objects.bindings[1]\\": {\\"name\\":\\"VALID\\"}
|
|
784
|
+
- binding should have a string \\"class_name\\" field.
|
|
785
|
+
|
|
786
|
+
- \\"durable_objects.bindings[2]\\": {\\"name\\":1555,\\"class_name\\":1666}
|
|
787
|
+
- binding should have a string \\"name\\" field.
|
|
788
|
+
- binding should have a string \\"class_name\\" field.
|
|
789
|
+
|
|
790
|
+
- \\"durable_objects.bindings[3]\\": {\\"name\\":1777,\\"class_name\\":1888,\\"script_name\\":1999}
|
|
791
|
+
- binding should have a string \\"name\\" field.
|
|
792
|
+
- binding should have a string \\"class_name\\" field.
|
|
793
|
+
- binding should, optionally, have a string \\"script_name\\" field."
|
|
794
|
+
`);
|
|
795
|
+
});
|
|
796
|
+
});
|
|
797
|
+
|
|
798
|
+
describe("kv_namespaces field", () => {
|
|
799
|
+
it("should error if kv_namespaces is an object", () => {
|
|
800
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
801
|
+
{ kv_namespaces: {} } as unknown as RawConfig,
|
|
802
|
+
undefined
|
|
803
|
+
);
|
|
804
|
+
|
|
805
|
+
expect(config).toEqual(
|
|
806
|
+
expect.not.objectContaining({ kv_namespaces: expect.anything })
|
|
807
|
+
);
|
|
808
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
809
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
810
|
+
"Processing wrangler configuration:
|
|
811
|
+
- The field \\"kv_namespaces\\" should be an array but got {}."
|
|
812
|
+
`);
|
|
813
|
+
});
|
|
814
|
+
|
|
815
|
+
it("should error if kv_namespaces is a string", () => {
|
|
816
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
817
|
+
{ kv_namespaces: "BAD" } as unknown as RawConfig,
|
|
818
|
+
undefined
|
|
819
|
+
);
|
|
820
|
+
|
|
821
|
+
expect(config).toEqual(
|
|
822
|
+
expect.not.objectContaining({ kv_namespaces: expect.anything })
|
|
823
|
+
);
|
|
824
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
825
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
826
|
+
"Processing wrangler configuration:
|
|
827
|
+
- The field \\"kv_namespaces\\" should be an array but got \\"BAD\\"."
|
|
828
|
+
`);
|
|
829
|
+
});
|
|
830
|
+
|
|
831
|
+
it("should error if kv_namespaces is a number", () => {
|
|
832
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
833
|
+
{ kv_namespaces: 999 } as unknown as RawConfig,
|
|
834
|
+
undefined
|
|
835
|
+
);
|
|
836
|
+
|
|
837
|
+
expect(config).toEqual(
|
|
838
|
+
expect.not.objectContaining({ kv_namespaces: expect.anything })
|
|
839
|
+
);
|
|
840
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
841
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
842
|
+
"Processing wrangler configuration:
|
|
843
|
+
- The field \\"kv_namespaces\\" should be an array but got 999."
|
|
844
|
+
`);
|
|
845
|
+
});
|
|
846
|
+
|
|
847
|
+
it("should error if kv_namespaces is null", () => {
|
|
848
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
849
|
+
{ kv_namespaces: null } as unknown as RawConfig,
|
|
850
|
+
undefined
|
|
851
|
+
);
|
|
852
|
+
|
|
853
|
+
expect(config).toEqual(
|
|
854
|
+
expect.not.objectContaining({ kv_namespaces: expect.anything })
|
|
855
|
+
);
|
|
856
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
857
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
858
|
+
"Processing wrangler configuration:
|
|
859
|
+
- The field \\"kv_namespaces\\" should be an array but got null."
|
|
860
|
+
`);
|
|
861
|
+
});
|
|
862
|
+
|
|
863
|
+
it("should error if kv_namespaces.bindings are not valid", () => {
|
|
864
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
865
|
+
{
|
|
866
|
+
kv_namespaces: [
|
|
867
|
+
{},
|
|
868
|
+
{ binding: "VALID" },
|
|
869
|
+
{ binding: 2000, id: 2111 },
|
|
870
|
+
{
|
|
871
|
+
binding: "KV_BINDING_2",
|
|
872
|
+
id: "KV_ID_2",
|
|
873
|
+
preview_id: 2222,
|
|
874
|
+
},
|
|
875
|
+
],
|
|
876
|
+
} as unknown as RawConfig,
|
|
877
|
+
undefined
|
|
878
|
+
);
|
|
879
|
+
|
|
880
|
+
expect(config).toEqual(
|
|
881
|
+
expect.not.objectContaining({
|
|
882
|
+
kv_namespaces: { bindings: expect.anything },
|
|
883
|
+
})
|
|
884
|
+
);
|
|
885
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
886
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
887
|
+
"Processing wrangler configuration:
|
|
888
|
+
- \\"kv_namespaces[0]\\" bindings should have a string \\"binding\\" field but got {}.
|
|
889
|
+
- \\"kv_namespaces[0]\\" bindings should have a string \\"id\\" field but got {}.
|
|
890
|
+
- \\"kv_namespaces[1]\\" bindings should have a string \\"id\\" field but got {\\"binding\\":\\"VALID\\"}.
|
|
891
|
+
- \\"kv_namespaces[2]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":2000,\\"id\\":2111}.
|
|
892
|
+
- \\"kv_namespaces[2]\\" bindings should have a string \\"id\\" field but got {\\"binding\\":2000,\\"id\\":2111}.
|
|
893
|
+
- \\"kv_namespaces[3]\\" bindings should, optionally, have a string \\"preview_id\\" field but got {\\"binding\\":\\"KV_BINDING_2\\",\\"id\\":\\"KV_ID_2\\",\\"preview_id\\":2222}."
|
|
894
|
+
`);
|
|
895
|
+
});
|
|
896
|
+
});
|
|
897
|
+
|
|
898
|
+
describe("r2_buckets field", () => {
|
|
899
|
+
it("should error if r2_buckets is an object", () => {
|
|
900
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
901
|
+
{ r2_buckets: {} } as unknown as RawConfig,
|
|
902
|
+
undefined
|
|
903
|
+
);
|
|
904
|
+
|
|
905
|
+
expect(config).toEqual(
|
|
906
|
+
expect.not.objectContaining({ r2_buckets: expect.anything })
|
|
907
|
+
);
|
|
908
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
909
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
910
|
+
"Processing wrangler configuration:
|
|
911
|
+
- The field \\"r2_buckets\\" should be an array but got {}."
|
|
912
|
+
`);
|
|
913
|
+
});
|
|
914
|
+
|
|
915
|
+
it("should error if r2_buckets is a string", () => {
|
|
916
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
917
|
+
{ r2_buckets: "BAD" } as unknown as RawConfig,
|
|
918
|
+
undefined
|
|
919
|
+
);
|
|
920
|
+
|
|
921
|
+
expect(config).toEqual(
|
|
922
|
+
expect.not.objectContaining({ r2_buckets: expect.anything })
|
|
923
|
+
);
|
|
924
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
925
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
926
|
+
"Processing wrangler configuration:
|
|
927
|
+
- The field \\"r2_buckets\\" should be an array but got \\"BAD\\"."
|
|
928
|
+
`);
|
|
929
|
+
});
|
|
930
|
+
|
|
931
|
+
it("should error if r2_buckets is a number", () => {
|
|
932
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
933
|
+
{ r2_buckets: 999 } as unknown as RawConfig,
|
|
934
|
+
undefined
|
|
935
|
+
);
|
|
936
|
+
|
|
937
|
+
expect(config).toEqual(
|
|
938
|
+
expect.not.objectContaining({ r2_buckets: expect.anything })
|
|
939
|
+
);
|
|
940
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
941
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
942
|
+
"Processing wrangler configuration:
|
|
943
|
+
- The field \\"r2_buckets\\" should be an array but got 999."
|
|
944
|
+
`);
|
|
945
|
+
});
|
|
946
|
+
|
|
947
|
+
it("should error if r2_buckets is null", () => {
|
|
948
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
949
|
+
{ r2_buckets: null } as unknown as RawConfig,
|
|
950
|
+
undefined
|
|
951
|
+
);
|
|
952
|
+
|
|
953
|
+
expect(config).toEqual(
|
|
954
|
+
expect.not.objectContaining({ r2_buckets: expect.anything })
|
|
955
|
+
);
|
|
956
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
957
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
958
|
+
"Processing wrangler configuration:
|
|
959
|
+
- The field \\"r2_buckets\\" should be an array but got null."
|
|
960
|
+
`);
|
|
961
|
+
});
|
|
962
|
+
|
|
963
|
+
it("should error if r2_buckets.bindings are not valid", () => {
|
|
964
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
965
|
+
{
|
|
966
|
+
r2_buckets: [
|
|
967
|
+
{},
|
|
968
|
+
{ binding: "R2_BINDING_1" },
|
|
969
|
+
{ binding: 2333, bucket_name: 2444 },
|
|
970
|
+
{
|
|
971
|
+
binding: "R2_BINDING_2",
|
|
972
|
+
bucket_name: "R2_BUCKET_2",
|
|
973
|
+
preview_bucket_name: 2555,
|
|
974
|
+
},
|
|
975
|
+
],
|
|
976
|
+
} as unknown as RawConfig,
|
|
977
|
+
undefined
|
|
978
|
+
);
|
|
979
|
+
|
|
980
|
+
expect(config).toEqual(
|
|
981
|
+
expect.not.objectContaining({
|
|
982
|
+
r2_buckets: { bindings: expect.anything },
|
|
983
|
+
})
|
|
984
|
+
);
|
|
985
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
986
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
987
|
+
"Processing wrangler configuration:
|
|
988
|
+
- \\"r2_buckets[0]\\" bindings should have a string \\"binding\\" field but got {}.
|
|
989
|
+
- \\"r2_buckets[0]\\" bindings should have a string \\"bucket_name\\" field but got {}.
|
|
990
|
+
- \\"r2_buckets[1]\\" bindings should have a string \\"bucket_name\\" field but got {\\"binding\\":\\"R2_BINDING_1\\"}.
|
|
991
|
+
- \\"r2_buckets[2]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":2333,\\"bucket_name\\":2444}.
|
|
992
|
+
- \\"r2_buckets[2]\\" bindings should have a string \\"bucket_name\\" field but got {\\"binding\\":2333,\\"bucket_name\\":2444}.
|
|
993
|
+
- \\"r2_buckets[3]\\" bindings should, optionally, have a string \\"preview_bucket_name\\" field but got {\\"binding\\":\\"R2_BINDING_2\\",\\"bucket_name\\":\\"R2_BUCKET_2\\",\\"preview_bucket_name\\":2555}."
|
|
994
|
+
`);
|
|
995
|
+
});
|
|
996
|
+
});
|
|
997
|
+
|
|
998
|
+
describe("unsafe field", () => {
|
|
999
|
+
it("should error if unsafe is an array", () => {
|
|
1000
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1001
|
+
{ unsafe: [] } as unknown as RawConfig,
|
|
1002
|
+
undefined
|
|
1003
|
+
);
|
|
1004
|
+
|
|
1005
|
+
expect(config).toEqual(
|
|
1006
|
+
expect.not.objectContaining({ unsafe: expect.anything })
|
|
1007
|
+
);
|
|
1008
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
1009
|
+
"Processing wrangler configuration:
|
|
1010
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
1011
|
+
`);
|
|
1012
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1013
|
+
"Processing wrangler configuration:
|
|
1014
|
+
- The field \\"unsafe\\" should be an object but got []."
|
|
1015
|
+
`);
|
|
1016
|
+
});
|
|
1017
|
+
|
|
1018
|
+
it("should error if unsafe is a string", () => {
|
|
1019
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1020
|
+
{ unsafe: "BAD" } as unknown as RawConfig,
|
|
1021
|
+
undefined
|
|
1022
|
+
);
|
|
1023
|
+
|
|
1024
|
+
expect(config).toEqual(
|
|
1025
|
+
expect.not.objectContaining({ unsafe: expect.anything })
|
|
1026
|
+
);
|
|
1027
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
1028
|
+
"Processing wrangler configuration:
|
|
1029
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
1030
|
+
`);
|
|
1031
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1032
|
+
"Processing wrangler configuration:
|
|
1033
|
+
- The field \\"unsafe\\" should be an object but got \\"BAD\\"."
|
|
1034
|
+
`);
|
|
1035
|
+
});
|
|
1036
|
+
|
|
1037
|
+
it("should error if unsafe is a number", () => {
|
|
1038
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1039
|
+
{ unsafe: 999 } as unknown as RawConfig,
|
|
1040
|
+
undefined
|
|
1041
|
+
);
|
|
1042
|
+
|
|
1043
|
+
expect(config).toEqual(
|
|
1044
|
+
expect.not.objectContaining({ unsafe: expect.anything })
|
|
1045
|
+
);
|
|
1046
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
1047
|
+
"Processing wrangler configuration:
|
|
1048
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
1049
|
+
`);
|
|
1050
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1051
|
+
"Processing wrangler configuration:
|
|
1052
|
+
- The field \\"unsafe\\" should be an object but got 999."
|
|
1053
|
+
`);
|
|
1054
|
+
});
|
|
1055
|
+
|
|
1056
|
+
it("should error if unsafe is null", () => {
|
|
1057
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1058
|
+
{ unsafe: null } as unknown as RawConfig,
|
|
1059
|
+
undefined
|
|
1060
|
+
);
|
|
1061
|
+
|
|
1062
|
+
expect(config).toEqual(
|
|
1063
|
+
expect.not.objectContaining({ unsafe: expect.anything })
|
|
1064
|
+
);
|
|
1065
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
1066
|
+
"Processing wrangler configuration:
|
|
1067
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
1068
|
+
`);
|
|
1069
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1070
|
+
"Processing wrangler configuration:
|
|
1071
|
+
- The field \\"unsafe\\" should be an object but got null."
|
|
1072
|
+
`);
|
|
1073
|
+
});
|
|
1074
|
+
|
|
1075
|
+
it("should error if unsafe.bindings is not defined", () => {
|
|
1076
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1077
|
+
{ unsafe: {} } as unknown as RawConfig,
|
|
1078
|
+
undefined
|
|
1079
|
+
);
|
|
1080
|
+
|
|
1081
|
+
expect(config).toEqual(
|
|
1082
|
+
expect.not.objectContaining({ unsafe: expect.anything })
|
|
1083
|
+
);
|
|
1084
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
1085
|
+
"Processing wrangler configuration:
|
|
1086
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
1087
|
+
`);
|
|
1088
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1089
|
+
"Processing wrangler configuration:
|
|
1090
|
+
- The field \\"unsafe\\" is missing the required \\"bindings\\" property."
|
|
1091
|
+
`);
|
|
1092
|
+
});
|
|
1093
|
+
|
|
1094
|
+
it("should error if unsafe.bindings is an object", () => {
|
|
1095
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1096
|
+
{ unsafe: { bindings: {} } } as unknown as RawConfig,
|
|
1097
|
+
undefined
|
|
1098
|
+
);
|
|
1099
|
+
|
|
1100
|
+
expect(config).toEqual(
|
|
1101
|
+
expect.not.objectContaining({
|
|
1102
|
+
unsafe: { bindings: expect.anything },
|
|
1103
|
+
})
|
|
1104
|
+
);
|
|
1105
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
1106
|
+
"Processing wrangler configuration:
|
|
1107
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
1108
|
+
`);
|
|
1109
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1110
|
+
"Processing wrangler configuration:
|
|
1111
|
+
- The field \\"unsafe.bindings\\" should be an array but got {}."
|
|
1112
|
+
`);
|
|
1113
|
+
});
|
|
1114
|
+
|
|
1115
|
+
it("should error if unsafe.bindings is a string", () => {
|
|
1116
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1117
|
+
{ unsafe: { bindings: "BAD" } } as unknown as RawConfig,
|
|
1118
|
+
undefined
|
|
1119
|
+
);
|
|
1120
|
+
|
|
1121
|
+
expect(config).toEqual(
|
|
1122
|
+
expect.not.objectContaining({
|
|
1123
|
+
unsafe: { bindings: expect.anything },
|
|
1124
|
+
})
|
|
1125
|
+
);
|
|
1126
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
1127
|
+
"Processing wrangler configuration:
|
|
1128
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
1129
|
+
`);
|
|
1130
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1131
|
+
"Processing wrangler configuration:
|
|
1132
|
+
- The field \\"unsafe.bindings\\" should be an array but got \\"BAD\\"."
|
|
1133
|
+
`);
|
|
1134
|
+
});
|
|
1135
|
+
|
|
1136
|
+
it("should error if unsafe.bindings is a number", () => {
|
|
1137
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1138
|
+
{ unsafe: { bindings: 999 } } as unknown as RawConfig,
|
|
1139
|
+
undefined
|
|
1140
|
+
);
|
|
1141
|
+
|
|
1142
|
+
expect(config).toEqual(
|
|
1143
|
+
expect.not.objectContaining({
|
|
1144
|
+
unsafe: { bindings: expect.anything },
|
|
1145
|
+
})
|
|
1146
|
+
);
|
|
1147
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
1148
|
+
"Processing wrangler configuration:
|
|
1149
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
1150
|
+
`);
|
|
1151
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1152
|
+
"Processing wrangler configuration:
|
|
1153
|
+
- The field \\"unsafe.bindings\\" should be an array but got 999."
|
|
1154
|
+
`);
|
|
1155
|
+
});
|
|
1156
|
+
|
|
1157
|
+
it("should error if unsafe.bindings is null", () => {
|
|
1158
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1159
|
+
{ unsafe: { bindings: null } } as unknown as RawConfig,
|
|
1160
|
+
undefined
|
|
1161
|
+
);
|
|
1162
|
+
|
|
1163
|
+
expect(config).toEqual(
|
|
1164
|
+
expect.not.objectContaining({
|
|
1165
|
+
unsafe: { bindings: expect.anything },
|
|
1166
|
+
})
|
|
1167
|
+
);
|
|
1168
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
1169
|
+
"Processing wrangler configuration:
|
|
1170
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
1171
|
+
`);
|
|
1172
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1173
|
+
"Processing wrangler configuration:
|
|
1174
|
+
- The field \\"unsafe.bindings\\" should be an array but got null."
|
|
1175
|
+
`);
|
|
1176
|
+
});
|
|
1177
|
+
|
|
1178
|
+
it("should error if durable_objects.bindings are not valid", () => {
|
|
1179
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1180
|
+
{
|
|
1181
|
+
unsafe: {
|
|
1182
|
+
bindings: [
|
|
1183
|
+
{},
|
|
1184
|
+
{ name: "UNSAFE_BINDING_1" },
|
|
1185
|
+
{ name: 2666, type: 2777 },
|
|
1186
|
+
{
|
|
1187
|
+
name: "UNSAFE_BINDING_2",
|
|
1188
|
+
type: "UNSAFE_TYPE_2",
|
|
1189
|
+
extra: 2888,
|
|
1190
|
+
},
|
|
1191
|
+
],
|
|
1192
|
+
},
|
|
1193
|
+
} as unknown as RawConfig,
|
|
1194
|
+
undefined
|
|
1195
|
+
);
|
|
1196
|
+
|
|
1197
|
+
expect(config).toEqual(
|
|
1198
|
+
expect.not.objectContaining({
|
|
1199
|
+
durable_objects: { bindings: expect.anything },
|
|
1200
|
+
})
|
|
1201
|
+
);
|
|
1202
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
1203
|
+
"Processing wrangler configuration:
|
|
1204
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
1205
|
+
`);
|
|
1206
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1207
|
+
"Processing wrangler configuration:
|
|
1208
|
+
|
|
1209
|
+
- \\"unsafe.bindings[0]\\": {}
|
|
1210
|
+
- binding should have a string \\"name\\" field.
|
|
1211
|
+
- binding should have a string \\"type\\" field.
|
|
1212
|
+
|
|
1213
|
+
- \\"unsafe.bindings[1]\\": {\\"name\\":\\"UNSAFE_BINDING_1\\"}
|
|
1214
|
+
- binding should have a string \\"type\\" field.
|
|
1215
|
+
|
|
1216
|
+
- \\"unsafe.bindings[2]\\": {\\"name\\":2666,\\"type\\":2777}
|
|
1217
|
+
- binding should have a string \\"name\\" field.
|
|
1218
|
+
- binding should have a string \\"type\\" field."
|
|
1219
|
+
`);
|
|
1220
|
+
});
|
|
1221
|
+
});
|
|
1222
|
+
|
|
1223
|
+
describe("(deprecated)", () => {
|
|
1224
|
+
it("should remove and warn about deprecated properties", () => {
|
|
1225
|
+
const rawConfig: RawConfig = {
|
|
1226
|
+
zone_id: "ZONE_ID",
|
|
1227
|
+
experimental_services: [
|
|
1228
|
+
{
|
|
1229
|
+
name: "NAME",
|
|
1230
|
+
service: "SERVICE",
|
|
1231
|
+
environment: "ENV",
|
|
1232
|
+
},
|
|
1233
|
+
],
|
|
1234
|
+
};
|
|
1235
|
+
|
|
1236
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1237
|
+
rawConfig,
|
|
1238
|
+
undefined
|
|
1239
|
+
);
|
|
1240
|
+
|
|
1241
|
+
expect("experimental_services" in config).toBe(false);
|
|
1242
|
+
// Zone is not removed yet, since `route` commands might use it
|
|
1243
|
+
expect(config.zone_id).toEqual("ZONE_ID");
|
|
1244
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
1245
|
+
expect(diagnostics.hasWarnings()).toBe(true);
|
|
1246
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
1247
|
+
"Processing wrangler configuration:
|
|
1248
|
+
- DEPRECATION: \\"zone_id\\":
|
|
1249
|
+
This is unnecessary since we can deduce this from routes directly.
|
|
1250
|
+
- DEPRECATION: \\"experimental_services\\":
|
|
1251
|
+
The \\"experimental_services\\" field is no longer supported. Instead, use [[unsafe.bindings]] to enable experimental features. Add this to your wrangler.toml:
|
|
1252
|
+
\`\`\`
|
|
1253
|
+
[[unsafe.bindings]]
|
|
1254
|
+
name = \\"NAME\\"
|
|
1255
|
+
type = \\"service\\"
|
|
1256
|
+
service = \\"SERVICE\\"
|
|
1257
|
+
environment = \\"ENV\\"
|
|
1258
|
+
\`\`\`"
|
|
1259
|
+
`);
|
|
1260
|
+
});
|
|
1261
|
+
});
|
|
1262
|
+
});
|
|
1263
|
+
|
|
1264
|
+
describe("named environments", () => {
|
|
1265
|
+
it("should use top-level values for inheritable config fields", () => {
|
|
1266
|
+
const expectedConfig: RawConfig = {
|
|
1267
|
+
name: "NAME",
|
|
1268
|
+
account_id: "ACCOUNT_ID",
|
|
1269
|
+
compatibility_date: "2022-01-01",
|
|
1270
|
+
compatibility_flags: ["FLAG1", "FLAG2"],
|
|
1271
|
+
workers_dev: false,
|
|
1272
|
+
routes: ["ROUTE_1", "ROUTE_2"],
|
|
1273
|
+
route: "ROUTE_3",
|
|
1274
|
+
jsx_factory: "JSX_FACTORY",
|
|
1275
|
+
jsx_fragment: "JSX_FRAGMENT",
|
|
1276
|
+
triggers: { crons: ["CRON_1", "CRON_2"] },
|
|
1277
|
+
usage_model: "bundled",
|
|
1278
|
+
};
|
|
1279
|
+
|
|
1280
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1281
|
+
{ ...expectedConfig, env: { DEV: {} } },
|
|
1282
|
+
undefined
|
|
1283
|
+
);
|
|
1284
|
+
|
|
1285
|
+
expect(config.env.DEV).toEqual(expect.objectContaining(expectedConfig));
|
|
1286
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
1287
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1288
|
+
});
|
|
1289
|
+
|
|
1290
|
+
it("should override top-level values for inheritable config fields", () => {
|
|
1291
|
+
const environment: RawEnvironment = {
|
|
1292
|
+
name: "ENV_NAME",
|
|
1293
|
+
account_id: "ENV_ACCOUNT_ID",
|
|
1294
|
+
compatibility_date: "2022-02-02",
|
|
1295
|
+
compatibility_flags: ["ENV_FLAG1", "ENV_FLAG2"],
|
|
1296
|
+
workers_dev: true,
|
|
1297
|
+
routes: ["ENV_ROUTE_1", "ENV_ROUTE_2"],
|
|
1298
|
+
route: "ENV_ROUTE_3",
|
|
1299
|
+
jsx_factory: "ENV_JSX_FACTORY",
|
|
1300
|
+
jsx_fragment: "ENV_JSX_FRAGMENT",
|
|
1301
|
+
triggers: { crons: ["ENV_CRON_1", "ENV_CRON_2"] },
|
|
1302
|
+
usage_model: "unbound",
|
|
1303
|
+
};
|
|
1304
|
+
const expectedConfig: RawConfig = {
|
|
1305
|
+
name: "NAME",
|
|
1306
|
+
account_id: "ACCOUNT_ID",
|
|
1307
|
+
compatibility_date: "2022-01-01",
|
|
1308
|
+
compatibility_flags: ["FLAG1", "FLAG2"],
|
|
1309
|
+
workers_dev: false,
|
|
1310
|
+
routes: ["ROUTE_1", "ROUTE_2"],
|
|
1311
|
+
route: "ROUTE_3",
|
|
1312
|
+
jsx_factory: "JSX_FACTORY",
|
|
1313
|
+
jsx_fragment: "JSX_FRAGMENT",
|
|
1314
|
+
triggers: { crons: ["CRON_1", "CRON_2"] },
|
|
1315
|
+
usage_model: "bundled",
|
|
1316
|
+
env: {
|
|
1317
|
+
ENV1: environment,
|
|
1318
|
+
},
|
|
1319
|
+
};
|
|
1320
|
+
|
|
1321
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1322
|
+
expectedConfig,
|
|
1323
|
+
undefined
|
|
1324
|
+
);
|
|
1325
|
+
|
|
1326
|
+
expect(config.env.ENV1).toEqual(expect.objectContaining(environment));
|
|
1327
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
1328
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1329
|
+
});
|
|
1330
|
+
|
|
1331
|
+
it("should warn for non-inherited fields that are missing in environments", () => {
|
|
1332
|
+
const vars: RawConfig["vars"] = {
|
|
1333
|
+
FOO: "foo",
|
|
1334
|
+
};
|
|
1335
|
+
const durable_objects: RawConfig["durable_objects"] = {
|
|
1336
|
+
bindings: [],
|
|
1337
|
+
};
|
|
1338
|
+
const kv_namespaces: RawConfig["kv_namespaces"] = [];
|
|
1339
|
+
const r2_buckets: RawConfig["r2_buckets"] = [];
|
|
1340
|
+
const unsafe: RawConfig["unsafe"] = { bindings: [] };
|
|
1341
|
+
const rawConfig: RawConfig = {
|
|
1342
|
+
vars,
|
|
1343
|
+
durable_objects,
|
|
1344
|
+
kv_namespaces,
|
|
1345
|
+
r2_buckets,
|
|
1346
|
+
unsafe,
|
|
1347
|
+
env: {
|
|
1348
|
+
ENV1: {},
|
|
1349
|
+
},
|
|
1350
|
+
};
|
|
1351
|
+
|
|
1352
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1353
|
+
rawConfig,
|
|
1354
|
+
undefined
|
|
1355
|
+
);
|
|
1356
|
+
|
|
1357
|
+
expect(config.env.ENV1).toEqual(
|
|
1358
|
+
expect.not.objectContaining({
|
|
1359
|
+
vars,
|
|
1360
|
+
durable_objects,
|
|
1361
|
+
kv_namespaces,
|
|
1362
|
+
r2_buckets,
|
|
1363
|
+
unsafe,
|
|
1364
|
+
})
|
|
1365
|
+
);
|
|
1366
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
1367
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
1368
|
+
"Processing wrangler configuration:
|
|
1369
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time.
|
|
1370
|
+
- \\"env.ENV1\\" environment configuration
|
|
1371
|
+
- \\"vars\\" exists at the top level, but not on \\"env.ENV1\\".
|
|
1372
|
+
This is not what you probably want, since \\"vars\\" is not inherited by environments.
|
|
1373
|
+
Please add \\"vars\\" to \\"env.ENV1\\".
|
|
1374
|
+
- \\"durable_objects\\" exists at the top level, but not on \\"env.ENV1\\".
|
|
1375
|
+
This is not what you probably want, since \\"durable_objects\\" is not inherited by environments.
|
|
1376
|
+
Please add \\"durable_objects\\" to \\"env.ENV1\\".
|
|
1377
|
+
- \\"kv_namespaces\\" exists at the top level, but not on \\"env.ENV1\\".
|
|
1378
|
+
This is not what you probably want, since \\"kv_namespaces\\" is not inherited by environments.
|
|
1379
|
+
Please add \\"kv_namespaces\\" to \\"env.ENV1\\".
|
|
1380
|
+
- \\"r2_buckets\\" exists at the top level, but not on \\"env.ENV1\\".
|
|
1381
|
+
This is not what you probably want, since \\"r2_buckets\\" is not inherited by environments.
|
|
1382
|
+
Please add \\"r2_buckets\\" to \\"env.ENV1\\".
|
|
1383
|
+
- \\"unsafe\\" exists at the top level, but not on \\"env.ENV1\\".
|
|
1384
|
+
This is not what you probably want, since \\"unsafe\\" is not inherited by environments.
|
|
1385
|
+
Please add \\"unsafe\\" to \\"env.ENV1\\"."
|
|
1386
|
+
`);
|
|
1387
|
+
});
|
|
1388
|
+
|
|
1389
|
+
it("should error on invalid environment values", () => {
|
|
1390
|
+
const expectedConfig: RawEnvironment = {
|
|
1391
|
+
name: 111,
|
|
1392
|
+
account_id: 222,
|
|
1393
|
+
compatibility_date: 333,
|
|
1394
|
+
compatibility_flags: [444, 555],
|
|
1395
|
+
workers_dev: "BAD",
|
|
1396
|
+
routes: [666, 777],
|
|
1397
|
+
route: 888,
|
|
1398
|
+
jsx_factory: 999,
|
|
1399
|
+
jsx_fragment: 1000,
|
|
1400
|
+
triggers: { crons: [1111, 1222] },
|
|
1401
|
+
usage_model: "INVALID",
|
|
1402
|
+
} as unknown as RawEnvironment;
|
|
1403
|
+
|
|
1404
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1405
|
+
{ env: { ENV1: expectedConfig } },
|
|
1406
|
+
undefined
|
|
1407
|
+
);
|
|
1408
|
+
|
|
1409
|
+
expect(config.env.ENV1).toEqual(expect.objectContaining(expectedConfig));
|
|
1410
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1411
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1412
|
+
"Processing wrangler configuration:
|
|
1413
|
+
|
|
1414
|
+
- \\"env.ENV1\\" environment configuration
|
|
1415
|
+
- Expected \\"route\\" field to be a string but got 888.
|
|
1416
|
+
- Expected \\"routes\\" field to be an array of strings but got [666,777].
|
|
1417
|
+
- Expected \\"workers_dev\\" field to be a boolean but got \\"BAD\\".
|
|
1418
|
+
- Expected \\"account_id\\" field to be a string but got 222.
|
|
1419
|
+
- Expected \\"compatibility_date\\" field to be a string but got 333.
|
|
1420
|
+
- Expected \\"compatibility_flags\\" field to be an array of strings but got [444,555].
|
|
1421
|
+
- Expected \\"jsx_factory\\" field to be a string but got 999.
|
|
1422
|
+
- Expected \\"jsx_fragment\\" field to be a string but got 1000.
|
|
1423
|
+
- Expected \\"name\\" field to be a string but got 111.
|
|
1424
|
+
- Expected \\"usage_model\\" field to be one of [\\"bundled\\",\\"unbound\\"] but got \\"INVALID\\"."
|
|
1425
|
+
`);
|
|
1426
|
+
});
|
|
1427
|
+
|
|
1428
|
+
describe("durable_objects field", () => {
|
|
1429
|
+
it("should error if durable_objects is an array", () => {
|
|
1430
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1431
|
+
{ env: { ENV1: { durable_objects: [] } } } as unknown as RawConfig,
|
|
1432
|
+
undefined
|
|
1433
|
+
);
|
|
1434
|
+
|
|
1435
|
+
expect(config.env.ENV1).toEqual(
|
|
1436
|
+
expect.not.objectContaining({ durable_objects: expect.anything })
|
|
1437
|
+
);
|
|
1438
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1439
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1440
|
+
"Processing wrangler configuration:
|
|
1441
|
+
|
|
1442
|
+
- \\"env.ENV1\\" environment configuration
|
|
1443
|
+
- The field \\"env.ENV1.durable_objects\\" should be an object but got []."
|
|
1444
|
+
`);
|
|
1445
|
+
});
|
|
1446
|
+
|
|
1447
|
+
it("should error if durable_objects is a string", () => {
|
|
1448
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1449
|
+
{ env: { ENV1: { durable_objects: "BAD" } } } as unknown as RawConfig,
|
|
1450
|
+
undefined
|
|
1451
|
+
);
|
|
1452
|
+
|
|
1453
|
+
expect(config.env.ENV1).toEqual(
|
|
1454
|
+
expect.not.objectContaining({ durable_objects: expect.anything })
|
|
1455
|
+
);
|
|
1456
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1457
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1458
|
+
"Processing wrangler configuration:
|
|
1459
|
+
|
|
1460
|
+
- \\"env.ENV1\\" environment configuration
|
|
1461
|
+
- The field \\"env.ENV1.durable_objects\\" should be an object but got \\"BAD\\"."
|
|
1462
|
+
`);
|
|
1463
|
+
});
|
|
1464
|
+
|
|
1465
|
+
it("should error if durable_objects is a number", () => {
|
|
1466
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1467
|
+
{ env: { ENV1: { durable_objects: 999 } } } as unknown as RawConfig,
|
|
1468
|
+
undefined
|
|
1469
|
+
);
|
|
1470
|
+
|
|
1471
|
+
expect(config.env.ENV1).toEqual(
|
|
1472
|
+
expect.not.objectContaining({ durable_objects: expect.anything })
|
|
1473
|
+
);
|
|
1474
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1475
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1476
|
+
"Processing wrangler configuration:
|
|
1477
|
+
|
|
1478
|
+
- \\"env.ENV1\\" environment configuration
|
|
1479
|
+
- The field \\"env.ENV1.durable_objects\\" should be an object but got 999."
|
|
1480
|
+
`);
|
|
1481
|
+
});
|
|
1482
|
+
|
|
1483
|
+
it("should error if durable_objects is null", () => {
|
|
1484
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1485
|
+
{ env: { ENV1: { durable_objects: null } } } as unknown as RawConfig,
|
|
1486
|
+
undefined
|
|
1487
|
+
);
|
|
1488
|
+
|
|
1489
|
+
expect(config.env.ENV1).toEqual(
|
|
1490
|
+
expect.not.objectContaining({ durable_objects: expect.anything })
|
|
1491
|
+
);
|
|
1492
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1493
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1494
|
+
"Processing wrangler configuration:
|
|
1495
|
+
|
|
1496
|
+
- \\"env.ENV1\\" environment configuration
|
|
1497
|
+
- The field \\"env.ENV1.durable_objects\\" should be an object but got null."
|
|
1498
|
+
`);
|
|
1499
|
+
});
|
|
1500
|
+
|
|
1501
|
+
it("should error if durable_objects.bindings is not defined", () => {
|
|
1502
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1503
|
+
{ env: { ENV1: { durable_objects: {} } } } as unknown as RawConfig,
|
|
1504
|
+
undefined
|
|
1505
|
+
);
|
|
1506
|
+
|
|
1507
|
+
expect(config.env.ENV1).toEqual(
|
|
1508
|
+
expect.not.objectContaining({ durable_objects: expect.anything })
|
|
1509
|
+
);
|
|
1510
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1511
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1512
|
+
"Processing wrangler configuration:
|
|
1513
|
+
|
|
1514
|
+
- \\"env.ENV1\\" environment configuration
|
|
1515
|
+
- The field \\"env.ENV1.durable_objects\\" is missing the required \\"bindings\\" property."
|
|
1516
|
+
`);
|
|
1517
|
+
});
|
|
1518
|
+
|
|
1519
|
+
it("should error if durable_objects.bindings is an object", () => {
|
|
1520
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1521
|
+
{
|
|
1522
|
+
env: { ENV1: { durable_objects: { bindings: {} } } },
|
|
1523
|
+
} as unknown as RawConfig,
|
|
1524
|
+
undefined
|
|
1525
|
+
);
|
|
1526
|
+
|
|
1527
|
+
expect(config.env.ENV1).toEqual(
|
|
1528
|
+
expect.not.objectContaining({
|
|
1529
|
+
durable_objects: { bindings: expect.anything },
|
|
1530
|
+
})
|
|
1531
|
+
);
|
|
1532
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1533
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1534
|
+
"Processing wrangler configuration:
|
|
1535
|
+
|
|
1536
|
+
- \\"env.ENV1\\" environment configuration
|
|
1537
|
+
- The field \\"env.ENV1.durable_objects.bindings\\" should be an array but got {}."
|
|
1538
|
+
`);
|
|
1539
|
+
});
|
|
1540
|
+
|
|
1541
|
+
it("should error if durable_objects.bindings is a string", () => {
|
|
1542
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1543
|
+
{
|
|
1544
|
+
env: { ENV1: { durable_objects: { bindings: "BAD" } } },
|
|
1545
|
+
} as unknown as RawConfig,
|
|
1546
|
+
undefined
|
|
1547
|
+
);
|
|
1548
|
+
|
|
1549
|
+
expect(config.env.ENV1).toEqual(
|
|
1550
|
+
expect.not.objectContaining({
|
|
1551
|
+
durable_objects: { bindings: expect.anything },
|
|
1552
|
+
})
|
|
1553
|
+
);
|
|
1554
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1555
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1556
|
+
"Processing wrangler configuration:
|
|
1557
|
+
|
|
1558
|
+
- \\"env.ENV1\\" environment configuration
|
|
1559
|
+
- The field \\"env.ENV1.durable_objects.bindings\\" should be an array but got \\"BAD\\"."
|
|
1560
|
+
`);
|
|
1561
|
+
});
|
|
1562
|
+
|
|
1563
|
+
it("should error if durable_objects.bindings is a number", () => {
|
|
1564
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1565
|
+
{
|
|
1566
|
+
env: { ENV1: { durable_objects: { bindings: 999 } } },
|
|
1567
|
+
} as unknown as RawConfig,
|
|
1568
|
+
undefined
|
|
1569
|
+
);
|
|
1570
|
+
|
|
1571
|
+
expect(config.env.ENV1).toEqual(
|
|
1572
|
+
expect.not.objectContaining({
|
|
1573
|
+
durable_objects: { bindings: expect.anything },
|
|
1574
|
+
})
|
|
1575
|
+
);
|
|
1576
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1577
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1578
|
+
"Processing wrangler configuration:
|
|
1579
|
+
|
|
1580
|
+
- \\"env.ENV1\\" environment configuration
|
|
1581
|
+
- The field \\"env.ENV1.durable_objects.bindings\\" should be an array but got 999."
|
|
1582
|
+
`);
|
|
1583
|
+
});
|
|
1584
|
+
|
|
1585
|
+
it("should error if durable_objects.bindings is null", () => {
|
|
1586
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1587
|
+
{
|
|
1588
|
+
env: { ENV1: { durable_objects: { bindings: null } } },
|
|
1589
|
+
} as unknown as RawConfig,
|
|
1590
|
+
undefined
|
|
1591
|
+
);
|
|
1592
|
+
|
|
1593
|
+
expect(config.env.ENV1).toEqual(
|
|
1594
|
+
expect.not.objectContaining({
|
|
1595
|
+
durable_objects: { bindings: expect.anything },
|
|
1596
|
+
})
|
|
1597
|
+
);
|
|
1598
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1599
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1600
|
+
"Processing wrangler configuration:
|
|
1601
|
+
|
|
1602
|
+
- \\"env.ENV1\\" environment configuration
|
|
1603
|
+
- The field \\"env.ENV1.durable_objects.bindings\\" should be an array but got null."
|
|
1604
|
+
`);
|
|
1605
|
+
});
|
|
1606
|
+
|
|
1607
|
+
it("should error if durable_objects.bindings are not valid", () => {
|
|
1608
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1609
|
+
{
|
|
1610
|
+
env: {
|
|
1611
|
+
ENV1: {
|
|
1612
|
+
durable_objects: {
|
|
1613
|
+
bindings: [
|
|
1614
|
+
{},
|
|
1615
|
+
{ name: "VALID" },
|
|
1616
|
+
{ name: 1555, class_name: 1666 },
|
|
1617
|
+
{
|
|
1618
|
+
name: 1777,
|
|
1619
|
+
class_name: 1888,
|
|
1620
|
+
script_name: 1999,
|
|
1621
|
+
},
|
|
1622
|
+
],
|
|
1623
|
+
},
|
|
1624
|
+
},
|
|
1625
|
+
},
|
|
1626
|
+
} as unknown as RawConfig,
|
|
1627
|
+
undefined
|
|
1628
|
+
);
|
|
1629
|
+
|
|
1630
|
+
expect(config.env.ENV1).toEqual(
|
|
1631
|
+
expect.not.objectContaining({
|
|
1632
|
+
durable_objects: { bindings: expect.anything },
|
|
1633
|
+
})
|
|
1634
|
+
);
|
|
1635
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1636
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1637
|
+
"Processing wrangler configuration:
|
|
1638
|
+
|
|
1639
|
+
- \\"env.ENV1\\" environment configuration
|
|
1640
|
+
|
|
1641
|
+
- \\"env.ENV1.durable_objects.bindings[0]\\": {}
|
|
1642
|
+
- binding should have a string \\"name\\" field.
|
|
1643
|
+
- binding should have a string \\"class_name\\" field.
|
|
1644
|
+
|
|
1645
|
+
- \\"env.ENV1.durable_objects.bindings[1]\\": {\\"name\\":\\"VALID\\"}
|
|
1646
|
+
- binding should have a string \\"class_name\\" field.
|
|
1647
|
+
|
|
1648
|
+
- \\"env.ENV1.durable_objects.bindings[2]\\": {\\"name\\":1555,\\"class_name\\":1666}
|
|
1649
|
+
- binding should have a string \\"name\\" field.
|
|
1650
|
+
- binding should have a string \\"class_name\\" field.
|
|
1651
|
+
|
|
1652
|
+
- \\"env.ENV1.durable_objects.bindings[3]\\": {\\"name\\":1777,\\"class_name\\":1888,\\"script_name\\":1999}
|
|
1653
|
+
- binding should have a string \\"name\\" field.
|
|
1654
|
+
- binding should have a string \\"class_name\\" field.
|
|
1655
|
+
- binding should, optionally, have a string \\"script_name\\" field."
|
|
1656
|
+
`);
|
|
1657
|
+
});
|
|
1658
|
+
});
|
|
1659
|
+
|
|
1660
|
+
describe("kv_namespaces field", () => {
|
|
1661
|
+
it("should error if kv_namespaces is an object", () => {
|
|
1662
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1663
|
+
{ env: { ENV1: { kv_namespaces: {} } } } as unknown as RawConfig,
|
|
1664
|
+
undefined
|
|
1665
|
+
);
|
|
1666
|
+
|
|
1667
|
+
expect(config.env.ENV1).toEqual(
|
|
1668
|
+
expect.not.objectContaining({ kv_namespaces: expect.anything })
|
|
1669
|
+
);
|
|
1670
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1671
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1672
|
+
"Processing wrangler configuration:
|
|
1673
|
+
|
|
1674
|
+
- \\"env.ENV1\\" environment configuration
|
|
1675
|
+
- The field \\"env.ENV1.kv_namespaces\\" should be an array but got {}."
|
|
1676
|
+
`);
|
|
1677
|
+
});
|
|
1678
|
+
|
|
1679
|
+
it("should error if kv_namespaces is a string", () => {
|
|
1680
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1681
|
+
{ env: { ENV1: { kv_namespaces: "BAD" } } } as unknown as RawConfig,
|
|
1682
|
+
undefined
|
|
1683
|
+
);
|
|
1684
|
+
|
|
1685
|
+
expect(config.env.ENV1).toEqual(
|
|
1686
|
+
expect.not.objectContaining({ kv_namespaces: expect.anything })
|
|
1687
|
+
);
|
|
1688
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1689
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1690
|
+
"Processing wrangler configuration:
|
|
1691
|
+
|
|
1692
|
+
- \\"env.ENV1\\" environment configuration
|
|
1693
|
+
- The field \\"env.ENV1.kv_namespaces\\" should be an array but got \\"BAD\\"."
|
|
1694
|
+
`);
|
|
1695
|
+
});
|
|
1696
|
+
|
|
1697
|
+
it("should error if kv_namespaces is a number", () => {
|
|
1698
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1699
|
+
{ env: { ENV1: { kv_namespaces: 999 } } } as unknown as RawConfig,
|
|
1700
|
+
undefined
|
|
1701
|
+
);
|
|
1702
|
+
|
|
1703
|
+
expect(config.env.ENV1).toEqual(
|
|
1704
|
+
expect.not.objectContaining({ kv_namespaces: expect.anything })
|
|
1705
|
+
);
|
|
1706
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1707
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1708
|
+
"Processing wrangler configuration:
|
|
1709
|
+
|
|
1710
|
+
- \\"env.ENV1\\" environment configuration
|
|
1711
|
+
- The field \\"env.ENV1.kv_namespaces\\" should be an array but got 999."
|
|
1712
|
+
`);
|
|
1713
|
+
});
|
|
1714
|
+
|
|
1715
|
+
it("should error if kv_namespaces is null", () => {
|
|
1716
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1717
|
+
{ env: { ENV1: { kv_namespaces: null } } } as unknown as RawConfig,
|
|
1718
|
+
undefined
|
|
1719
|
+
);
|
|
1720
|
+
|
|
1721
|
+
expect(config.env.ENV1).toEqual(
|
|
1722
|
+
expect.not.objectContaining({ kv_namespaces: expect.anything })
|
|
1723
|
+
);
|
|
1724
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1725
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1726
|
+
"Processing wrangler configuration:
|
|
1727
|
+
|
|
1728
|
+
- \\"env.ENV1\\" environment configuration
|
|
1729
|
+
- The field \\"env.ENV1.kv_namespaces\\" should be an array but got null."
|
|
1730
|
+
`);
|
|
1731
|
+
});
|
|
1732
|
+
|
|
1733
|
+
it("should error if kv_namespaces.bindings are not valid", () => {
|
|
1734
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1735
|
+
{
|
|
1736
|
+
env: {
|
|
1737
|
+
ENV1: {
|
|
1738
|
+
kv_namespaces: [
|
|
1739
|
+
{},
|
|
1740
|
+
{ binding: "VALID" },
|
|
1741
|
+
{ binding: 2000, id: 2111 },
|
|
1742
|
+
{
|
|
1743
|
+
binding: "KV_BINDING_2",
|
|
1744
|
+
id: "KV_ID_2",
|
|
1745
|
+
preview_id: 2222,
|
|
1746
|
+
},
|
|
1747
|
+
],
|
|
1748
|
+
},
|
|
1749
|
+
},
|
|
1750
|
+
} as unknown as RawConfig,
|
|
1751
|
+
undefined
|
|
1752
|
+
);
|
|
1753
|
+
|
|
1754
|
+
expect(config.env.ENV1).toEqual(
|
|
1755
|
+
expect.not.objectContaining({
|
|
1756
|
+
kv_namespaces: { bindings: expect.anything },
|
|
1757
|
+
})
|
|
1758
|
+
);
|
|
1759
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1760
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1761
|
+
"Processing wrangler configuration:
|
|
1762
|
+
|
|
1763
|
+
- \\"env.ENV1\\" environment configuration
|
|
1764
|
+
- \\"env.ENV1.kv_namespaces[0]\\" bindings should have a string \\"binding\\" field but got {}.
|
|
1765
|
+
- \\"env.ENV1.kv_namespaces[0]\\" bindings should have a string \\"id\\" field but got {}.
|
|
1766
|
+
- \\"env.ENV1.kv_namespaces[1]\\" bindings should have a string \\"id\\" field but got {\\"binding\\":\\"VALID\\"}.
|
|
1767
|
+
- \\"env.ENV1.kv_namespaces[2]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":2000,\\"id\\":2111}.
|
|
1768
|
+
- \\"env.ENV1.kv_namespaces[2]\\" bindings should have a string \\"id\\" field but got {\\"binding\\":2000,\\"id\\":2111}.
|
|
1769
|
+
- \\"env.ENV1.kv_namespaces[3]\\" bindings should, optionally, have a string \\"preview_id\\" field but got {\\"binding\\":\\"KV_BINDING_2\\",\\"id\\":\\"KV_ID_2\\",\\"preview_id\\":2222}."
|
|
1770
|
+
`);
|
|
1771
|
+
});
|
|
1772
|
+
});
|
|
1773
|
+
|
|
1774
|
+
describe("r2_buckets field", () => {
|
|
1775
|
+
it("should error if r2_buckets is an object", () => {
|
|
1776
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1777
|
+
{ env: { ENV1: { r2_buckets: {} } } } as unknown as RawConfig,
|
|
1778
|
+
undefined
|
|
1779
|
+
);
|
|
1780
|
+
|
|
1781
|
+
expect(config.env.ENV1).toEqual(
|
|
1782
|
+
expect.not.objectContaining({ r2_buckets: expect.anything })
|
|
1783
|
+
);
|
|
1784
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1785
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1786
|
+
"Processing wrangler configuration:
|
|
1787
|
+
|
|
1788
|
+
- \\"env.ENV1\\" environment configuration
|
|
1789
|
+
- The field \\"env.ENV1.r2_buckets\\" should be an array but got {}."
|
|
1790
|
+
`);
|
|
1791
|
+
});
|
|
1792
|
+
|
|
1793
|
+
it("should error if r2_buckets is a string", () => {
|
|
1794
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1795
|
+
{ env: { ENV1: { r2_buckets: "BAD" } } } as unknown as RawConfig,
|
|
1796
|
+
undefined
|
|
1797
|
+
);
|
|
1798
|
+
|
|
1799
|
+
expect(config.env.ENV1).toEqual(
|
|
1800
|
+
expect.not.objectContaining({ r2_buckets: expect.anything })
|
|
1801
|
+
);
|
|
1802
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1803
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1804
|
+
"Processing wrangler configuration:
|
|
1805
|
+
|
|
1806
|
+
- \\"env.ENV1\\" environment configuration
|
|
1807
|
+
- The field \\"env.ENV1.r2_buckets\\" should be an array but got \\"BAD\\"."
|
|
1808
|
+
`);
|
|
1809
|
+
});
|
|
1810
|
+
|
|
1811
|
+
it("should error if r2_buckets is a number", () => {
|
|
1812
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1813
|
+
{ env: { ENV1: { r2_buckets: 999 } } } as unknown as RawConfig,
|
|
1814
|
+
undefined
|
|
1815
|
+
);
|
|
1816
|
+
|
|
1817
|
+
expect(config.env.ENV1).toEqual(
|
|
1818
|
+
expect.not.objectContaining({ r2_buckets: expect.anything })
|
|
1819
|
+
);
|
|
1820
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1821
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1822
|
+
"Processing wrangler configuration:
|
|
1823
|
+
|
|
1824
|
+
- \\"env.ENV1\\" environment configuration
|
|
1825
|
+
- The field \\"env.ENV1.r2_buckets\\" should be an array but got 999."
|
|
1826
|
+
`);
|
|
1827
|
+
});
|
|
1828
|
+
|
|
1829
|
+
it("should error if r2_buckets is null", () => {
|
|
1830
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1831
|
+
{ env: { ENV1: { r2_buckets: null } } } as unknown as RawConfig,
|
|
1832
|
+
undefined
|
|
1833
|
+
);
|
|
1834
|
+
|
|
1835
|
+
expect(config.env.ENV1).toEqual(
|
|
1836
|
+
expect.not.objectContaining({ r2_buckets: expect.anything })
|
|
1837
|
+
);
|
|
1838
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1839
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1840
|
+
"Processing wrangler configuration:
|
|
1841
|
+
|
|
1842
|
+
- \\"env.ENV1\\" environment configuration
|
|
1843
|
+
- The field \\"env.ENV1.r2_buckets\\" should be an array but got null."
|
|
1844
|
+
`);
|
|
1845
|
+
});
|
|
1846
|
+
|
|
1847
|
+
it("should error if r2_buckets.bindings are not valid", () => {
|
|
1848
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1849
|
+
{
|
|
1850
|
+
env: {
|
|
1851
|
+
ENV1: {
|
|
1852
|
+
r2_buckets: [
|
|
1853
|
+
{},
|
|
1854
|
+
{ binding: "R2_BINDING_1" },
|
|
1855
|
+
{ binding: 2333, bucket_name: 2444 },
|
|
1856
|
+
{
|
|
1857
|
+
binding: "R2_BINDING_2",
|
|
1858
|
+
bucket_name: "R2_BUCKET_2",
|
|
1859
|
+
preview_bucket_name: 2555,
|
|
1860
|
+
},
|
|
1861
|
+
],
|
|
1862
|
+
},
|
|
1863
|
+
},
|
|
1864
|
+
} as unknown as RawConfig,
|
|
1865
|
+
undefined
|
|
1866
|
+
);
|
|
1867
|
+
|
|
1868
|
+
expect(config.env.ENV1).toEqual(
|
|
1869
|
+
expect.not.objectContaining({
|
|
1870
|
+
r2_buckets: { bindings: expect.anything },
|
|
1871
|
+
})
|
|
1872
|
+
);
|
|
1873
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1874
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1875
|
+
"Processing wrangler configuration:
|
|
1876
|
+
|
|
1877
|
+
- \\"env.ENV1\\" environment configuration
|
|
1878
|
+
- \\"env.ENV1.r2_buckets[0]\\" bindings should have a string \\"binding\\" field but got {}.
|
|
1879
|
+
- \\"env.ENV1.r2_buckets[0]\\" bindings should have a string \\"bucket_name\\" field but got {}.
|
|
1880
|
+
- \\"env.ENV1.r2_buckets[1]\\" bindings should have a string \\"bucket_name\\" field but got {\\"binding\\":\\"R2_BINDING_1\\"}.
|
|
1881
|
+
- \\"env.ENV1.r2_buckets[2]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":2333,\\"bucket_name\\":2444}.
|
|
1882
|
+
- \\"env.ENV1.r2_buckets[2]\\" bindings should have a string \\"bucket_name\\" field but got {\\"binding\\":2333,\\"bucket_name\\":2444}.
|
|
1883
|
+
- \\"env.ENV1.r2_buckets[3]\\" bindings should, optionally, have a string \\"preview_bucket_name\\" field but got {\\"binding\\":\\"R2_BINDING_2\\",\\"bucket_name\\":\\"R2_BUCKET_2\\",\\"preview_bucket_name\\":2555}."
|
|
1884
|
+
`);
|
|
1885
|
+
});
|
|
1886
|
+
});
|
|
1887
|
+
|
|
1888
|
+
describe("unsafe field", () => {
|
|
1889
|
+
it("should error if unsafe is an array", () => {
|
|
1890
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1891
|
+
{ env: { ENV1: { unsafe: [] } } } as unknown as RawConfig,
|
|
1892
|
+
undefined
|
|
1893
|
+
);
|
|
1894
|
+
|
|
1895
|
+
expect(config.env.ENV1).toEqual(
|
|
1896
|
+
expect.not.objectContaining({ unsafe: expect.anything })
|
|
1897
|
+
);
|
|
1898
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
1899
|
+
"Processing wrangler configuration:
|
|
1900
|
+
|
|
1901
|
+
- \\"env.ENV1\\" environment configuration
|
|
1902
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
1903
|
+
`);
|
|
1904
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1905
|
+
"Processing wrangler configuration:
|
|
1906
|
+
|
|
1907
|
+
- \\"env.ENV1\\" environment configuration
|
|
1908
|
+
- The field \\"env.ENV1.unsafe\\" should be an object but got []."
|
|
1909
|
+
`);
|
|
1910
|
+
});
|
|
1911
|
+
|
|
1912
|
+
it("should error if unsafe is a string", () => {
|
|
1913
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1914
|
+
{ env: { ENV1: { unsafe: "BAD" } } } as unknown as RawConfig,
|
|
1915
|
+
undefined
|
|
1916
|
+
);
|
|
1917
|
+
|
|
1918
|
+
expect(config.env.ENV1).toEqual(
|
|
1919
|
+
expect.not.objectContaining({ unsafe: expect.anything })
|
|
1920
|
+
);
|
|
1921
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
1922
|
+
"Processing wrangler configuration:
|
|
1923
|
+
|
|
1924
|
+
- \\"env.ENV1\\" environment configuration
|
|
1925
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
1926
|
+
`);
|
|
1927
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1928
|
+
"Processing wrangler configuration:
|
|
1929
|
+
|
|
1930
|
+
- \\"env.ENV1\\" environment configuration
|
|
1931
|
+
- The field \\"env.ENV1.unsafe\\" should be an object but got \\"BAD\\"."
|
|
1932
|
+
`);
|
|
1933
|
+
});
|
|
1934
|
+
|
|
1935
|
+
it("should error if unsafe is a number", () => {
|
|
1936
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1937
|
+
{ env: { ENV1: { unsafe: 999 } } } as unknown as RawConfig,
|
|
1938
|
+
undefined
|
|
1939
|
+
);
|
|
1940
|
+
|
|
1941
|
+
expect(config.env.ENV1).toEqual(
|
|
1942
|
+
expect.not.objectContaining({ unsafe: expect.anything })
|
|
1943
|
+
);
|
|
1944
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
1945
|
+
"Processing wrangler configuration:
|
|
1946
|
+
|
|
1947
|
+
- \\"env.ENV1\\" environment configuration
|
|
1948
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
1949
|
+
`);
|
|
1950
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1951
|
+
"Processing wrangler configuration:
|
|
1952
|
+
|
|
1953
|
+
- \\"env.ENV1\\" environment configuration
|
|
1954
|
+
- The field \\"env.ENV1.unsafe\\" should be an object but got 999."
|
|
1955
|
+
`);
|
|
1956
|
+
});
|
|
1957
|
+
|
|
1958
|
+
it("should error if unsafe is null", () => {
|
|
1959
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1960
|
+
{ env: { ENV1: { unsafe: null } } } as unknown as RawConfig,
|
|
1961
|
+
undefined
|
|
1962
|
+
);
|
|
1963
|
+
|
|
1964
|
+
expect(config.env.ENV1).toEqual(
|
|
1965
|
+
expect.not.objectContaining({ unsafe: expect.anything })
|
|
1966
|
+
);
|
|
1967
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
1968
|
+
"Processing wrangler configuration:
|
|
1969
|
+
|
|
1970
|
+
- \\"env.ENV1\\" environment configuration
|
|
1971
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
1972
|
+
`);
|
|
1973
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1974
|
+
"Processing wrangler configuration:
|
|
1975
|
+
|
|
1976
|
+
- \\"env.ENV1\\" environment configuration
|
|
1977
|
+
- The field \\"env.ENV1.unsafe\\" should be an object but got null."
|
|
1978
|
+
`);
|
|
1979
|
+
});
|
|
1980
|
+
|
|
1981
|
+
it("should error if unsafe.bindings is not defined", () => {
|
|
1982
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1983
|
+
{ env: { ENV1: { unsafe: {} } } } as unknown as RawConfig,
|
|
1984
|
+
undefined
|
|
1985
|
+
);
|
|
1986
|
+
|
|
1987
|
+
expect(config.env.ENV1).toEqual(
|
|
1988
|
+
expect.not.objectContaining({ unsafe: expect.anything })
|
|
1989
|
+
);
|
|
1990
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
1991
|
+
"Processing wrangler configuration:
|
|
1992
|
+
|
|
1993
|
+
- \\"env.ENV1\\" environment configuration
|
|
1994
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
1995
|
+
`);
|
|
1996
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1997
|
+
"Processing wrangler configuration:
|
|
1998
|
+
|
|
1999
|
+
- \\"env.ENV1\\" environment configuration
|
|
2000
|
+
- The field \\"env.ENV1.unsafe\\" is missing the required \\"bindings\\" property."
|
|
2001
|
+
`);
|
|
2002
|
+
});
|
|
2003
|
+
|
|
2004
|
+
it("should error if unsafe.bindings is an object", () => {
|
|
2005
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
2006
|
+
{
|
|
2007
|
+
env: { ENV1: { unsafe: { bindings: {} } } },
|
|
2008
|
+
} as unknown as RawConfig,
|
|
2009
|
+
undefined
|
|
2010
|
+
);
|
|
2011
|
+
|
|
2012
|
+
expect(config.env.ENV1).toEqual(
|
|
2013
|
+
expect.not.objectContaining({
|
|
2014
|
+
unsafe: { bindings: expect.anything },
|
|
2015
|
+
})
|
|
2016
|
+
);
|
|
2017
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
2018
|
+
"Processing wrangler configuration:
|
|
2019
|
+
|
|
2020
|
+
- \\"env.ENV1\\" environment configuration
|
|
2021
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
2022
|
+
`);
|
|
2023
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
2024
|
+
"Processing wrangler configuration:
|
|
2025
|
+
|
|
2026
|
+
- \\"env.ENV1\\" environment configuration
|
|
2027
|
+
- The field \\"env.ENV1.unsafe.bindings\\" should be an array but got {}."
|
|
2028
|
+
`);
|
|
2029
|
+
});
|
|
2030
|
+
|
|
2031
|
+
it("should error if unsafe.bindings is a string", () => {
|
|
2032
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
2033
|
+
{
|
|
2034
|
+
env: { ENV1: { unsafe: { bindings: "BAD" } } },
|
|
2035
|
+
} as unknown as RawConfig,
|
|
2036
|
+
undefined
|
|
2037
|
+
);
|
|
2038
|
+
|
|
2039
|
+
expect(config.env.ENV1).toEqual(
|
|
2040
|
+
expect.not.objectContaining({
|
|
2041
|
+
unsafe: { bindings: expect.anything },
|
|
2042
|
+
})
|
|
2043
|
+
);
|
|
2044
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
2045
|
+
"Processing wrangler configuration:
|
|
2046
|
+
|
|
2047
|
+
- \\"env.ENV1\\" environment configuration
|
|
2048
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
2049
|
+
`);
|
|
2050
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
2051
|
+
"Processing wrangler configuration:
|
|
2052
|
+
|
|
2053
|
+
- \\"env.ENV1\\" environment configuration
|
|
2054
|
+
- The field \\"env.ENV1.unsafe.bindings\\" should be an array but got \\"BAD\\"."
|
|
2055
|
+
`);
|
|
2056
|
+
});
|
|
2057
|
+
|
|
2058
|
+
it("should error if unsafe.bindings is a number", () => {
|
|
2059
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
2060
|
+
{
|
|
2061
|
+
env: { ENV1: { unsafe: { bindings: 999 } } },
|
|
2062
|
+
} as unknown as RawConfig,
|
|
2063
|
+
undefined
|
|
2064
|
+
);
|
|
2065
|
+
|
|
2066
|
+
expect(config.env.ENV1).toEqual(
|
|
2067
|
+
expect.not.objectContaining({
|
|
2068
|
+
unsafe: { bindings: expect.anything },
|
|
2069
|
+
})
|
|
2070
|
+
);
|
|
2071
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
2072
|
+
"Processing wrangler configuration:
|
|
2073
|
+
|
|
2074
|
+
- \\"env.ENV1\\" environment configuration
|
|
2075
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
2076
|
+
`);
|
|
2077
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
2078
|
+
"Processing wrangler configuration:
|
|
2079
|
+
|
|
2080
|
+
- \\"env.ENV1\\" environment configuration
|
|
2081
|
+
- The field \\"env.ENV1.unsafe.bindings\\" should be an array but got 999."
|
|
2082
|
+
`);
|
|
2083
|
+
});
|
|
2084
|
+
|
|
2085
|
+
it("should error if unsafe.bindings is null", () => {
|
|
2086
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
2087
|
+
{
|
|
2088
|
+
env: { ENV1: { unsafe: { bindings: null } } },
|
|
2089
|
+
} as unknown as RawConfig,
|
|
2090
|
+
undefined
|
|
2091
|
+
);
|
|
2092
|
+
|
|
2093
|
+
expect(config.env.ENV1).toEqual(
|
|
2094
|
+
expect.not.objectContaining({
|
|
2095
|
+
unsafe: { bindings: expect.anything },
|
|
2096
|
+
})
|
|
2097
|
+
);
|
|
2098
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
2099
|
+
"Processing wrangler configuration:
|
|
2100
|
+
|
|
2101
|
+
- \\"env.ENV1\\" environment configuration
|
|
2102
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
2103
|
+
`);
|
|
2104
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
2105
|
+
"Processing wrangler configuration:
|
|
2106
|
+
|
|
2107
|
+
- \\"env.ENV1\\" environment configuration
|
|
2108
|
+
- The field \\"env.ENV1.unsafe.bindings\\" should be an array but got null."
|
|
2109
|
+
`);
|
|
2110
|
+
});
|
|
2111
|
+
|
|
2112
|
+
it("should error if unsafe.bindings are not valid", () => {
|
|
2113
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
2114
|
+
{
|
|
2115
|
+
env: {
|
|
2116
|
+
ENV1: {
|
|
2117
|
+
unsafe: {
|
|
2118
|
+
bindings: [
|
|
2119
|
+
{},
|
|
2120
|
+
{ name: "UNSAFE_BINDING_1" },
|
|
2121
|
+
{ name: 2666, type: 2777 },
|
|
2122
|
+
{
|
|
2123
|
+
name: "UNSAFE_BINDING_2",
|
|
2124
|
+
type: "UNSAFE_TYPE_2",
|
|
2125
|
+
extra: 2888,
|
|
2126
|
+
},
|
|
2127
|
+
],
|
|
2128
|
+
},
|
|
2129
|
+
},
|
|
2130
|
+
},
|
|
2131
|
+
} as unknown as RawConfig,
|
|
2132
|
+
undefined
|
|
2133
|
+
);
|
|
2134
|
+
|
|
2135
|
+
expect(config.env.ENV1).toEqual(
|
|
2136
|
+
expect.not.objectContaining({
|
|
2137
|
+
durable_objects: { bindings: expect.anything },
|
|
2138
|
+
})
|
|
2139
|
+
);
|
|
2140
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
2141
|
+
"Processing wrangler configuration:
|
|
2142
|
+
|
|
2143
|
+
- \\"env.ENV1\\" environment configuration
|
|
2144
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
2145
|
+
`);
|
|
2146
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
2147
|
+
"Processing wrangler configuration:
|
|
2148
|
+
|
|
2149
|
+
- \\"env.ENV1\\" environment configuration
|
|
2150
|
+
|
|
2151
|
+
- \\"env.ENV1.unsafe.bindings[0]\\": {}
|
|
2152
|
+
- binding should have a string \\"name\\" field.
|
|
2153
|
+
- binding should have a string \\"type\\" field.
|
|
2154
|
+
|
|
2155
|
+
- \\"env.ENV1.unsafe.bindings[1]\\": {\\"name\\":\\"UNSAFE_BINDING_1\\"}
|
|
2156
|
+
- binding should have a string \\"type\\" field.
|
|
2157
|
+
|
|
2158
|
+
- \\"env.ENV1.unsafe.bindings[2]\\": {\\"name\\":2666,\\"type\\":2777}
|
|
2159
|
+
- binding should have a string \\"name\\" field.
|
|
2160
|
+
- binding should have a string \\"type\\" field."
|
|
2161
|
+
`);
|
|
2162
|
+
});
|
|
2163
|
+
});
|
|
2164
|
+
|
|
2165
|
+
describe("(deprecated)", () => {
|
|
2166
|
+
it("should remove and warn about deprecated properties", () => {
|
|
2167
|
+
const environment: RawEnvironment = {
|
|
2168
|
+
zone_id: "ZONE_ID",
|
|
2169
|
+
experimental_services: [
|
|
2170
|
+
{
|
|
2171
|
+
name: "NAME",
|
|
2172
|
+
service: "SERVICE",
|
|
2173
|
+
environment: "ENV",
|
|
2174
|
+
},
|
|
2175
|
+
],
|
|
2176
|
+
};
|
|
2177
|
+
|
|
2178
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
2179
|
+
{
|
|
2180
|
+
env: {
|
|
2181
|
+
ENV1: environment,
|
|
2182
|
+
},
|
|
2183
|
+
},
|
|
2184
|
+
undefined
|
|
2185
|
+
);
|
|
2186
|
+
|
|
2187
|
+
expect("experimental_services" in config.env.ENV1).toBe(false);
|
|
2188
|
+
// Zone is not removed yet, since `route` commands might use it
|
|
2189
|
+
expect(config.env.ENV1.zone_id).toEqual("ZONE_ID");
|
|
2190
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
2191
|
+
expect(diagnostics.hasWarnings()).toBe(true);
|
|
2192
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
2193
|
+
"Processing wrangler configuration:
|
|
2194
|
+
|
|
2195
|
+
- \\"env.ENV1\\" environment configuration
|
|
2196
|
+
- DEPRECATION: \\"zone_id\\":
|
|
2197
|
+
This is unnecessary since we can deduce this from routes directly.
|
|
2198
|
+
- DEPRECATION: \\"experimental_services\\":
|
|
2199
|
+
The \\"experimental_services\\" field is no longer supported. Instead, use [[unsafe.bindings]] to enable experimental features. Add this to your wrangler.toml:
|
|
2200
|
+
\`\`\`
|
|
2201
|
+
[[unsafe.bindings]]
|
|
2202
|
+
name = \\"NAME\\"
|
|
2203
|
+
type = \\"service\\"
|
|
2204
|
+
service = \\"SERVICE\\"
|
|
2205
|
+
environment = \\"ENV\\"
|
|
2206
|
+
\`\`\`"
|
|
2207
|
+
`);
|
|
2208
|
+
});
|
|
2209
|
+
});
|
|
2210
|
+
});
|
|
2211
|
+
});
|
|
2212
|
+
|
|
2213
|
+
function normalizePath(text: string): string {
|
|
2214
|
+
return text
|
|
2215
|
+
.replace("project\\wrangler.toml", "project/wrangler.toml")
|
|
2216
|
+
.replace("src\\index.ts", "src/index.ts");
|
|
2217
|
+
}
|