wrangler 0.0.0-e88a54e → 0.0.0-e89ee2a5
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/Cloudflare_CA.pem +18 -0
- package/README.md +47 -16
- package/bin/wrangler.js +123 -32
- package/kv-asset-handler.js +1 -0
- package/package.json +168 -86
- package/templates/__tests__/pages-dev-util.test.ts +128 -0
- package/templates/__tests__/tsconfig-sanity.ts +12 -0
- package/templates/__tests__/tsconfig.json +8 -0
- package/templates/checked-fetch.js +30 -0
- package/templates/facade.d.ts +17 -0
- package/templates/gitignore +167 -0
- package/templates/init-tests/test-jest-new-worker.js +23 -0
- package/templates/init-tests/test-vitest-new-worker.js +24 -0
- package/templates/init-tests/test-vitest-new-worker.ts +25 -0
- package/templates/middleware/common.ts +67 -0
- package/templates/middleware/loader-modules.ts +136 -0
- package/templates/middleware/loader-sw.ts +229 -0
- package/templates/middleware/middleware-d1-beta.d.ts +3 -0
- package/templates/middleware/middleware-ensure-req-body-drained.ts +19 -0
- package/templates/middleware/middleware-miniflare3-json-error.ts +33 -0
- package/templates/middleware/middleware-multiworker-dev.d.ts +4 -0
- package/templates/middleware/middleware-multiworker-dev.ts +68 -0
- package/templates/middleware/middleware-pretty-error.ts +40 -0
- package/templates/middleware/middleware-scheduled.ts +15 -0
- package/templates/middleware/middleware-serve-static-assets.d.ts +6 -0
- package/templates/middleware/middleware-serve-static-assets.ts +56 -0
- package/templates/modules-watch-stub.js +4 -0
- package/templates/new-worker-scheduled.js +17 -0
- package/templates/new-worker-scheduled.ts +32 -0
- package/templates/new-worker.js +3 -3
- package/templates/new-worker.ts +22 -4
- package/templates/no-op-worker.js +10 -0
- package/templates/pages-dev-pipeline.ts +32 -0
- package/templates/pages-dev-util.ts +55 -0
- package/templates/pages-shim.ts +9 -0
- package/templates/pages-template-plugin.ts +190 -0
- package/templates/pages-template-worker.ts +198 -0
- package/templates/startDevWorker/InspectorProxyWorker.ts +661 -0
- package/templates/startDevWorker/ProxyWorker.ts +326 -0
- package/templates/tsconfig-sanity.ts +11 -0
- package/templates/tsconfig.init.json +105 -0
- package/templates/tsconfig.json +6 -103
- package/wrangler-dist/InspectorProxyWorker.js +464 -0
- package/wrangler-dist/InspectorProxyWorker.js.map +6 -0
- package/wrangler-dist/ProxyWorker.js +237 -0
- package/wrangler-dist/ProxyWorker.js.map +6 -0
- package/wrangler-dist/cli.d.ts +23948 -0
- package/wrangler-dist/cli.js +164439 -134006
- package/wrangler-dist/wasm-sync.wasm +0 -0
- package/import_meta_url.js +0 -3
- package/miniflare-config-stubs/.env.empty +0 -0
- package/miniflare-config-stubs/package.empty.json +0 -1
- package/miniflare-config-stubs/wrangler.empty.toml +0 -0
- package/miniflare-dist/index.mjs +0 -79
- package/miniflare-dist/index.mjs.map +0 -7
- package/pages/functions/buildWorker.ts +0 -62
- package/pages/functions/filepath-routing.test.ts +0 -223
- package/pages/functions/filepath-routing.ts +0 -181
- package/pages/functions/identifiers.ts +0 -78
- package/pages/functions/routes.ts +0 -151
- package/pages/functions/template-worker.ts +0 -130
- package/src/__tests__/configuration.test.ts +0 -2796
- package/src/__tests__/dev.test.tsx +0 -496
- package/src/__tests__/dev2.test.tsx +0 -154
- package/src/__tests__/guess-worker-format.test.ts +0 -58
- package/src/__tests__/helpers/clipboardy-mock.js +0 -4
- package/src/__tests__/helpers/cmd-shim.d.ts +0 -11
- package/src/__tests__/helpers/faye-websocket.d.ts +0 -6
- package/src/__tests__/helpers/mock-account-id.ts +0 -48
- package/src/__tests__/helpers/mock-bin.ts +0 -36
- package/src/__tests__/helpers/mock-cfetch.ts +0 -207
- package/src/__tests__/helpers/mock-console.ts +0 -70
- package/src/__tests__/helpers/mock-dialogs.ts +0 -65
- package/src/__tests__/helpers/mock-kv.ts +0 -33
- package/src/__tests__/helpers/mock-stdin.ts +0 -103
- package/src/__tests__/helpers/mock-web-socket.ts +0 -29
- package/src/__tests__/helpers/run-in-tmp.ts +0 -32
- package/src/__tests__/helpers/run-wrangler.ts +0 -16
- package/src/__tests__/helpers/write-wrangler-toml.ts +0 -17
- package/src/__tests__/https-options.test.ts +0 -127
- package/src/__tests__/index.test.ts +0 -991
- package/src/__tests__/jest.setup.ts +0 -69
- package/src/__tests__/kv.test.ts +0 -1382
- package/src/__tests__/logout.test.ts +0 -52
- package/src/__tests__/package-manager.test.ts +0 -206
- package/src/__tests__/pages.test.ts +0 -44
- package/src/__tests__/parse.test.ts +0 -322
- package/src/__tests__/publish.test.ts +0 -2704
- package/src/__tests__/r2.test.ts +0 -198
- package/src/__tests__/route.test.ts +0 -45
- package/src/__tests__/secret.test.ts +0 -425
- package/src/__tests__/sentry.test.ts +0 -146
- package/src/__tests__/tail.test.ts +0 -564
- package/src/__tests__/whoami.test.tsx +0 -100
- package/src/bundle.ts +0 -142
- package/src/cfetch/index.ts +0 -104
- package/src/cfetch/internal.ts +0 -139
- package/src/cli.ts +0 -19
- package/src/config/README.md +0 -107
- package/src/config/config.ts +0 -218
- package/src/config/diagnostics.ts +0 -80
- package/src/config/environment.ts +0 -366
- package/src/config/index.ts +0 -62
- package/src/config/validation-helpers.ts +0 -486
- package/src/config/validation.ts +0 -1090
- package/src/create-worker-preview.ts +0 -166
- package/src/create-worker-upload-form.ts +0 -217
- package/src/dev/dev.tsx +0 -364
- package/src/dev/local.tsx +0 -232
- package/src/dev/remote.tsx +0 -203
- package/src/dev/use-esbuild.ts +0 -100
- package/src/dialogs.tsx +0 -77
- package/src/entry.ts +0 -208
- package/src/environment-variables.ts +0 -33
- package/src/https-options.ts +0 -122
- package/src/index.tsx +0 -2373
- package/src/inspect.ts +0 -617
- package/src/kv.ts +0 -319
- package/src/miniflare-cli/README.md +0 -30
- package/src/miniflare-cli/enum-keys.ts +0 -17
- package/src/miniflare-cli/index.ts +0 -37
- package/src/module-collection.ts +0 -258
- package/src/open-in-browser.ts +0 -25
- package/src/package-manager.ts +0 -126
- package/src/pages.tsx +0 -1047
- package/src/parse.ts +0 -183
- package/src/paths.ts +0 -26
- package/src/proxy.ts +0 -440
- package/src/publish.ts +0 -347
- package/src/r2.ts +0 -50
- package/src/reporting.ts +0 -131
- package/src/selfsigned.d.ts +0 -29
- package/src/sites.tsx +0 -280
- package/src/tail/filters.ts +0 -279
- package/src/tail/index.ts +0 -299
- package/src/tail/printing.ts +0 -62
- package/src/user.tsx +0 -1118
- package/src/whoami.tsx +0 -69
- package/src/worker.ts +0 -163
- package/templates/static-asset-facade.js +0 -47
- package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
- package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
- package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
- package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
- package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
- package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
- package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
- package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
- package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
- package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
- package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
- package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
- package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
- package/vendor/wrangler-mime/CHANGELOG.md +0 -289
- package/vendor/wrangler-mime/LICENSE +0 -21
- package/vendor/wrangler-mime/Mime.js +0 -97
- package/vendor/wrangler-mime/README.md +0 -187
- package/vendor/wrangler-mime/cli.js +0 -46
- package/vendor/wrangler-mime/index.js +0 -4
- package/vendor/wrangler-mime/lite.js +0 -4
- package/vendor/wrangler-mime/package.json +0 -52
- package/vendor/wrangler-mime/types/other.js +0 -1
- package/vendor/wrangler-mime/types/standard.js +0 -1
- package/wrangler-dist/cli.js.map +0 -7
|
@@ -1,496 +0,0 @@
|
|
|
1
|
-
import * as fs from "node:fs";
|
|
2
|
-
import { readFileSync } from "node:fs";
|
|
3
|
-
import patchConsole from "patch-console";
|
|
4
|
-
import Dev from "../dev/dev";
|
|
5
|
-
import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
|
|
6
|
-
import { setMockResponse, unsetAllMocks } from "./helpers/mock-cfetch";
|
|
7
|
-
import { mockConsoleMethods } from "./helpers/mock-console";
|
|
8
|
-
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
9
|
-
import { runWrangler } from "./helpers/run-wrangler";
|
|
10
|
-
import writeWranglerToml from "./helpers/write-wrangler-toml";
|
|
11
|
-
|
|
12
|
-
describe("Dev component", () => {
|
|
13
|
-
mockAccountId();
|
|
14
|
-
mockApiToken();
|
|
15
|
-
runInTempDir();
|
|
16
|
-
const std = mockConsoleMethods();
|
|
17
|
-
afterEach(() => {
|
|
18
|
-
(Dev as jest.Mock).mockClear();
|
|
19
|
-
patchConsole(() => {});
|
|
20
|
-
unsetAllMocks();
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
describe("entry-points", () => {
|
|
24
|
-
it("should error if there is no entry-point specified", async () => {
|
|
25
|
-
writeWranglerToml();
|
|
26
|
-
|
|
27
|
-
await expect(
|
|
28
|
-
runWrangler("dev")
|
|
29
|
-
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
30
|
-
`"Missing entry-point: The entry-point should be specified via the command line (e.g. \`wrangler dev path/to/script\`) or the \`main\` config field."`
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
34
|
-
expect(std.err).toMatchInlineSnapshot(`
|
|
35
|
-
"Missing entry-point: The entry-point should be specified via the command line (e.g. \`wrangler dev path/to/script\`) or the \`main\` config field.
|
|
36
|
-
|
|
37
|
-
[32m%s[0m If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
|
|
38
|
-
`);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it("should use `main` from the top-level environment", async () => {
|
|
42
|
-
writeWranglerToml({
|
|
43
|
-
main: "index.js",
|
|
44
|
-
});
|
|
45
|
-
fs.writeFileSync("index.js", `export default {};`);
|
|
46
|
-
await runWrangler("dev");
|
|
47
|
-
expect((Dev as jest.Mock).mock.calls[0][0].entry.file).toMatch(
|
|
48
|
-
/index\.js$/
|
|
49
|
-
);
|
|
50
|
-
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
51
|
-
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
52
|
-
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it("should use `main` from a named environment", async () => {
|
|
56
|
-
writeWranglerToml({
|
|
57
|
-
env: {
|
|
58
|
-
ENV1: {
|
|
59
|
-
main: "index.js",
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
});
|
|
63
|
-
fs.writeFileSync("index.js", `export default {};`);
|
|
64
|
-
await runWrangler("dev --env=ENV1");
|
|
65
|
-
expect((Dev as jest.Mock).mock.calls[0][0].entry.file).toMatch(
|
|
66
|
-
/index\.js$/
|
|
67
|
-
);
|
|
68
|
-
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
69
|
-
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
70
|
-
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it("should use `main` from a named environment, rather than the top-level", async () => {
|
|
74
|
-
writeWranglerToml({
|
|
75
|
-
main: "other.js",
|
|
76
|
-
env: {
|
|
77
|
-
ENV1: {
|
|
78
|
-
main: "index.js",
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
});
|
|
82
|
-
fs.writeFileSync("index.js", `export default {};`);
|
|
83
|
-
await runWrangler("dev --env=ENV1");
|
|
84
|
-
expect((Dev as jest.Mock).mock.calls[0][0].entry.file).toMatch(
|
|
85
|
-
/index\.js$/
|
|
86
|
-
);
|
|
87
|
-
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
88
|
-
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
89
|
-
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
describe("host", () => {
|
|
94
|
-
it("should resolve a host to its zone", async () => {
|
|
95
|
-
writeWranglerToml({
|
|
96
|
-
main: "index.js",
|
|
97
|
-
});
|
|
98
|
-
fs.writeFileSync("index.js", `export default {};`);
|
|
99
|
-
mockGetZones("some-host.com", [{ id: "some-zone-id" }]);
|
|
100
|
-
await runWrangler("dev --host some-host.com");
|
|
101
|
-
expect((Dev as jest.Mock).mock.calls[0][0].zone).toEqual({
|
|
102
|
-
host: "some-host.com",
|
|
103
|
-
id: "some-zone-id",
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it("should read wrangler.toml's dev.host", async () => {
|
|
108
|
-
writeWranglerToml({
|
|
109
|
-
main: "index.js",
|
|
110
|
-
dev: {
|
|
111
|
-
host: "some-host.com",
|
|
112
|
-
},
|
|
113
|
-
});
|
|
114
|
-
fs.writeFileSync("index.js", `export default {};`);
|
|
115
|
-
mockGetZones("some-host.com", [{ id: "some-zone-id" }]);
|
|
116
|
-
await runWrangler("dev");
|
|
117
|
-
expect((Dev as jest.Mock).mock.calls[0][0].zone.host).toEqual(
|
|
118
|
-
"some-host.com"
|
|
119
|
-
);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it("should read --route", async () => {
|
|
123
|
-
writeWranglerToml({
|
|
124
|
-
main: "index.js",
|
|
125
|
-
});
|
|
126
|
-
fs.writeFileSync("index.js", `export default {};`);
|
|
127
|
-
mockGetZones("some-host.com", [{ id: "some-zone-id" }]);
|
|
128
|
-
await runWrangler("dev --route http://some-host.com/some/path/*");
|
|
129
|
-
expect((Dev as jest.Mock).mock.calls[0][0].zone.host).toEqual(
|
|
130
|
-
"some-host.com"
|
|
131
|
-
);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it("should read wrangler.toml's routes", async () => {
|
|
135
|
-
writeWranglerToml({
|
|
136
|
-
main: "index.js",
|
|
137
|
-
routes: [
|
|
138
|
-
"http://some-host.com/some/path/*",
|
|
139
|
-
"http://some-other-host.com/path/*",
|
|
140
|
-
],
|
|
141
|
-
});
|
|
142
|
-
fs.writeFileSync("index.js", `export default {};`);
|
|
143
|
-
mockGetZones("some-host.com", [{ id: "some-zone-id" }]);
|
|
144
|
-
await runWrangler("dev");
|
|
145
|
-
expect((Dev as jest.Mock).mock.calls[0][0].zone.host).toEqual(
|
|
146
|
-
"some-host.com"
|
|
147
|
-
);
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
it("should read wrangler.toml's environment specific routes", async () => {
|
|
151
|
-
writeWranglerToml({
|
|
152
|
-
main: "index.js",
|
|
153
|
-
routes: [
|
|
154
|
-
"http://a-host.com/some/path/*",
|
|
155
|
-
"http://another-host.com/path/*",
|
|
156
|
-
],
|
|
157
|
-
env: {
|
|
158
|
-
staging: {
|
|
159
|
-
routes: [
|
|
160
|
-
"http://some-host.com/some/path/*",
|
|
161
|
-
"http://some-other-host.com/path/*",
|
|
162
|
-
],
|
|
163
|
-
},
|
|
164
|
-
},
|
|
165
|
-
});
|
|
166
|
-
fs.writeFileSync("index.js", `export default {};`);
|
|
167
|
-
mockGetZones("some-host.com", [{ id: "some-zone-id" }]);
|
|
168
|
-
await runWrangler("dev --env staging");
|
|
169
|
-
expect((Dev as jest.Mock).mock.calls[0][0].zone.host).toEqual(
|
|
170
|
-
"some-host.com"
|
|
171
|
-
);
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
it("given a long host, it should use the longest subdomain that resolves to a zone", async () => {
|
|
175
|
-
writeWranglerToml({
|
|
176
|
-
main: "index.js",
|
|
177
|
-
});
|
|
178
|
-
fs.writeFileSync("index.js", `export default {};`);
|
|
179
|
-
mockGetZones("111.222.333.some-host.com", []);
|
|
180
|
-
mockGetZones("222.333.some-host.com", []);
|
|
181
|
-
mockGetZones("333.some-host.com", [{ id: "some-zone-id" }]);
|
|
182
|
-
await runWrangler("dev --host 111.222.333.some-host.com");
|
|
183
|
-
expect((Dev as jest.Mock).mock.calls[0][0].zone).toEqual({
|
|
184
|
-
host: "111.222.333.some-host.com",
|
|
185
|
-
id: "some-zone-id",
|
|
186
|
-
});
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
it("should, in order, use args.host/config.dev.host/args.routes/(config.route|config.routes)", async () => {
|
|
190
|
-
// This test might seem like it's testing implementation details, but let's be specific and consider it a spec
|
|
191
|
-
|
|
192
|
-
fs.writeFileSync("index.js", `export default {};`);
|
|
193
|
-
|
|
194
|
-
// config.routes
|
|
195
|
-
mockGetZones("5.some-host.com", [{ id: "some-zone-id-5" }]);
|
|
196
|
-
writeWranglerToml({
|
|
197
|
-
main: "index.js",
|
|
198
|
-
routes: ["http://5.some-host.com/some/path/*"],
|
|
199
|
-
});
|
|
200
|
-
await runWrangler("dev");
|
|
201
|
-
expect((Dev as jest.Mock).mock.calls[0][0].zone).toEqual({
|
|
202
|
-
host: "5.some-host.com",
|
|
203
|
-
id: "some-zone-id-5",
|
|
204
|
-
});
|
|
205
|
-
(Dev as jest.Mock).mockClear();
|
|
206
|
-
|
|
207
|
-
// config.route
|
|
208
|
-
mockGetZones("4.some-host.com", [{ id: "some-zone-id-4" }]);
|
|
209
|
-
writeWranglerToml({
|
|
210
|
-
main: "index.js",
|
|
211
|
-
route: "https://4.some-host.com/some/path/*",
|
|
212
|
-
});
|
|
213
|
-
await runWrangler("dev");
|
|
214
|
-
expect((Dev as jest.Mock).mock.calls[0][0].zone).toEqual({
|
|
215
|
-
host: "4.some-host.com",
|
|
216
|
-
id: "some-zone-id-4",
|
|
217
|
-
});
|
|
218
|
-
(Dev as jest.Mock).mockClear();
|
|
219
|
-
|
|
220
|
-
// --routes
|
|
221
|
-
mockGetZones("3.some-host.com", [{ id: "some-zone-id-3" }]);
|
|
222
|
-
writeWranglerToml({
|
|
223
|
-
main: "index.js",
|
|
224
|
-
route: "https://4.some-host.com/some/path/*",
|
|
225
|
-
});
|
|
226
|
-
await runWrangler("dev --routes http://3.some-host.com/some/path/*");
|
|
227
|
-
expect((Dev as jest.Mock).mock.calls[0][0].zone).toEqual({
|
|
228
|
-
host: "3.some-host.com",
|
|
229
|
-
id: "some-zone-id-3",
|
|
230
|
-
});
|
|
231
|
-
(Dev as jest.Mock).mockClear();
|
|
232
|
-
|
|
233
|
-
// config.dev.host
|
|
234
|
-
mockGetZones("2.some-host.com", [{ id: "some-zone-id-2" }]);
|
|
235
|
-
writeWranglerToml({
|
|
236
|
-
main: "index.js",
|
|
237
|
-
dev: {
|
|
238
|
-
host: `2.some-host.com`,
|
|
239
|
-
},
|
|
240
|
-
route: "4.some-host.com/some/path/*",
|
|
241
|
-
});
|
|
242
|
-
await runWrangler("dev --routes http://3.some-host.com/some/path/*");
|
|
243
|
-
expect((Dev as jest.Mock).mock.calls[0][0].zone).toEqual({
|
|
244
|
-
host: "2.some-host.com",
|
|
245
|
-
id: "some-zone-id-2",
|
|
246
|
-
});
|
|
247
|
-
(Dev as jest.Mock).mockClear();
|
|
248
|
-
|
|
249
|
-
// --host
|
|
250
|
-
mockGetZones("1.some-host.com", [{ id: "some-zone-id-1" }]);
|
|
251
|
-
writeWranglerToml({
|
|
252
|
-
main: "index.js",
|
|
253
|
-
dev: {
|
|
254
|
-
host: `2.some-host.com`,
|
|
255
|
-
},
|
|
256
|
-
route: "4.some-host.com/some/path/*",
|
|
257
|
-
});
|
|
258
|
-
await runWrangler(
|
|
259
|
-
"dev --routes http://3.some-host.com/some/path/* --host 1.some-host.com"
|
|
260
|
-
);
|
|
261
|
-
expect((Dev as jest.Mock).mock.calls[0][0].zone).toEqual({
|
|
262
|
-
host: "1.some-host.com",
|
|
263
|
-
id: "some-zone-id-1",
|
|
264
|
-
});
|
|
265
|
-
(Dev as jest.Mock).mockClear();
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
it("should error if a host can't resolve to a zone", async () => {
|
|
269
|
-
writeWranglerToml({
|
|
270
|
-
main: "index.js",
|
|
271
|
-
});
|
|
272
|
-
fs.writeFileSync("index.js", `export default {};`);
|
|
273
|
-
mockGetZones("some-host.com", []);
|
|
274
|
-
await expect(
|
|
275
|
-
runWrangler("dev --host some-host.com")
|
|
276
|
-
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
277
|
-
`"Could not find zone for some-host.com"`
|
|
278
|
-
);
|
|
279
|
-
});
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
describe("custom builds", () => {
|
|
283
|
-
it("should run a custom build before starting `dev`", async () => {
|
|
284
|
-
writeWranglerToml({
|
|
285
|
-
build: {
|
|
286
|
-
command: `node -e "console.log('custom build'); require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')"`,
|
|
287
|
-
},
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
await runWrangler("dev index.js");
|
|
291
|
-
|
|
292
|
-
expect(readFileSync("index.js", "utf-8")).toMatchInlineSnapshot(
|
|
293
|
-
`"export default { fetch(){ return new Response(123) } }"`
|
|
294
|
-
);
|
|
295
|
-
|
|
296
|
-
// and the command would pass through
|
|
297
|
-
expect((Dev as jest.Mock).mock.calls[0][0].buildCommand).toEqual({
|
|
298
|
-
command:
|
|
299
|
-
"node -e \"console.log('custom build'); require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')\"",
|
|
300
|
-
cwd: undefined,
|
|
301
|
-
watch_dir: "src",
|
|
302
|
-
});
|
|
303
|
-
expect(std.out).toMatchInlineSnapshot(
|
|
304
|
-
`"running: node -e \\"console.log('custom build'); require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')\\""`
|
|
305
|
-
);
|
|
306
|
-
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
307
|
-
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
if (process.platform !== "win32") {
|
|
311
|
-
it("should run a custom build of multiple steps combined by && before starting `dev`", async () => {
|
|
312
|
-
writeWranglerToml({
|
|
313
|
-
build: {
|
|
314
|
-
command: `echo "custom build" && echo "export default { fetch(){ return new Response(123) } }" > index.js`,
|
|
315
|
-
},
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
await runWrangler("dev index.js");
|
|
319
|
-
|
|
320
|
-
expect(readFileSync("index.js", "utf-8")).toMatchInlineSnapshot(`
|
|
321
|
-
"export default { fetch(){ return new Response(123) } }
|
|
322
|
-
"
|
|
323
|
-
`);
|
|
324
|
-
|
|
325
|
-
expect(std.out).toMatchInlineSnapshot(
|
|
326
|
-
`"running: echo \\"custom build\\" && echo \\"export default { fetch(){ return new Response(123) } }\\" > index.js"`
|
|
327
|
-
);
|
|
328
|
-
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
329
|
-
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
330
|
-
});
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
it("should throw an error if the entry doesn't exist after the build finishes", async () => {
|
|
334
|
-
writeWranglerToml({
|
|
335
|
-
main: "index.js",
|
|
336
|
-
build: {
|
|
337
|
-
command: `node -e "console.log('custom build');"`,
|
|
338
|
-
},
|
|
339
|
-
});
|
|
340
|
-
|
|
341
|
-
await expect(
|
|
342
|
-
runWrangler("dev")
|
|
343
|
-
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
344
|
-
`"Could not resolve \\"index.js\\" after running custom build: node -e \\"console.log('custom build');\\""`
|
|
345
|
-
);
|
|
346
|
-
expect(std.out).toMatchInlineSnapshot(
|
|
347
|
-
`"running: node -e \\"console.log('custom build');\\""`
|
|
348
|
-
);
|
|
349
|
-
expect(std.err).toMatchInlineSnapshot(`
|
|
350
|
-
"Could not resolve \\"index.js\\" after running custom build: node -e \\"console.log('custom build');\\"
|
|
351
|
-
|
|
352
|
-
[32m%s[0m If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
|
|
353
|
-
`);
|
|
354
|
-
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
355
|
-
});
|
|
356
|
-
});
|
|
357
|
-
|
|
358
|
-
describe("upstream-protocol", () => {
|
|
359
|
-
it("should default upstream-protocol to `https`", async () => {
|
|
360
|
-
writeWranglerToml({
|
|
361
|
-
main: "index.js",
|
|
362
|
-
});
|
|
363
|
-
fs.writeFileSync("index.js", `export default {};`);
|
|
364
|
-
await runWrangler("dev");
|
|
365
|
-
expect((Dev as jest.Mock).mock.calls[0][0].upstreamProtocol).toEqual(
|
|
366
|
-
"https"
|
|
367
|
-
);
|
|
368
|
-
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
369
|
-
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
370
|
-
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
371
|
-
});
|
|
372
|
-
|
|
373
|
-
it("should warn if `--upstream-protocol=http` is used", async () => {
|
|
374
|
-
writeWranglerToml({
|
|
375
|
-
main: "index.js",
|
|
376
|
-
});
|
|
377
|
-
fs.writeFileSync("index.js", `export default {};`);
|
|
378
|
-
await runWrangler("dev --upstream-protocol=http");
|
|
379
|
-
expect((Dev as jest.Mock).mock.calls[0][0].upstreamProtocol).toEqual(
|
|
380
|
-
"http"
|
|
381
|
-
);
|
|
382
|
-
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
383
|
-
expect(std.warn).toMatchInlineSnapshot(`
|
|
384
|
-
"Setting upstream-protocol to http is not currently implemented.
|
|
385
|
-
If this is required in your project, please add your use case to the following issue:
|
|
386
|
-
https://github.com/cloudflare/wrangler2/issues/583."
|
|
387
|
-
`);
|
|
388
|
-
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
389
|
-
});
|
|
390
|
-
});
|
|
391
|
-
|
|
392
|
-
describe("local-protocol", () => {
|
|
393
|
-
it("should default local-protocol to `http`", async () => {
|
|
394
|
-
writeWranglerToml({
|
|
395
|
-
main: "index.js",
|
|
396
|
-
});
|
|
397
|
-
fs.writeFileSync("index.js", `export default {};`);
|
|
398
|
-
await runWrangler("dev");
|
|
399
|
-
expect((Dev as jest.Mock).mock.calls[0][0].localProtocol).toEqual("http");
|
|
400
|
-
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
401
|
-
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
402
|
-
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
403
|
-
});
|
|
404
|
-
|
|
405
|
-
it("should use `local_protocol` from `wrangler.toml`, if available", async () => {
|
|
406
|
-
writeWranglerToml({
|
|
407
|
-
main: "index.js",
|
|
408
|
-
dev: {
|
|
409
|
-
local_protocol: "https",
|
|
410
|
-
},
|
|
411
|
-
});
|
|
412
|
-
fs.writeFileSync("index.js", `export default {};`);
|
|
413
|
-
await runWrangler("dev");
|
|
414
|
-
expect((Dev as jest.Mock).mock.calls[0][0].localProtocol).toEqual(
|
|
415
|
-
"https"
|
|
416
|
-
);
|
|
417
|
-
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
418
|
-
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
419
|
-
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
420
|
-
});
|
|
421
|
-
|
|
422
|
-
it("should use --local-protocol command line arg, if provided", async () => {
|
|
423
|
-
// Here we show that the command line overrides the wrangler.toml by
|
|
424
|
-
// setting the config to https, and then setting it back to http on the command line.
|
|
425
|
-
writeWranglerToml({
|
|
426
|
-
main: "index.js",
|
|
427
|
-
dev: {
|
|
428
|
-
local_protocol: "https",
|
|
429
|
-
},
|
|
430
|
-
});
|
|
431
|
-
fs.writeFileSync("index.js", `export default {};`);
|
|
432
|
-
await runWrangler("dev --local-protocol=http");
|
|
433
|
-
expect((Dev as jest.Mock).mock.calls[0][0].localProtocol).toEqual("http");
|
|
434
|
-
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
435
|
-
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
436
|
-
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
437
|
-
});
|
|
438
|
-
});
|
|
439
|
-
|
|
440
|
-
describe("ip", () => {
|
|
441
|
-
it("should default ip to localhost", async () => {
|
|
442
|
-
writeWranglerToml({
|
|
443
|
-
main: "index.js",
|
|
444
|
-
});
|
|
445
|
-
fs.writeFileSync("index.js", `export default {};`);
|
|
446
|
-
await runWrangler("dev");
|
|
447
|
-
expect((Dev as jest.Mock).mock.calls[0][0].ip).toEqual("localhost");
|
|
448
|
-
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
449
|
-
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
450
|
-
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
451
|
-
});
|
|
452
|
-
|
|
453
|
-
it("should use to `ip` from `wrangler.toml`, if available", async () => {
|
|
454
|
-
writeWranglerToml({
|
|
455
|
-
main: "index.js",
|
|
456
|
-
dev: {
|
|
457
|
-
ip: "0.0.0.0",
|
|
458
|
-
},
|
|
459
|
-
});
|
|
460
|
-
fs.writeFileSync("index.js", `export default {};`);
|
|
461
|
-
await runWrangler("dev");
|
|
462
|
-
expect((Dev as jest.Mock).mock.calls[0][0].ip).toEqual("0.0.0.0");
|
|
463
|
-
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
464
|
-
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
465
|
-
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
466
|
-
});
|
|
467
|
-
|
|
468
|
-
it("should use --ip command line arg, if provided", async () => {
|
|
469
|
-
writeWranglerToml({
|
|
470
|
-
main: "index.js",
|
|
471
|
-
dev: {
|
|
472
|
-
ip: "1.1.1.1",
|
|
473
|
-
},
|
|
474
|
-
});
|
|
475
|
-
fs.writeFileSync("index.js", `export default {};`);
|
|
476
|
-
await runWrangler("dev --ip=0.0.0.0");
|
|
477
|
-
expect((Dev as jest.Mock).mock.calls[0][0].ip).toEqual("0.0.0.0");
|
|
478
|
-
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
479
|
-
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
480
|
-
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
481
|
-
});
|
|
482
|
-
});
|
|
483
|
-
});
|
|
484
|
-
|
|
485
|
-
function mockGetZones(domain: string, zones: { id: string }[] = []) {
|
|
486
|
-
const removeMock = setMockResponse(
|
|
487
|
-
"/zones",
|
|
488
|
-
"GET",
|
|
489
|
-
(_urlPieces, _init, queryParams) => {
|
|
490
|
-
expect([...queryParams.entries()]).toEqual([["name", domain]]);
|
|
491
|
-
// Because the API URL `/zones` is the same for each request, we can get into a situation where earlier mocks get triggered for later requests. So, we simply clear the mock on every trigger.
|
|
492
|
-
removeMock();
|
|
493
|
-
return zones;
|
|
494
|
-
}
|
|
495
|
-
);
|
|
496
|
-
}
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import * as fs from "node:fs";
|
|
2
|
-
import React from "react";
|
|
3
|
-
import TestRenderer from "react-test-renderer";
|
|
4
|
-
import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
|
|
5
|
-
import { unsetAllMocks } from "./helpers/mock-cfetch";
|
|
6
|
-
import { mockConsoleMethods } from "./helpers/mock-console";
|
|
7
|
-
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
8
|
-
import type { DevProps, default as DevType } from "../dev/dev";
|
|
9
|
-
|
|
10
|
-
function sleep(period = 100): Promise<void> {
|
|
11
|
-
return new Promise((resolve) => setTimeout(resolve, period));
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// we use this ["mock"] form to avoid esbuild-jest from rewriting it
|
|
15
|
-
jest["mock"]("../proxy", () => {
|
|
16
|
-
return {
|
|
17
|
-
usePreviewServer() {},
|
|
18
|
-
waitForPortToBeAvailable() {},
|
|
19
|
-
};
|
|
20
|
-
});
|
|
21
|
-
jest["mock"]("../inspect", () => {
|
|
22
|
-
return () => {};
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
const Dev: typeof DevType = jest.requireActual("../dev/dev").DevImplementation;
|
|
26
|
-
|
|
27
|
-
mockAccountId();
|
|
28
|
-
mockApiToken();
|
|
29
|
-
runInTempDir();
|
|
30
|
-
mockConsoleMethods();
|
|
31
|
-
afterEach(() => {
|
|
32
|
-
unsetAllMocks();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
describe("dev", () => {
|
|
36
|
-
it("should render", async () => {
|
|
37
|
-
fs.writeFileSync("./index.js", `export default {}`);
|
|
38
|
-
|
|
39
|
-
const testRenderer = await renderDev({
|
|
40
|
-
entry: {
|
|
41
|
-
file: "./index.js",
|
|
42
|
-
directory: process.cwd(),
|
|
43
|
-
format: "modules",
|
|
44
|
-
},
|
|
45
|
-
});
|
|
46
|
-
expect(testRenderer.toJSON()).toMatchInlineSnapshot(`
|
|
47
|
-
<ink-box
|
|
48
|
-
style={
|
|
49
|
-
Object {
|
|
50
|
-
"borderStyle": "round",
|
|
51
|
-
"flexDirection": "row",
|
|
52
|
-
"flexGrow": 0,
|
|
53
|
-
"flexShrink": 1,
|
|
54
|
-
"marginBottom": 0,
|
|
55
|
-
"marginLeft": 0,
|
|
56
|
-
"marginRight": 0,
|
|
57
|
-
"marginTop": 0,
|
|
58
|
-
"paddingBottom": 0,
|
|
59
|
-
"paddingLeft": 1,
|
|
60
|
-
"paddingRight": 1,
|
|
61
|
-
"paddingTop": 0,
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
>
|
|
65
|
-
<ink-text
|
|
66
|
-
internal_transform={[Function]}
|
|
67
|
-
style={
|
|
68
|
-
Object {
|
|
69
|
-
"flexDirection": "row",
|
|
70
|
-
"flexGrow": 0,
|
|
71
|
-
"flexShrink": 1,
|
|
72
|
-
"textWrap": "wrap",
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
>
|
|
76
|
-
B to open a browser, D to open Devtools, L to turn off local mode, X to exit
|
|
77
|
-
</ink-text>
|
|
78
|
-
</ink-box>
|
|
79
|
-
`);
|
|
80
|
-
await TestRenderer.act(async () => {
|
|
81
|
-
// TODO: get rid of these sleep statements
|
|
82
|
-
await sleep(50);
|
|
83
|
-
testRenderer.unmount();
|
|
84
|
-
await sleep(50);
|
|
85
|
-
});
|
|
86
|
-
await sleep(50);
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
async function renderDev({
|
|
91
|
-
name,
|
|
92
|
-
entry = { file: "index.js", directory: "", format: "modules" },
|
|
93
|
-
port,
|
|
94
|
-
ip = "localhost",
|
|
95
|
-
inspectorPort = 9229,
|
|
96
|
-
accountId,
|
|
97
|
-
legacyEnv = true,
|
|
98
|
-
initialMode = "local",
|
|
99
|
-
jsxFactory,
|
|
100
|
-
jsxFragment,
|
|
101
|
-
localProtocol = "http",
|
|
102
|
-
upstreamProtocol = "https",
|
|
103
|
-
rules = [],
|
|
104
|
-
bindings = {
|
|
105
|
-
kv_namespaces: [],
|
|
106
|
-
vars: {},
|
|
107
|
-
durable_objects: { bindings: [] },
|
|
108
|
-
r2_buckets: [],
|
|
109
|
-
wasm_modules: undefined,
|
|
110
|
-
text_blobs: undefined,
|
|
111
|
-
unsafe: [],
|
|
112
|
-
},
|
|
113
|
-
public: publicDir,
|
|
114
|
-
assetPaths,
|
|
115
|
-
compatibilityDate,
|
|
116
|
-
compatibilityFlags,
|
|
117
|
-
usageModel,
|
|
118
|
-
buildCommand = {},
|
|
119
|
-
enableLocalPersistence = false,
|
|
120
|
-
env,
|
|
121
|
-
zone,
|
|
122
|
-
}: Partial<DevProps>): Promise<TestRenderer.ReactTestRenderer> {
|
|
123
|
-
let instance: TestRenderer.ReactTestRenderer | undefined;
|
|
124
|
-
await TestRenderer.act(async () => {
|
|
125
|
-
instance = TestRenderer.create(
|
|
126
|
-
<Dev
|
|
127
|
-
name={name}
|
|
128
|
-
entry={entry}
|
|
129
|
-
env={env}
|
|
130
|
-
rules={rules}
|
|
131
|
-
port={port}
|
|
132
|
-
ip={ip}
|
|
133
|
-
inspectorPort={inspectorPort}
|
|
134
|
-
legacyEnv={legacyEnv}
|
|
135
|
-
buildCommand={buildCommand}
|
|
136
|
-
initialMode={initialMode}
|
|
137
|
-
localProtocol={localProtocol}
|
|
138
|
-
upstreamProtocol={upstreamProtocol}
|
|
139
|
-
jsxFactory={jsxFactory}
|
|
140
|
-
jsxFragment={jsxFragment}
|
|
141
|
-
accountId={accountId}
|
|
142
|
-
assetPaths={assetPaths}
|
|
143
|
-
public={publicDir}
|
|
144
|
-
compatibilityDate={compatibilityDate}
|
|
145
|
-
compatibilityFlags={compatibilityFlags}
|
|
146
|
-
usageModel={usageModel}
|
|
147
|
-
bindings={bindings}
|
|
148
|
-
enableLocalPersistence={enableLocalPersistence}
|
|
149
|
-
zone={zone}
|
|
150
|
-
/>
|
|
151
|
-
);
|
|
152
|
-
});
|
|
153
|
-
return instance as TestRenderer.ReactTestRenderer;
|
|
154
|
-
}
|