wrangler 0.0.0-fb43821 → 0.0.0-fb53fda
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/bin/wrangler.js +12 -3
- package/miniflare-dist/index.mjs +79 -0
- package/miniflare-dist/index.mjs.map +7 -0
- package/package.json +46 -17
- package/pages/functions/buildWorker.ts +62 -0
- package/pages/functions/filepath-routing.test.ts +223 -0
- package/pages/functions/filepath-routing.ts +181 -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 +2790 -0
- package/src/__tests__/dev.test.tsx +532 -0
- package/src/__tests__/guess-worker-format.test.ts +68 -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 +48 -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 +33 -0
- package/src/__tests__/helpers/mock-stdin.ts +103 -0
- package/src/__tests__/helpers/mock-web-socket.ts +29 -0
- package/src/__tests__/helpers/run-in-tmp.ts +32 -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 +770 -209
- package/src/__tests__/jest.setup.ts +69 -0
- package/src/__tests__/kv.test.ts +1380 -0
- package/src/__tests__/logout.test.ts +52 -0
- package/src/__tests__/package-manager.test.ts +206 -0
- package/src/__tests__/pages.test.ts +82 -0
- package/src/__tests__/parse.test.ts +322 -0
- package/src/__tests__/publish.test.ts +3431 -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 +562 -0
- package/src/__tests__/whoami.test.tsx +100 -0
- package/src/bundle.ts +142 -0
- package/src/cfetch/index.ts +104 -0
- package/src/cfetch/internal.ts +139 -0
- package/src/cli.ts +16 -7
- package/src/config/README.md +107 -0
- package/src/config/config.ts +218 -0
- package/src/config/diagnostics.ts +80 -0
- package/src/config/environment.ts +366 -0
- package/src/config/index.ts +62 -0
- package/src/config/validation-helpers.ts +554 -0
- package/src/config/validation.ts +1191 -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 +390 -0
- package/src/dev/local.tsx +232 -0
- package/src/dev/remote.tsx +203 -0
- package/src/dev/use-esbuild.ts +100 -0
- package/src/dialogs.tsx +4 -4
- package/src/entry.ts +237 -0
- package/src/environment-variables.ts +33 -0
- package/src/https-options.ts +122 -0
- package/src/index.tsx +1417 -915
- package/src/inspect.ts +617 -0
- package/src/intl-polyfill.d.ts +139 -0
- package/src/kv.ts +319 -0
- package/src/miniflare-cli/README.md +30 -0
- package/src/miniflare-cli/enum-keys.ts +17 -0
- package/src/miniflare-cli/index.ts +37 -0
- package/src/module-collection.ts +229 -35
- package/src/open-in-browser.ts +25 -0
- package/src/package-manager.ts +126 -0
- package/src/pages.tsx +470 -227
- package/src/parse.ts +183 -0
- package/src/paths.ts +26 -0
- package/src/proxy.ts +440 -0
- package/src/publish.ts +292 -290
- package/src/r2.ts +50 -0
- package/src/reporting.ts +131 -0
- package/src/selfsigned.d.ts +29 -0
- package/src/sites.tsx +224 -59
- 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 +301 -203
- 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 +134241 -116339
- package/wrangler-dist/cli.js.map +3 -3
- package/src/__tests__/mock-cfetch.js +0 -42
- package/src/api/form_data.ts +0 -141
- package/src/api/inspect.ts +0 -430
- package/src/api/worker.ts +0 -161
- package/src/cfetch.ts +0 -72
- package/src/config.ts +0 -122
- package/src/dev.tsx +0 -776
- package/src/kv.tsx +0 -211
- package/src/tail.tsx +0 -71
|
@@ -0,0 +1,2790 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { normalizeAndValidateConfig } from "../config/validation";
|
|
3
|
+
import type {
|
|
4
|
+
ConfigFields,
|
|
5
|
+
RawDevConfig,
|
|
6
|
+
RawConfig,
|
|
7
|
+
RawEnvironment,
|
|
8
|
+
} from "../config";
|
|
9
|
+
|
|
10
|
+
describe("normalizeAndValidateConfig()", () => {
|
|
11
|
+
it("should use defaults for empty configuration", () => {
|
|
12
|
+
const { config, diagnostics } = normalizeAndValidateConfig({}, undefined, {
|
|
13
|
+
env: undefined,
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
expect(config).toEqual({
|
|
17
|
+
account_id: undefined,
|
|
18
|
+
build: {
|
|
19
|
+
command: undefined,
|
|
20
|
+
cwd: undefined,
|
|
21
|
+
watch_dir: undefined,
|
|
22
|
+
},
|
|
23
|
+
compatibility_date: undefined,
|
|
24
|
+
compatibility_flags: [],
|
|
25
|
+
configPath: undefined,
|
|
26
|
+
dev: {
|
|
27
|
+
ip: "localhost",
|
|
28
|
+
local_protocol: "http",
|
|
29
|
+
port: 8787,
|
|
30
|
+
upstream_protocol: "https",
|
|
31
|
+
host: undefined,
|
|
32
|
+
},
|
|
33
|
+
durable_objects: {
|
|
34
|
+
bindings: [],
|
|
35
|
+
},
|
|
36
|
+
jsx_factory: "React.createElement",
|
|
37
|
+
jsx_fragment: "React.Fragment",
|
|
38
|
+
kv_namespaces: [],
|
|
39
|
+
legacy_env: true,
|
|
40
|
+
main: undefined,
|
|
41
|
+
migrations: [],
|
|
42
|
+
name: undefined,
|
|
43
|
+
r2_buckets: [],
|
|
44
|
+
route: undefined,
|
|
45
|
+
routes: undefined,
|
|
46
|
+
rules: [],
|
|
47
|
+
site: undefined,
|
|
48
|
+
text_blobs: undefined,
|
|
49
|
+
triggers: {
|
|
50
|
+
crons: [],
|
|
51
|
+
},
|
|
52
|
+
unsafe: {
|
|
53
|
+
bindings: [],
|
|
54
|
+
},
|
|
55
|
+
usage_model: undefined,
|
|
56
|
+
vars: {},
|
|
57
|
+
wasm_modules: undefined,
|
|
58
|
+
workers_dev: undefined,
|
|
59
|
+
zone_id: undefined,
|
|
60
|
+
});
|
|
61
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
62
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
describe("top-level non-environment configuration", () => {
|
|
66
|
+
it("should override config defaults with provided values", () => {
|
|
67
|
+
const expectedConfig: Partial<ConfigFields<RawDevConfig>> = {
|
|
68
|
+
legacy_env: true,
|
|
69
|
+
dev: {
|
|
70
|
+
ip: "255.255.255.255",
|
|
71
|
+
port: 9999,
|
|
72
|
+
local_protocol: "https",
|
|
73
|
+
upstream_protocol: "http",
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
78
|
+
expectedConfig,
|
|
79
|
+
undefined,
|
|
80
|
+
{ env: undefined }
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
expect(config).toEqual(expect.objectContaining(expectedConfig));
|
|
84
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
85
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("should error on invalid top level fields", () => {
|
|
89
|
+
const expectedConfig = {
|
|
90
|
+
legacy_env: "FOO",
|
|
91
|
+
dev: {
|
|
92
|
+
ip: 222,
|
|
93
|
+
port: "FOO",
|
|
94
|
+
local_protocol: "wss",
|
|
95
|
+
upstream_protocol: "ws",
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
100
|
+
expectedConfig as unknown as RawConfig,
|
|
101
|
+
undefined,
|
|
102
|
+
{ env: undefined }
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
expect(config).toEqual(
|
|
106
|
+
expect.objectContaining({ ...expectedConfig, main: undefined })
|
|
107
|
+
);
|
|
108
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
109
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
110
|
+
"Processing wrangler configuration:
|
|
111
|
+
- Expected \\"legacy_env\\" to be of type boolean but got \\"FOO\\".
|
|
112
|
+
- Expected \\"dev.ip\\" to be of type string but got 222.
|
|
113
|
+
- Expected \\"dev.port\\" to be of type number but got \\"FOO\\".
|
|
114
|
+
- Expected \\"dev.local_protocol\\" field to be one of [\\"http\\",\\"https\\"] but got \\"wss\\".
|
|
115
|
+
- Expected \\"dev.upstream_protocol\\" field to be one of [\\"http\\",\\"https\\"] but got \\"ws\\"."
|
|
116
|
+
`);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("should warn on and remove unexpected top level fields", () => {
|
|
120
|
+
const expectedConfig = {
|
|
121
|
+
unexpected: {
|
|
122
|
+
subkey: "some-value",
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
127
|
+
expectedConfig as unknown as RawConfig,
|
|
128
|
+
undefined,
|
|
129
|
+
{ env: undefined }
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
expect("unexpected" in config).toBe(false);
|
|
133
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
134
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
135
|
+
"Processing wrangler configuration:
|
|
136
|
+
- Unexpected fields found in top-level field: \\"unexpected\\""
|
|
137
|
+
`);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it("should ignore `miniflare` top level fields", () => {
|
|
141
|
+
const expectedConfig = {
|
|
142
|
+
miniflare: {
|
|
143
|
+
host: "localhost",
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
148
|
+
expectedConfig as unknown as RawConfig,
|
|
149
|
+
undefined,
|
|
150
|
+
{ env: undefined }
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
expect("miniflare" in config).toBe(false);
|
|
154
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
155
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
156
|
+
"Processing wrangler configuration:
|
|
157
|
+
"
|
|
158
|
+
`);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("should override `migrations` config defaults with provided values", () => {
|
|
162
|
+
const expectedConfig: RawConfig = {
|
|
163
|
+
migrations: [
|
|
164
|
+
{
|
|
165
|
+
tag: "TAG",
|
|
166
|
+
new_classes: ["CLASS_1", "CLASS_2"],
|
|
167
|
+
renamed_classes: [
|
|
168
|
+
{
|
|
169
|
+
from: "FROM_CLASS",
|
|
170
|
+
to: "TO_CLASS",
|
|
171
|
+
},
|
|
172
|
+
],
|
|
173
|
+
deleted_classes: ["CLASS_3", "CLASS_4"],
|
|
174
|
+
},
|
|
175
|
+
],
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
179
|
+
expectedConfig,
|
|
180
|
+
undefined,
|
|
181
|
+
{ env: undefined }
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
expect(config).toEqual(expect.objectContaining(expectedConfig));
|
|
185
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
186
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("should error on invalid `migrations` values", () => {
|
|
190
|
+
const expectedConfig = {
|
|
191
|
+
migrations: [
|
|
192
|
+
{
|
|
193
|
+
tag: 111,
|
|
194
|
+
new_classes: [222, 333],
|
|
195
|
+
renamed_classes: [
|
|
196
|
+
{
|
|
197
|
+
from: 444,
|
|
198
|
+
to: 555,
|
|
199
|
+
},
|
|
200
|
+
],
|
|
201
|
+
deleted_classes: [666, 777],
|
|
202
|
+
},
|
|
203
|
+
],
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
207
|
+
expectedConfig as unknown as RawConfig,
|
|
208
|
+
undefined,
|
|
209
|
+
{ env: undefined }
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
expect(config).toEqual(expect.objectContaining(expectedConfig));
|
|
213
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
214
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
215
|
+
"Processing wrangler configuration:
|
|
216
|
+
- Expected \\"migrations[0].tag\\" to be of type string but got 111.
|
|
217
|
+
- Expected \\"migrations[0].new_classes.[0]\\" to be of type string but got 222.
|
|
218
|
+
- Expected \\"migrations[0].new_classes.[1]\\" to be of type string but got 333.
|
|
219
|
+
- Expected \\"migrations[0].renamed_classes\\" to be an array of \\"{from: string, to: string}\\" objects but got [{\\"from\\":444,\\"to\\":555}].
|
|
220
|
+
- Expected \\"migrations[0].deleted_classes.[0]\\" to be of type string but got 666.
|
|
221
|
+
- Expected \\"migrations[0].deleted_classes.[1]\\" to be of type string but got 777."
|
|
222
|
+
`);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
describe("site", () => {
|
|
226
|
+
it("should override `site` config defaults with provided values", () => {
|
|
227
|
+
const expectedConfig: RawConfig = {
|
|
228
|
+
site: {
|
|
229
|
+
bucket: "BUCKET",
|
|
230
|
+
include: ["INCLUDE_1", "INCLUDE_2"],
|
|
231
|
+
exclude: ["EXCLUDE_1", "EXCLUDE_2"],
|
|
232
|
+
},
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
236
|
+
expectedConfig,
|
|
237
|
+
undefined,
|
|
238
|
+
{ env: undefined }
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
expect(config).toEqual(expect.objectContaining(expectedConfig));
|
|
242
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
243
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it("should error if `site` config is missing `bucket`", () => {
|
|
247
|
+
const expectedConfig: RawConfig = {
|
|
248
|
+
// @ts-expect-error we're intentionally passing an invalid configuration here
|
|
249
|
+
site: {
|
|
250
|
+
include: ["INCLUDE_1", "INCLUDE_2"],
|
|
251
|
+
exclude: ["EXCLUDE_1", "EXCLUDE_2"],
|
|
252
|
+
},
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
256
|
+
expectedConfig,
|
|
257
|
+
undefined,
|
|
258
|
+
{ env: undefined }
|
|
259
|
+
);
|
|
260
|
+
|
|
261
|
+
expect(config).toEqual(expect.objectContaining(expectedConfig));
|
|
262
|
+
expect(diagnostics.hasErrors()).toBe(true);
|
|
263
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
264
|
+
"Processing wrangler configuration:
|
|
265
|
+
- \\"site.bucket\\" is a required field."
|
|
266
|
+
`);
|
|
267
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it("should error on invalid `site` values", () => {
|
|
271
|
+
const expectedConfig = {
|
|
272
|
+
site: {
|
|
273
|
+
bucket: "BUCKET",
|
|
274
|
+
include: [222, 333],
|
|
275
|
+
exclude: [444, 555],
|
|
276
|
+
},
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
280
|
+
expectedConfig as unknown as RawConfig,
|
|
281
|
+
undefined,
|
|
282
|
+
{ env: undefined }
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
expect(config).toEqual(expect.objectContaining(expectedConfig));
|
|
286
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
287
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
288
|
+
"Processing wrangler configuration:
|
|
289
|
+
- Expected \\"sites.include.[0]\\" to be of type string but got 222.
|
|
290
|
+
- Expected \\"sites.include.[1]\\" to be of type string but got 333.
|
|
291
|
+
- Expected \\"sites.exclude.[0]\\" to be of type string but got 444.
|
|
292
|
+
- Expected \\"sites.exclude.[1]\\" to be of type string but got 555."
|
|
293
|
+
`);
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
it("should error with a deprecation warning if entry-point is defined", async () => {
|
|
297
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
298
|
+
{
|
|
299
|
+
site: {
|
|
300
|
+
bucket: "some/path",
|
|
301
|
+
"entry-point": "some/other/script.js",
|
|
302
|
+
},
|
|
303
|
+
} as unknown as RawConfig,
|
|
304
|
+
undefined,
|
|
305
|
+
{ env: undefined }
|
|
306
|
+
);
|
|
307
|
+
|
|
308
|
+
expect(config.site).toMatchInlineSnapshot(`
|
|
309
|
+
Object {
|
|
310
|
+
"bucket": "some/path",
|
|
311
|
+
"exclude": Array [],
|
|
312
|
+
"include": Array [],
|
|
313
|
+
}
|
|
314
|
+
`);
|
|
315
|
+
expect(diagnostics.hasWarnings()).toBe(true);
|
|
316
|
+
expect(diagnostics.hasErrors()).toBe(true);
|
|
317
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
318
|
+
"Processing wrangler configuration:
|
|
319
|
+
- Unexpected fields found in site field: \\"entry-point\\""
|
|
320
|
+
`);
|
|
321
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
322
|
+
"Processing wrangler configuration:
|
|
323
|
+
- DEPRECATION: \\"site.entry-point\\":
|
|
324
|
+
The \`site.entry-point\` config field is no longer used.
|
|
325
|
+
The entry-point should be specified via the command line or the \`main\` config field."
|
|
326
|
+
`);
|
|
327
|
+
});
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
it("should map `wasm_module` paths from relative to the config path to relative to the cwd", () => {
|
|
331
|
+
const expectedConfig: RawConfig = {
|
|
332
|
+
wasm_modules: {
|
|
333
|
+
MODULE_1: "path/to/module_1.mjs",
|
|
334
|
+
MODULE_2: "module_2.mjs",
|
|
335
|
+
},
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
339
|
+
expectedConfig,
|
|
340
|
+
"project/wrangler.toml",
|
|
341
|
+
{ env: undefined }
|
|
342
|
+
);
|
|
343
|
+
|
|
344
|
+
expect(config).toEqual(
|
|
345
|
+
expect.objectContaining({
|
|
346
|
+
wasm_modules: {
|
|
347
|
+
MODULE_1: path.normalize("project/path/to/module_1.mjs"),
|
|
348
|
+
MODULE_2: path.normalize("project/module_2.mjs"),
|
|
349
|
+
},
|
|
350
|
+
})
|
|
351
|
+
);
|
|
352
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
353
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
it("should error on invalid `wasm_module` paths", () => {
|
|
357
|
+
const expectedConfig = {
|
|
358
|
+
wasm_modules: {
|
|
359
|
+
MODULE_1: 111,
|
|
360
|
+
MODULE_2: 222,
|
|
361
|
+
},
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
365
|
+
expectedConfig as unknown as RawConfig,
|
|
366
|
+
"project/wrangler.toml",
|
|
367
|
+
{ env: undefined }
|
|
368
|
+
);
|
|
369
|
+
|
|
370
|
+
expect(config).toEqual(
|
|
371
|
+
expect.objectContaining({
|
|
372
|
+
wasm_modules: {},
|
|
373
|
+
})
|
|
374
|
+
);
|
|
375
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
376
|
+
expect(normalizePath(diagnostics.renderErrors())).toMatchInlineSnapshot(`
|
|
377
|
+
"Processing project/wrangler.toml configuration:
|
|
378
|
+
- Expected \\"wasm_modules['MODULE_1']\\" to be of type string but got 111.
|
|
379
|
+
- Expected \\"wasm_modules['MODULE_2']\\" to be of type string but got 222."
|
|
380
|
+
`);
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
it("should map `text_blobs` paths from relative to the config path to relative to the cwd", () => {
|
|
384
|
+
const expectedConfig: RawConfig = {
|
|
385
|
+
text_blobs: {
|
|
386
|
+
BLOB_1: "path/to/text1.txt",
|
|
387
|
+
BLOB_2: "text2.md",
|
|
388
|
+
},
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
392
|
+
expectedConfig,
|
|
393
|
+
"project/wrangler.toml",
|
|
394
|
+
{ env: undefined }
|
|
395
|
+
);
|
|
396
|
+
|
|
397
|
+
expect(config).toEqual(
|
|
398
|
+
expect.objectContaining({
|
|
399
|
+
text_blobs: {
|
|
400
|
+
BLOB_1: path.normalize("project/path/to/text1.txt"),
|
|
401
|
+
BLOB_2: path.normalize("project/text2.md"),
|
|
402
|
+
},
|
|
403
|
+
})
|
|
404
|
+
);
|
|
405
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
406
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
it("should error on invalid `text_blob` paths", () => {
|
|
410
|
+
const expectedConfig = {
|
|
411
|
+
text_blobs: {
|
|
412
|
+
MODULE_1: 111,
|
|
413
|
+
MODULE_2: 222,
|
|
414
|
+
},
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
418
|
+
expectedConfig as unknown as RawConfig,
|
|
419
|
+
"project/wrangler.toml",
|
|
420
|
+
{ env: undefined }
|
|
421
|
+
);
|
|
422
|
+
|
|
423
|
+
expect(config).toEqual(
|
|
424
|
+
expect.objectContaining({
|
|
425
|
+
text_blobs: {},
|
|
426
|
+
})
|
|
427
|
+
);
|
|
428
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
429
|
+
expect(normalizePath(diagnostics.renderErrors())).toMatchInlineSnapshot(`
|
|
430
|
+
"Processing project/wrangler.toml configuration:
|
|
431
|
+
- Expected \\"text_blobs['MODULE_1']\\" to be of type string but got 111.
|
|
432
|
+
- Expected \\"text_blobs['MODULE_2']\\" to be of type string but got 222."
|
|
433
|
+
`);
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
describe("(deprecated)", () => {
|
|
437
|
+
it("should remove and warn about deprecated properties", () => {
|
|
438
|
+
const rawConfig: RawConfig = {
|
|
439
|
+
type: "webpack",
|
|
440
|
+
webpack_config: "CONFIG",
|
|
441
|
+
};
|
|
442
|
+
|
|
443
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
444
|
+
rawConfig,
|
|
445
|
+
undefined,
|
|
446
|
+
{ env: undefined }
|
|
447
|
+
);
|
|
448
|
+
|
|
449
|
+
// Note the `.not.` here...
|
|
450
|
+
expect(config).toEqual(
|
|
451
|
+
expect.not.objectContaining({
|
|
452
|
+
type: expect.anything(),
|
|
453
|
+
webpack_config: expect.anything(),
|
|
454
|
+
})
|
|
455
|
+
);
|
|
456
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
457
|
+
expect(diagnostics.hasWarnings()).toBe(true);
|
|
458
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
459
|
+
"Processing wrangler configuration:
|
|
460
|
+
- DEPRECATION: \\"type\\":
|
|
461
|
+
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.
|
|
462
|
+
- DEPRECATION: \\"webpack_config\\":
|
|
463
|
+
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."
|
|
464
|
+
`);
|
|
465
|
+
});
|
|
466
|
+
});
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
describe("top-level environment configuration", () => {
|
|
470
|
+
it("should override config defaults with provided values", () => {
|
|
471
|
+
const main = "src/index.ts";
|
|
472
|
+
const resolvedMain = path.resolve(process.cwd(), main);
|
|
473
|
+
|
|
474
|
+
const expectedConfig: RawEnvironment = {
|
|
475
|
+
name: "NAME",
|
|
476
|
+
account_id: "ACCOUNT_ID",
|
|
477
|
+
compatibility_date: "2022-01-01",
|
|
478
|
+
compatibility_flags: ["FLAG1", "FLAG2"],
|
|
479
|
+
workers_dev: false,
|
|
480
|
+
routes: ["ROUTE_1", "ROUTE_2"],
|
|
481
|
+
jsx_factory: "JSX_FACTORY",
|
|
482
|
+
jsx_fragment: "JSX_FRAGMENT",
|
|
483
|
+
triggers: { crons: ["CRON_1", "CRON_2"] },
|
|
484
|
+
usage_model: "bundled",
|
|
485
|
+
main,
|
|
486
|
+
build: {
|
|
487
|
+
command: "COMMAND",
|
|
488
|
+
cwd: "CWD",
|
|
489
|
+
watch_dir: "WATCH_DIR",
|
|
490
|
+
},
|
|
491
|
+
vars: {
|
|
492
|
+
VAR1: "VALUE_1",
|
|
493
|
+
VAR2: "VALUE_2",
|
|
494
|
+
},
|
|
495
|
+
durable_objects: {
|
|
496
|
+
bindings: [
|
|
497
|
+
{ name: "DO_BINDING_1", class_name: "CLASS1" },
|
|
498
|
+
{
|
|
499
|
+
name: "DO_BINDING_2",
|
|
500
|
+
class_name: "CLASS2",
|
|
501
|
+
script_name: "SCRIPT2",
|
|
502
|
+
},
|
|
503
|
+
],
|
|
504
|
+
},
|
|
505
|
+
kv_namespaces: [
|
|
506
|
+
{ binding: "KV_BINDING_1", id: "KV_ID_1" },
|
|
507
|
+
{
|
|
508
|
+
binding: "KV_BINDING_2",
|
|
509
|
+
id: "KV_ID_2",
|
|
510
|
+
preview_id: "KV_PREVIEW_1",
|
|
511
|
+
},
|
|
512
|
+
],
|
|
513
|
+
r2_buckets: [
|
|
514
|
+
{ binding: "R2_BINDING_1", bucket_name: "R2_BUCKET_1" },
|
|
515
|
+
{
|
|
516
|
+
binding: "R2_BINDING_2",
|
|
517
|
+
bucket_name: "R2_BUCKET_2",
|
|
518
|
+
preview_bucket_name: "R2_PREVIEW_2",
|
|
519
|
+
},
|
|
520
|
+
],
|
|
521
|
+
unsafe: {
|
|
522
|
+
bindings: [
|
|
523
|
+
{ name: "UNSAFE_BINDING_1", type: "UNSAFE_TYPE_1" },
|
|
524
|
+
{
|
|
525
|
+
name: "UNSAFE_BINDING_2",
|
|
526
|
+
type: "UNSAFE_TYPE_2",
|
|
527
|
+
extra: "UNSAFE_EXTRA_1",
|
|
528
|
+
},
|
|
529
|
+
],
|
|
530
|
+
},
|
|
531
|
+
};
|
|
532
|
+
|
|
533
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
534
|
+
expectedConfig,
|
|
535
|
+
undefined,
|
|
536
|
+
{ env: undefined }
|
|
537
|
+
);
|
|
538
|
+
|
|
539
|
+
expect(config).toEqual(
|
|
540
|
+
expect.objectContaining({ ...expectedConfig, main: resolvedMain })
|
|
541
|
+
);
|
|
542
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
543
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
544
|
+
"Processing wrangler configuration:
|
|
545
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
546
|
+
`);
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
it("should error on invalid environment values", () => {
|
|
550
|
+
const expectedConfig: RawEnvironment = {
|
|
551
|
+
name: 111,
|
|
552
|
+
account_id: 222,
|
|
553
|
+
compatibility_date: 333,
|
|
554
|
+
compatibility_flags: [444, 555],
|
|
555
|
+
workers_dev: "BAD",
|
|
556
|
+
routes: [666, 777],
|
|
557
|
+
route: 888,
|
|
558
|
+
jsx_factory: 999,
|
|
559
|
+
jsx_fragment: 1000,
|
|
560
|
+
triggers: { crons: [1111, 1222] },
|
|
561
|
+
usage_model: "INVALID",
|
|
562
|
+
main: 1333,
|
|
563
|
+
build: {
|
|
564
|
+
command: 1444,
|
|
565
|
+
cwd: 1555,
|
|
566
|
+
watch_dir: 1666,
|
|
567
|
+
},
|
|
568
|
+
} as unknown as RawEnvironment;
|
|
569
|
+
|
|
570
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
571
|
+
expectedConfig,
|
|
572
|
+
undefined,
|
|
573
|
+
{ env: undefined }
|
|
574
|
+
);
|
|
575
|
+
|
|
576
|
+
expect(config).toEqual(expect.objectContaining(expectedConfig));
|
|
577
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
578
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
579
|
+
"Processing wrangler configuration:
|
|
580
|
+
- Expected \\"route\\" to be of type string but got 888.
|
|
581
|
+
- Expected \\"routes\\" to be of type string array but got [666,777].
|
|
582
|
+
- Expected exactly one of the following fields [\\"routes\\",\\"route\\"].
|
|
583
|
+
- Expected \\"workers_dev\\" to be of type boolean but got \\"BAD\\".
|
|
584
|
+
- Expected \\"build.command\\" to be of type string but got 1444.
|
|
585
|
+
- Expected \\"build.cwd\\" to be of type string but got 1555.
|
|
586
|
+
- Expected \\"build.watch_dir\\" to be of type string but got 1666.
|
|
587
|
+
- Expected \\"account_id\\" to be of type string but got 222.
|
|
588
|
+
- Expected \\"compatibility_date\\" to be of type string but got 333.
|
|
589
|
+
- Expected \\"compatibility_flags\\" to be of type string array but got [444,555].
|
|
590
|
+
- Expected \\"jsx_factory\\" to be of type string but got 999.
|
|
591
|
+
- Expected \\"jsx_fragment\\" to be of type string but got 1000.
|
|
592
|
+
- Expected \\"name\\" to be of type string but got 111.
|
|
593
|
+
- Expected \\"main\\" to be of type string but got 1333.
|
|
594
|
+
- Expected \\"usage_model\\" field to be one of [\\"bundled\\",\\"unbound\\"] but got \\"INVALID\\"."
|
|
595
|
+
`);
|
|
596
|
+
});
|
|
597
|
+
|
|
598
|
+
it("should override build.upload config defaults with provided values and warn about deprecations", () => {
|
|
599
|
+
const expectedConfig: RawEnvironment = {
|
|
600
|
+
build: {
|
|
601
|
+
upload: {
|
|
602
|
+
dir: "src",
|
|
603
|
+
format: "modules",
|
|
604
|
+
main: "index.ts",
|
|
605
|
+
rules: [{ type: "Text", globs: ["GLOB"], fallthrough: true }],
|
|
606
|
+
},
|
|
607
|
+
},
|
|
608
|
+
};
|
|
609
|
+
|
|
610
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
611
|
+
expectedConfig,
|
|
612
|
+
path.resolve("project/wrangler.toml"),
|
|
613
|
+
{ env: undefined }
|
|
614
|
+
);
|
|
615
|
+
|
|
616
|
+
expect(config.main).toEqual(path.resolve("project/src/index.ts"));
|
|
617
|
+
expect(config.build.upload).toBeUndefined();
|
|
618
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
619
|
+
expect(diagnostics.hasWarnings()).toBe(true);
|
|
620
|
+
expect(normalizePath(diagnostics.renderWarnings()))
|
|
621
|
+
.toMatchInlineSnapshot(`
|
|
622
|
+
"Processing project/wrangler.toml configuration:
|
|
623
|
+
- DEPRECATION: \\"build.upload.format\\":
|
|
624
|
+
The format is inferred automatically from the code.
|
|
625
|
+
- DEPRECATION: \\"build.upload.main\\":
|
|
626
|
+
Delete the \`build.upload.main\` and \`build.upload.dir\` fields.
|
|
627
|
+
Then add the top level \`main\` field to your configuration file:
|
|
628
|
+
\`\`\`
|
|
629
|
+
main = \\"src/index.ts\\"
|
|
630
|
+
\`\`\`
|
|
631
|
+
- DEPRECATION: \\"build.upload.dir\\":
|
|
632
|
+
Use the top level \\"main\\" field or a command-line argument to specify the entry-point for the Worker.
|
|
633
|
+
- 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:
|
|
634
|
+
\`\`\`
|
|
635
|
+
[[rules]]
|
|
636
|
+
type = \\"Text\\"
|
|
637
|
+
globs = [ \\"GLOB\\" ]
|
|
638
|
+
fallthrough = true
|
|
639
|
+
\`\`\`"
|
|
640
|
+
`);
|
|
641
|
+
});
|
|
642
|
+
|
|
643
|
+
it("should default custom build watch directories to src", () => {
|
|
644
|
+
const expectedConfig: RawEnvironment = {
|
|
645
|
+
build: {
|
|
646
|
+
command: "execute some --build",
|
|
647
|
+
},
|
|
648
|
+
};
|
|
649
|
+
|
|
650
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
651
|
+
expectedConfig,
|
|
652
|
+
undefined,
|
|
653
|
+
{ env: undefined }
|
|
654
|
+
);
|
|
655
|
+
|
|
656
|
+
expect(config.build).toEqual(
|
|
657
|
+
expect.objectContaining({
|
|
658
|
+
command: "execute some --build",
|
|
659
|
+
watch_dir: "./src",
|
|
660
|
+
})
|
|
661
|
+
);
|
|
662
|
+
|
|
663
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
664
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
665
|
+
});
|
|
666
|
+
|
|
667
|
+
it("should resolve custom build watch directories relative to wrangler.toml", async () => {
|
|
668
|
+
const expectedConfig: RawEnvironment = {
|
|
669
|
+
build: {
|
|
670
|
+
command: "execute some --build",
|
|
671
|
+
watch_dir: "some/path",
|
|
672
|
+
},
|
|
673
|
+
};
|
|
674
|
+
|
|
675
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
676
|
+
expectedConfig,
|
|
677
|
+
"project/wrangler.toml",
|
|
678
|
+
{ env: undefined }
|
|
679
|
+
);
|
|
680
|
+
|
|
681
|
+
expect(config.build).toEqual(
|
|
682
|
+
expect.objectContaining({
|
|
683
|
+
command: "execute some --build",
|
|
684
|
+
watch_dir: path.normalize("project/some/path"),
|
|
685
|
+
})
|
|
686
|
+
);
|
|
687
|
+
|
|
688
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
689
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
690
|
+
});
|
|
691
|
+
|
|
692
|
+
describe("durable_objects field", () => {
|
|
693
|
+
it("should error if durable_objects is an array", () => {
|
|
694
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
695
|
+
{ durable_objects: [] } as unknown as RawConfig,
|
|
696
|
+
undefined,
|
|
697
|
+
{ env: undefined }
|
|
698
|
+
);
|
|
699
|
+
|
|
700
|
+
expect(config).toEqual(
|
|
701
|
+
expect.not.objectContaining({ durable_objects: expect.anything })
|
|
702
|
+
);
|
|
703
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
704
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
705
|
+
"Processing wrangler configuration:
|
|
706
|
+
- The field \\"durable_objects\\" should be an object but got []."
|
|
707
|
+
`);
|
|
708
|
+
});
|
|
709
|
+
|
|
710
|
+
it("should error if durable_objects is a string", () => {
|
|
711
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
712
|
+
{ durable_objects: "BAD" } as unknown as RawConfig,
|
|
713
|
+
undefined,
|
|
714
|
+
{ env: undefined }
|
|
715
|
+
);
|
|
716
|
+
|
|
717
|
+
expect(config).toEqual(
|
|
718
|
+
expect.not.objectContaining({ durable_objects: expect.anything })
|
|
719
|
+
);
|
|
720
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
721
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
722
|
+
"Processing wrangler configuration:
|
|
723
|
+
- The field \\"durable_objects\\" should be an object but got \\"BAD\\"."
|
|
724
|
+
`);
|
|
725
|
+
});
|
|
726
|
+
|
|
727
|
+
it("should error if durable_objects is a number", () => {
|
|
728
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
729
|
+
{ durable_objects: 999 } as unknown as RawConfig,
|
|
730
|
+
undefined,
|
|
731
|
+
{ env: undefined }
|
|
732
|
+
);
|
|
733
|
+
|
|
734
|
+
expect(config).toEqual(
|
|
735
|
+
expect.not.objectContaining({ durable_objects: expect.anything })
|
|
736
|
+
);
|
|
737
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
738
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
739
|
+
"Processing wrangler configuration:
|
|
740
|
+
- The field \\"durable_objects\\" should be an object but got 999."
|
|
741
|
+
`);
|
|
742
|
+
});
|
|
743
|
+
|
|
744
|
+
it("should error if durable_objects is null", () => {
|
|
745
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
746
|
+
{ durable_objects: null } as unknown as RawConfig,
|
|
747
|
+
undefined,
|
|
748
|
+
{ env: undefined }
|
|
749
|
+
);
|
|
750
|
+
|
|
751
|
+
expect(config).toEqual(
|
|
752
|
+
expect.not.objectContaining({ durable_objects: expect.anything })
|
|
753
|
+
);
|
|
754
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
755
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
756
|
+
"Processing wrangler configuration:
|
|
757
|
+
- The field \\"durable_objects\\" should be an object but got null."
|
|
758
|
+
`);
|
|
759
|
+
});
|
|
760
|
+
|
|
761
|
+
it("should error if durable_objects.bindings is not defined", () => {
|
|
762
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
763
|
+
{ durable_objects: {} } as unknown as RawConfig,
|
|
764
|
+
undefined,
|
|
765
|
+
{ env: undefined }
|
|
766
|
+
);
|
|
767
|
+
|
|
768
|
+
expect(config).toEqual(
|
|
769
|
+
expect.not.objectContaining({ durable_objects: expect.anything })
|
|
770
|
+
);
|
|
771
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
772
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
773
|
+
"Processing wrangler configuration:
|
|
774
|
+
- The field \\"durable_objects\\" is missing the required \\"bindings\\" property."
|
|
775
|
+
`);
|
|
776
|
+
});
|
|
777
|
+
|
|
778
|
+
it("should error if durable_objects.bindings is an object", () => {
|
|
779
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
780
|
+
{ durable_objects: { bindings: {} } } as unknown as RawConfig,
|
|
781
|
+
undefined,
|
|
782
|
+
{ env: undefined }
|
|
783
|
+
);
|
|
784
|
+
|
|
785
|
+
expect(config).toEqual(
|
|
786
|
+
expect.not.objectContaining({
|
|
787
|
+
durable_objects: { bindings: expect.anything },
|
|
788
|
+
})
|
|
789
|
+
);
|
|
790
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
791
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
792
|
+
"Processing wrangler configuration:
|
|
793
|
+
- The field \\"durable_objects.bindings\\" should be an array but got {}."
|
|
794
|
+
`);
|
|
795
|
+
});
|
|
796
|
+
|
|
797
|
+
it("should error if durable_objects.bindings is a string", () => {
|
|
798
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
799
|
+
{ durable_objects: { bindings: "BAD" } } as unknown as RawConfig,
|
|
800
|
+
undefined,
|
|
801
|
+
{ env: undefined }
|
|
802
|
+
);
|
|
803
|
+
|
|
804
|
+
expect(config).toEqual(
|
|
805
|
+
expect.not.objectContaining({
|
|
806
|
+
durable_objects: { bindings: expect.anything },
|
|
807
|
+
})
|
|
808
|
+
);
|
|
809
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
810
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
811
|
+
"Processing wrangler configuration:
|
|
812
|
+
- The field \\"durable_objects.bindings\\" should be an array but got \\"BAD\\"."
|
|
813
|
+
`);
|
|
814
|
+
});
|
|
815
|
+
|
|
816
|
+
it("should error if durable_objects.bindings is a number", () => {
|
|
817
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
818
|
+
{ durable_objects: { bindings: 999 } } as unknown as RawConfig,
|
|
819
|
+
undefined,
|
|
820
|
+
{ env: undefined }
|
|
821
|
+
);
|
|
822
|
+
|
|
823
|
+
expect(config).toEqual(
|
|
824
|
+
expect.not.objectContaining({
|
|
825
|
+
durable_objects: { bindings: expect.anything },
|
|
826
|
+
})
|
|
827
|
+
);
|
|
828
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
829
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
830
|
+
"Processing wrangler configuration:
|
|
831
|
+
- The field \\"durable_objects.bindings\\" should be an array but got 999."
|
|
832
|
+
`);
|
|
833
|
+
});
|
|
834
|
+
|
|
835
|
+
it("should error if durable_objects.bindings is null", () => {
|
|
836
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
837
|
+
{ durable_objects: { bindings: null } } as unknown as RawConfig,
|
|
838
|
+
undefined,
|
|
839
|
+
{ env: undefined }
|
|
840
|
+
);
|
|
841
|
+
|
|
842
|
+
expect(config).toEqual(
|
|
843
|
+
expect.not.objectContaining({
|
|
844
|
+
durable_objects: { bindings: expect.anything },
|
|
845
|
+
})
|
|
846
|
+
);
|
|
847
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
848
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
849
|
+
"Processing wrangler configuration:
|
|
850
|
+
- The field \\"durable_objects.bindings\\" should be an array but got null."
|
|
851
|
+
`);
|
|
852
|
+
});
|
|
853
|
+
|
|
854
|
+
it("should error if durable_objects.bindings are not valid", () => {
|
|
855
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
856
|
+
{
|
|
857
|
+
durable_objects: {
|
|
858
|
+
bindings: [
|
|
859
|
+
{},
|
|
860
|
+
{ name: "VALID" },
|
|
861
|
+
{ name: 1555, class_name: 1666 },
|
|
862
|
+
{
|
|
863
|
+
name: 1777,
|
|
864
|
+
class_name: 1888,
|
|
865
|
+
script_name: 1999,
|
|
866
|
+
},
|
|
867
|
+
],
|
|
868
|
+
},
|
|
869
|
+
} as unknown as RawConfig,
|
|
870
|
+
undefined,
|
|
871
|
+
{ env: undefined }
|
|
872
|
+
);
|
|
873
|
+
|
|
874
|
+
expect(config).toEqual(
|
|
875
|
+
expect.not.objectContaining({
|
|
876
|
+
durable_objects: { bindings: expect.anything },
|
|
877
|
+
})
|
|
878
|
+
);
|
|
879
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
880
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
881
|
+
"Processing wrangler configuration:
|
|
882
|
+
|
|
883
|
+
- \\"durable_objects.bindings[0]\\": {}
|
|
884
|
+
- binding should have a string \\"name\\" field.
|
|
885
|
+
- binding should have a string \\"class_name\\" field.
|
|
886
|
+
|
|
887
|
+
- \\"durable_objects.bindings[1]\\": {\\"name\\":\\"VALID\\"}
|
|
888
|
+
- binding should have a string \\"class_name\\" field.
|
|
889
|
+
|
|
890
|
+
- \\"durable_objects.bindings[2]\\": {\\"name\\":1555,\\"class_name\\":1666}
|
|
891
|
+
- binding should have a string \\"name\\" field.
|
|
892
|
+
- binding should have a string \\"class_name\\" field.
|
|
893
|
+
|
|
894
|
+
- \\"durable_objects.bindings[3]\\": {\\"name\\":1777,\\"class_name\\":1888,\\"script_name\\":1999}
|
|
895
|
+
- binding should have a string \\"name\\" field.
|
|
896
|
+
- binding should have a string \\"class_name\\" field.
|
|
897
|
+
- binding should, optionally, have a string \\"script_name\\" field."
|
|
898
|
+
`);
|
|
899
|
+
});
|
|
900
|
+
});
|
|
901
|
+
|
|
902
|
+
describe("kv_namespaces field", () => {
|
|
903
|
+
it("should error if kv_namespaces is an object", () => {
|
|
904
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
905
|
+
{ kv_namespaces: {} } as unknown as RawConfig,
|
|
906
|
+
undefined,
|
|
907
|
+
{ env: undefined }
|
|
908
|
+
);
|
|
909
|
+
|
|
910
|
+
expect(config).toEqual(
|
|
911
|
+
expect.not.objectContaining({ kv_namespaces: expect.anything })
|
|
912
|
+
);
|
|
913
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
914
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
915
|
+
"Processing wrangler configuration:
|
|
916
|
+
- The field \\"kv_namespaces\\" should be an array but got {}."
|
|
917
|
+
`);
|
|
918
|
+
});
|
|
919
|
+
|
|
920
|
+
it("should error if kv_namespaces is a string", () => {
|
|
921
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
922
|
+
{ kv_namespaces: "BAD" } as unknown as RawConfig,
|
|
923
|
+
undefined,
|
|
924
|
+
{ env: undefined }
|
|
925
|
+
);
|
|
926
|
+
|
|
927
|
+
expect(config).toEqual(
|
|
928
|
+
expect.not.objectContaining({ kv_namespaces: expect.anything })
|
|
929
|
+
);
|
|
930
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
931
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
932
|
+
"Processing wrangler configuration:
|
|
933
|
+
- The field \\"kv_namespaces\\" should be an array but got \\"BAD\\"."
|
|
934
|
+
`);
|
|
935
|
+
});
|
|
936
|
+
|
|
937
|
+
it("should error if kv_namespaces is a number", () => {
|
|
938
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
939
|
+
{ kv_namespaces: 999 } as unknown as RawConfig,
|
|
940
|
+
undefined,
|
|
941
|
+
{ env: undefined }
|
|
942
|
+
);
|
|
943
|
+
|
|
944
|
+
expect(config).toEqual(
|
|
945
|
+
expect.not.objectContaining({ kv_namespaces: expect.anything })
|
|
946
|
+
);
|
|
947
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
948
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
949
|
+
"Processing wrangler configuration:
|
|
950
|
+
- The field \\"kv_namespaces\\" should be an array but got 999."
|
|
951
|
+
`);
|
|
952
|
+
});
|
|
953
|
+
|
|
954
|
+
it("should error if kv_namespaces is null", () => {
|
|
955
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
956
|
+
{ kv_namespaces: null } as unknown as RawConfig,
|
|
957
|
+
undefined,
|
|
958
|
+
{ env: undefined }
|
|
959
|
+
);
|
|
960
|
+
|
|
961
|
+
expect(config).toEqual(
|
|
962
|
+
expect.not.objectContaining({ kv_namespaces: expect.anything })
|
|
963
|
+
);
|
|
964
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
965
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
966
|
+
"Processing wrangler configuration:
|
|
967
|
+
- The field \\"kv_namespaces\\" should be an array but got null."
|
|
968
|
+
`);
|
|
969
|
+
});
|
|
970
|
+
|
|
971
|
+
it("should error if kv_namespaces.bindings are not valid", () => {
|
|
972
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
973
|
+
{
|
|
974
|
+
kv_namespaces: [
|
|
975
|
+
{},
|
|
976
|
+
{ binding: "VALID" },
|
|
977
|
+
{ binding: 2000, id: 2111 },
|
|
978
|
+
{
|
|
979
|
+
binding: "KV_BINDING_2",
|
|
980
|
+
id: "KV_ID_2",
|
|
981
|
+
preview_id: 2222,
|
|
982
|
+
},
|
|
983
|
+
],
|
|
984
|
+
} as unknown as RawConfig,
|
|
985
|
+
undefined,
|
|
986
|
+
{ env: undefined }
|
|
987
|
+
);
|
|
988
|
+
|
|
989
|
+
expect(config).toEqual(
|
|
990
|
+
expect.not.objectContaining({
|
|
991
|
+
kv_namespaces: { bindings: expect.anything },
|
|
992
|
+
})
|
|
993
|
+
);
|
|
994
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
995
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
996
|
+
"Processing wrangler configuration:
|
|
997
|
+
- \\"kv_namespaces[0]\\" bindings should have a string \\"binding\\" field but got {}.
|
|
998
|
+
- \\"kv_namespaces[0]\\" bindings should have a string \\"id\\" field but got {}.
|
|
999
|
+
- \\"kv_namespaces[1]\\" bindings should have a string \\"id\\" field but got {\\"binding\\":\\"VALID\\"}.
|
|
1000
|
+
- \\"kv_namespaces[2]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":2000,\\"id\\":2111}.
|
|
1001
|
+
- \\"kv_namespaces[2]\\" bindings should have a string \\"id\\" field but got {\\"binding\\":2000,\\"id\\":2111}.
|
|
1002
|
+
- \\"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}."
|
|
1003
|
+
`);
|
|
1004
|
+
});
|
|
1005
|
+
});
|
|
1006
|
+
|
|
1007
|
+
describe("r2_buckets field", () => {
|
|
1008
|
+
it("should error if r2_buckets is an object", () => {
|
|
1009
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1010
|
+
{ r2_buckets: {} } as unknown as RawConfig,
|
|
1011
|
+
undefined,
|
|
1012
|
+
{ env: undefined }
|
|
1013
|
+
);
|
|
1014
|
+
|
|
1015
|
+
expect(config).toEqual(
|
|
1016
|
+
expect.not.objectContaining({ r2_buckets: expect.anything })
|
|
1017
|
+
);
|
|
1018
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1019
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1020
|
+
"Processing wrangler configuration:
|
|
1021
|
+
- The field \\"r2_buckets\\" should be an array but got {}."
|
|
1022
|
+
`);
|
|
1023
|
+
});
|
|
1024
|
+
|
|
1025
|
+
it("should error if r2_buckets is a string", () => {
|
|
1026
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1027
|
+
{ r2_buckets: "BAD" } as unknown as RawConfig,
|
|
1028
|
+
undefined,
|
|
1029
|
+
{ env: undefined }
|
|
1030
|
+
);
|
|
1031
|
+
|
|
1032
|
+
expect(config).toEqual(
|
|
1033
|
+
expect.not.objectContaining({ r2_buckets: expect.anything })
|
|
1034
|
+
);
|
|
1035
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1036
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1037
|
+
"Processing wrangler configuration:
|
|
1038
|
+
- The field \\"r2_buckets\\" should be an array but got \\"BAD\\"."
|
|
1039
|
+
`);
|
|
1040
|
+
});
|
|
1041
|
+
|
|
1042
|
+
it("should error if r2_buckets is a number", () => {
|
|
1043
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1044
|
+
{ r2_buckets: 999 } as unknown as RawConfig,
|
|
1045
|
+
undefined,
|
|
1046
|
+
{ env: undefined }
|
|
1047
|
+
);
|
|
1048
|
+
|
|
1049
|
+
expect(config).toEqual(
|
|
1050
|
+
expect.not.objectContaining({ r2_buckets: expect.anything })
|
|
1051
|
+
);
|
|
1052
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1053
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1054
|
+
"Processing wrangler configuration:
|
|
1055
|
+
- The field \\"r2_buckets\\" should be an array but got 999."
|
|
1056
|
+
`);
|
|
1057
|
+
});
|
|
1058
|
+
|
|
1059
|
+
it("should error if r2_buckets is null", () => {
|
|
1060
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1061
|
+
{ r2_buckets: null } as unknown as RawConfig,
|
|
1062
|
+
undefined,
|
|
1063
|
+
{ env: undefined }
|
|
1064
|
+
);
|
|
1065
|
+
|
|
1066
|
+
expect(config).toEqual(
|
|
1067
|
+
expect.not.objectContaining({ r2_buckets: expect.anything })
|
|
1068
|
+
);
|
|
1069
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1070
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1071
|
+
"Processing wrangler configuration:
|
|
1072
|
+
- The field \\"r2_buckets\\" should be an array but got null."
|
|
1073
|
+
`);
|
|
1074
|
+
});
|
|
1075
|
+
|
|
1076
|
+
it("should error if r2_buckets.bindings are not valid", () => {
|
|
1077
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1078
|
+
{
|
|
1079
|
+
r2_buckets: [
|
|
1080
|
+
{},
|
|
1081
|
+
{ binding: "R2_BINDING_1" },
|
|
1082
|
+
{ binding: 2333, bucket_name: 2444 },
|
|
1083
|
+
{
|
|
1084
|
+
binding: "R2_BINDING_2",
|
|
1085
|
+
bucket_name: "R2_BUCKET_2",
|
|
1086
|
+
preview_bucket_name: 2555,
|
|
1087
|
+
},
|
|
1088
|
+
],
|
|
1089
|
+
} as unknown as RawConfig,
|
|
1090
|
+
undefined,
|
|
1091
|
+
{ env: undefined }
|
|
1092
|
+
);
|
|
1093
|
+
|
|
1094
|
+
expect(config).toEqual(
|
|
1095
|
+
expect.not.objectContaining({
|
|
1096
|
+
r2_buckets: { bindings: expect.anything },
|
|
1097
|
+
})
|
|
1098
|
+
);
|
|
1099
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1100
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1101
|
+
"Processing wrangler configuration:
|
|
1102
|
+
- \\"r2_buckets[0]\\" bindings should have a string \\"binding\\" field but got {}.
|
|
1103
|
+
- \\"r2_buckets[0]\\" bindings should have a string \\"bucket_name\\" field but got {}.
|
|
1104
|
+
- \\"r2_buckets[1]\\" bindings should have a string \\"bucket_name\\" field but got {\\"binding\\":\\"R2_BINDING_1\\"}.
|
|
1105
|
+
- \\"r2_buckets[2]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":2333,\\"bucket_name\\":2444}.
|
|
1106
|
+
- \\"r2_buckets[2]\\" bindings should have a string \\"bucket_name\\" field but got {\\"binding\\":2333,\\"bucket_name\\":2444}.
|
|
1107
|
+
- \\"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}."
|
|
1108
|
+
`);
|
|
1109
|
+
});
|
|
1110
|
+
});
|
|
1111
|
+
|
|
1112
|
+
describe("unsafe field", () => {
|
|
1113
|
+
it("should error if unsafe is an array", () => {
|
|
1114
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1115
|
+
{ unsafe: [] } as unknown as RawConfig,
|
|
1116
|
+
undefined,
|
|
1117
|
+
{ env: undefined }
|
|
1118
|
+
);
|
|
1119
|
+
|
|
1120
|
+
expect(config).toEqual(
|
|
1121
|
+
expect.not.objectContaining({ unsafe: expect.anything })
|
|
1122
|
+
);
|
|
1123
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
1124
|
+
"Processing wrangler configuration:
|
|
1125
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
1126
|
+
`);
|
|
1127
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1128
|
+
"Processing wrangler configuration:
|
|
1129
|
+
- The field \\"unsafe\\" should be an object but got []."
|
|
1130
|
+
`);
|
|
1131
|
+
});
|
|
1132
|
+
|
|
1133
|
+
it("should error if unsafe is a string", () => {
|
|
1134
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1135
|
+
{ unsafe: "BAD" } as unknown as RawConfig,
|
|
1136
|
+
undefined,
|
|
1137
|
+
{ env: undefined }
|
|
1138
|
+
);
|
|
1139
|
+
|
|
1140
|
+
expect(config).toEqual(
|
|
1141
|
+
expect.not.objectContaining({ unsafe: expect.anything })
|
|
1142
|
+
);
|
|
1143
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
1144
|
+
"Processing wrangler configuration:
|
|
1145
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
1146
|
+
`);
|
|
1147
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1148
|
+
"Processing wrangler configuration:
|
|
1149
|
+
- The field \\"unsafe\\" should be an object but got \\"BAD\\"."
|
|
1150
|
+
`);
|
|
1151
|
+
});
|
|
1152
|
+
|
|
1153
|
+
it("should error if unsafe is a number", () => {
|
|
1154
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1155
|
+
{ unsafe: 999 } as unknown as RawConfig,
|
|
1156
|
+
undefined,
|
|
1157
|
+
{ env: undefined }
|
|
1158
|
+
);
|
|
1159
|
+
|
|
1160
|
+
expect(config).toEqual(
|
|
1161
|
+
expect.not.objectContaining({ unsafe: expect.anything })
|
|
1162
|
+
);
|
|
1163
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
1164
|
+
"Processing wrangler configuration:
|
|
1165
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
1166
|
+
`);
|
|
1167
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1168
|
+
"Processing wrangler configuration:
|
|
1169
|
+
- The field \\"unsafe\\" should be an object but got 999."
|
|
1170
|
+
`);
|
|
1171
|
+
});
|
|
1172
|
+
|
|
1173
|
+
it("should error if unsafe is null", () => {
|
|
1174
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1175
|
+
{ unsafe: null } as unknown as RawConfig,
|
|
1176
|
+
undefined,
|
|
1177
|
+
{ env: undefined }
|
|
1178
|
+
);
|
|
1179
|
+
|
|
1180
|
+
expect(config).toEqual(
|
|
1181
|
+
expect.not.objectContaining({ unsafe: expect.anything })
|
|
1182
|
+
);
|
|
1183
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
1184
|
+
"Processing wrangler configuration:
|
|
1185
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
1186
|
+
`);
|
|
1187
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1188
|
+
"Processing wrangler configuration:
|
|
1189
|
+
- The field \\"unsafe\\" should be an object but got null."
|
|
1190
|
+
`);
|
|
1191
|
+
});
|
|
1192
|
+
|
|
1193
|
+
it("should error if unsafe.bindings is not defined", () => {
|
|
1194
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1195
|
+
{ unsafe: {} } as unknown as RawConfig,
|
|
1196
|
+
undefined,
|
|
1197
|
+
{ env: undefined }
|
|
1198
|
+
);
|
|
1199
|
+
|
|
1200
|
+
expect(config).toEqual(
|
|
1201
|
+
expect.not.objectContaining({ unsafe: expect.anything })
|
|
1202
|
+
);
|
|
1203
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
1204
|
+
"Processing wrangler configuration:
|
|
1205
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
1206
|
+
`);
|
|
1207
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1208
|
+
"Processing wrangler configuration:
|
|
1209
|
+
- The field \\"unsafe\\" is missing the required \\"bindings\\" property."
|
|
1210
|
+
`);
|
|
1211
|
+
});
|
|
1212
|
+
|
|
1213
|
+
it("should error if unsafe.bindings is an object", () => {
|
|
1214
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1215
|
+
{ unsafe: { bindings: {} } } as unknown as RawConfig,
|
|
1216
|
+
undefined,
|
|
1217
|
+
{ env: undefined }
|
|
1218
|
+
);
|
|
1219
|
+
|
|
1220
|
+
expect(config).toEqual(
|
|
1221
|
+
expect.not.objectContaining({
|
|
1222
|
+
unsafe: { bindings: expect.anything },
|
|
1223
|
+
})
|
|
1224
|
+
);
|
|
1225
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
1226
|
+
"Processing wrangler configuration:
|
|
1227
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
1228
|
+
`);
|
|
1229
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1230
|
+
"Processing wrangler configuration:
|
|
1231
|
+
- The field \\"unsafe.bindings\\" should be an array but got {}."
|
|
1232
|
+
`);
|
|
1233
|
+
});
|
|
1234
|
+
|
|
1235
|
+
it("should error if unsafe.bindings is a string", () => {
|
|
1236
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1237
|
+
{ unsafe: { bindings: "BAD" } } as unknown as RawConfig,
|
|
1238
|
+
undefined,
|
|
1239
|
+
{ env: undefined }
|
|
1240
|
+
);
|
|
1241
|
+
|
|
1242
|
+
expect(config).toEqual(
|
|
1243
|
+
expect.not.objectContaining({
|
|
1244
|
+
unsafe: { bindings: expect.anything },
|
|
1245
|
+
})
|
|
1246
|
+
);
|
|
1247
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
1248
|
+
"Processing wrangler configuration:
|
|
1249
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
1250
|
+
`);
|
|
1251
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1252
|
+
"Processing wrangler configuration:
|
|
1253
|
+
- The field \\"unsafe.bindings\\" should be an array but got \\"BAD\\"."
|
|
1254
|
+
`);
|
|
1255
|
+
});
|
|
1256
|
+
|
|
1257
|
+
it("should error if unsafe.bindings is a number", () => {
|
|
1258
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1259
|
+
{ unsafe: { bindings: 999 } } as unknown as RawConfig,
|
|
1260
|
+
undefined,
|
|
1261
|
+
{ env: undefined }
|
|
1262
|
+
);
|
|
1263
|
+
|
|
1264
|
+
expect(config).toEqual(
|
|
1265
|
+
expect.not.objectContaining({
|
|
1266
|
+
unsafe: { bindings: expect.anything },
|
|
1267
|
+
})
|
|
1268
|
+
);
|
|
1269
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
1270
|
+
"Processing wrangler configuration:
|
|
1271
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
1272
|
+
`);
|
|
1273
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1274
|
+
"Processing wrangler configuration:
|
|
1275
|
+
- The field \\"unsafe.bindings\\" should be an array but got 999."
|
|
1276
|
+
`);
|
|
1277
|
+
});
|
|
1278
|
+
|
|
1279
|
+
it("should error if unsafe.bindings is null", () => {
|
|
1280
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1281
|
+
{ unsafe: { bindings: null } } as unknown as RawConfig,
|
|
1282
|
+
undefined,
|
|
1283
|
+
{ env: undefined }
|
|
1284
|
+
);
|
|
1285
|
+
|
|
1286
|
+
expect(config).toEqual(
|
|
1287
|
+
expect.not.objectContaining({
|
|
1288
|
+
unsafe: { bindings: expect.anything },
|
|
1289
|
+
})
|
|
1290
|
+
);
|
|
1291
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
1292
|
+
"Processing wrangler configuration:
|
|
1293
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
1294
|
+
`);
|
|
1295
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1296
|
+
"Processing wrangler configuration:
|
|
1297
|
+
- The field \\"unsafe.bindings\\" should be an array but got null."
|
|
1298
|
+
`);
|
|
1299
|
+
});
|
|
1300
|
+
|
|
1301
|
+
it("should error if durable_objects.bindings are not valid", () => {
|
|
1302
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1303
|
+
{
|
|
1304
|
+
unsafe: {
|
|
1305
|
+
bindings: [
|
|
1306
|
+
{},
|
|
1307
|
+
{ name: "UNSAFE_BINDING_1" },
|
|
1308
|
+
{ name: 2666, type: 2777 },
|
|
1309
|
+
{
|
|
1310
|
+
name: "UNSAFE_BINDING_2",
|
|
1311
|
+
type: "UNSAFE_TYPE_2",
|
|
1312
|
+
extra: 2888,
|
|
1313
|
+
},
|
|
1314
|
+
],
|
|
1315
|
+
},
|
|
1316
|
+
} as unknown as RawConfig,
|
|
1317
|
+
undefined,
|
|
1318
|
+
{ env: undefined }
|
|
1319
|
+
);
|
|
1320
|
+
|
|
1321
|
+
expect(config).toEqual(
|
|
1322
|
+
expect.not.objectContaining({
|
|
1323
|
+
durable_objects: { bindings: expect.anything },
|
|
1324
|
+
})
|
|
1325
|
+
);
|
|
1326
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
1327
|
+
"Processing wrangler configuration:
|
|
1328
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
1329
|
+
`);
|
|
1330
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1331
|
+
"Processing wrangler configuration:
|
|
1332
|
+
|
|
1333
|
+
- \\"unsafe.bindings[0]\\": {}
|
|
1334
|
+
- binding should have a string \\"name\\" field.
|
|
1335
|
+
- binding should have a string \\"type\\" field.
|
|
1336
|
+
|
|
1337
|
+
- \\"unsafe.bindings[1]\\": {\\"name\\":\\"UNSAFE_BINDING_1\\"}
|
|
1338
|
+
- binding should have a string \\"type\\" field.
|
|
1339
|
+
|
|
1340
|
+
- \\"unsafe.bindings[2]\\": {\\"name\\":2666,\\"type\\":2777}
|
|
1341
|
+
- binding should have a string \\"name\\" field.
|
|
1342
|
+
- binding should have a string \\"type\\" field."
|
|
1343
|
+
`);
|
|
1344
|
+
});
|
|
1345
|
+
});
|
|
1346
|
+
|
|
1347
|
+
describe("(deprecated)", () => {
|
|
1348
|
+
it("should remove and warn about deprecated properties", () => {
|
|
1349
|
+
const rawConfig: RawConfig = {
|
|
1350
|
+
zone_id: "ZONE_ID",
|
|
1351
|
+
experimental_services: [
|
|
1352
|
+
{
|
|
1353
|
+
name: "NAME",
|
|
1354
|
+
service: "SERVICE",
|
|
1355
|
+
environment: "ENV",
|
|
1356
|
+
},
|
|
1357
|
+
],
|
|
1358
|
+
};
|
|
1359
|
+
|
|
1360
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1361
|
+
rawConfig,
|
|
1362
|
+
undefined,
|
|
1363
|
+
{ env: undefined }
|
|
1364
|
+
);
|
|
1365
|
+
|
|
1366
|
+
expect("experimental_services" in config).toBe(false);
|
|
1367
|
+
// Zone is not removed yet, since `route` commands might use it
|
|
1368
|
+
expect(config.zone_id).toEqual("ZONE_ID");
|
|
1369
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
1370
|
+
expect(diagnostics.hasWarnings()).toBe(true);
|
|
1371
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
1372
|
+
"Processing wrangler configuration:
|
|
1373
|
+
- DEPRECATION: \\"zone_id\\":
|
|
1374
|
+
This is unnecessary since we can deduce this from routes directly.
|
|
1375
|
+
- DEPRECATION: \\"experimental_services\\":
|
|
1376
|
+
The \\"experimental_services\\" field is no longer supported. Instead, use [[unsafe.bindings]] to enable experimental features. Add this to your wrangler.toml:
|
|
1377
|
+
\`\`\`
|
|
1378
|
+
[[unsafe.bindings]]
|
|
1379
|
+
name = \\"NAME\\"
|
|
1380
|
+
type = \\"service\\"
|
|
1381
|
+
service = \\"SERVICE\\"
|
|
1382
|
+
environment = \\"ENV\\"
|
|
1383
|
+
\`\`\`"
|
|
1384
|
+
`);
|
|
1385
|
+
});
|
|
1386
|
+
});
|
|
1387
|
+
|
|
1388
|
+
describe("route & routes fields", () => {
|
|
1389
|
+
it("should error if both route and routes are specified", () => {
|
|
1390
|
+
const rawConfig: RawConfig = {
|
|
1391
|
+
route: "route1",
|
|
1392
|
+
routes: ["route2", "route3"],
|
|
1393
|
+
};
|
|
1394
|
+
|
|
1395
|
+
const { diagnostics } = normalizeAndValidateConfig(
|
|
1396
|
+
rawConfig,
|
|
1397
|
+
undefined,
|
|
1398
|
+
{ env: undefined }
|
|
1399
|
+
);
|
|
1400
|
+
|
|
1401
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1402
|
+
"Processing wrangler configuration:
|
|
1403
|
+
- Expected exactly one of the following fields [\\"routes\\",\\"route\\"]."
|
|
1404
|
+
`);
|
|
1405
|
+
});
|
|
1406
|
+
});
|
|
1407
|
+
});
|
|
1408
|
+
|
|
1409
|
+
describe("named environments", () => {
|
|
1410
|
+
it("should warn if we specify an environment but there are no named environments", () => {
|
|
1411
|
+
const rawConfig: RawConfig = {};
|
|
1412
|
+
const { diagnostics } = normalizeAndValidateConfig(rawConfig, undefined, {
|
|
1413
|
+
env: "DEV",
|
|
1414
|
+
});
|
|
1415
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1416
|
+
"Processing wrangler configuration:
|
|
1417
|
+
"
|
|
1418
|
+
`);
|
|
1419
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
1420
|
+
"Processing wrangler configuration:
|
|
1421
|
+
- No environment found in configuration with name \\"DEV\\".
|
|
1422
|
+
Before using \`--env=DEV\` there should be an equivalent environment section in the configuration.
|
|
1423
|
+
|
|
1424
|
+
Consider adding an environment configuration section to the wrangler.toml file:
|
|
1425
|
+
\`\`\`
|
|
1426
|
+
[env.DEV]
|
|
1427
|
+
\`\`\`
|
|
1428
|
+
"
|
|
1429
|
+
`);
|
|
1430
|
+
});
|
|
1431
|
+
|
|
1432
|
+
it("should error if we specify an environment that does not match the named environments", () => {
|
|
1433
|
+
const rawConfig: RawConfig = { env: { ENV1: {} } };
|
|
1434
|
+
const { diagnostics } = normalizeAndValidateConfig(rawConfig, undefined, {
|
|
1435
|
+
env: "DEV",
|
|
1436
|
+
});
|
|
1437
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1438
|
+
"Processing wrangler configuration:
|
|
1439
|
+
- No environment found in configuration with name \\"DEV\\".
|
|
1440
|
+
Before using \`--env=DEV\` there should be an equivalent environment section in the configuration.
|
|
1441
|
+
The available configured environment names are: [\\"ENV1\\"]
|
|
1442
|
+
|
|
1443
|
+
Consider adding an environment configuration section to the wrangler.toml file:
|
|
1444
|
+
\`\`\`
|
|
1445
|
+
[env.DEV]
|
|
1446
|
+
\`\`\`
|
|
1447
|
+
"
|
|
1448
|
+
`);
|
|
1449
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
1450
|
+
"Processing wrangler configuration:
|
|
1451
|
+
"
|
|
1452
|
+
`);
|
|
1453
|
+
});
|
|
1454
|
+
|
|
1455
|
+
it("should use top-level values for inheritable config fields", () => {
|
|
1456
|
+
const main = "src/index.ts";
|
|
1457
|
+
const resolvedMain = path.resolve(process.cwd(), main);
|
|
1458
|
+
const rawConfig: RawConfig = {
|
|
1459
|
+
name: "NAME",
|
|
1460
|
+
account_id: "ACCOUNT_ID",
|
|
1461
|
+
compatibility_date: "2022-01-01",
|
|
1462
|
+
compatibility_flags: ["FLAG1", "FLAG2"],
|
|
1463
|
+
workers_dev: false,
|
|
1464
|
+
routes: ["ROUTE_1", "ROUTE_2"],
|
|
1465
|
+
jsx_factory: "JSX_FACTORY",
|
|
1466
|
+
jsx_fragment: "JSX_FRAGMENT",
|
|
1467
|
+
triggers: { crons: ["CRON_1", "CRON_2"] },
|
|
1468
|
+
usage_model: "bundled",
|
|
1469
|
+
main,
|
|
1470
|
+
build: {
|
|
1471
|
+
command: "COMMAND",
|
|
1472
|
+
cwd: "CWD",
|
|
1473
|
+
watch_dir: "WATCH_DIR",
|
|
1474
|
+
},
|
|
1475
|
+
};
|
|
1476
|
+
|
|
1477
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1478
|
+
{ ...rawConfig, env: { DEV: {} } },
|
|
1479
|
+
undefined,
|
|
1480
|
+
{ env: "DEV" }
|
|
1481
|
+
);
|
|
1482
|
+
|
|
1483
|
+
expect(config).toEqual(
|
|
1484
|
+
expect.objectContaining({
|
|
1485
|
+
...rawConfig,
|
|
1486
|
+
main: resolvedMain,
|
|
1487
|
+
name: "NAME-DEV",
|
|
1488
|
+
})
|
|
1489
|
+
);
|
|
1490
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
1491
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1492
|
+
});
|
|
1493
|
+
|
|
1494
|
+
it("should override top-level values for inheritable config fields", () => {
|
|
1495
|
+
const main = "src/index.ts";
|
|
1496
|
+
const resolvedMain = path.resolve(process.cwd(), main);
|
|
1497
|
+
const rawEnv: RawEnvironment = {
|
|
1498
|
+
name: "ENV_NAME",
|
|
1499
|
+
account_id: "ENV_ACCOUNT_ID",
|
|
1500
|
+
compatibility_date: "2022-02-02",
|
|
1501
|
+
compatibility_flags: ["ENV_FLAG1", "ENV_FLAG2"],
|
|
1502
|
+
workers_dev: true,
|
|
1503
|
+
routes: ["ENV_ROUTE_1", "ENV_ROUTE_2"],
|
|
1504
|
+
jsx_factory: "ENV_JSX_FACTORY",
|
|
1505
|
+
jsx_fragment: "ENV_JSX_FRAGMENT",
|
|
1506
|
+
triggers: { crons: ["ENV_CRON_1", "ENV_CRON_2"] },
|
|
1507
|
+
usage_model: "unbound",
|
|
1508
|
+
main,
|
|
1509
|
+
build: {
|
|
1510
|
+
command: "ENV_COMMAND",
|
|
1511
|
+
cwd: "ENV_CWD",
|
|
1512
|
+
watch_dir: "ENV_WATCH_DIR",
|
|
1513
|
+
},
|
|
1514
|
+
};
|
|
1515
|
+
const rawConfig: RawConfig = {
|
|
1516
|
+
name: "NAME",
|
|
1517
|
+
account_id: "ACCOUNT_ID",
|
|
1518
|
+
compatibility_date: "2022-01-01",
|
|
1519
|
+
compatibility_flags: ["FLAG1", "FLAG2"],
|
|
1520
|
+
workers_dev: false,
|
|
1521
|
+
routes: ["ROUTE_1", "ROUTE_2"],
|
|
1522
|
+
jsx_factory: "JSX_FACTORY",
|
|
1523
|
+
jsx_fragment: "JSX_FRAGMENT",
|
|
1524
|
+
triggers: { crons: ["CRON_1", "CRON_2"] },
|
|
1525
|
+
usage_model: "bundled",
|
|
1526
|
+
main: "top-level.js",
|
|
1527
|
+
build: {
|
|
1528
|
+
command: "COMMAND",
|
|
1529
|
+
cwd: "CWD",
|
|
1530
|
+
watch_dir: "WATCH_DIR",
|
|
1531
|
+
},
|
|
1532
|
+
env: {
|
|
1533
|
+
ENV1: rawEnv,
|
|
1534
|
+
},
|
|
1535
|
+
};
|
|
1536
|
+
|
|
1537
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1538
|
+
rawConfig,
|
|
1539
|
+
undefined,
|
|
1540
|
+
{ env: "ENV1" }
|
|
1541
|
+
);
|
|
1542
|
+
|
|
1543
|
+
expect(config).toEqual(
|
|
1544
|
+
expect.objectContaining({ ...rawEnv, main: resolvedMain })
|
|
1545
|
+
);
|
|
1546
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
1547
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1548
|
+
});
|
|
1549
|
+
|
|
1550
|
+
describe("non-legacy", () => {
|
|
1551
|
+
it("should use top-level `name` field", () => {
|
|
1552
|
+
const rawConfig: RawConfig = {
|
|
1553
|
+
name: "NAME",
|
|
1554
|
+
legacy_env: false,
|
|
1555
|
+
env: { DEV: {} },
|
|
1556
|
+
};
|
|
1557
|
+
|
|
1558
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1559
|
+
rawConfig,
|
|
1560
|
+
undefined,
|
|
1561
|
+
{ env: "DEV" }
|
|
1562
|
+
);
|
|
1563
|
+
|
|
1564
|
+
expect(config.name).toEqual("NAME");
|
|
1565
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
1566
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1567
|
+
});
|
|
1568
|
+
|
|
1569
|
+
it("should error if named environment contains a `name` field, even if there is no top-level name", () => {
|
|
1570
|
+
const rawConfig: RawConfig = {
|
|
1571
|
+
legacy_env: false,
|
|
1572
|
+
env: {
|
|
1573
|
+
DEV: {
|
|
1574
|
+
name: "ENV_NAME",
|
|
1575
|
+
},
|
|
1576
|
+
},
|
|
1577
|
+
};
|
|
1578
|
+
|
|
1579
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1580
|
+
rawConfig,
|
|
1581
|
+
undefined,
|
|
1582
|
+
{ env: "DEV" }
|
|
1583
|
+
);
|
|
1584
|
+
|
|
1585
|
+
expect(config.name).toBeUndefined();
|
|
1586
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1587
|
+
"Processing wrangler configuration:
|
|
1588
|
+
|
|
1589
|
+
- \\"env.DEV\\" environment configuration
|
|
1590
|
+
- The \\"name\\" field is not allowed in named service environments.
|
|
1591
|
+
Please remove the field from this environment."
|
|
1592
|
+
`);
|
|
1593
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1594
|
+
});
|
|
1595
|
+
|
|
1596
|
+
it("should error if top-level config and a named environment both contain a `name` field", () => {
|
|
1597
|
+
const rawConfig: RawConfig = {
|
|
1598
|
+
name: "NAME",
|
|
1599
|
+
legacy_env: false,
|
|
1600
|
+
env: {
|
|
1601
|
+
DEV: {
|
|
1602
|
+
name: "ENV_NAME",
|
|
1603
|
+
},
|
|
1604
|
+
},
|
|
1605
|
+
};
|
|
1606
|
+
|
|
1607
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1608
|
+
rawConfig,
|
|
1609
|
+
undefined,
|
|
1610
|
+
{ env: "DEV" }
|
|
1611
|
+
);
|
|
1612
|
+
|
|
1613
|
+
expect(config.name).toEqual("NAME");
|
|
1614
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1615
|
+
"Processing wrangler configuration:
|
|
1616
|
+
|
|
1617
|
+
- \\"env.DEV\\" environment configuration
|
|
1618
|
+
- The \\"name\\" field is not allowed in named service environments.
|
|
1619
|
+
Please remove the field from this environment."
|
|
1620
|
+
`);
|
|
1621
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1622
|
+
});
|
|
1623
|
+
});
|
|
1624
|
+
|
|
1625
|
+
it("should warn for non-inherited fields that are missing in environments", () => {
|
|
1626
|
+
const vars: RawConfig["vars"] = {
|
|
1627
|
+
FOO: "foo",
|
|
1628
|
+
};
|
|
1629
|
+
const durable_objects: RawConfig["durable_objects"] = {
|
|
1630
|
+
bindings: [],
|
|
1631
|
+
};
|
|
1632
|
+
const kv_namespaces: RawConfig["kv_namespaces"] = [];
|
|
1633
|
+
const r2_buckets: RawConfig["r2_buckets"] = [];
|
|
1634
|
+
const unsafe: RawConfig["unsafe"] = { bindings: [] };
|
|
1635
|
+
const rawConfig: RawConfig = {
|
|
1636
|
+
vars,
|
|
1637
|
+
durable_objects,
|
|
1638
|
+
kv_namespaces,
|
|
1639
|
+
r2_buckets,
|
|
1640
|
+
unsafe,
|
|
1641
|
+
env: {
|
|
1642
|
+
ENV1: {},
|
|
1643
|
+
},
|
|
1644
|
+
};
|
|
1645
|
+
|
|
1646
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1647
|
+
rawConfig,
|
|
1648
|
+
undefined,
|
|
1649
|
+
{ env: "ENV1" }
|
|
1650
|
+
);
|
|
1651
|
+
|
|
1652
|
+
expect(config).toEqual(
|
|
1653
|
+
expect.not.objectContaining({
|
|
1654
|
+
vars,
|
|
1655
|
+
durable_objects,
|
|
1656
|
+
kv_namespaces,
|
|
1657
|
+
r2_buckets,
|
|
1658
|
+
unsafe,
|
|
1659
|
+
})
|
|
1660
|
+
);
|
|
1661
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
1662
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
1663
|
+
"Processing wrangler configuration:
|
|
1664
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time.
|
|
1665
|
+
- \\"env.ENV1\\" environment configuration
|
|
1666
|
+
- \\"vars\\" exists at the top level, but not on \\"env.ENV1\\".
|
|
1667
|
+
This is not what you probably want, since \\"vars\\" is not inherited by environments.
|
|
1668
|
+
Please add \\"vars\\" to \\"env.ENV1\\".
|
|
1669
|
+
- \\"durable_objects\\" exists at the top level, but not on \\"env.ENV1\\".
|
|
1670
|
+
This is not what you probably want, since \\"durable_objects\\" is not inherited by environments.
|
|
1671
|
+
Please add \\"durable_objects\\" to \\"env.ENV1\\".
|
|
1672
|
+
- \\"kv_namespaces\\" exists at the top level, but not on \\"env.ENV1\\".
|
|
1673
|
+
This is not what you probably want, since \\"kv_namespaces\\" is not inherited by environments.
|
|
1674
|
+
Please add \\"kv_namespaces\\" to \\"env.ENV1\\".
|
|
1675
|
+
- \\"r2_buckets\\" exists at the top level, but not on \\"env.ENV1\\".
|
|
1676
|
+
This is not what you probably want, since \\"r2_buckets\\" is not inherited by environments.
|
|
1677
|
+
Please add \\"r2_buckets\\" to \\"env.ENV1\\".
|
|
1678
|
+
- \\"unsafe\\" exists at the top level, but not on \\"env.ENV1\\".
|
|
1679
|
+
This is not what you probably want, since \\"unsafe\\" is not inherited by environments.
|
|
1680
|
+
Please add \\"unsafe\\" to \\"env.ENV1\\"."
|
|
1681
|
+
`);
|
|
1682
|
+
});
|
|
1683
|
+
|
|
1684
|
+
it("should error on invalid environment values", () => {
|
|
1685
|
+
const expectedConfig: RawEnvironment = {
|
|
1686
|
+
name: 111,
|
|
1687
|
+
account_id: 222,
|
|
1688
|
+
compatibility_date: 333,
|
|
1689
|
+
compatibility_flags: [444, 555],
|
|
1690
|
+
workers_dev: "BAD",
|
|
1691
|
+
routes: [666, 777],
|
|
1692
|
+
route: 888,
|
|
1693
|
+
jsx_factory: 999,
|
|
1694
|
+
jsx_fragment: 1000,
|
|
1695
|
+
triggers: { crons: [1111, 1222] },
|
|
1696
|
+
usage_model: "INVALID",
|
|
1697
|
+
main: 1333,
|
|
1698
|
+
build: {
|
|
1699
|
+
command: 1444,
|
|
1700
|
+
cwd: 1555,
|
|
1701
|
+
watch_dir: 1666,
|
|
1702
|
+
},
|
|
1703
|
+
} as unknown as RawEnvironment;
|
|
1704
|
+
|
|
1705
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1706
|
+
{ env: { ENV1: expectedConfig } },
|
|
1707
|
+
undefined,
|
|
1708
|
+
{ env: "ENV1" }
|
|
1709
|
+
);
|
|
1710
|
+
|
|
1711
|
+
expect(config).toEqual(expect.objectContaining(expectedConfig));
|
|
1712
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1713
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1714
|
+
"Processing wrangler configuration:
|
|
1715
|
+
|
|
1716
|
+
- \\"env.ENV1\\" environment configuration
|
|
1717
|
+
- Expected \\"route\\" to be of type string but got 888.
|
|
1718
|
+
- Expected \\"routes\\" to be of type string array but got [666,777].
|
|
1719
|
+
- Expected exactly one of the following fields [\\"routes\\",\\"route\\"].
|
|
1720
|
+
- Expected \\"workers_dev\\" to be of type boolean but got \\"BAD\\".
|
|
1721
|
+
- Expected \\"build.command\\" to be of type string but got 1444.
|
|
1722
|
+
- Expected \\"build.cwd\\" to be of type string but got 1555.
|
|
1723
|
+
- Expected \\"build.watch_dir\\" to be of type string but got 1666.
|
|
1724
|
+
- Expected \\"account_id\\" to be of type string but got 222.
|
|
1725
|
+
- Expected \\"compatibility_date\\" to be of type string but got 333.
|
|
1726
|
+
- Expected \\"compatibility_flags\\" to be of type string array but got [444,555].
|
|
1727
|
+
- Expected \\"jsx_factory\\" to be of type string but got 999.
|
|
1728
|
+
- Expected \\"jsx_fragment\\" to be of type string but got 1000.
|
|
1729
|
+
- Expected \\"name\\" to be of type string but got 111.
|
|
1730
|
+
- Expected \\"main\\" to be of type string but got 1333.
|
|
1731
|
+
- Expected \\"usage_model\\" field to be one of [\\"bundled\\",\\"unbound\\"] but got \\"INVALID\\"."
|
|
1732
|
+
`);
|
|
1733
|
+
});
|
|
1734
|
+
|
|
1735
|
+
describe("durable_objects field", () => {
|
|
1736
|
+
it("should error if durable_objects is an array", () => {
|
|
1737
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1738
|
+
{ env: { ENV1: { durable_objects: [] } } } as unknown as RawConfig,
|
|
1739
|
+
undefined,
|
|
1740
|
+
{ env: "ENV1" }
|
|
1741
|
+
);
|
|
1742
|
+
|
|
1743
|
+
expect(config).toEqual(
|
|
1744
|
+
expect.not.objectContaining({ durable_objects: expect.anything })
|
|
1745
|
+
);
|
|
1746
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1747
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1748
|
+
"Processing wrangler configuration:
|
|
1749
|
+
|
|
1750
|
+
- \\"env.ENV1\\" environment configuration
|
|
1751
|
+
- The field \\"env.ENV1.durable_objects\\" should be an object but got []."
|
|
1752
|
+
`);
|
|
1753
|
+
});
|
|
1754
|
+
|
|
1755
|
+
it("should error if durable_objects is a string", () => {
|
|
1756
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1757
|
+
{ env: { ENV1: { durable_objects: "BAD" } } } as unknown as RawConfig,
|
|
1758
|
+
undefined,
|
|
1759
|
+
{ env: "ENV1" }
|
|
1760
|
+
);
|
|
1761
|
+
|
|
1762
|
+
expect(config).toEqual(
|
|
1763
|
+
expect.not.objectContaining({ durable_objects: expect.anything })
|
|
1764
|
+
);
|
|
1765
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1766
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1767
|
+
"Processing wrangler configuration:
|
|
1768
|
+
|
|
1769
|
+
- \\"env.ENV1\\" environment configuration
|
|
1770
|
+
- The field \\"env.ENV1.durable_objects\\" should be an object but got \\"BAD\\"."
|
|
1771
|
+
`);
|
|
1772
|
+
});
|
|
1773
|
+
|
|
1774
|
+
it("should error if durable_objects is a number", () => {
|
|
1775
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1776
|
+
{ env: { ENV1: { durable_objects: 999 } } } as unknown as RawConfig,
|
|
1777
|
+
undefined,
|
|
1778
|
+
{ env: "ENV1" }
|
|
1779
|
+
);
|
|
1780
|
+
|
|
1781
|
+
expect(config).toEqual(
|
|
1782
|
+
expect.not.objectContaining({ durable_objects: 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.durable_objects\\" should be an object but got 999."
|
|
1790
|
+
`);
|
|
1791
|
+
});
|
|
1792
|
+
|
|
1793
|
+
it("should error if durable_objects is null", () => {
|
|
1794
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1795
|
+
{ env: { ENV1: { durable_objects: null } } } as unknown as RawConfig,
|
|
1796
|
+
undefined,
|
|
1797
|
+
{ env: "ENV1" }
|
|
1798
|
+
);
|
|
1799
|
+
|
|
1800
|
+
expect(config).toEqual(
|
|
1801
|
+
expect.not.objectContaining({ durable_objects: expect.anything })
|
|
1802
|
+
);
|
|
1803
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1804
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1805
|
+
"Processing wrangler configuration:
|
|
1806
|
+
|
|
1807
|
+
- \\"env.ENV1\\" environment configuration
|
|
1808
|
+
- The field \\"env.ENV1.durable_objects\\" should be an object but got null."
|
|
1809
|
+
`);
|
|
1810
|
+
});
|
|
1811
|
+
|
|
1812
|
+
it("should error if durable_objects.bindings is not defined", () => {
|
|
1813
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1814
|
+
{ env: { ENV1: { durable_objects: {} } } } as unknown as RawConfig,
|
|
1815
|
+
undefined,
|
|
1816
|
+
{ env: "ENV1" }
|
|
1817
|
+
);
|
|
1818
|
+
|
|
1819
|
+
expect(config).toEqual(
|
|
1820
|
+
expect.not.objectContaining({ durable_objects: expect.anything })
|
|
1821
|
+
);
|
|
1822
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1823
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1824
|
+
"Processing wrangler configuration:
|
|
1825
|
+
|
|
1826
|
+
- \\"env.ENV1\\" environment configuration
|
|
1827
|
+
- The field \\"env.ENV1.durable_objects\\" is missing the required \\"bindings\\" property."
|
|
1828
|
+
`);
|
|
1829
|
+
});
|
|
1830
|
+
|
|
1831
|
+
it("should error if durable_objects.bindings is an object", () => {
|
|
1832
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1833
|
+
{
|
|
1834
|
+
env: { ENV1: { durable_objects: { bindings: {} } } },
|
|
1835
|
+
} as unknown as RawConfig,
|
|
1836
|
+
undefined,
|
|
1837
|
+
{ env: "ENV1" }
|
|
1838
|
+
);
|
|
1839
|
+
|
|
1840
|
+
expect(config).toEqual(
|
|
1841
|
+
expect.not.objectContaining({
|
|
1842
|
+
durable_objects: { bindings: expect.anything },
|
|
1843
|
+
})
|
|
1844
|
+
);
|
|
1845
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1846
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1847
|
+
"Processing wrangler configuration:
|
|
1848
|
+
|
|
1849
|
+
- \\"env.ENV1\\" environment configuration
|
|
1850
|
+
- The field \\"env.ENV1.durable_objects.bindings\\" should be an array but got {}."
|
|
1851
|
+
`);
|
|
1852
|
+
});
|
|
1853
|
+
|
|
1854
|
+
it("should error if durable_objects.bindings is a string", () => {
|
|
1855
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1856
|
+
{
|
|
1857
|
+
env: { ENV1: { durable_objects: { bindings: "BAD" } } },
|
|
1858
|
+
} as unknown as RawConfig,
|
|
1859
|
+
undefined,
|
|
1860
|
+
{ env: "ENV1" }
|
|
1861
|
+
);
|
|
1862
|
+
|
|
1863
|
+
expect(config).toEqual(
|
|
1864
|
+
expect.not.objectContaining({
|
|
1865
|
+
durable_objects: { bindings: expect.anything },
|
|
1866
|
+
})
|
|
1867
|
+
);
|
|
1868
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1869
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1870
|
+
"Processing wrangler configuration:
|
|
1871
|
+
|
|
1872
|
+
- \\"env.ENV1\\" environment configuration
|
|
1873
|
+
- The field \\"env.ENV1.durable_objects.bindings\\" should be an array but got \\"BAD\\"."
|
|
1874
|
+
`);
|
|
1875
|
+
});
|
|
1876
|
+
|
|
1877
|
+
it("should error if durable_objects.bindings is a number", () => {
|
|
1878
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1879
|
+
{
|
|
1880
|
+
env: { ENV1: { durable_objects: { bindings: 999 } } },
|
|
1881
|
+
} as unknown as RawConfig,
|
|
1882
|
+
undefined,
|
|
1883
|
+
{ env: "ENV1" }
|
|
1884
|
+
);
|
|
1885
|
+
|
|
1886
|
+
expect(config).toEqual(
|
|
1887
|
+
expect.not.objectContaining({
|
|
1888
|
+
durable_objects: { bindings: expect.anything },
|
|
1889
|
+
})
|
|
1890
|
+
);
|
|
1891
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1892
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1893
|
+
"Processing wrangler configuration:
|
|
1894
|
+
|
|
1895
|
+
- \\"env.ENV1\\" environment configuration
|
|
1896
|
+
- The field \\"env.ENV1.durable_objects.bindings\\" should be an array but got 999."
|
|
1897
|
+
`);
|
|
1898
|
+
});
|
|
1899
|
+
|
|
1900
|
+
it("should error if durable_objects.bindings is null", () => {
|
|
1901
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1902
|
+
{
|
|
1903
|
+
env: { ENV1: { durable_objects: { bindings: null } } },
|
|
1904
|
+
} as unknown as RawConfig,
|
|
1905
|
+
undefined,
|
|
1906
|
+
{ env: "ENV1" }
|
|
1907
|
+
);
|
|
1908
|
+
|
|
1909
|
+
expect(config).toEqual(
|
|
1910
|
+
expect.not.objectContaining({
|
|
1911
|
+
durable_objects: { bindings: expect.anything },
|
|
1912
|
+
})
|
|
1913
|
+
);
|
|
1914
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1915
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1916
|
+
"Processing wrangler configuration:
|
|
1917
|
+
|
|
1918
|
+
- \\"env.ENV1\\" environment configuration
|
|
1919
|
+
- The field \\"env.ENV1.durable_objects.bindings\\" should be an array but got null."
|
|
1920
|
+
`);
|
|
1921
|
+
});
|
|
1922
|
+
|
|
1923
|
+
it("should error if durable_objects.bindings are not valid", () => {
|
|
1924
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1925
|
+
{
|
|
1926
|
+
env: {
|
|
1927
|
+
ENV1: {
|
|
1928
|
+
durable_objects: {
|
|
1929
|
+
bindings: [
|
|
1930
|
+
{},
|
|
1931
|
+
{ name: "VALID" },
|
|
1932
|
+
{ name: 1555, class_name: 1666 },
|
|
1933
|
+
{
|
|
1934
|
+
name: 1777,
|
|
1935
|
+
class_name: 1888,
|
|
1936
|
+
script_name: 1999,
|
|
1937
|
+
},
|
|
1938
|
+
],
|
|
1939
|
+
},
|
|
1940
|
+
},
|
|
1941
|
+
},
|
|
1942
|
+
} as unknown as RawConfig,
|
|
1943
|
+
undefined,
|
|
1944
|
+
{ env: "ENV1" }
|
|
1945
|
+
);
|
|
1946
|
+
|
|
1947
|
+
expect(config).toEqual(
|
|
1948
|
+
expect.not.objectContaining({
|
|
1949
|
+
durable_objects: { bindings: expect.anything },
|
|
1950
|
+
})
|
|
1951
|
+
);
|
|
1952
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1953
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1954
|
+
"Processing wrangler configuration:
|
|
1955
|
+
|
|
1956
|
+
- \\"env.ENV1\\" environment configuration
|
|
1957
|
+
|
|
1958
|
+
- \\"env.ENV1.durable_objects.bindings[0]\\": {}
|
|
1959
|
+
- binding should have a string \\"name\\" field.
|
|
1960
|
+
- binding should have a string \\"class_name\\" field.
|
|
1961
|
+
|
|
1962
|
+
- \\"env.ENV1.durable_objects.bindings[1]\\": {\\"name\\":\\"VALID\\"}
|
|
1963
|
+
- binding should have a string \\"class_name\\" field.
|
|
1964
|
+
|
|
1965
|
+
- \\"env.ENV1.durable_objects.bindings[2]\\": {\\"name\\":1555,\\"class_name\\":1666}
|
|
1966
|
+
- binding should have a string \\"name\\" field.
|
|
1967
|
+
- binding should have a string \\"class_name\\" field.
|
|
1968
|
+
|
|
1969
|
+
- \\"env.ENV1.durable_objects.bindings[3]\\": {\\"name\\":1777,\\"class_name\\":1888,\\"script_name\\":1999}
|
|
1970
|
+
- binding should have a string \\"name\\" field.
|
|
1971
|
+
- binding should have a string \\"class_name\\" field.
|
|
1972
|
+
- binding should, optionally, have a string \\"script_name\\" field."
|
|
1973
|
+
`);
|
|
1974
|
+
});
|
|
1975
|
+
});
|
|
1976
|
+
|
|
1977
|
+
describe("kv_namespaces field", () => {
|
|
1978
|
+
it("should error if kv_namespaces is an object", () => {
|
|
1979
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1980
|
+
{ env: { ENV1: { kv_namespaces: {} } } } as unknown as RawConfig,
|
|
1981
|
+
undefined,
|
|
1982
|
+
{ env: "ENV1" }
|
|
1983
|
+
);
|
|
1984
|
+
|
|
1985
|
+
expect(config).toEqual(
|
|
1986
|
+
expect.not.objectContaining({ kv_namespaces: expect.anything })
|
|
1987
|
+
);
|
|
1988
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
1989
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
1990
|
+
"Processing wrangler configuration:
|
|
1991
|
+
|
|
1992
|
+
- \\"env.ENV1\\" environment configuration
|
|
1993
|
+
- The field \\"env.ENV1.kv_namespaces\\" should be an array but got {}."
|
|
1994
|
+
`);
|
|
1995
|
+
});
|
|
1996
|
+
|
|
1997
|
+
it("should error if kv_namespaces is a string", () => {
|
|
1998
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
1999
|
+
{ env: { ENV1: { kv_namespaces: "BAD" } } } as unknown as RawConfig,
|
|
2000
|
+
undefined,
|
|
2001
|
+
{ env: "ENV1" }
|
|
2002
|
+
);
|
|
2003
|
+
|
|
2004
|
+
expect(config).toEqual(
|
|
2005
|
+
expect.not.objectContaining({ kv_namespaces: expect.anything })
|
|
2006
|
+
);
|
|
2007
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
2008
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
2009
|
+
"Processing wrangler configuration:
|
|
2010
|
+
|
|
2011
|
+
- \\"env.ENV1\\" environment configuration
|
|
2012
|
+
- The field \\"env.ENV1.kv_namespaces\\" should be an array but got \\"BAD\\"."
|
|
2013
|
+
`);
|
|
2014
|
+
});
|
|
2015
|
+
|
|
2016
|
+
it("should error if kv_namespaces is a number", () => {
|
|
2017
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
2018
|
+
{ env: { ENV1: { kv_namespaces: 999 } } } as unknown as RawConfig,
|
|
2019
|
+
undefined,
|
|
2020
|
+
{ env: "ENV1" }
|
|
2021
|
+
);
|
|
2022
|
+
|
|
2023
|
+
expect(config).toEqual(
|
|
2024
|
+
expect.not.objectContaining({ kv_namespaces: expect.anything })
|
|
2025
|
+
);
|
|
2026
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
2027
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
2028
|
+
"Processing wrangler configuration:
|
|
2029
|
+
|
|
2030
|
+
- \\"env.ENV1\\" environment configuration
|
|
2031
|
+
- The field \\"env.ENV1.kv_namespaces\\" should be an array but got 999."
|
|
2032
|
+
`);
|
|
2033
|
+
});
|
|
2034
|
+
|
|
2035
|
+
it("should error if kv_namespaces is null", () => {
|
|
2036
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
2037
|
+
{ env: { ENV1: { kv_namespaces: null } } } as unknown as RawConfig,
|
|
2038
|
+
undefined,
|
|
2039
|
+
{ env: "ENV1" }
|
|
2040
|
+
);
|
|
2041
|
+
|
|
2042
|
+
expect(config).toEqual(
|
|
2043
|
+
expect.not.objectContaining({ kv_namespaces: expect.anything })
|
|
2044
|
+
);
|
|
2045
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
2046
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
2047
|
+
"Processing wrangler configuration:
|
|
2048
|
+
|
|
2049
|
+
- \\"env.ENV1\\" environment configuration
|
|
2050
|
+
- The field \\"env.ENV1.kv_namespaces\\" should be an array but got null."
|
|
2051
|
+
`);
|
|
2052
|
+
});
|
|
2053
|
+
|
|
2054
|
+
it("should error if kv_namespaces.bindings are not valid", () => {
|
|
2055
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
2056
|
+
{
|
|
2057
|
+
env: {
|
|
2058
|
+
ENV1: {
|
|
2059
|
+
kv_namespaces: [
|
|
2060
|
+
{},
|
|
2061
|
+
{ binding: "VALID" },
|
|
2062
|
+
{ binding: 2000, id: 2111 },
|
|
2063
|
+
{
|
|
2064
|
+
binding: "KV_BINDING_2",
|
|
2065
|
+
id: "KV_ID_2",
|
|
2066
|
+
preview_id: 2222,
|
|
2067
|
+
},
|
|
2068
|
+
],
|
|
2069
|
+
},
|
|
2070
|
+
},
|
|
2071
|
+
} as unknown as RawConfig,
|
|
2072
|
+
undefined,
|
|
2073
|
+
{ env: "ENV1" }
|
|
2074
|
+
);
|
|
2075
|
+
|
|
2076
|
+
expect(config).toEqual(
|
|
2077
|
+
expect.not.objectContaining({
|
|
2078
|
+
kv_namespaces: { bindings: expect.anything },
|
|
2079
|
+
})
|
|
2080
|
+
);
|
|
2081
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
2082
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
2083
|
+
"Processing wrangler configuration:
|
|
2084
|
+
|
|
2085
|
+
- \\"env.ENV1\\" environment configuration
|
|
2086
|
+
- \\"env.ENV1.kv_namespaces[0]\\" bindings should have a string \\"binding\\" field but got {}.
|
|
2087
|
+
- \\"env.ENV1.kv_namespaces[0]\\" bindings should have a string \\"id\\" field but got {}.
|
|
2088
|
+
- \\"env.ENV1.kv_namespaces[1]\\" bindings should have a string \\"id\\" field but got {\\"binding\\":\\"VALID\\"}.
|
|
2089
|
+
- \\"env.ENV1.kv_namespaces[2]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":2000,\\"id\\":2111}.
|
|
2090
|
+
- \\"env.ENV1.kv_namespaces[2]\\" bindings should have a string \\"id\\" field but got {\\"binding\\":2000,\\"id\\":2111}.
|
|
2091
|
+
- \\"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}."
|
|
2092
|
+
`);
|
|
2093
|
+
});
|
|
2094
|
+
});
|
|
2095
|
+
|
|
2096
|
+
describe("r2_buckets field", () => {
|
|
2097
|
+
it("should error if r2_buckets is an object", () => {
|
|
2098
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
2099
|
+
{ env: { ENV1: { r2_buckets: {} } } } as unknown as RawConfig,
|
|
2100
|
+
undefined,
|
|
2101
|
+
{ env: "ENV1" }
|
|
2102
|
+
);
|
|
2103
|
+
|
|
2104
|
+
expect(config).toEqual(
|
|
2105
|
+
expect.not.objectContaining({ r2_buckets: expect.anything })
|
|
2106
|
+
);
|
|
2107
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
2108
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
2109
|
+
"Processing wrangler configuration:
|
|
2110
|
+
|
|
2111
|
+
- \\"env.ENV1\\" environment configuration
|
|
2112
|
+
- The field \\"env.ENV1.r2_buckets\\" should be an array but got {}."
|
|
2113
|
+
`);
|
|
2114
|
+
});
|
|
2115
|
+
|
|
2116
|
+
it("should error if r2_buckets is a string", () => {
|
|
2117
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
2118
|
+
{ env: { ENV1: { r2_buckets: "BAD" } } } as unknown as RawConfig,
|
|
2119
|
+
undefined,
|
|
2120
|
+
{ env: "ENV1" }
|
|
2121
|
+
);
|
|
2122
|
+
|
|
2123
|
+
expect(config).toEqual(
|
|
2124
|
+
expect.not.objectContaining({ r2_buckets: expect.anything })
|
|
2125
|
+
);
|
|
2126
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
2127
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
2128
|
+
"Processing wrangler configuration:
|
|
2129
|
+
|
|
2130
|
+
- \\"env.ENV1\\" environment configuration
|
|
2131
|
+
- The field \\"env.ENV1.r2_buckets\\" should be an array but got \\"BAD\\"."
|
|
2132
|
+
`);
|
|
2133
|
+
});
|
|
2134
|
+
|
|
2135
|
+
it("should error if r2_buckets is a number", () => {
|
|
2136
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
2137
|
+
{ env: { ENV1: { r2_buckets: 999 } } } as unknown as RawConfig,
|
|
2138
|
+
undefined,
|
|
2139
|
+
{ env: "ENV1" }
|
|
2140
|
+
);
|
|
2141
|
+
|
|
2142
|
+
expect(config).toEqual(
|
|
2143
|
+
expect.not.objectContaining({ r2_buckets: expect.anything })
|
|
2144
|
+
);
|
|
2145
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
2146
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
2147
|
+
"Processing wrangler configuration:
|
|
2148
|
+
|
|
2149
|
+
- \\"env.ENV1\\" environment configuration
|
|
2150
|
+
- The field \\"env.ENV1.r2_buckets\\" should be an array but got 999."
|
|
2151
|
+
`);
|
|
2152
|
+
});
|
|
2153
|
+
|
|
2154
|
+
it("should error if r2_buckets is null", () => {
|
|
2155
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
2156
|
+
{ env: { ENV1: { r2_buckets: null } } } as unknown as RawConfig,
|
|
2157
|
+
undefined,
|
|
2158
|
+
{ env: "ENV1" }
|
|
2159
|
+
);
|
|
2160
|
+
|
|
2161
|
+
expect(config).toEqual(
|
|
2162
|
+
expect.not.objectContaining({ r2_buckets: expect.anything })
|
|
2163
|
+
);
|
|
2164
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
2165
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
2166
|
+
"Processing wrangler configuration:
|
|
2167
|
+
|
|
2168
|
+
- \\"env.ENV1\\" environment configuration
|
|
2169
|
+
- The field \\"env.ENV1.r2_buckets\\" should be an array but got null."
|
|
2170
|
+
`);
|
|
2171
|
+
});
|
|
2172
|
+
|
|
2173
|
+
it("should error if r2_buckets.bindings are not valid", () => {
|
|
2174
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
2175
|
+
{
|
|
2176
|
+
env: {
|
|
2177
|
+
ENV1: {
|
|
2178
|
+
r2_buckets: [
|
|
2179
|
+
{},
|
|
2180
|
+
{ binding: "R2_BINDING_1" },
|
|
2181
|
+
{ binding: 2333, bucket_name: 2444 },
|
|
2182
|
+
{
|
|
2183
|
+
binding: "R2_BINDING_2",
|
|
2184
|
+
bucket_name: "R2_BUCKET_2",
|
|
2185
|
+
preview_bucket_name: 2555,
|
|
2186
|
+
},
|
|
2187
|
+
],
|
|
2188
|
+
},
|
|
2189
|
+
},
|
|
2190
|
+
} as unknown as RawConfig,
|
|
2191
|
+
undefined,
|
|
2192
|
+
{ env: "ENV1" }
|
|
2193
|
+
);
|
|
2194
|
+
|
|
2195
|
+
expect(config).toEqual(
|
|
2196
|
+
expect.not.objectContaining({
|
|
2197
|
+
r2_buckets: { bindings: expect.anything },
|
|
2198
|
+
})
|
|
2199
|
+
);
|
|
2200
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
2201
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
2202
|
+
"Processing wrangler configuration:
|
|
2203
|
+
|
|
2204
|
+
- \\"env.ENV1\\" environment configuration
|
|
2205
|
+
- \\"env.ENV1.r2_buckets[0]\\" bindings should have a string \\"binding\\" field but got {}.
|
|
2206
|
+
- \\"env.ENV1.r2_buckets[0]\\" bindings should have a string \\"bucket_name\\" field but got {}.
|
|
2207
|
+
- \\"env.ENV1.r2_buckets[1]\\" bindings should have a string \\"bucket_name\\" field but got {\\"binding\\":\\"R2_BINDING_1\\"}.
|
|
2208
|
+
- \\"env.ENV1.r2_buckets[2]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":2333,\\"bucket_name\\":2444}.
|
|
2209
|
+
- \\"env.ENV1.r2_buckets[2]\\" bindings should have a string \\"bucket_name\\" field but got {\\"binding\\":2333,\\"bucket_name\\":2444}.
|
|
2210
|
+
- \\"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}."
|
|
2211
|
+
`);
|
|
2212
|
+
});
|
|
2213
|
+
});
|
|
2214
|
+
|
|
2215
|
+
describe("unsafe field", () => {
|
|
2216
|
+
it("should error if unsafe is an array", () => {
|
|
2217
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
2218
|
+
{ env: { ENV1: { unsafe: [] } } } as unknown as RawConfig,
|
|
2219
|
+
undefined,
|
|
2220
|
+
{ env: "ENV1" }
|
|
2221
|
+
);
|
|
2222
|
+
|
|
2223
|
+
expect(config).toEqual(
|
|
2224
|
+
expect.not.objectContaining({ unsafe: expect.anything })
|
|
2225
|
+
);
|
|
2226
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
2227
|
+
"Processing wrangler configuration:
|
|
2228
|
+
|
|
2229
|
+
- \\"env.ENV1\\" environment configuration
|
|
2230
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
2231
|
+
`);
|
|
2232
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
2233
|
+
"Processing wrangler configuration:
|
|
2234
|
+
|
|
2235
|
+
- \\"env.ENV1\\" environment configuration
|
|
2236
|
+
- The field \\"env.ENV1.unsafe\\" should be an object but got []."
|
|
2237
|
+
`);
|
|
2238
|
+
});
|
|
2239
|
+
|
|
2240
|
+
it("should error if unsafe is a string", () => {
|
|
2241
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
2242
|
+
{ env: { ENV1: { unsafe: "BAD" } } } as unknown as RawConfig,
|
|
2243
|
+
undefined,
|
|
2244
|
+
{ env: "ENV1" }
|
|
2245
|
+
);
|
|
2246
|
+
|
|
2247
|
+
expect(config).toEqual(
|
|
2248
|
+
expect.not.objectContaining({ unsafe: expect.anything })
|
|
2249
|
+
);
|
|
2250
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
2251
|
+
"Processing wrangler configuration:
|
|
2252
|
+
|
|
2253
|
+
- \\"env.ENV1\\" environment configuration
|
|
2254
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
2255
|
+
`);
|
|
2256
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
2257
|
+
"Processing wrangler configuration:
|
|
2258
|
+
|
|
2259
|
+
- \\"env.ENV1\\" environment configuration
|
|
2260
|
+
- The field \\"env.ENV1.unsafe\\" should be an object but got \\"BAD\\"."
|
|
2261
|
+
`);
|
|
2262
|
+
});
|
|
2263
|
+
|
|
2264
|
+
it("should error if unsafe is a number", () => {
|
|
2265
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
2266
|
+
{ env: { ENV1: { unsafe: 999 } } } as unknown as RawConfig,
|
|
2267
|
+
undefined,
|
|
2268
|
+
{ env: "ENV1" }
|
|
2269
|
+
);
|
|
2270
|
+
|
|
2271
|
+
expect(config).toEqual(
|
|
2272
|
+
expect.not.objectContaining({ unsafe: expect.anything })
|
|
2273
|
+
);
|
|
2274
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
2275
|
+
"Processing wrangler configuration:
|
|
2276
|
+
|
|
2277
|
+
- \\"env.ENV1\\" environment configuration
|
|
2278
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
2279
|
+
`);
|
|
2280
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
2281
|
+
"Processing wrangler configuration:
|
|
2282
|
+
|
|
2283
|
+
- \\"env.ENV1\\" environment configuration
|
|
2284
|
+
- The field \\"env.ENV1.unsafe\\" should be an object but got 999."
|
|
2285
|
+
`);
|
|
2286
|
+
});
|
|
2287
|
+
|
|
2288
|
+
it("should error if unsafe is null", () => {
|
|
2289
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
2290
|
+
{ env: { ENV1: { unsafe: null } } } as unknown as RawConfig,
|
|
2291
|
+
undefined,
|
|
2292
|
+
{ env: "ENV1" }
|
|
2293
|
+
);
|
|
2294
|
+
|
|
2295
|
+
expect(config).toEqual(
|
|
2296
|
+
expect.not.objectContaining({ unsafe: expect.anything })
|
|
2297
|
+
);
|
|
2298
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
2299
|
+
"Processing wrangler configuration:
|
|
2300
|
+
|
|
2301
|
+
- \\"env.ENV1\\" environment configuration
|
|
2302
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
2303
|
+
`);
|
|
2304
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
2305
|
+
"Processing wrangler configuration:
|
|
2306
|
+
|
|
2307
|
+
- \\"env.ENV1\\" environment configuration
|
|
2308
|
+
- The field \\"env.ENV1.unsafe\\" should be an object but got null."
|
|
2309
|
+
`);
|
|
2310
|
+
});
|
|
2311
|
+
|
|
2312
|
+
it("should error if unsafe.bindings is not defined", () => {
|
|
2313
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
2314
|
+
{ env: { ENV1: { unsafe: {} } } } as unknown as RawConfig,
|
|
2315
|
+
undefined,
|
|
2316
|
+
{ env: "ENV1" }
|
|
2317
|
+
);
|
|
2318
|
+
|
|
2319
|
+
expect(config).toEqual(
|
|
2320
|
+
expect.not.objectContaining({ unsafe: expect.anything })
|
|
2321
|
+
);
|
|
2322
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
2323
|
+
"Processing wrangler configuration:
|
|
2324
|
+
|
|
2325
|
+
- \\"env.ENV1\\" environment configuration
|
|
2326
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
2327
|
+
`);
|
|
2328
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
2329
|
+
"Processing wrangler configuration:
|
|
2330
|
+
|
|
2331
|
+
- \\"env.ENV1\\" environment configuration
|
|
2332
|
+
- The field \\"env.ENV1.unsafe\\" is missing the required \\"bindings\\" property."
|
|
2333
|
+
`);
|
|
2334
|
+
});
|
|
2335
|
+
|
|
2336
|
+
it("should error if unsafe.bindings is an object", () => {
|
|
2337
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
2338
|
+
{
|
|
2339
|
+
env: { ENV1: { unsafe: { bindings: {} } } },
|
|
2340
|
+
} as unknown as RawConfig,
|
|
2341
|
+
undefined,
|
|
2342
|
+
{ env: "ENV1" }
|
|
2343
|
+
);
|
|
2344
|
+
|
|
2345
|
+
expect(config).toEqual(
|
|
2346
|
+
expect.not.objectContaining({
|
|
2347
|
+
unsafe: { bindings: expect.anything },
|
|
2348
|
+
})
|
|
2349
|
+
);
|
|
2350
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
2351
|
+
"Processing wrangler configuration:
|
|
2352
|
+
|
|
2353
|
+
- \\"env.ENV1\\" environment configuration
|
|
2354
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
2355
|
+
`);
|
|
2356
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
2357
|
+
"Processing wrangler configuration:
|
|
2358
|
+
|
|
2359
|
+
- \\"env.ENV1\\" environment configuration
|
|
2360
|
+
- The field \\"env.ENV1.unsafe.bindings\\" should be an array but got {}."
|
|
2361
|
+
`);
|
|
2362
|
+
});
|
|
2363
|
+
|
|
2364
|
+
it("should error if unsafe.bindings is a string", () => {
|
|
2365
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
2366
|
+
{
|
|
2367
|
+
env: { ENV1: { unsafe: { bindings: "BAD" } } },
|
|
2368
|
+
} as unknown as RawConfig,
|
|
2369
|
+
undefined,
|
|
2370
|
+
{ env: "ENV1" }
|
|
2371
|
+
);
|
|
2372
|
+
|
|
2373
|
+
expect(config).toEqual(
|
|
2374
|
+
expect.not.objectContaining({
|
|
2375
|
+
unsafe: { bindings: expect.anything },
|
|
2376
|
+
})
|
|
2377
|
+
);
|
|
2378
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
2379
|
+
"Processing wrangler configuration:
|
|
2380
|
+
|
|
2381
|
+
- \\"env.ENV1\\" environment configuration
|
|
2382
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
2383
|
+
`);
|
|
2384
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
2385
|
+
"Processing wrangler configuration:
|
|
2386
|
+
|
|
2387
|
+
- \\"env.ENV1\\" environment configuration
|
|
2388
|
+
- The field \\"env.ENV1.unsafe.bindings\\" should be an array but got \\"BAD\\"."
|
|
2389
|
+
`);
|
|
2390
|
+
});
|
|
2391
|
+
|
|
2392
|
+
it("should error if unsafe.bindings is a number", () => {
|
|
2393
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
2394
|
+
{
|
|
2395
|
+
env: { ENV1: { unsafe: { bindings: 999 } } },
|
|
2396
|
+
} as unknown as RawConfig,
|
|
2397
|
+
undefined,
|
|
2398
|
+
{ env: "ENV1" }
|
|
2399
|
+
);
|
|
2400
|
+
|
|
2401
|
+
expect(config).toEqual(
|
|
2402
|
+
expect.not.objectContaining({
|
|
2403
|
+
unsafe: { bindings: expect.anything },
|
|
2404
|
+
})
|
|
2405
|
+
);
|
|
2406
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
2407
|
+
"Processing wrangler configuration:
|
|
2408
|
+
|
|
2409
|
+
- \\"env.ENV1\\" environment configuration
|
|
2410
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
2411
|
+
`);
|
|
2412
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
2413
|
+
"Processing wrangler configuration:
|
|
2414
|
+
|
|
2415
|
+
- \\"env.ENV1\\" environment configuration
|
|
2416
|
+
- The field \\"env.ENV1.unsafe.bindings\\" should be an array but got 999."
|
|
2417
|
+
`);
|
|
2418
|
+
});
|
|
2419
|
+
|
|
2420
|
+
it("should error if unsafe.bindings is null", () => {
|
|
2421
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
2422
|
+
{
|
|
2423
|
+
env: { ENV1: { unsafe: { bindings: null } } },
|
|
2424
|
+
} as unknown as RawConfig,
|
|
2425
|
+
undefined,
|
|
2426
|
+
{ env: "ENV1" }
|
|
2427
|
+
);
|
|
2428
|
+
|
|
2429
|
+
expect(config).toEqual(
|
|
2430
|
+
expect.not.objectContaining({
|
|
2431
|
+
unsafe: { bindings: expect.anything },
|
|
2432
|
+
})
|
|
2433
|
+
);
|
|
2434
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
2435
|
+
"Processing wrangler configuration:
|
|
2436
|
+
|
|
2437
|
+
- \\"env.ENV1\\" environment configuration
|
|
2438
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
2439
|
+
`);
|
|
2440
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
2441
|
+
"Processing wrangler configuration:
|
|
2442
|
+
|
|
2443
|
+
- \\"env.ENV1\\" environment configuration
|
|
2444
|
+
- The field \\"env.ENV1.unsafe.bindings\\" should be an array but got null."
|
|
2445
|
+
`);
|
|
2446
|
+
});
|
|
2447
|
+
|
|
2448
|
+
it("should error if unsafe.bindings are not valid", () => {
|
|
2449
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
2450
|
+
{
|
|
2451
|
+
env: {
|
|
2452
|
+
ENV1: {
|
|
2453
|
+
unsafe: {
|
|
2454
|
+
bindings: [
|
|
2455
|
+
{},
|
|
2456
|
+
{ name: "UNSAFE_BINDING_1" },
|
|
2457
|
+
{ name: 2666, type: 2777 },
|
|
2458
|
+
{
|
|
2459
|
+
name: "UNSAFE_BINDING_2",
|
|
2460
|
+
type: "UNSAFE_TYPE_2",
|
|
2461
|
+
extra: 2888,
|
|
2462
|
+
},
|
|
2463
|
+
],
|
|
2464
|
+
},
|
|
2465
|
+
},
|
|
2466
|
+
},
|
|
2467
|
+
} as unknown as RawConfig,
|
|
2468
|
+
undefined,
|
|
2469
|
+
{ env: "ENV1" }
|
|
2470
|
+
);
|
|
2471
|
+
|
|
2472
|
+
expect(config).toEqual(
|
|
2473
|
+
expect.not.objectContaining({
|
|
2474
|
+
durable_objects: { bindings: expect.anything },
|
|
2475
|
+
})
|
|
2476
|
+
);
|
|
2477
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
2478
|
+
"Processing wrangler configuration:
|
|
2479
|
+
|
|
2480
|
+
- \\"env.ENV1\\" environment configuration
|
|
2481
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
2482
|
+
`);
|
|
2483
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
2484
|
+
"Processing wrangler configuration:
|
|
2485
|
+
|
|
2486
|
+
- \\"env.ENV1\\" environment configuration
|
|
2487
|
+
|
|
2488
|
+
- \\"env.ENV1.unsafe.bindings[0]\\": {}
|
|
2489
|
+
- binding should have a string \\"name\\" field.
|
|
2490
|
+
- binding should have a string \\"type\\" field.
|
|
2491
|
+
|
|
2492
|
+
- \\"env.ENV1.unsafe.bindings[1]\\": {\\"name\\":\\"UNSAFE_BINDING_1\\"}
|
|
2493
|
+
- binding should have a string \\"type\\" field.
|
|
2494
|
+
|
|
2495
|
+
- \\"env.ENV1.unsafe.bindings[2]\\": {\\"name\\":2666,\\"type\\":2777}
|
|
2496
|
+
- binding should have a string \\"name\\" field.
|
|
2497
|
+
- binding should have a string \\"type\\" field."
|
|
2498
|
+
`);
|
|
2499
|
+
});
|
|
2500
|
+
});
|
|
2501
|
+
|
|
2502
|
+
describe("(deprecated)", () => {
|
|
2503
|
+
it("should remove and warn about deprecated properties", () => {
|
|
2504
|
+
const environment: RawEnvironment = {
|
|
2505
|
+
zone_id: "ZONE_ID",
|
|
2506
|
+
experimental_services: [
|
|
2507
|
+
{
|
|
2508
|
+
name: "NAME",
|
|
2509
|
+
service: "SERVICE",
|
|
2510
|
+
environment: "ENV",
|
|
2511
|
+
},
|
|
2512
|
+
],
|
|
2513
|
+
};
|
|
2514
|
+
|
|
2515
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
2516
|
+
{
|
|
2517
|
+
env: {
|
|
2518
|
+
ENV1: environment,
|
|
2519
|
+
},
|
|
2520
|
+
},
|
|
2521
|
+
undefined,
|
|
2522
|
+
{ env: "ENV1" }
|
|
2523
|
+
);
|
|
2524
|
+
|
|
2525
|
+
expect("experimental_services" in config).toBe(false);
|
|
2526
|
+
// Zone is not removed yet, since `route` commands might use it
|
|
2527
|
+
expect(config.zone_id).toEqual("ZONE_ID");
|
|
2528
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
2529
|
+
expect(diagnostics.hasWarnings()).toBe(true);
|
|
2530
|
+
expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
|
|
2531
|
+
"Processing wrangler configuration:
|
|
2532
|
+
|
|
2533
|
+
- \\"env.ENV1\\" environment configuration
|
|
2534
|
+
- DEPRECATION: \\"zone_id\\":
|
|
2535
|
+
This is unnecessary since we can deduce this from routes directly.
|
|
2536
|
+
- DEPRECATION: \\"experimental_services\\":
|
|
2537
|
+
The \\"experimental_services\\" field is no longer supported. Instead, use [[unsafe.bindings]] to enable experimental features. Add this to your wrangler.toml:
|
|
2538
|
+
\`\`\`
|
|
2539
|
+
[[unsafe.bindings]]
|
|
2540
|
+
name = \\"NAME\\"
|
|
2541
|
+
type = \\"service\\"
|
|
2542
|
+
service = \\"SERVICE\\"
|
|
2543
|
+
environment = \\"ENV\\"
|
|
2544
|
+
\`\`\`"
|
|
2545
|
+
`);
|
|
2546
|
+
});
|
|
2547
|
+
});
|
|
2548
|
+
|
|
2549
|
+
describe("route & routes fields", () => {
|
|
2550
|
+
it("should error if both route and routes are specified in the same environment", () => {
|
|
2551
|
+
const environment: RawEnvironment = {
|
|
2552
|
+
name: "ENV_NAME",
|
|
2553
|
+
account_id: "ENV_ACCOUNT_ID",
|
|
2554
|
+
compatibility_date: "2022-02-02",
|
|
2555
|
+
compatibility_flags: ["ENV_FLAG1", "ENV_FLAG2"],
|
|
2556
|
+
workers_dev: true,
|
|
2557
|
+
route: "ENV_ROUTE_1",
|
|
2558
|
+
routes: ["ENV_ROUTE_2", "ENV_ROUTE_3"],
|
|
2559
|
+
jsx_factory: "ENV_JSX_FACTORY",
|
|
2560
|
+
jsx_fragment: "ENV_JSX_FRAGMENT",
|
|
2561
|
+
triggers: { crons: ["ENV_CRON_1", "ENV_CRON_2"] },
|
|
2562
|
+
usage_model: "unbound",
|
|
2563
|
+
};
|
|
2564
|
+
const expectedConfig: RawConfig = {
|
|
2565
|
+
name: "NAME",
|
|
2566
|
+
account_id: "ACCOUNT_ID",
|
|
2567
|
+
compatibility_date: "2022-01-01",
|
|
2568
|
+
compatibility_flags: ["FLAG1", "FLAG2"],
|
|
2569
|
+
workers_dev: false,
|
|
2570
|
+
routes: ["ROUTE_1", "ROUTE_2"],
|
|
2571
|
+
jsx_factory: "JSX_FACTORY",
|
|
2572
|
+
jsx_fragment: "JSX_FRAGMENT",
|
|
2573
|
+
triggers: { crons: ["CRON_1", "CRON_2"] },
|
|
2574
|
+
usage_model: "bundled",
|
|
2575
|
+
env: {
|
|
2576
|
+
ENV1: environment,
|
|
2577
|
+
},
|
|
2578
|
+
};
|
|
2579
|
+
|
|
2580
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
2581
|
+
expectedConfig,
|
|
2582
|
+
undefined,
|
|
2583
|
+
{ env: "ENV1" }
|
|
2584
|
+
);
|
|
2585
|
+
|
|
2586
|
+
expect(config).toEqual(expect.objectContaining(environment));
|
|
2587
|
+
expect(diagnostics.hasErrors()).toBe(true);
|
|
2588
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
2589
|
+
|
|
2590
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
2591
|
+
"Processing wrangler configuration:
|
|
2592
|
+
|
|
2593
|
+
- \\"env.ENV1\\" environment configuration
|
|
2594
|
+
- Expected exactly one of the following fields [\\"routes\\",\\"route\\"]."
|
|
2595
|
+
`);
|
|
2596
|
+
});
|
|
2597
|
+
|
|
2598
|
+
it("should error if both route and routes are specified in the top-level environment", () => {
|
|
2599
|
+
const environment: RawEnvironment = {
|
|
2600
|
+
name: "ENV_NAME",
|
|
2601
|
+
account_id: "ENV_ACCOUNT_ID",
|
|
2602
|
+
compatibility_date: "2022-02-02",
|
|
2603
|
+
compatibility_flags: ["ENV_FLAG1", "ENV_FLAG2"],
|
|
2604
|
+
workers_dev: true,
|
|
2605
|
+
routes: ["ENV_ROUTE_1", "ENV_ROUTE_2"],
|
|
2606
|
+
jsx_factory: "ENV_JSX_FACTORY",
|
|
2607
|
+
jsx_fragment: "ENV_JSX_FRAGMENT",
|
|
2608
|
+
triggers: { crons: ["ENV_CRON_1", "ENV_CRON_2"] },
|
|
2609
|
+
usage_model: "unbound",
|
|
2610
|
+
};
|
|
2611
|
+
const expectedConfig: RawConfig = {
|
|
2612
|
+
name: "NAME",
|
|
2613
|
+
account_id: "ACCOUNT_ID",
|
|
2614
|
+
compatibility_date: "2022-01-01",
|
|
2615
|
+
compatibility_flags: ["FLAG1", "FLAG2"],
|
|
2616
|
+
workers_dev: false,
|
|
2617
|
+
route: "ROUTE_1",
|
|
2618
|
+
routes: ["ROUTE_2", "ROUTE_3"],
|
|
2619
|
+
jsx_factory: "JSX_FACTORY",
|
|
2620
|
+
jsx_fragment: "JSX_FRAGMENT",
|
|
2621
|
+
triggers: { crons: ["CRON_1", "CRON_2"] },
|
|
2622
|
+
usage_model: "bundled",
|
|
2623
|
+
env: {
|
|
2624
|
+
ENV1: environment,
|
|
2625
|
+
},
|
|
2626
|
+
};
|
|
2627
|
+
|
|
2628
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
2629
|
+
expectedConfig,
|
|
2630
|
+
undefined,
|
|
2631
|
+
{ env: "ENV1" }
|
|
2632
|
+
);
|
|
2633
|
+
|
|
2634
|
+
expect(config).toEqual(expect.objectContaining(environment));
|
|
2635
|
+
expect(diagnostics.hasErrors()).toBe(true);
|
|
2636
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
2637
|
+
|
|
2638
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
2639
|
+
"Processing wrangler configuration:
|
|
2640
|
+
- Expected exactly one of the following fields [\\"routes\\",\\"route\\"]."
|
|
2641
|
+
`);
|
|
2642
|
+
});
|
|
2643
|
+
|
|
2644
|
+
it("should not error if <env>.route and <top-level>.routes are specified", () => {
|
|
2645
|
+
const environment: RawEnvironment = {
|
|
2646
|
+
name: "ENV_NAME",
|
|
2647
|
+
account_id: "ENV_ACCOUNT_ID",
|
|
2648
|
+
compatibility_date: "2022-02-02",
|
|
2649
|
+
compatibility_flags: ["ENV_FLAG1", "ENV_FLAG2"],
|
|
2650
|
+
workers_dev: true,
|
|
2651
|
+
route: "ENV_ROUTE_1",
|
|
2652
|
+
jsx_factory: "ENV_JSX_FACTORY",
|
|
2653
|
+
jsx_fragment: "ENV_JSX_FRAGMENT",
|
|
2654
|
+
triggers: { crons: ["ENV_CRON_1", "ENV_CRON_2"] },
|
|
2655
|
+
usage_model: "unbound",
|
|
2656
|
+
};
|
|
2657
|
+
const expectedConfig: RawConfig = {
|
|
2658
|
+
name: "NAME",
|
|
2659
|
+
account_id: "ACCOUNT_ID",
|
|
2660
|
+
compatibility_date: "2022-01-01",
|
|
2661
|
+
compatibility_flags: ["FLAG1", "FLAG2"],
|
|
2662
|
+
workers_dev: false,
|
|
2663
|
+
routes: ["ROUTE_1", "ROUTE_2"],
|
|
2664
|
+
jsx_factory: "JSX_FACTORY",
|
|
2665
|
+
jsx_fragment: "JSX_FRAGMENT",
|
|
2666
|
+
triggers: { crons: ["CRON_1", "CRON_2"] },
|
|
2667
|
+
usage_model: "bundled",
|
|
2668
|
+
env: {
|
|
2669
|
+
ENV1: environment,
|
|
2670
|
+
},
|
|
2671
|
+
};
|
|
2672
|
+
|
|
2673
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
2674
|
+
expectedConfig,
|
|
2675
|
+
undefined,
|
|
2676
|
+
{ env: "ENV1" }
|
|
2677
|
+
);
|
|
2678
|
+
|
|
2679
|
+
expect(config).toEqual(expect.objectContaining(environment));
|
|
2680
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
2681
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
2682
|
+
});
|
|
2683
|
+
|
|
2684
|
+
it("should not error if <env>.routes and <top-level>.route are specified", () => {
|
|
2685
|
+
const environment: RawEnvironment = {
|
|
2686
|
+
name: "ENV_NAME",
|
|
2687
|
+
account_id: "ENV_ACCOUNT_ID",
|
|
2688
|
+
compatibility_date: "2022-02-02",
|
|
2689
|
+
compatibility_flags: ["ENV_FLAG1", "ENV_FLAG2"],
|
|
2690
|
+
workers_dev: true,
|
|
2691
|
+
routes: ["ENV_ROUTE_1", "ENV_ROUTE_2"],
|
|
2692
|
+
jsx_factory: "ENV_JSX_FACTORY",
|
|
2693
|
+
jsx_fragment: "ENV_JSX_FRAGMENT",
|
|
2694
|
+
triggers: { crons: ["ENV_CRON_1", "ENV_CRON_2"] },
|
|
2695
|
+
usage_model: "unbound",
|
|
2696
|
+
};
|
|
2697
|
+
const expectedConfig: RawConfig = {
|
|
2698
|
+
name: "NAME",
|
|
2699
|
+
account_id: "ACCOUNT_ID",
|
|
2700
|
+
compatibility_date: "2022-01-01",
|
|
2701
|
+
compatibility_flags: ["FLAG1", "FLAG2"],
|
|
2702
|
+
workers_dev: false,
|
|
2703
|
+
route: "ROUTE_1",
|
|
2704
|
+
jsx_factory: "JSX_FACTORY",
|
|
2705
|
+
jsx_fragment: "JSX_FRAGMENT",
|
|
2706
|
+
triggers: { crons: ["CRON_1", "CRON_2"] },
|
|
2707
|
+
usage_model: "bundled",
|
|
2708
|
+
env: {
|
|
2709
|
+
ENV1: environment,
|
|
2710
|
+
},
|
|
2711
|
+
};
|
|
2712
|
+
|
|
2713
|
+
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
2714
|
+
expectedConfig,
|
|
2715
|
+
undefined,
|
|
2716
|
+
{ env: "ENV1" }
|
|
2717
|
+
);
|
|
2718
|
+
|
|
2719
|
+
expect(config).toEqual(expect.objectContaining(environment));
|
|
2720
|
+
expect(diagnostics.hasErrors()).toBe(false);
|
|
2721
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
2722
|
+
});
|
|
2723
|
+
|
|
2724
|
+
it("should not error if <env1>.route and <env2>.routes are specified", () => {
|
|
2725
|
+
const environment1: RawEnvironment = {
|
|
2726
|
+
name: "ENV_NAME",
|
|
2727
|
+
account_id: "ENV_ACCOUNT_ID",
|
|
2728
|
+
compatibility_date: "2022-02-02",
|
|
2729
|
+
compatibility_flags: ["ENV_FLAG1", "ENV_FLAG2"],
|
|
2730
|
+
workers_dev: true,
|
|
2731
|
+
routes: ["ENV1_ROUTE_1", "ENV2_ROUTE_2"],
|
|
2732
|
+
jsx_factory: "ENV_JSX_FACTORY",
|
|
2733
|
+
jsx_fragment: "ENV_JSX_FRAGMENT",
|
|
2734
|
+
triggers: { crons: ["ENV_CRON_1", "ENV_CRON_2"] },
|
|
2735
|
+
usage_model: "unbound",
|
|
2736
|
+
};
|
|
2737
|
+
const environment2: RawEnvironment = {
|
|
2738
|
+
name: "ENV_NAME",
|
|
2739
|
+
account_id: "ENV_ACCOUNT_ID",
|
|
2740
|
+
compatibility_date: "2022-02-02",
|
|
2741
|
+
compatibility_flags: ["ENV_FLAG1", "ENV_FLAG2"],
|
|
2742
|
+
workers_dev: true,
|
|
2743
|
+
route: "ENV2_ROUTE_1",
|
|
2744
|
+
jsx_factory: "ENV_JSX_FACTORY",
|
|
2745
|
+
jsx_fragment: "ENV_JSX_FRAGMENT",
|
|
2746
|
+
triggers: { crons: ["ENV_CRON_1", "ENV_CRON_2"] },
|
|
2747
|
+
usage_model: "unbound",
|
|
2748
|
+
};
|
|
2749
|
+
const expectedConfig: RawConfig = {
|
|
2750
|
+
name: "NAME",
|
|
2751
|
+
account_id: "ACCOUNT_ID",
|
|
2752
|
+
compatibility_date: "2022-01-01",
|
|
2753
|
+
compatibility_flags: ["FLAG1", "FLAG2"],
|
|
2754
|
+
workers_dev: false,
|
|
2755
|
+
route: "ROUTE_1",
|
|
2756
|
+
jsx_factory: "JSX_FACTORY",
|
|
2757
|
+
jsx_fragment: "JSX_FRAGMENT",
|
|
2758
|
+
triggers: { crons: ["CRON_1", "CRON_2"] },
|
|
2759
|
+
usage_model: "bundled",
|
|
2760
|
+
env: {
|
|
2761
|
+
ENV1: environment1,
|
|
2762
|
+
ENV2: environment2,
|
|
2763
|
+
},
|
|
2764
|
+
};
|
|
2765
|
+
|
|
2766
|
+
const result1 = normalizeAndValidateConfig(expectedConfig, undefined, {
|
|
2767
|
+
env: "ENV1",
|
|
2768
|
+
});
|
|
2769
|
+
|
|
2770
|
+
expect(result1.config).toEqual(expect.objectContaining(environment1));
|
|
2771
|
+
expect(result1.diagnostics.hasErrors()).toBe(false);
|
|
2772
|
+
expect(result1.diagnostics.hasWarnings()).toBe(false);
|
|
2773
|
+
|
|
2774
|
+
const result2 = normalizeAndValidateConfig(expectedConfig, undefined, {
|
|
2775
|
+
env: "ENV2",
|
|
2776
|
+
});
|
|
2777
|
+
|
|
2778
|
+
expect(result2.config).toEqual(expect.objectContaining(environment2));
|
|
2779
|
+
expect(result2.diagnostics.hasErrors()).toBe(false);
|
|
2780
|
+
expect(result2.diagnostics.hasWarnings()).toBe(false);
|
|
2781
|
+
});
|
|
2782
|
+
});
|
|
2783
|
+
});
|
|
2784
|
+
});
|
|
2785
|
+
|
|
2786
|
+
function normalizePath(text: string): string {
|
|
2787
|
+
return text
|
|
2788
|
+
.replace("project\\wrangler.toml", "project/wrangler.toml")
|
|
2789
|
+
.replace("src\\index.ts", "src/index.ts");
|
|
2790
|
+
}
|