wrangler 0.0.0-ddde8d4 → 0.0.0-e043479
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/package.json +7 -5
- package/src/__tests__/configuration.test.ts +2186 -0
- package/src/__tests__/dev.test.tsx +218 -75
- package/src/__tests__/helpers/faye-websocket.d.ts +6 -0
- package/src/__tests__/helpers/mock-account-id.ts +18 -4
- package/src/__tests__/helpers/mock-console.ts +17 -9
- package/src/__tests__/helpers/mock-stdin.ts +103 -0
- package/src/__tests__/helpers/write-wrangler-toml.ts +2 -5
- package/src/__tests__/index.test.ts +125 -49
- package/src/__tests__/jest.setup.ts +16 -4
- package/src/__tests__/kv.test.ts +399 -132
- package/src/__tests__/parse.test.ts +322 -0
- package/src/__tests__/publish.test.ts +791 -382
- package/src/__tests__/r2.test.ts +16 -24
- package/src/__tests__/secret.test.ts +299 -84
- package/src/__tests__/tail.test.ts +309 -176
- package/src/api/form_data.ts +43 -7
- package/src/api/preview.ts +36 -17
- package/src/api/worker.ts +18 -6
- package/src/bundle.ts +21 -15
- package/src/cfetch/index.ts +7 -5
- package/src/cfetch/internal.ts +24 -7
- package/src/config/README.md +107 -0
- package/src/config/config.ts +270 -0
- package/src/config/diagnostics.ts +80 -0
- package/src/config/environment.ts +305 -0
- package/src/config/index.ts +52 -0
- package/src/config/validation-helpers.ts +370 -0
- package/src/config/validation.ts +1019 -0
- package/src/dev.tsx +123 -49
- package/src/entry.ts +57 -0
- package/src/guess-worker-format.ts +1 -1
- package/src/index.tsx +631 -869
- package/src/kv.tsx +101 -44
- package/src/module-collection.ts +133 -47
- package/src/package-manager.ts +21 -15
- package/src/parse.ts +183 -0
- package/src/proxy.ts +18 -10
- package/src/publish.ts +70 -65
- package/src/sites.tsx +5 -11
- package/src/tail/index.ts +17 -7
- package/src/user.tsx +19 -5
- package/templates/tsconfig.json +105 -0
- package/wrangler-dist/cli.js +6177 -2424
- package/wrangler-dist/cli.js.map +3 -3
- package/src/config.ts +0 -671
|
@@ -9,6 +9,7 @@ import { runInTempDir } from "./helpers/run-in-tmp";
|
|
|
9
9
|
import { runWrangler } from "./helpers/run-wrangler";
|
|
10
10
|
import writeWranglerToml from "./helpers/write-wrangler-toml";
|
|
11
11
|
import type { WorkerMetadata } from "../api/form_data";
|
|
12
|
+
import type { Config } from "../config";
|
|
12
13
|
import type { KVNamespaceInfo } from "../kv";
|
|
13
14
|
import type { FormData, File } from "undici";
|
|
14
15
|
|
|
@@ -28,6 +29,100 @@ describe("publish", () => {
|
|
|
28
29
|
unsetAllMocks();
|
|
29
30
|
});
|
|
30
31
|
|
|
32
|
+
describe("environments", () => {
|
|
33
|
+
it("should use legacy environments by default", async () => {
|
|
34
|
+
writeWranglerToml();
|
|
35
|
+
writeWorkerSource();
|
|
36
|
+
mockSubDomainRequest();
|
|
37
|
+
mockUploadWorkerRequest({
|
|
38
|
+
env: "some-env",
|
|
39
|
+
legacyEnv: true,
|
|
40
|
+
});
|
|
41
|
+
await runWrangler("publish index.js --env some-env");
|
|
42
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
43
|
+
"Uploaded test-name-some-env (TIMINGS)
|
|
44
|
+
Published test-name-some-env (TIMINGS)
|
|
45
|
+
test-name-some-env.test-sub-domain.workers.dev"
|
|
46
|
+
`);
|
|
47
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
48
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe("legacy", () => {
|
|
52
|
+
it("uses the script name when no environment is specified", async () => {
|
|
53
|
+
writeWranglerToml();
|
|
54
|
+
writeWorkerSource();
|
|
55
|
+
mockSubDomainRequest();
|
|
56
|
+
mockUploadWorkerRequest({
|
|
57
|
+
legacyEnv: true,
|
|
58
|
+
});
|
|
59
|
+
await runWrangler("publish index.js --legacy-env true");
|
|
60
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
61
|
+
"Uploaded test-name (TIMINGS)
|
|
62
|
+
Published test-name (TIMINGS)
|
|
63
|
+
test-name.test-sub-domain.workers.dev"
|
|
64
|
+
`);
|
|
65
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
66
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("appends the environment name when provided", async () => {
|
|
70
|
+
writeWranglerToml();
|
|
71
|
+
writeWorkerSource();
|
|
72
|
+
mockSubDomainRequest();
|
|
73
|
+
mockUploadWorkerRequest({
|
|
74
|
+
env: "some-env",
|
|
75
|
+
legacyEnv: true,
|
|
76
|
+
});
|
|
77
|
+
await runWrangler("publish index.js --env some-env --legacy-env true");
|
|
78
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
79
|
+
"Uploaded test-name-some-env (TIMINGS)
|
|
80
|
+
Published test-name-some-env (TIMINGS)
|
|
81
|
+
test-name-some-env.test-sub-domain.workers.dev"
|
|
82
|
+
`);
|
|
83
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
84
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
describe("services", () => {
|
|
89
|
+
it("uses the script name when no environment is specified", async () => {
|
|
90
|
+
writeWranglerToml();
|
|
91
|
+
writeWorkerSource();
|
|
92
|
+
mockSubDomainRequest();
|
|
93
|
+
mockUploadWorkerRequest({
|
|
94
|
+
legacyEnv: false,
|
|
95
|
+
});
|
|
96
|
+
await runWrangler("publish index.js");
|
|
97
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
98
|
+
"Uploaded test-name (TIMINGS)
|
|
99
|
+
Published test-name (TIMINGS)
|
|
100
|
+
test-name.test-sub-domain.workers.dev"
|
|
101
|
+
`);
|
|
102
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
103
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("publishes as an environment when provided", async () => {
|
|
107
|
+
writeWranglerToml();
|
|
108
|
+
writeWorkerSource();
|
|
109
|
+
mockSubDomainRequest();
|
|
110
|
+
mockUploadWorkerRequest({
|
|
111
|
+
env: "some-env",
|
|
112
|
+
legacyEnv: false,
|
|
113
|
+
});
|
|
114
|
+
await runWrangler("publish index.js --env some-env --legacy-env false");
|
|
115
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
116
|
+
"Uploaded test-name (some-env) (TIMINGS)
|
|
117
|
+
Published test-name (some-env) (TIMINGS)
|
|
118
|
+
some-env.test-name.test-sub-domain.workers.dev"
|
|
119
|
+
`);
|
|
120
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
121
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
31
126
|
it("should resolve wrangler.toml relative to the entrypoint", async () => {
|
|
32
127
|
fs.mkdirSync("./some-path/worker", { recursive: true });
|
|
33
128
|
fs.writeFileSync(
|
|
@@ -52,18 +147,74 @@ describe("publish", () => {
|
|
|
52
147
|
mockSubDomainRequest();
|
|
53
148
|
await runWrangler("publish ./some-path/worker/index.js");
|
|
54
149
|
expect(std.out).toMatchInlineSnapshot(`
|
|
55
|
-
"Uploaded
|
|
56
|
-
test-name
|
|
57
|
-
|
|
58
|
-
Published
|
|
59
|
-
test-name
|
|
60
|
-
(TIMINGS)
|
|
61
|
-
|
|
62
|
-
test-name.test-sub-domain.workers.dev"
|
|
150
|
+
"Uploaded test-name (TIMINGS)
|
|
151
|
+
Published test-name (TIMINGS)
|
|
152
|
+
test-name.test-sub-domain.workers.dev"
|
|
63
153
|
`);
|
|
64
154
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
65
155
|
});
|
|
66
156
|
|
|
157
|
+
describe("routes", () => {
|
|
158
|
+
it("should publish the worker to a route", async () => {
|
|
159
|
+
writeWranglerToml({
|
|
160
|
+
routes: ["example.com/some-route/*"],
|
|
161
|
+
});
|
|
162
|
+
writeWorkerSource();
|
|
163
|
+
mockUpdateWorkerRequest({ enabled: false });
|
|
164
|
+
mockUploadWorkerRequest({ expectedType: "esm" });
|
|
165
|
+
mockPublishRoutesRequest({ routes: ["example.com/some-route/*"] });
|
|
166
|
+
await runWrangler("publish ./index");
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it("should publish to legacy environment specific routes", async () => {
|
|
170
|
+
writeWranglerToml({
|
|
171
|
+
routes: ["example.com/some-route/*"],
|
|
172
|
+
env: {
|
|
173
|
+
dev: {
|
|
174
|
+
routes: ["dev-example.com/some-route/*"],
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
});
|
|
178
|
+
writeWorkerSource();
|
|
179
|
+
mockUpdateWorkerRequest({ enabled: false, legacyEnv: true, env: "dev" });
|
|
180
|
+
mockUploadWorkerRequest({
|
|
181
|
+
expectedType: "esm",
|
|
182
|
+
legacyEnv: true,
|
|
183
|
+
env: "dev",
|
|
184
|
+
});
|
|
185
|
+
mockPublishRoutesRequest({
|
|
186
|
+
routes: ["dev-example.com/some-route/*"],
|
|
187
|
+
legacyEnv: true,
|
|
188
|
+
env: "dev",
|
|
189
|
+
});
|
|
190
|
+
await runWrangler("publish ./index --env dev --legacy-env true");
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it("services: should publish to service environment specific routes", async () => {
|
|
194
|
+
writeWranglerToml({
|
|
195
|
+
routes: ["example.com/some-route/*"],
|
|
196
|
+
env: {
|
|
197
|
+
dev: {
|
|
198
|
+
routes: ["dev-example.com/some-route/*"],
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
});
|
|
202
|
+
writeWorkerSource();
|
|
203
|
+
mockUpdateWorkerRequest({ enabled: false, env: "dev" });
|
|
204
|
+
mockUploadWorkerRequest({
|
|
205
|
+
expectedType: "esm",
|
|
206
|
+
env: "dev",
|
|
207
|
+
});
|
|
208
|
+
mockPublishRoutesRequest({
|
|
209
|
+
routes: ["dev-example.com/some-route/*"],
|
|
210
|
+
env: "dev",
|
|
211
|
+
});
|
|
212
|
+
await runWrangler("publish ./index --env dev --legacy-env false");
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it.todo("should error if it's a workers.dev route");
|
|
216
|
+
});
|
|
217
|
+
|
|
67
218
|
describe("entry-points", () => {
|
|
68
219
|
it("should be able to use `index` with no extension as the entry-point (esm)", async () => {
|
|
69
220
|
writeWranglerToml();
|
|
@@ -74,14 +225,9 @@ describe("publish", () => {
|
|
|
74
225
|
await runWrangler("publish ./index");
|
|
75
226
|
|
|
76
227
|
expect(std.out).toMatchInlineSnapshot(`
|
|
77
|
-
"Uploaded
|
|
78
|
-
test-name
|
|
79
|
-
|
|
80
|
-
Published
|
|
81
|
-
test-name
|
|
82
|
-
(TIMINGS)
|
|
83
|
-
|
|
84
|
-
test-name.test-sub-domain.workers.dev"
|
|
228
|
+
"Uploaded test-name (TIMINGS)
|
|
229
|
+
Published test-name (TIMINGS)
|
|
230
|
+
test-name.test-sub-domain.workers.dev"
|
|
85
231
|
`);
|
|
86
232
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
87
233
|
});
|
|
@@ -95,20 +241,15 @@ describe("publish", () => {
|
|
|
95
241
|
await runWrangler("publish ./index");
|
|
96
242
|
|
|
97
243
|
expect(std.out).toMatchInlineSnapshot(`
|
|
98
|
-
"Uploaded
|
|
99
|
-
test-name
|
|
100
|
-
|
|
101
|
-
Published
|
|
102
|
-
test-name
|
|
103
|
-
(TIMINGS)
|
|
104
|
-
|
|
105
|
-
test-name.test-sub-domain.workers.dev"
|
|
244
|
+
"Uploaded test-name (TIMINGS)
|
|
245
|
+
Published test-name (TIMINGS)
|
|
246
|
+
test-name.test-sub-domain.workers.dev"
|
|
106
247
|
`);
|
|
107
248
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
108
249
|
});
|
|
109
250
|
|
|
110
|
-
it("should be able to use the `
|
|
111
|
-
writeWranglerToml({
|
|
251
|
+
it("should be able to use the `main` config as the entry-point for ESM sources", async () => {
|
|
252
|
+
writeWranglerToml({ main: "./index.js" });
|
|
112
253
|
writeWorkerSource();
|
|
113
254
|
mockUploadWorkerRequest();
|
|
114
255
|
mockSubDomainRequest();
|
|
@@ -116,25 +257,16 @@ describe("publish", () => {
|
|
|
116
257
|
await runWrangler("publish");
|
|
117
258
|
|
|
118
259
|
expect(std.out).toMatchInlineSnapshot(`
|
|
119
|
-
"Uploaded
|
|
120
|
-
test-name
|
|
121
|
-
|
|
122
|
-
Published
|
|
123
|
-
test-name
|
|
124
|
-
(TIMINGS)
|
|
125
|
-
|
|
126
|
-
test-name.test-sub-domain.workers.dev"
|
|
260
|
+
"Uploaded test-name (TIMINGS)
|
|
261
|
+
Published test-name (TIMINGS)
|
|
262
|
+
test-name.test-sub-domain.workers.dev"
|
|
127
263
|
`);
|
|
128
264
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
129
265
|
});
|
|
130
266
|
|
|
131
|
-
it("should use `
|
|
267
|
+
it("should use `main` relative to the wrangler.toml not cwd", async () => {
|
|
132
268
|
writeWranglerToml({
|
|
133
|
-
|
|
134
|
-
upload: {
|
|
135
|
-
main: "./foo/index.js",
|
|
136
|
-
},
|
|
137
|
-
},
|
|
269
|
+
main: "./foo/index.js",
|
|
138
270
|
});
|
|
139
271
|
writeWorkerSource({ basePath: "foo" });
|
|
140
272
|
mockUploadWorkerRequest({ expectedEntry: "var foo = 100;" });
|
|
@@ -143,23 +275,42 @@ describe("publish", () => {
|
|
|
143
275
|
await runWrangler("publish");
|
|
144
276
|
|
|
145
277
|
expect(std.out).toMatchInlineSnapshot(`
|
|
146
|
-
"Uploaded
|
|
147
|
-
test-name
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
278
|
+
"Uploaded test-name (TIMINGS)
|
|
279
|
+
Published test-name (TIMINGS)
|
|
280
|
+
test-name.test-sub-domain.workers.dev"
|
|
281
|
+
`);
|
|
282
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
283
|
+
});
|
|
152
284
|
|
|
153
|
-
|
|
285
|
+
it('should use `build.upload.main` as an entry point, where `build.upload.dir` defaults to "./dist", and log a deprecation warning', async () => {
|
|
286
|
+
writeWranglerToml({ build: { upload: { main: "./index.js" } } });
|
|
287
|
+
writeWorkerSource({ basePath: "./dist" });
|
|
288
|
+
mockUploadWorkerRequest();
|
|
289
|
+
mockSubDomainRequest();
|
|
290
|
+
|
|
291
|
+
await runWrangler("publish");
|
|
292
|
+
|
|
293
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
294
|
+
"Uploaded test-name (TIMINGS)
|
|
295
|
+
Published test-name (TIMINGS)
|
|
296
|
+
test-name.test-sub-domain.workers.dev"
|
|
154
297
|
`);
|
|
155
298
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
299
|
+
expect(std.warn).toMatchInlineSnapshot(`
|
|
300
|
+
"Processing wrangler.toml configuration:
|
|
301
|
+
- DEPRECATION: \\"build.upload.main\\":
|
|
302
|
+
Delete the \`build.upload.main\` and \`build.upload.dir\` fields.
|
|
303
|
+
Then add the top level \`main\` field to your configuration file:
|
|
304
|
+
\`\`\`
|
|
305
|
+
main = \\"dist/index.js\\"
|
|
306
|
+
\`\`\`"
|
|
307
|
+
`);
|
|
156
308
|
});
|
|
157
309
|
|
|
158
|
-
it("should use `build.upload.main` relative to `build.upload.dir`
|
|
310
|
+
it("should use `build.upload.main` relative to `build.upload.dir`", async () => {
|
|
159
311
|
writeWranglerToml({
|
|
160
312
|
build: {
|
|
161
313
|
upload: {
|
|
162
|
-
format: "modules",
|
|
163
314
|
main: "./index.js",
|
|
164
315
|
dir: "./foo",
|
|
165
316
|
},
|
|
@@ -172,16 +323,41 @@ describe("publish", () => {
|
|
|
172
323
|
await runWrangler("publish");
|
|
173
324
|
|
|
174
325
|
expect(std.out).toMatchInlineSnapshot(`
|
|
175
|
-
"Uploaded
|
|
176
|
-
test-name
|
|
177
|
-
|
|
178
|
-
Published
|
|
179
|
-
test-name
|
|
180
|
-
(TIMINGS)
|
|
181
|
-
|
|
182
|
-
test-name.test-sub-domain.workers.dev"
|
|
326
|
+
"Uploaded test-name (TIMINGS)
|
|
327
|
+
Published test-name (TIMINGS)
|
|
328
|
+
test-name.test-sub-domain.workers.dev"
|
|
183
329
|
`);
|
|
184
330
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
331
|
+
expect(std.warn).toMatchInlineSnapshot(`
|
|
332
|
+
"Processing ../wrangler.toml configuration:
|
|
333
|
+
- DEPRECATION: \\"build.upload.main\\":
|
|
334
|
+
Delete the \`build.upload.main\` and \`build.upload.dir\` fields.
|
|
335
|
+
Then add the top level \`main\` field to your configuration file:
|
|
336
|
+
\`\`\`
|
|
337
|
+
main = \\"foo/index.js\\"
|
|
338
|
+
\`\`\`
|
|
339
|
+
- DEPRECATION: \\"build.upload.dir\\":
|
|
340
|
+
Use the top level \\"main\\" field or a command-line argument to specify the entry-point for the Worker."
|
|
341
|
+
`);
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
it("should error when both `main` and `build.upload.main` are used", async () => {
|
|
345
|
+
writeWranglerToml({
|
|
346
|
+
main: "./index.js",
|
|
347
|
+
build: {
|
|
348
|
+
upload: {
|
|
349
|
+
main: "./index.js",
|
|
350
|
+
dir: "./foo",
|
|
351
|
+
},
|
|
352
|
+
},
|
|
353
|
+
});
|
|
354
|
+
await expect(runWrangler("publish")).rejects
|
|
355
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
356
|
+
"Processing wrangler.toml configuration:
|
|
357
|
+
- Don't define both the \`main\` and \`build.upload.main\` fields in your configuration.
|
|
358
|
+
They serve the same purpose: to point to the entry-point of your worker.
|
|
359
|
+
Delete the \`build.upload.main\` and \`build.upload.dir\` field from your config."
|
|
360
|
+
`);
|
|
185
361
|
});
|
|
186
362
|
|
|
187
363
|
it("should be able to transpile TypeScript (esm)", async () => {
|
|
@@ -192,14 +368,9 @@ describe("publish", () => {
|
|
|
192
368
|
await runWrangler("publish index.ts");
|
|
193
369
|
|
|
194
370
|
expect(std.out).toMatchInlineSnapshot(`
|
|
195
|
-
"Uploaded
|
|
196
|
-
test-name
|
|
197
|
-
|
|
198
|
-
Published
|
|
199
|
-
test-name
|
|
200
|
-
(TIMINGS)
|
|
201
|
-
|
|
202
|
-
test-name.test-sub-domain.workers.dev"
|
|
371
|
+
"Uploaded test-name (TIMINGS)
|
|
372
|
+
Published test-name (TIMINGS)
|
|
373
|
+
test-name.test-sub-domain.workers.dev"
|
|
203
374
|
`);
|
|
204
375
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
205
376
|
});
|
|
@@ -215,19 +386,14 @@ describe("publish", () => {
|
|
|
215
386
|
await runWrangler("publish index.ts");
|
|
216
387
|
|
|
217
388
|
expect(std.out).toMatchInlineSnapshot(`
|
|
218
|
-
"Uploaded
|
|
219
|
-
test-name
|
|
220
|
-
|
|
221
|
-
Published
|
|
222
|
-
test-name
|
|
223
|
-
(TIMINGS)
|
|
224
|
-
|
|
225
|
-
test-name.test-sub-domain.workers.dev"
|
|
389
|
+
"Uploaded test-name (TIMINGS)
|
|
390
|
+
Published test-name (TIMINGS)
|
|
391
|
+
test-name.test-sub-domain.workers.dev"
|
|
226
392
|
`);
|
|
227
393
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
228
394
|
});
|
|
229
395
|
|
|
230
|
-
it("should
|
|
396
|
+
it("should add referenced text modules into the form upload", async () => {
|
|
231
397
|
writeWranglerToml();
|
|
232
398
|
fs.writeFileSync(
|
|
233
399
|
"./index.js",
|
|
@@ -241,18 +407,18 @@ export default{
|
|
|
241
407
|
`
|
|
242
408
|
);
|
|
243
409
|
fs.writeFileSync("./textfile.txt", "Hello, World!");
|
|
244
|
-
mockUploadWorkerRequest({
|
|
410
|
+
mockUploadWorkerRequest({
|
|
411
|
+
expectedModules: {
|
|
412
|
+
"./0a0a9f2a6772942557ab5355d76af442f8f65e01-textfile.txt":
|
|
413
|
+
"Hello, World!",
|
|
414
|
+
},
|
|
415
|
+
});
|
|
245
416
|
mockSubDomainRequest();
|
|
246
417
|
await runWrangler("publish index.js");
|
|
247
418
|
expect(std.out).toMatchInlineSnapshot(`
|
|
248
|
-
"Uploaded
|
|
249
|
-
test-name
|
|
250
|
-
|
|
251
|
-
Published
|
|
252
|
-
test-name
|
|
253
|
-
(TIMINGS)
|
|
254
|
-
|
|
255
|
-
test-name.test-sub-domain.workers.dev"
|
|
419
|
+
"Uploaded test-name (TIMINGS)
|
|
420
|
+
Published test-name (TIMINGS)
|
|
421
|
+
test-name.test-sub-domain.workers.dev"
|
|
256
422
|
`);
|
|
257
423
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
258
424
|
});
|
|
@@ -266,14 +432,9 @@ export default{
|
|
|
266
432
|
await runWrangler("publish ./src/index.js");
|
|
267
433
|
|
|
268
434
|
expect(std.out).toMatchInlineSnapshot(`
|
|
269
|
-
"Uploaded
|
|
270
|
-
test-name
|
|
271
|
-
|
|
272
|
-
Published
|
|
273
|
-
test-name
|
|
274
|
-
(TIMINGS)
|
|
275
|
-
|
|
276
|
-
test-name.test-sub-domain.workers.dev"
|
|
435
|
+
"Uploaded test-name (TIMINGS)
|
|
436
|
+
Published test-name (TIMINGS)
|
|
437
|
+
test-name.test-sub-domain.workers.dev"
|
|
277
438
|
`);
|
|
278
439
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
279
440
|
});
|
|
@@ -290,47 +451,37 @@ export default{
|
|
|
290
451
|
await runWrangler("publish ./src/index.js");
|
|
291
452
|
|
|
292
453
|
expect(std.out).toMatchInlineSnapshot(`
|
|
293
|
-
"Uploaded
|
|
294
|
-
test-name
|
|
295
|
-
|
|
296
|
-
Published
|
|
297
|
-
test-name
|
|
298
|
-
(TIMINGS)
|
|
299
|
-
|
|
300
|
-
test-name.test-sub-domain.workers.dev"
|
|
454
|
+
"Uploaded test-name (TIMINGS)
|
|
455
|
+
Published test-name (TIMINGS)
|
|
456
|
+
test-name.test-sub-domain.workers.dev"
|
|
301
457
|
`);
|
|
302
458
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
303
459
|
});
|
|
304
460
|
|
|
305
461
|
it('should error if a site definition doesn\'t have a "bucket" field', async () => {
|
|
306
462
|
writeWranglerToml({
|
|
307
|
-
// @ts-expect-error we're purposely missing the required `site.bucket` field
|
|
308
463
|
site: {
|
|
309
464
|
"entry-point": "./index.js",
|
|
310
|
-
},
|
|
465
|
+
} as Config["site"],
|
|
311
466
|
});
|
|
312
467
|
writeWorkerSource();
|
|
313
468
|
mockUploadWorkerRequest();
|
|
314
469
|
mockSubDomainRequest();
|
|
315
470
|
|
|
316
|
-
await expect(
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
471
|
+
await expect(runWrangler("publish ./index.js")).rejects
|
|
472
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
473
|
+
"Processing wrangler.toml configuration:
|
|
474
|
+
- ERROR: \\"site.bucket\\" is a required field."
|
|
475
|
+
`);
|
|
321
476
|
|
|
322
477
|
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
323
478
|
expect(std.err).toMatchInlineSnapshot(`
|
|
324
|
-
"
|
|
479
|
+
"Processing wrangler.toml configuration:
|
|
480
|
+
- ERROR: \\"site.bucket\\" is a required field.
|
|
325
481
|
|
|
326
|
-
[32m%s[0m
|
|
327
|
-
If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
|
|
328
|
-
`);
|
|
329
|
-
expect(std.warn).toMatchInlineSnapshot(`
|
|
330
|
-
"Deprecation notice: The \`site.entry-point\` config field is no longer used.
|
|
331
|
-
The entry-point should be specified via the command line (e.g. \`wrangler publish path/to/script\`) or the \`build.upload.main\` config field.
|
|
332
|
-
Please remove the \`site.entry-point\` field from the \`wrangler.toml\` file."
|
|
482
|
+
[32m%s[0m If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
|
|
333
483
|
`);
|
|
484
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
334
485
|
});
|
|
335
486
|
|
|
336
487
|
it("should warn if there is a `site.entry-point` configuration", async () => {
|
|
@@ -364,19 +515,14 @@ export default{
|
|
|
364
515
|
uploading as assets/file-1.2ca234f380.txt...
|
|
365
516
|
reading assets/file-2.txt...
|
|
366
517
|
uploading as assets/file-2.5938485188.txt...
|
|
367
|
-
Uploaded
|
|
368
|
-
test-name
|
|
369
|
-
|
|
370
|
-
Published
|
|
371
|
-
test-name
|
|
372
|
-
(TIMINGS)
|
|
373
|
-
|
|
374
|
-
test-name.test-sub-domain.workers.dev"
|
|
518
|
+
Uploaded test-name (TIMINGS)
|
|
519
|
+
Published test-name (TIMINGS)
|
|
520
|
+
test-name.test-sub-domain.workers.dev"
|
|
375
521
|
`);
|
|
376
522
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
377
523
|
expect(std.warn).toMatchInlineSnapshot(`
|
|
378
524
|
"Deprecation notice: The \`site.entry-point\` config field is no longer used.
|
|
379
|
-
The entry-point should be specified via the command line (e.g. \`wrangler publish path/to/script\`) or the \`
|
|
525
|
+
The entry-point should be specified via the command line (e.g. \`wrangler publish path/to/script\`) or the \`main\` config field.
|
|
380
526
|
Please remove the \`site.entry-point\` field from the \`wrangler.toml\` file."
|
|
381
527
|
`);
|
|
382
528
|
});
|
|
@@ -389,15 +535,14 @@ export default{
|
|
|
389
535
|
await expect(
|
|
390
536
|
runWrangler("publish")
|
|
391
537
|
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
392
|
-
`"Missing entry-point: The entry-point should be specified via the command line (e.g. \`wrangler publish path/to/script\`) or the \`
|
|
538
|
+
`"Missing entry-point: The entry-point should be specified via the command line (e.g. \`wrangler publish path/to/script\`) or the \`main\` config field."`
|
|
393
539
|
);
|
|
394
540
|
|
|
395
541
|
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
396
542
|
expect(std.err).toMatchInlineSnapshot(`
|
|
397
|
-
"Missing entry-point: The entry-point should be specified via the command line (e.g. \`wrangler publish path/to/script\`) or the \`
|
|
543
|
+
"Missing entry-point: The entry-point should be specified via the command line (e.g. \`wrangler publish path/to/script\`) or the \`main\` config field.
|
|
398
544
|
|
|
399
|
-
[32m%s[0m
|
|
400
|
-
If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
|
|
545
|
+
[32m%s[0m If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
|
|
401
546
|
`);
|
|
402
547
|
});
|
|
403
548
|
});
|
|
@@ -413,7 +558,7 @@ export default{
|
|
|
413
558
|
id: "__test-name-workers_sites_assets-id",
|
|
414
559
|
};
|
|
415
560
|
writeWranglerToml({
|
|
416
|
-
|
|
561
|
+
main: "./index.js",
|
|
417
562
|
site: {
|
|
418
563
|
bucket: "assets",
|
|
419
564
|
},
|
|
@@ -432,19 +577,14 @@ export default{
|
|
|
432
577
|
uploading as assets/file-1.2ca234f380.txt...
|
|
433
578
|
reading assets/file-2.txt...
|
|
434
579
|
uploading as assets/file-2.5938485188.txt...
|
|
435
|
-
Uploaded
|
|
436
|
-
test-name
|
|
437
|
-
|
|
438
|
-
Published
|
|
439
|
-
test-name
|
|
440
|
-
(TIMINGS)
|
|
441
|
-
|
|
442
|
-
test-name.test-sub-domain.workers.dev"
|
|
580
|
+
Uploaded test-name (TIMINGS)
|
|
581
|
+
Published test-name (TIMINGS)
|
|
582
|
+
test-name.test-sub-domain.workers.dev"
|
|
443
583
|
`);
|
|
444
584
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
445
585
|
});
|
|
446
586
|
|
|
447
|
-
it("when using a service worker type, it should
|
|
587
|
+
it("when using a service worker type, it should add an asset manifest as a text_blob, and bind to a namespace", async () => {
|
|
448
588
|
const assets = [
|
|
449
589
|
{ filePath: "assets/file-1.txt", content: "Content of file-1" },
|
|
450
590
|
{ filePath: "assets/file-2.txt", content: "Content of file-2" },
|
|
@@ -454,7 +594,7 @@ export default{
|
|
|
454
594
|
id: "__test-name-workers_sites_assets-id",
|
|
455
595
|
};
|
|
456
596
|
writeWranglerToml({
|
|
457
|
-
|
|
597
|
+
main: "./index.js",
|
|
458
598
|
site: {
|
|
459
599
|
bucket: "assets",
|
|
460
600
|
},
|
|
@@ -463,13 +603,21 @@ export default{
|
|
|
463
603
|
writeAssets(assets);
|
|
464
604
|
mockUploadWorkerRequest({
|
|
465
605
|
expectedType: "sw",
|
|
466
|
-
|
|
606
|
+
expectedModules: {
|
|
607
|
+
__STATIC_CONTENT_MANIFEST:
|
|
608
|
+
'{"file-1.txt":"assets/file-1.2ca234f380.txt","file-2.txt":"assets/file-2.5938485188.txt"}',
|
|
609
|
+
},
|
|
467
610
|
expectedBindings: [
|
|
468
611
|
{
|
|
469
612
|
name: "__STATIC_CONTENT",
|
|
470
613
|
namespace_id: "__test-name-workers_sites_assets-id",
|
|
471
614
|
type: "kv_namespace",
|
|
472
615
|
},
|
|
616
|
+
{
|
|
617
|
+
name: "__STATIC_CONTENT_MANIFEST",
|
|
618
|
+
part: "__STATIC_CONTENT_MANIFEST",
|
|
619
|
+
type: "text_blob",
|
|
620
|
+
},
|
|
473
621
|
],
|
|
474
622
|
});
|
|
475
623
|
mockSubDomainRequest();
|
|
@@ -484,14 +632,9 @@ export default{
|
|
|
484
632
|
uploading as assets/file-1.2ca234f380.txt...
|
|
485
633
|
reading assets/file-2.txt...
|
|
486
634
|
uploading as assets/file-2.5938485188.txt...
|
|
487
|
-
Uploaded
|
|
488
|
-
test-name
|
|
489
|
-
|
|
490
|
-
Published
|
|
491
|
-
test-name
|
|
492
|
-
(TIMINGS)
|
|
493
|
-
|
|
494
|
-
test-name.test-sub-domain.workers.dev"
|
|
635
|
+
Uploaded test-name (TIMINGS)
|
|
636
|
+
Published test-name (TIMINGS)
|
|
637
|
+
test-name.test-sub-domain.workers.dev"
|
|
495
638
|
`);
|
|
496
639
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
497
640
|
});
|
|
@@ -506,7 +649,7 @@ export default{
|
|
|
506
649
|
id: "__test-name-workers_sites_assets-id",
|
|
507
650
|
};
|
|
508
651
|
writeWranglerToml({
|
|
509
|
-
|
|
652
|
+
main: "./index.js",
|
|
510
653
|
site: {
|
|
511
654
|
bucket: "assets",
|
|
512
655
|
},
|
|
@@ -538,19 +681,14 @@ export default{
|
|
|
538
681
|
uploading as assets/file-1.2ca234f380.txt...
|
|
539
682
|
reading assets/file-2.txt...
|
|
540
683
|
uploading as assets/file-2.5938485188.txt...
|
|
541
|
-
Uploaded
|
|
542
|
-
test-name
|
|
543
|
-
|
|
544
|
-
Published
|
|
545
|
-
test-name
|
|
546
|
-
(TIMINGS)
|
|
547
|
-
|
|
548
|
-
test-name.test-sub-domain.workers.dev"
|
|
684
|
+
Uploaded test-name (TIMINGS)
|
|
685
|
+
Published test-name (TIMINGS)
|
|
686
|
+
test-name.test-sub-domain.workers.dev"
|
|
549
687
|
`);
|
|
550
688
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
551
689
|
});
|
|
552
690
|
|
|
553
|
-
it("should make environment specific kv namespace for assets", async () => {
|
|
691
|
+
it("should make environment specific kv namespace for assets, even for service envs", async () => {
|
|
554
692
|
// This is the same test as the one before this, but with an env arg
|
|
555
693
|
const assets = [
|
|
556
694
|
{ filePath: "assets/file-1.txt", content: "Content of file-1" },
|
|
@@ -561,7 +699,7 @@ export default{
|
|
|
561
699
|
id: "__test-name-some-env-workers_sites_assets-id",
|
|
562
700
|
};
|
|
563
701
|
writeWranglerToml({
|
|
564
|
-
|
|
702
|
+
main: "./index.js",
|
|
565
703
|
site: {
|
|
566
704
|
bucket: "assets",
|
|
567
705
|
},
|
|
@@ -582,21 +720,63 @@ export default{
|
|
|
582
720
|
mockListKVNamespacesRequest(kvNamespace);
|
|
583
721
|
mockKeyListRequest(kvNamespace.id, []);
|
|
584
722
|
mockUploadAssetsToKVRequest(kvNamespace.id, assets);
|
|
585
|
-
await runWrangler("publish --env some-env");
|
|
723
|
+
await runWrangler("publish --env some-env --legacy-env false");
|
|
586
724
|
|
|
587
725
|
expect(std.out).toMatchInlineSnapshot(`
|
|
588
726
|
"reading assets/file-1.txt...
|
|
589
727
|
uploading as assets/file-1.2ca234f380.txt...
|
|
590
728
|
reading assets/file-2.txt...
|
|
591
729
|
uploading as assets/file-2.5938485188.txt...
|
|
592
|
-
Uploaded
|
|
593
|
-
test-name (some-env)
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
730
|
+
Uploaded test-name (some-env) (TIMINGS)
|
|
731
|
+
Published test-name (some-env) (TIMINGS)
|
|
732
|
+
some-env.test-name.test-sub-domain.workers.dev"
|
|
733
|
+
`);
|
|
734
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
735
|
+
});
|
|
736
|
+
|
|
737
|
+
it("should make environment specific kv namespace for assets, even for legacy envs", async () => {
|
|
738
|
+
// And this is the same test as the one before this, but with legacyEnv:true
|
|
739
|
+
const assets = [
|
|
740
|
+
{ filePath: "assets/file-1.txt", content: "Content of file-1" },
|
|
741
|
+
{ filePath: "assets/file-2.txt", content: "Content of file-2" },
|
|
742
|
+
];
|
|
743
|
+
const kvNamespace = {
|
|
744
|
+
title: "__test-name-some-env-workers_sites_assets",
|
|
745
|
+
id: "__test-name-some-env-workers_sites_assets-id",
|
|
746
|
+
};
|
|
747
|
+
writeWranglerToml({
|
|
748
|
+
main: "./index.js",
|
|
749
|
+
site: {
|
|
750
|
+
bucket: "assets",
|
|
751
|
+
},
|
|
752
|
+
});
|
|
753
|
+
writeWorkerSource();
|
|
754
|
+
writeAssets(assets);
|
|
755
|
+
mockUploadWorkerRequest({
|
|
756
|
+
legacyEnv: true,
|
|
757
|
+
env: "some-env",
|
|
758
|
+
expectedBindings: [
|
|
759
|
+
{
|
|
760
|
+
name: "__STATIC_CONTENT",
|
|
761
|
+
namespace_id: "__test-name-some-env-workers_sites_assets-id",
|
|
762
|
+
type: "kv_namespace",
|
|
763
|
+
},
|
|
764
|
+
],
|
|
765
|
+
});
|
|
766
|
+
mockSubDomainRequest();
|
|
767
|
+
mockListKVNamespacesRequest(kvNamespace);
|
|
768
|
+
mockKeyListRequest(kvNamespace.id, []);
|
|
769
|
+
mockUploadAssetsToKVRequest(kvNamespace.id, assets);
|
|
770
|
+
await runWrangler("publish --env some-env --legacy-env true");
|
|
771
|
+
|
|
772
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
773
|
+
"reading assets/file-1.txt...
|
|
774
|
+
uploading as assets/file-1.2ca234f380.txt...
|
|
775
|
+
reading assets/file-2.txt...
|
|
776
|
+
uploading as assets/file-2.5938485188.txt...
|
|
777
|
+
Uploaded test-name-some-env (TIMINGS)
|
|
778
|
+
Published test-name-some-env (TIMINGS)
|
|
779
|
+
test-name-some-env.test-sub-domain.workers.dev"
|
|
600
780
|
`);
|
|
601
781
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
602
782
|
});
|
|
@@ -611,7 +791,7 @@ export default{
|
|
|
611
791
|
id: "__test-name-workers_sites_assets-id",
|
|
612
792
|
};
|
|
613
793
|
writeWranglerToml({
|
|
614
|
-
|
|
794
|
+
main: "./index.js",
|
|
615
795
|
site: {
|
|
616
796
|
bucket: "assets",
|
|
617
797
|
},
|
|
@@ -635,14 +815,9 @@ export default{
|
|
|
635
815
|
skipping - already uploaded
|
|
636
816
|
reading assets/file-2.txt...
|
|
637
817
|
uploading as assets/file-2.5938485188.txt...
|
|
638
|
-
Uploaded
|
|
639
|
-
test-name
|
|
640
|
-
|
|
641
|
-
Published
|
|
642
|
-
test-name
|
|
643
|
-
(TIMINGS)
|
|
644
|
-
|
|
645
|
-
test-name.test-sub-domain.workers.dev"
|
|
818
|
+
Uploaded test-name (TIMINGS)
|
|
819
|
+
Published test-name (TIMINGS)
|
|
820
|
+
test-name.test-sub-domain.workers.dev"
|
|
646
821
|
`);
|
|
647
822
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
648
823
|
});
|
|
@@ -657,7 +832,7 @@ export default{
|
|
|
657
832
|
id: "__test-name-workers_sites_assets-id",
|
|
658
833
|
};
|
|
659
834
|
writeWranglerToml({
|
|
660
|
-
|
|
835
|
+
main: "./index.js",
|
|
661
836
|
site: {
|
|
662
837
|
bucket: "assets",
|
|
663
838
|
},
|
|
@@ -678,14 +853,9 @@ export default{
|
|
|
678
853
|
expect(std.out).toMatchInlineSnapshot(`
|
|
679
854
|
"reading assets/file-1.txt...
|
|
680
855
|
uploading as assets/file-1.2ca234f380.txt...
|
|
681
|
-
Uploaded
|
|
682
|
-
test-name
|
|
683
|
-
|
|
684
|
-
Published
|
|
685
|
-
test-name
|
|
686
|
-
(TIMINGS)
|
|
687
|
-
|
|
688
|
-
test-name.test-sub-domain.workers.dev"
|
|
856
|
+
Uploaded test-name (TIMINGS)
|
|
857
|
+
Published test-name (TIMINGS)
|
|
858
|
+
test-name.test-sub-domain.workers.dev"
|
|
689
859
|
`);
|
|
690
860
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
691
861
|
});
|
|
@@ -700,7 +870,7 @@ export default{
|
|
|
700
870
|
id: "__test-name-workers_sites_assets-id",
|
|
701
871
|
};
|
|
702
872
|
writeWranglerToml({
|
|
703
|
-
|
|
873
|
+
main: "./index.js",
|
|
704
874
|
site: {
|
|
705
875
|
bucket: "assets",
|
|
706
876
|
},
|
|
@@ -721,14 +891,9 @@ export default{
|
|
|
721
891
|
expect(std.out).toMatchInlineSnapshot(`
|
|
722
892
|
"reading assets/file-1.txt...
|
|
723
893
|
uploading as assets/file-1.2ca234f380.txt...
|
|
724
|
-
Uploaded
|
|
725
|
-
test-name
|
|
726
|
-
|
|
727
|
-
Published
|
|
728
|
-
test-name
|
|
729
|
-
(TIMINGS)
|
|
730
|
-
|
|
731
|
-
test-name.test-sub-domain.workers.dev"
|
|
894
|
+
Uploaded test-name (TIMINGS)
|
|
895
|
+
Published test-name (TIMINGS)
|
|
896
|
+
test-name.test-sub-domain.workers.dev"
|
|
732
897
|
`);
|
|
733
898
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
734
899
|
});
|
|
@@ -743,7 +908,7 @@ export default{
|
|
|
743
908
|
id: "__test-name-workers_sites_assets-id",
|
|
744
909
|
};
|
|
745
910
|
writeWranglerToml({
|
|
746
|
-
|
|
911
|
+
main: "./index.js",
|
|
747
912
|
site: {
|
|
748
913
|
bucket: "assets",
|
|
749
914
|
include: ["file-1.txt"],
|
|
@@ -765,14 +930,9 @@ export default{
|
|
|
765
930
|
expect(std.out).toMatchInlineSnapshot(`
|
|
766
931
|
"reading assets/file-1.txt...
|
|
767
932
|
uploading as assets/file-1.2ca234f380.txt...
|
|
768
|
-
Uploaded
|
|
769
|
-
test-name
|
|
770
|
-
|
|
771
|
-
Published
|
|
772
|
-
test-name
|
|
773
|
-
(TIMINGS)
|
|
774
|
-
|
|
775
|
-
test-name.test-sub-domain.workers.dev"
|
|
933
|
+
Uploaded test-name (TIMINGS)
|
|
934
|
+
Published test-name (TIMINGS)
|
|
935
|
+
test-name.test-sub-domain.workers.dev"
|
|
776
936
|
`);
|
|
777
937
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
778
938
|
});
|
|
@@ -787,7 +947,7 @@ export default{
|
|
|
787
947
|
id: "__test-name-workers_sites_assets-id",
|
|
788
948
|
};
|
|
789
949
|
writeWranglerToml({
|
|
790
|
-
|
|
950
|
+
main: "./index.js",
|
|
791
951
|
site: {
|
|
792
952
|
bucket: "assets",
|
|
793
953
|
exclude: ["file-2.txt"],
|
|
@@ -809,14 +969,9 @@ export default{
|
|
|
809
969
|
expect(std.out).toMatchInlineSnapshot(`
|
|
810
970
|
"reading assets/file-1.txt...
|
|
811
971
|
uploading as assets/file-1.2ca234f380.txt...
|
|
812
|
-
Uploaded
|
|
813
|
-
test-name
|
|
814
|
-
|
|
815
|
-
Published
|
|
816
|
-
test-name
|
|
817
|
-
(TIMINGS)
|
|
818
|
-
|
|
819
|
-
test-name.test-sub-domain.workers.dev"
|
|
972
|
+
Uploaded test-name (TIMINGS)
|
|
973
|
+
Published test-name (TIMINGS)
|
|
974
|
+
test-name.test-sub-domain.workers.dev"
|
|
820
975
|
`);
|
|
821
976
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
822
977
|
});
|
|
@@ -831,7 +986,7 @@ export default{
|
|
|
831
986
|
id: "__test-name-workers_sites_assets-id",
|
|
832
987
|
};
|
|
833
988
|
writeWranglerToml({
|
|
834
|
-
|
|
989
|
+
main: "./index.js",
|
|
835
990
|
site: {
|
|
836
991
|
bucket: "assets",
|
|
837
992
|
include: ["file-2.txt"],
|
|
@@ -853,14 +1008,9 @@ export default{
|
|
|
853
1008
|
expect(std.out).toMatchInlineSnapshot(`
|
|
854
1009
|
"reading assets/file-1.txt...
|
|
855
1010
|
uploading as assets/file-1.2ca234f380.txt...
|
|
856
|
-
Uploaded
|
|
857
|
-
test-name
|
|
858
|
-
|
|
859
|
-
Published
|
|
860
|
-
test-name
|
|
861
|
-
(TIMINGS)
|
|
862
|
-
|
|
863
|
-
test-name.test-sub-domain.workers.dev"
|
|
1011
|
+
Uploaded test-name (TIMINGS)
|
|
1012
|
+
Published test-name (TIMINGS)
|
|
1013
|
+
test-name.test-sub-domain.workers.dev"
|
|
864
1014
|
`);
|
|
865
1015
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
866
1016
|
});
|
|
@@ -875,7 +1025,7 @@ export default{
|
|
|
875
1025
|
id: "__test-name-workers_sites_assets-id",
|
|
876
1026
|
};
|
|
877
1027
|
writeWranglerToml({
|
|
878
|
-
|
|
1028
|
+
main: "./index.js",
|
|
879
1029
|
site: {
|
|
880
1030
|
bucket: "assets",
|
|
881
1031
|
exclude: ["assets/file-1.txt"],
|
|
@@ -897,14 +1047,9 @@ export default{
|
|
|
897
1047
|
expect(std.out).toMatchInlineSnapshot(`
|
|
898
1048
|
"reading assets/file-1.txt...
|
|
899
1049
|
uploading as assets/file-1.2ca234f380.txt...
|
|
900
|
-
Uploaded
|
|
901
|
-
test-name
|
|
902
|
-
|
|
903
|
-
Published
|
|
904
|
-
test-name
|
|
905
|
-
(TIMINGS)
|
|
906
|
-
|
|
907
|
-
test-name.test-sub-domain.workers.dev"
|
|
1050
|
+
Uploaded test-name (TIMINGS)
|
|
1051
|
+
Published test-name (TIMINGS)
|
|
1052
|
+
test-name.test-sub-domain.workers.dev"
|
|
908
1053
|
`);
|
|
909
1054
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
910
1055
|
});
|
|
@@ -925,7 +1070,7 @@ export default{
|
|
|
925
1070
|
id: "__test-name-workers_sites_assets-id",
|
|
926
1071
|
};
|
|
927
1072
|
writeWranglerToml({
|
|
928
|
-
|
|
1073
|
+
main: "./index.js",
|
|
929
1074
|
site: {
|
|
930
1075
|
bucket: "assets",
|
|
931
1076
|
},
|
|
@@ -943,14 +1088,9 @@ export default{
|
|
|
943
1088
|
expect(std.out).toMatchInlineSnapshot(`
|
|
944
1089
|
"reading assets/directory-1/file-1.txt...
|
|
945
1090
|
uploading as assets/directory-1/file-1.2ca234f380.txt...
|
|
946
|
-
Uploaded
|
|
947
|
-
test-name
|
|
948
|
-
|
|
949
|
-
Published
|
|
950
|
-
test-name
|
|
951
|
-
(TIMINGS)
|
|
952
|
-
|
|
953
|
-
test-name.test-sub-domain.workers.dev"
|
|
1091
|
+
Uploaded test-name (TIMINGS)
|
|
1092
|
+
Published test-name (TIMINGS)
|
|
1093
|
+
test-name.test-sub-domain.workers.dev"
|
|
954
1094
|
`);
|
|
955
1095
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
956
1096
|
});
|
|
@@ -975,7 +1115,7 @@ export default{
|
|
|
975
1115
|
id: "__test-name-workers_sites_assets-id",
|
|
976
1116
|
};
|
|
977
1117
|
writeWranglerToml({
|
|
978
|
-
|
|
1118
|
+
main: "./index.js",
|
|
979
1119
|
site: {
|
|
980
1120
|
bucket: "assets",
|
|
981
1121
|
},
|
|
@@ -993,14 +1133,9 @@ export default{
|
|
|
993
1133
|
expect(std.out).toMatchInlineSnapshot(`
|
|
994
1134
|
"reading assets/.well-known/file-2.txt...
|
|
995
1135
|
uploading as assets/.well-known/file-2.5938485188.txt...
|
|
996
|
-
Uploaded
|
|
997
|
-
test-name
|
|
998
|
-
|
|
999
|
-
Published
|
|
1000
|
-
test-name
|
|
1001
|
-
(TIMINGS)
|
|
1002
|
-
|
|
1003
|
-
test-name.test-sub-domain.workers.dev"
|
|
1136
|
+
Uploaded test-name (TIMINGS)
|
|
1137
|
+
Published test-name (TIMINGS)
|
|
1138
|
+
test-name.test-sub-domain.workers.dev"
|
|
1004
1139
|
`);
|
|
1005
1140
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1006
1141
|
});
|
|
@@ -1022,7 +1157,7 @@ export default{
|
|
|
1022
1157
|
id: "__test-name-workers_sites_assets-id",
|
|
1023
1158
|
};
|
|
1024
1159
|
writeWranglerToml({
|
|
1025
|
-
|
|
1160
|
+
main: "./index.js",
|
|
1026
1161
|
site: {
|
|
1027
1162
|
bucket: "assets",
|
|
1028
1163
|
exclude: ["assets/file-1.txt"],
|
|
@@ -1048,8 +1183,7 @@ export default{
|
|
|
1048
1183
|
expect(std.err).toMatchInlineSnapshot(`
|
|
1049
1184
|
"File assets/too-large-file.txt is too big, it should be under 25 MiB. See https://developers.cloudflare.com/workers/platform/limits#kv-limits
|
|
1050
1185
|
|
|
1051
|
-
[32m%s[0m
|
|
1052
|
-
If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
|
|
1186
|
+
[32m%s[0m If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
|
|
1053
1187
|
`);
|
|
1054
1188
|
});
|
|
1055
1189
|
|
|
@@ -1063,7 +1197,7 @@ export default{
|
|
|
1063
1197
|
id: "__test-name-workers_sites_assets-id",
|
|
1064
1198
|
};
|
|
1065
1199
|
writeWranglerToml({
|
|
1066
|
-
|
|
1200
|
+
main: "./index.js",
|
|
1067
1201
|
site: {
|
|
1068
1202
|
bucket: "assets",
|
|
1069
1203
|
},
|
|
@@ -1087,8 +1221,7 @@ export default{
|
|
|
1087
1221
|
expect(std.err).toMatchInlineSnapshot(`
|
|
1088
1222
|
"The asset path key \\"assets/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/file.3da0d0cd12.txt\\" exceeds the maximum key size limit of 512. See https://developers.cloudflare.com/workers/platform/limits#kv-limits\\",
|
|
1089
1223
|
|
|
1090
|
-
[32m%s[0m
|
|
1091
|
-
If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
|
|
1224
|
+
[32m%s[0m If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
|
|
1092
1225
|
`);
|
|
1093
1226
|
});
|
|
1094
1227
|
});
|
|
@@ -1103,14 +1236,9 @@ export default{
|
|
|
1103
1236
|
await runWrangler("publish ./index");
|
|
1104
1237
|
|
|
1105
1238
|
expect(std.out).toMatchInlineSnapshot(`
|
|
1106
|
-
"Uploaded
|
|
1107
|
-
test-name
|
|
1108
|
-
|
|
1109
|
-
Published
|
|
1110
|
-
test-name
|
|
1111
|
-
(TIMINGS)
|
|
1112
|
-
|
|
1113
|
-
test-name.test-sub-domain.workers.dev"
|
|
1239
|
+
"Uploaded test-name (TIMINGS)
|
|
1240
|
+
Published test-name (TIMINGS)
|
|
1241
|
+
test-name.test-sub-domain.workers.dev"
|
|
1114
1242
|
`);
|
|
1115
1243
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1116
1244
|
});
|
|
@@ -1126,14 +1254,9 @@ export default{
|
|
|
1126
1254
|
await runWrangler("publish ./index");
|
|
1127
1255
|
|
|
1128
1256
|
expect(std.out).toMatchInlineSnapshot(`
|
|
1129
|
-
"Uploaded
|
|
1130
|
-
test-name
|
|
1131
|
-
|
|
1132
|
-
Published
|
|
1133
|
-
test-name
|
|
1134
|
-
(TIMINGS)
|
|
1135
|
-
|
|
1136
|
-
test-name.test-sub-domain.workers.dev"
|
|
1257
|
+
"Uploaded test-name (TIMINGS)
|
|
1258
|
+
Published test-name (TIMINGS)
|
|
1259
|
+
test-name.test-sub-domain.workers.dev"
|
|
1137
1260
|
`);
|
|
1138
1261
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1139
1262
|
});
|
|
@@ -1150,12 +1273,8 @@ export default{
|
|
|
1150
1273
|
await runWrangler("publish ./index");
|
|
1151
1274
|
|
|
1152
1275
|
expect(std.out).toMatchInlineSnapshot(`
|
|
1153
|
-
"Uploaded
|
|
1154
|
-
test-name
|
|
1155
|
-
(TIMINGS)
|
|
1156
|
-
No publish targets for
|
|
1157
|
-
test-name
|
|
1158
|
-
(TIMINGS)"
|
|
1276
|
+
"Uploaded test-name (TIMINGS)
|
|
1277
|
+
No publish targets for test-name (TIMINGS)"
|
|
1159
1278
|
`);
|
|
1160
1279
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1161
1280
|
});
|
|
@@ -1170,14 +1289,9 @@ export default{
|
|
|
1170
1289
|
await runWrangler("publish ./index");
|
|
1171
1290
|
|
|
1172
1291
|
expect(std.out).toMatchInlineSnapshot(`
|
|
1173
|
-
"Uploaded
|
|
1174
|
-
test-name
|
|
1175
|
-
|
|
1176
|
-
Published
|
|
1177
|
-
test-name
|
|
1178
|
-
(TIMINGS)
|
|
1179
|
-
|
|
1180
|
-
test-name.test-sub-domain.workers.dev"
|
|
1292
|
+
"Uploaded test-name (TIMINGS)
|
|
1293
|
+
Published test-name (TIMINGS)
|
|
1294
|
+
test-name.test-sub-domain.workers.dev"
|
|
1181
1295
|
`);
|
|
1182
1296
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1183
1297
|
});
|
|
@@ -1192,14 +1306,9 @@ export default{
|
|
|
1192
1306
|
await runWrangler("publish ./index");
|
|
1193
1307
|
|
|
1194
1308
|
expect(std.out).toMatchInlineSnapshot(`
|
|
1195
|
-
"Uploaded
|
|
1196
|
-
test-name
|
|
1197
|
-
|
|
1198
|
-
Published
|
|
1199
|
-
test-name
|
|
1200
|
-
(TIMINGS)
|
|
1201
|
-
|
|
1202
|
-
test-name.test-sub-domain.workers.dev"
|
|
1309
|
+
"Uploaded test-name (TIMINGS)
|
|
1310
|
+
Published test-name (TIMINGS)
|
|
1311
|
+
test-name.test-sub-domain.workers.dev"
|
|
1203
1312
|
`);
|
|
1204
1313
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1205
1314
|
});
|
|
@@ -1225,16 +1334,10 @@ export default{
|
|
|
1225
1334
|
|
|
1226
1335
|
await runWrangler("publish index.js");
|
|
1227
1336
|
expect(std.out).toMatchInlineSnapshot(`
|
|
1228
|
-
"running:
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
(TIMINGS)
|
|
1233
|
-
Published
|
|
1234
|
-
test-name
|
|
1235
|
-
(TIMINGS)
|
|
1236
|
-
|
|
1237
|
-
test-name.test-sub-domain.workers.dev"
|
|
1337
|
+
"running: node -e \\"console.log('custom build'); require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')\\"
|
|
1338
|
+
Uploaded test-name (TIMINGS)
|
|
1339
|
+
Published test-name (TIMINGS)
|
|
1340
|
+
test-name.test-sub-domain.workers.dev"
|
|
1238
1341
|
`);
|
|
1239
1342
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1240
1343
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
@@ -1255,16 +1358,10 @@ export default{
|
|
|
1255
1358
|
|
|
1256
1359
|
await runWrangler("publish index.js");
|
|
1257
1360
|
expect(std.out).toMatchInlineSnapshot(`
|
|
1258
|
-
"running:
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
(TIMINGS)
|
|
1263
|
-
Published
|
|
1264
|
-
test-name
|
|
1265
|
-
(TIMINGS)
|
|
1266
|
-
|
|
1267
|
-
test-name.test-sub-domain.workers.dev"
|
|
1361
|
+
"running: echo \\"custom build\\" && echo \\"export default { fetch(){ return new Response(123) } }\\" > index.js
|
|
1362
|
+
Uploaded test-name (TIMINGS)
|
|
1363
|
+
Published test-name (TIMINGS)
|
|
1364
|
+
test-name.test-sub-domain.workers.dev"
|
|
1268
1365
|
`);
|
|
1269
1366
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1270
1367
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
@@ -1292,14 +1389,9 @@ export default{
|
|
|
1292
1389
|
mockSubDomainRequest();
|
|
1293
1390
|
await runWrangler("publish index.js");
|
|
1294
1391
|
expect(std.out).toMatchInlineSnapshot(`
|
|
1295
|
-
"Uploaded
|
|
1296
|
-
test-name
|
|
1297
|
-
|
|
1298
|
-
Published
|
|
1299
|
-
test-name
|
|
1300
|
-
(TIMINGS)
|
|
1301
|
-
|
|
1302
|
-
test-name.test-sub-domain.workers.dev"
|
|
1392
|
+
"Uploaded test-name (TIMINGS)
|
|
1393
|
+
Published test-name (TIMINGS)
|
|
1394
|
+
test-name.test-sub-domain.workers.dev"
|
|
1303
1395
|
`);
|
|
1304
1396
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1305
1397
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
@@ -1324,8 +1416,7 @@ export default{
|
|
|
1324
1416
|
expect(std.err).toMatchInlineSnapshot(`
|
|
1325
1417
|
"You cannot configure [wasm_modules] with an ES module worker. Instead, import the .wasm module directly in your code
|
|
1326
1418
|
|
|
1327
|
-
[32m%s[0m
|
|
1328
|
-
If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
|
|
1419
|
+
[32m%s[0m If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
|
|
1329
1420
|
`);
|
|
1330
1421
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1331
1422
|
});
|
|
@@ -1360,14 +1451,9 @@ export default{
|
|
|
1360
1451
|
mockSubDomainRequest();
|
|
1361
1452
|
await runWrangler("publish index.js --config ./path/to/wrangler.toml");
|
|
1362
1453
|
expect(std.out).toMatchInlineSnapshot(`
|
|
1363
|
-
"Uploaded
|
|
1364
|
-
test-name
|
|
1365
|
-
|
|
1366
|
-
Published
|
|
1367
|
-
test-name
|
|
1368
|
-
(TIMINGS)
|
|
1369
|
-
|
|
1370
|
-
test-name.test-sub-domain.workers.dev"
|
|
1454
|
+
"Uploaded test-name (TIMINGS)
|
|
1455
|
+
Published test-name (TIMINGS)
|
|
1456
|
+
test-name.test-sub-domain.workers.dev"
|
|
1371
1457
|
`);
|
|
1372
1458
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1373
1459
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
@@ -1394,14 +1480,108 @@ export default{
|
|
|
1394
1480
|
mockSubDomainRequest();
|
|
1395
1481
|
await runWrangler("publish index.js");
|
|
1396
1482
|
expect(std.out).toMatchInlineSnapshot(`
|
|
1397
|
-
"Uploaded
|
|
1398
|
-
test-name
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1483
|
+
"Uploaded test-name (TIMINGS)
|
|
1484
|
+
Published test-name (TIMINGS)
|
|
1485
|
+
test-name.test-sub-domain.workers.dev"
|
|
1486
|
+
`);
|
|
1487
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1488
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1489
|
+
});
|
|
1490
|
+
});
|
|
1403
1491
|
|
|
1404
|
-
|
|
1492
|
+
describe("[text_blobs]", () => {
|
|
1493
|
+
it("should be able to define text blobs for service-worker format workers", async () => {
|
|
1494
|
+
writeWranglerToml({
|
|
1495
|
+
text_blobs: {
|
|
1496
|
+
TESTTEXTBLOBNAME: "./path/to/text.file",
|
|
1497
|
+
},
|
|
1498
|
+
});
|
|
1499
|
+
writeWorkerSource({ type: "sw" });
|
|
1500
|
+
fs.mkdirSync("./path/to", { recursive: true });
|
|
1501
|
+
fs.writeFileSync("./path/to/text.file", "SOME TEXT CONTENT");
|
|
1502
|
+
mockUploadWorkerRequest({
|
|
1503
|
+
expectedType: "sw",
|
|
1504
|
+
expectedModules: { TESTTEXTBLOBNAME: "SOME TEXT CONTENT" },
|
|
1505
|
+
expectedBindings: [
|
|
1506
|
+
{
|
|
1507
|
+
name: "TESTTEXTBLOBNAME",
|
|
1508
|
+
part: "TESTTEXTBLOBNAME",
|
|
1509
|
+
type: "text_blob",
|
|
1510
|
+
},
|
|
1511
|
+
],
|
|
1512
|
+
});
|
|
1513
|
+
mockSubDomainRequest();
|
|
1514
|
+
await runWrangler("publish index.js");
|
|
1515
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
1516
|
+
"Uploaded test-name (TIMINGS)
|
|
1517
|
+
Published test-name (TIMINGS)
|
|
1518
|
+
test-name.test-sub-domain.workers.dev"
|
|
1519
|
+
`);
|
|
1520
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1521
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1522
|
+
});
|
|
1523
|
+
|
|
1524
|
+
it("should error when defining text blobs for modules format workers", async () => {
|
|
1525
|
+
writeWranglerToml({
|
|
1526
|
+
text_blobs: {
|
|
1527
|
+
TESTTEXTBLOBNAME: "./path/to/text.file",
|
|
1528
|
+
},
|
|
1529
|
+
});
|
|
1530
|
+
writeWorkerSource({ type: "esm" });
|
|
1531
|
+
fs.mkdirSync("./path/to", { recursive: true });
|
|
1532
|
+
fs.writeFileSync("./path/to/text.file", "SOME TEXT CONTENT");
|
|
1533
|
+
|
|
1534
|
+
await expect(
|
|
1535
|
+
runWrangler("publish index.js")
|
|
1536
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
1537
|
+
`"You cannot configure [text_blobs] with an ES module worker. Instead, import the file directly in your code, and optionally configure \`[build.upload.rules]\` in your wrangler.toml"`
|
|
1538
|
+
);
|
|
1539
|
+
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
1540
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
1541
|
+
"You cannot configure [text_blobs] with an ES module worker. Instead, import the file directly in your code, and optionally configure \`[build.upload.rules]\` in your wrangler.toml
|
|
1542
|
+
|
|
1543
|
+
[32m%s[0m If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
|
|
1544
|
+
`);
|
|
1545
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1546
|
+
});
|
|
1547
|
+
|
|
1548
|
+
it("should resolve text blobs relative to the wrangler.toml file", async () => {
|
|
1549
|
+
fs.mkdirSync("./path/to/and/the/path/to/", { recursive: true });
|
|
1550
|
+
fs.writeFileSync(
|
|
1551
|
+
"./path/to/wrangler.toml",
|
|
1552
|
+
TOML.stringify({
|
|
1553
|
+
compatibility_date: "2022-01-12",
|
|
1554
|
+
name: "test-name",
|
|
1555
|
+
text_blobs: {
|
|
1556
|
+
TESTTEXTBLOBNAME: "./and/the/path/to/text.file",
|
|
1557
|
+
},
|
|
1558
|
+
}),
|
|
1559
|
+
|
|
1560
|
+
"utf-8"
|
|
1561
|
+
);
|
|
1562
|
+
|
|
1563
|
+
writeWorkerSource({ type: "sw" });
|
|
1564
|
+
fs.writeFileSync(
|
|
1565
|
+
"./path/to/and/the/path/to/text.file",
|
|
1566
|
+
"SOME TEXT CONTENT"
|
|
1567
|
+
);
|
|
1568
|
+
mockUploadWorkerRequest({
|
|
1569
|
+
expectedType: "sw",
|
|
1570
|
+
expectedModules: { TESTTEXTBLOBNAME: "SOME TEXT CONTENT" },
|
|
1571
|
+
expectedBindings: [
|
|
1572
|
+
{
|
|
1573
|
+
name: "TESTTEXTBLOBNAME",
|
|
1574
|
+
part: "TESTTEXTBLOBNAME",
|
|
1575
|
+
type: "text_blob",
|
|
1576
|
+
},
|
|
1577
|
+
],
|
|
1578
|
+
});
|
|
1579
|
+
mockSubDomainRequest();
|
|
1580
|
+
await runWrangler("publish index.js --config ./path/to/wrangler.toml");
|
|
1581
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
1582
|
+
"Uploaded test-name (TIMINGS)
|
|
1583
|
+
Published test-name (TIMINGS)
|
|
1584
|
+
test-name.test-sub-domain.workers.dev"
|
|
1405
1585
|
`);
|
|
1406
1586
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1407
1587
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
@@ -1433,14 +1613,9 @@ export default{
|
|
|
1433
1613
|
|
|
1434
1614
|
await runWrangler("publish index.js");
|
|
1435
1615
|
expect(std.out).toMatchInlineSnapshot(`
|
|
1436
|
-
"Uploaded
|
|
1437
|
-
test-name
|
|
1438
|
-
|
|
1439
|
-
Published
|
|
1440
|
-
test-name
|
|
1441
|
-
(TIMINGS)
|
|
1442
|
-
|
|
1443
|
-
test-name.test-sub-domain.workers.dev"
|
|
1616
|
+
"Uploaded test-name (TIMINGS)
|
|
1617
|
+
Published test-name (TIMINGS)
|
|
1618
|
+
test-name.test-sub-domain.workers.dev"
|
|
1444
1619
|
`);
|
|
1445
1620
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1446
1621
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
@@ -1462,14 +1637,9 @@ export default{
|
|
|
1462
1637
|
|
|
1463
1638
|
await runWrangler("publish index.js");
|
|
1464
1639
|
expect(std.out).toMatchInlineSnapshot(`
|
|
1465
|
-
"Uploaded
|
|
1466
|
-
test-name
|
|
1467
|
-
|
|
1468
|
-
Published
|
|
1469
|
-
test-name
|
|
1470
|
-
(TIMINGS)
|
|
1471
|
-
|
|
1472
|
-
test-name.test-sub-domain.workers.dev"
|
|
1640
|
+
"Uploaded test-name (TIMINGS)
|
|
1641
|
+
Published test-name (TIMINGS)
|
|
1642
|
+
test-name.test-sub-domain.workers.dev"
|
|
1473
1643
|
`);
|
|
1474
1644
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1475
1645
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
@@ -1503,19 +1673,15 @@ export default{
|
|
|
1503
1673
|
|
|
1504
1674
|
await runWrangler("publish index.js");
|
|
1505
1675
|
expect(std.out).toMatchInlineSnapshot(`
|
|
1506
|
-
"Uploaded
|
|
1507
|
-
test-name
|
|
1508
|
-
|
|
1509
|
-
Published
|
|
1510
|
-
test-name
|
|
1511
|
-
(TIMINGS)
|
|
1512
|
-
|
|
1513
|
-
test-name.test-sub-domain.workers.dev"
|
|
1676
|
+
"Uploaded test-name (TIMINGS)
|
|
1677
|
+
Published test-name (TIMINGS)
|
|
1678
|
+
test-name.test-sub-domain.workers.dev"
|
|
1514
1679
|
`);
|
|
1515
1680
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1516
|
-
expect(std.warn).toMatchInlineSnapshot(
|
|
1517
|
-
|
|
1518
|
-
|
|
1681
|
+
expect(std.warn).toMatchInlineSnapshot(`
|
|
1682
|
+
"Processing wrangler.toml configuration:
|
|
1683
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time."
|
|
1684
|
+
`);
|
|
1519
1685
|
});
|
|
1520
1686
|
it("should warn if using unsafe bindings already handled by wrangler", async () => {
|
|
1521
1687
|
writeWranglerToml({
|
|
@@ -1543,19 +1709,213 @@ export default{
|
|
|
1543
1709
|
|
|
1544
1710
|
await runWrangler("publish index.js");
|
|
1545
1711
|
expect(std.out).toMatchInlineSnapshot(`
|
|
1546
|
-
"Uploaded
|
|
1547
|
-
test-name
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1712
|
+
"Uploaded test-name (TIMINGS)
|
|
1713
|
+
Published test-name (TIMINGS)
|
|
1714
|
+
test-name.test-sub-domain.workers.dev"
|
|
1715
|
+
`);
|
|
1716
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1717
|
+
expect(std.warn).toMatchInlineSnapshot(`
|
|
1718
|
+
"Processing wrangler.toml configuration:
|
|
1719
|
+
- \\"unsafe\\" fields are experimental and may change or break at any time.
|
|
1720
|
+
- \\"unsafe.bindings[0]\\": {\\"name\\":\\"my-binding\\",\\"type\\":\\"plain_text\\",\\"text\\":\\"text\\"}
|
|
1721
|
+
- The binding type \\"plain_text\\" is directly supported by wrangler.
|
|
1722
|
+
Consider migrating this unsafe binding to a format for 'plain_text' bindings that is supported by wrangler for optimal support.
|
|
1723
|
+
For more details, see https://developers.cloudflare.com/workers/cli-wrangler/configuration"
|
|
1724
|
+
`);
|
|
1725
|
+
});
|
|
1726
|
+
});
|
|
1552
1727
|
|
|
1553
|
-
|
|
1728
|
+
describe("upload rules", () => {
|
|
1729
|
+
it("should be able to define rules for uploading non-js modules (sw)", async () => {
|
|
1730
|
+
writeWranglerToml({
|
|
1731
|
+
rules: [{ type: "Text", globs: ["**/*.file"], fallthrough: true }],
|
|
1732
|
+
});
|
|
1733
|
+
fs.writeFileSync("./index.js", `import TEXT from './text.file';`);
|
|
1734
|
+
fs.writeFileSync("./text.file", "SOME TEXT CONTENT");
|
|
1735
|
+
mockSubDomainRequest();
|
|
1736
|
+
mockUploadWorkerRequest({
|
|
1737
|
+
expectedType: "sw",
|
|
1738
|
+
expectedBindings: [
|
|
1739
|
+
{
|
|
1740
|
+
name: "__2d91d1c4dd6e57d4f5432187ab7c25f45a8973f0_text_file",
|
|
1741
|
+
part: "__2d91d1c4dd6e57d4f5432187ab7c25f45a8973f0_text_file",
|
|
1742
|
+
type: "text_blob",
|
|
1743
|
+
},
|
|
1744
|
+
],
|
|
1745
|
+
expectedModules: {
|
|
1746
|
+
__2d91d1c4dd6e57d4f5432187ab7c25f45a8973f0_text_file:
|
|
1747
|
+
"SOME TEXT CONTENT",
|
|
1748
|
+
},
|
|
1749
|
+
});
|
|
1750
|
+
await runWrangler("publish index.js");
|
|
1751
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
1752
|
+
"Uploaded test-name (TIMINGS)
|
|
1753
|
+
Published test-name (TIMINGS)
|
|
1754
|
+
test-name.test-sub-domain.workers.dev"
|
|
1755
|
+
`);
|
|
1756
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1757
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1758
|
+
});
|
|
1759
|
+
|
|
1760
|
+
it("should be able to define rules for uploading non-js modules (esm)", async () => {
|
|
1761
|
+
writeWranglerToml({
|
|
1762
|
+
rules: [{ type: "Text", globs: ["**/*.file"], fallthrough: true }],
|
|
1763
|
+
});
|
|
1764
|
+
fs.writeFileSync(
|
|
1765
|
+
"./index.js",
|
|
1766
|
+
`import TEXT from './text.file'; export default {};`
|
|
1767
|
+
);
|
|
1768
|
+
fs.writeFileSync("./text.file", "SOME TEXT CONTENT");
|
|
1769
|
+
mockSubDomainRequest();
|
|
1770
|
+
mockUploadWorkerRequest({
|
|
1771
|
+
expectedType: "esm",
|
|
1772
|
+
expectedBindings: [],
|
|
1773
|
+
expectedModules: {
|
|
1774
|
+
"./2d91d1c4dd6e57d4f5432187ab7c25f45a8973f0-text.file":
|
|
1775
|
+
"SOME TEXT CONTENT",
|
|
1776
|
+
},
|
|
1777
|
+
});
|
|
1778
|
+
await runWrangler("publish index.js");
|
|
1779
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
1780
|
+
"Uploaded test-name (TIMINGS)
|
|
1781
|
+
Published test-name (TIMINGS)
|
|
1782
|
+
test-name.test-sub-domain.workers.dev"
|
|
1783
|
+
`);
|
|
1784
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1785
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1786
|
+
});
|
|
1787
|
+
|
|
1788
|
+
it("should log a deprecation warning when using `build.upload.rules`", async () => {
|
|
1789
|
+
writeWranglerToml({
|
|
1790
|
+
build: {
|
|
1791
|
+
upload: {
|
|
1792
|
+
rules: [{ type: "Text", globs: ["**/*.file"], fallthrough: true }],
|
|
1793
|
+
},
|
|
1794
|
+
},
|
|
1795
|
+
});
|
|
1796
|
+
fs.writeFileSync(
|
|
1797
|
+
"./index.js",
|
|
1798
|
+
`import TEXT from './text.file'; export default {};`
|
|
1799
|
+
);
|
|
1800
|
+
fs.writeFileSync("./text.file", "SOME TEXT CONTENT");
|
|
1801
|
+
mockSubDomainRequest();
|
|
1802
|
+
mockUploadWorkerRequest({
|
|
1803
|
+
expectedType: "esm",
|
|
1804
|
+
expectedBindings: [],
|
|
1805
|
+
expectedModules: {
|
|
1806
|
+
"./2d91d1c4dd6e57d4f5432187ab7c25f45a8973f0-text.file":
|
|
1807
|
+
"SOME TEXT CONTENT",
|
|
1808
|
+
},
|
|
1809
|
+
});
|
|
1810
|
+
await runWrangler("publish index.js");
|
|
1811
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
1812
|
+
"Uploaded test-name (TIMINGS)
|
|
1813
|
+
Published test-name (TIMINGS)
|
|
1814
|
+
test-name.test-sub-domain.workers.dev"
|
|
1554
1815
|
`);
|
|
1555
1816
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1556
1817
|
expect(std.warn).toMatchInlineSnapshot(`
|
|
1557
|
-
"
|
|
1558
|
-
|
|
1818
|
+
"Processing wrangler.toml configuration:
|
|
1819
|
+
- 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:
|
|
1820
|
+
\`\`\`
|
|
1821
|
+
[[rules]]
|
|
1822
|
+
type = \\"Text\\"
|
|
1823
|
+
globs = [ \\"**/*.file\\" ]
|
|
1824
|
+
fallthrough = true
|
|
1825
|
+
\`\`\`"
|
|
1826
|
+
`);
|
|
1827
|
+
});
|
|
1828
|
+
|
|
1829
|
+
it("should be able to use fallthrough:true for multiple rules", async () => {
|
|
1830
|
+
writeWranglerToml({
|
|
1831
|
+
rules: [
|
|
1832
|
+
{ type: "Text", globs: ["**/*.file"], fallthrough: true },
|
|
1833
|
+
{ type: "Text", globs: ["**/*.other"], fallthrough: true },
|
|
1834
|
+
],
|
|
1835
|
+
});
|
|
1836
|
+
fs.writeFileSync(
|
|
1837
|
+
"./index.js",
|
|
1838
|
+
`import TEXT from './text.file'; import OTHER from './other.other'; export default {};`
|
|
1839
|
+
);
|
|
1840
|
+
fs.writeFileSync("./text.file", "SOME TEXT CONTENT");
|
|
1841
|
+
fs.writeFileSync("./other.other", "SOME OTHER TEXT CONTENT");
|
|
1842
|
+
mockSubDomainRequest();
|
|
1843
|
+
mockUploadWorkerRequest({
|
|
1844
|
+
expectedType: "esm",
|
|
1845
|
+
expectedBindings: [],
|
|
1846
|
+
expectedModules: {
|
|
1847
|
+
"./2d91d1c4dd6e57d4f5432187ab7c25f45a8973f0-text.file":
|
|
1848
|
+
"SOME TEXT CONTENT",
|
|
1849
|
+
"./16347a01366873ed80fe45115119de3c92ab8db0-other.other":
|
|
1850
|
+
"SOME OTHER TEXT CONTENT",
|
|
1851
|
+
},
|
|
1852
|
+
});
|
|
1853
|
+
await runWrangler("publish index.js");
|
|
1854
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
1855
|
+
"Uploaded test-name (TIMINGS)
|
|
1856
|
+
Published test-name (TIMINGS)
|
|
1857
|
+
test-name.test-sub-domain.workers.dev"
|
|
1858
|
+
`);
|
|
1859
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1860
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1861
|
+
});
|
|
1862
|
+
|
|
1863
|
+
it("should be able to use fallthrough:false for multiple rules", async () => {
|
|
1864
|
+
writeWranglerToml({
|
|
1865
|
+
rules: [
|
|
1866
|
+
{ type: "Text", globs: ["**/*.file"], fallthrough: false },
|
|
1867
|
+
{ type: "Text", globs: ["**/*.other"] },
|
|
1868
|
+
],
|
|
1869
|
+
});
|
|
1870
|
+
fs.writeFileSync(
|
|
1871
|
+
"./index.js",
|
|
1872
|
+
`import TEXT from './text.file'; import OTHER from './other.other'; export default {};`
|
|
1873
|
+
);
|
|
1874
|
+
fs.writeFileSync("./text.file", "SOME TEXT CONTENT");
|
|
1875
|
+
fs.writeFileSync("./other.other", "SOME OTHER TEXT CONTENT");
|
|
1876
|
+
|
|
1877
|
+
// We throw an error when we come across a file that matched a rule
|
|
1878
|
+
// but was skipped because of fallthrough = false
|
|
1879
|
+
let err: Error | undefined;
|
|
1880
|
+
try {
|
|
1881
|
+
await runWrangler("publish index.js");
|
|
1882
|
+
} catch (e) {
|
|
1883
|
+
err = e as Error;
|
|
1884
|
+
}
|
|
1885
|
+
expect(err?.message).toMatch(
|
|
1886
|
+
`The file ./other.other matched a module rule in your configuration ({"type":"Text","globs":["**/*.other"]}), but was ignored because a previous rule with the same type was not marked as \`fallthrough = true\`.`
|
|
1887
|
+
);
|
|
1888
|
+
});
|
|
1889
|
+
|
|
1890
|
+
it("should warn when multiple rules for the same type do not have fallback defined", async () => {
|
|
1891
|
+
writeWranglerToml({
|
|
1892
|
+
rules: [
|
|
1893
|
+
{ type: "Text", globs: ["**/*.file"] },
|
|
1894
|
+
{ type: "Text", globs: ["**/*.other"] },
|
|
1895
|
+
],
|
|
1896
|
+
});
|
|
1897
|
+
fs.writeFileSync(
|
|
1898
|
+
"./index.js",
|
|
1899
|
+
`import TEXT from './text.file'; import OTHER from './other.other'; export default {};`
|
|
1900
|
+
);
|
|
1901
|
+
fs.writeFileSync("./text.file", "SOME TEXT CONTENT");
|
|
1902
|
+
fs.writeFileSync("./other.other", "SOME OTHER TEXT CONTENT");
|
|
1903
|
+
|
|
1904
|
+
// We throw an error when we come across a file that matched a rule
|
|
1905
|
+
// but was skipped because of fallthrough = false
|
|
1906
|
+
let err: Error | undefined;
|
|
1907
|
+
try {
|
|
1908
|
+
await runWrangler("publish index.js");
|
|
1909
|
+
} catch (e) {
|
|
1910
|
+
err = e as Error;
|
|
1911
|
+
}
|
|
1912
|
+
expect(err?.message).toMatch(
|
|
1913
|
+
`The file ./other.other matched a module rule in your configuration ({"type":"Text","globs":["**/*.other"]}), but was ignored because a previous rule with the same type was not marked as \`fallthrough = true\`.`
|
|
1914
|
+
);
|
|
1915
|
+
// and the warnings because fallthrough was not explicitly set
|
|
1916
|
+
expect(std.warn).toMatchInlineSnapshot(`
|
|
1917
|
+
"The module rule at position 1 ({\\"type\\":\\"Text\\",\\"globs\\":[\\"**/*.other\\"]}) has the same type as a previous rule (at position 0, {\\"type\\":\\"Text\\",\\"globs\\":[\\"**/*.file\\"]}). This rule will be ignored. To the previous rule, add \`fallthrough = true\` to allow this one to also be used, or \`fallthrough = false\` to silence this warning.
|
|
1918
|
+
The default module rule {\\"type\\":\\"Text\\",\\"globs\\":[\\"**/*.txt\\",\\"**/*.html\\"]} has the same type as a previous rule (at position 0, {\\"type\\":\\"Text\\",\\"globs\\":[\\"**/*.file\\"]}). This rule will be ignored. To the previous rule, add \`fallthrough = true\` to allow the default one to also be used, or \`fallthrough = false\` to silence this warning."
|
|
1559
1919
|
`);
|
|
1560
1920
|
});
|
|
1561
1921
|
});
|
|
@@ -1607,6 +1967,7 @@ function mockUploadWorkerRequest({
|
|
|
1607
1967
|
expectedBindings,
|
|
1608
1968
|
expectedModules = {},
|
|
1609
1969
|
env = undefined,
|
|
1970
|
+
legacyEnv = false,
|
|
1610
1971
|
}: {
|
|
1611
1972
|
available_on_subdomain?: boolean;
|
|
1612
1973
|
expectedEntry?: string;
|
|
@@ -1614,15 +1975,21 @@ function mockUploadWorkerRequest({
|
|
|
1614
1975
|
expectedBindings?: unknown;
|
|
1615
1976
|
expectedModules?: Record<string, string>;
|
|
1616
1977
|
env?: string | undefined;
|
|
1978
|
+
legacyEnv?: boolean | undefined;
|
|
1617
1979
|
} = {}) {
|
|
1618
1980
|
setMockResponse(
|
|
1619
|
-
env
|
|
1620
|
-
?
|
|
1981
|
+
env && !legacyEnv
|
|
1982
|
+
? "/accounts/:accountId/workers/services/:scriptName/environments/:envName"
|
|
1621
1983
|
: "/accounts/:accountId/workers/scripts/:scriptName",
|
|
1622
1984
|
"PUT",
|
|
1623
|
-
async ([_url, accountId, scriptName], { body }, queryParams) => {
|
|
1985
|
+
async ([_url, accountId, scriptName, envName], { body }, queryParams) => {
|
|
1624
1986
|
expect(accountId).toEqual("some-account-id");
|
|
1625
|
-
expect(scriptName).toEqual(
|
|
1987
|
+
expect(scriptName).toEqual(
|
|
1988
|
+
legacyEnv && env ? `test-name-${env}` : "test-name"
|
|
1989
|
+
);
|
|
1990
|
+
if (!legacyEnv) {
|
|
1991
|
+
expect(envName).toEqual(env);
|
|
1992
|
+
}
|
|
1626
1993
|
expect(queryParams.get("available_on_subdomain")).toEqual("true");
|
|
1627
1994
|
const formBody = body as FormData;
|
|
1628
1995
|
if (expectedEntry !== undefined) {
|
|
@@ -1643,7 +2010,7 @@ function mockUploadWorkerRequest({
|
|
|
1643
2010
|
expect(metadata.bindings).toEqual(expectedBindings);
|
|
1644
2011
|
}
|
|
1645
2012
|
for (const [name, content] of Object.entries(expectedModules)) {
|
|
1646
|
-
expect(await (formBody.get(name) as File).text()).
|
|
2013
|
+
expect(await (formBody.get(name) as File).text()).toEqual(content);
|
|
1647
2014
|
}
|
|
1648
2015
|
|
|
1649
2016
|
return { available_on_subdomain };
|
|
@@ -1658,20 +2025,30 @@ function mockSubDomainRequest(subdomain = "test-sub-domain") {
|
|
|
1658
2025
|
});
|
|
1659
2026
|
}
|
|
1660
2027
|
|
|
2028
|
+
/** Create a mock handler to toggle a <script>.<user>.workers.dev subdomain */
|
|
1661
2029
|
function mockUpdateWorkerRequest({
|
|
1662
2030
|
env,
|
|
1663
2031
|
enabled,
|
|
2032
|
+
legacyEnv = false,
|
|
1664
2033
|
}: {
|
|
1665
|
-
env?: string | undefined;
|
|
1666
2034
|
enabled: boolean;
|
|
2035
|
+
env?: string | undefined;
|
|
2036
|
+
legacyEnv?: boolean | undefined;
|
|
1667
2037
|
}) {
|
|
1668
2038
|
const requests = { count: 0 };
|
|
1669
|
-
const servicesOrScripts = env ? "services" : "scripts";
|
|
1670
|
-
const environment = env ? "/environments/:envName" : "";
|
|
2039
|
+
const servicesOrScripts = env && !legacyEnv ? "services" : "scripts";
|
|
2040
|
+
const environment = env && !legacyEnv ? "/environments/:envName" : "";
|
|
1671
2041
|
setMockResponse(
|
|
1672
2042
|
`/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/subdomain`,
|
|
1673
2043
|
"POST",
|
|
1674
|
-
(
|
|
2044
|
+
([_url, accountId, scriptName, envName], { body }) => {
|
|
2045
|
+
expect(accountId).toEqual("some-account-id");
|
|
2046
|
+
expect(scriptName).toEqual(
|
|
2047
|
+
legacyEnv && env ? `test-name-${env}` : "test-name"
|
|
2048
|
+
);
|
|
2049
|
+
if (!legacyEnv) {
|
|
2050
|
+
expect(envName).toEqual(env);
|
|
2051
|
+
}
|
|
1675
2052
|
expect(JSON.parse(body as string)).toEqual({ enabled });
|
|
1676
2053
|
return null;
|
|
1677
2054
|
}
|
|
@@ -1679,6 +2056,38 @@ function mockUpdateWorkerRequest({
|
|
|
1679
2056
|
return requests;
|
|
1680
2057
|
}
|
|
1681
2058
|
|
|
2059
|
+
function mockPublishRoutesRequest({
|
|
2060
|
+
routes,
|
|
2061
|
+
env = undefined,
|
|
2062
|
+
legacyEnv = false,
|
|
2063
|
+
}: {
|
|
2064
|
+
routes: string[];
|
|
2065
|
+
env?: string | undefined;
|
|
2066
|
+
legacyEnv?: boolean | undefined;
|
|
2067
|
+
}) {
|
|
2068
|
+
const servicesOrScripts = env && !legacyEnv ? "services" : "scripts";
|
|
2069
|
+
const environment = env && !legacyEnv ? "/environments/:envName" : "";
|
|
2070
|
+
|
|
2071
|
+
setMockResponse(
|
|
2072
|
+
`/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/routes`,
|
|
2073
|
+
"PUT",
|
|
2074
|
+
([_url, accountId, scriptName, envName], { body }) => {
|
|
2075
|
+
expect(accountId).toEqual("some-account-id");
|
|
2076
|
+
expect(scriptName).toEqual(
|
|
2077
|
+
legacyEnv && env ? `test-name-${env}` : "test-name"
|
|
2078
|
+
);
|
|
2079
|
+
if (!legacyEnv) {
|
|
2080
|
+
expect(envName).toEqual(env);
|
|
2081
|
+
}
|
|
2082
|
+
|
|
2083
|
+
expect(JSON.parse(body as string)).toEqual(
|
|
2084
|
+
routes.map((pattern) => ({ pattern }))
|
|
2085
|
+
);
|
|
2086
|
+
return null;
|
|
2087
|
+
}
|
|
2088
|
+
);
|
|
2089
|
+
}
|
|
2090
|
+
|
|
1682
2091
|
/** Create a mock handler for the request to get a list of all KV namespaces. */
|
|
1683
2092
|
function mockListKVNamespacesRequest(...namespaces: KVNamespaceInfo[]) {
|
|
1684
2093
|
setMockResponse(
|