wrangler 0.0.0-e178d6fb → 0.0.0-e1c2f5b9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -2
- package/bin/wrangler.js +31 -11
- package/miniflare-dist/index.mjs +1340 -330
- package/package.json +40 -13
- package/src/__tests__/access.test.ts +25 -0
- package/src/__tests__/api-dev.test.ts +238 -0
- package/src/__tests__/api-devregistry.test.js +64 -0
- package/src/__tests__/api.test.ts +80 -0
- package/src/__tests__/configuration.test.ts +683 -470
- package/src/__tests__/d1.test.ts +123 -0
- package/src/__tests__/delete.test.ts +263 -0
- package/src/__tests__/deployments.test.ts +105 -0
- package/src/__tests__/dev.test.tsx +453 -70
- package/src/__tests__/dialogs.test.tsx +40 -0
- package/src/__tests__/generate.test.ts +235 -0
- package/src/__tests__/get-host-from-url.test.ts +16 -0
- package/src/__tests__/helpers/mock-auth-domain.ts +20 -0
- package/src/__tests__/helpers/mock-cfetch.ts +92 -26
- package/src/__tests__/helpers/mock-console.ts +11 -2
- package/src/__tests__/helpers/mock-dialogs.ts +1 -1
- package/src/__tests__/helpers/mock-get-zone-from-host.ts +8 -0
- package/src/__tests__/helpers/mock-known-routes.ts +7 -0
- package/src/__tests__/helpers/mock-kv.ts +1 -1
- package/src/__tests__/helpers/mock-oauth-flow.ts +74 -53
- package/src/__tests__/helpers/mock-process.ts +8 -13
- package/src/__tests__/helpers/msw/handlers/access.ts +13 -0
- package/src/__tests__/helpers/msw/handlers/deployments.ts +59 -0
- package/src/__tests__/helpers/msw/handlers/namespaces.ts +104 -0
- package/src/__tests__/helpers/msw/handlers/oauth.ts +31 -0
- package/src/__tests__/helpers/msw/handlers/r2.ts +80 -0
- package/src/__tests__/helpers/msw/handlers/script.ts +75 -0
- package/src/__tests__/helpers/msw/handlers/user.ts +63 -0
- package/src/__tests__/helpers/msw/handlers/zones.ts +22 -0
- package/src/__tests__/helpers/msw/index.ts +21 -0
- package/src/__tests__/helpers/worker-scripts/child-wrangler.toml +1 -0
- package/src/__tests__/helpers/worker-scripts/hello-world-worker.js +5 -0
- package/src/__tests__/helpers/worker-scripts/hello-world-wrangler.toml +1 -0
- package/src/__tests__/helpers/worker-scripts/parent-worker.js +8 -0
- package/src/__tests__/helpers/worker-scripts/parent-wrangler.toml +5 -0
- package/src/__tests__/index.test.ts +103 -97
- package/src/__tests__/init.test.ts +1484 -382
- package/src/__tests__/jest.setup.ts +88 -5
- package/src/__tests__/kv.test.ts +655 -540
- package/src/__tests__/logout.test.ts +47 -0
- package/src/__tests__/metrics.test.ts +95 -45
- package/src/__tests__/middleware.scheduled.test.ts +145 -0
- package/src/__tests__/middleware.test.ts +750 -0
- package/src/__tests__/pages-deployment-tail.test.ts +884 -0
- package/src/__tests__/pages.test.ts +1301 -119
- package/src/__tests__/paths.test.ts +39 -0
- package/src/__tests__/publish.test.ts +2266 -1180
- package/src/__tests__/pubsub.test.ts +211 -88
- package/src/__tests__/queues.test.ts +522 -0
- package/src/__tests__/r2.test.ts +363 -203
- package/src/__tests__/secret.test.ts +261 -59
- package/src/__tests__/tail.test.ts +352 -151
- package/src/__tests__/test-old-node-version.js +3 -3
- package/src/__tests__/tsconfig-sanity.ts +12 -0
- package/src/__tests__/tsconfig.json +8 -0
- package/src/__tests__/tsconfig.tsbuildinfo +1 -0
- package/src/__tests__/type-generation.test.ts +233 -0
- package/src/__tests__/user.test.ts +59 -73
- package/src/__tests__/utils-collectKeyValues.test.ts +47 -0
- package/src/__tests__/validate-dev-props.test.ts +56 -0
- package/src/__tests__/whoami.test.tsx +114 -66
- package/src/__tests__/worker-namespace.test.ts +154 -155
- package/src/api/dev.ts +170 -38
- package/src/api/index.ts +1 -0
- package/src/bundle-reporter.tsx +41 -2
- package/src/bundle.ts +668 -81
- package/src/cfetch/index.ts +40 -3
- package/src/cfetch/internal.ts +144 -32
- package/src/cli.ts +4 -3
- package/src/config/config.ts +27 -3
- package/src/config/environment.ts +131 -7
- package/src/config/index.ts +128 -8
- package/src/config/validation-helpers.ts +19 -6
- package/src/config/validation.ts +411 -14
- package/src/config-cache.ts +3 -2
- package/src/create-worker-preview.ts +31 -6
- package/src/create-worker-upload-form.ts +84 -22
- package/src/d1/backups.tsx +223 -0
- package/src/d1/constants.ts +2 -0
- package/src/d1/create.tsx +63 -0
- package/src/d1/delete.tsx +56 -0
- package/src/d1/execute.tsx +352 -0
- package/src/d1/formatTimeAgo.ts +14 -0
- package/src/d1/index.ts +101 -0
- package/src/d1/list.tsx +48 -0
- package/src/d1/migrations/apply.tsx +196 -0
- package/src/d1/migrations/create.tsx +77 -0
- package/src/d1/migrations/helpers.ts +147 -0
- package/src/d1/migrations/index.tsx +3 -0
- package/src/d1/migrations/list.tsx +79 -0
- package/src/d1/migrations/options.ts +18 -0
- package/src/d1/options.ts +22 -0
- package/src/d1/types.tsx +24 -0
- package/src/d1/utils.ts +48 -0
- package/src/delete.ts +108 -0
- package/src/deployments.ts +83 -0
- package/src/deprecated/index.ts +145 -0
- package/src/dev/dev-vars.ts +11 -8
- package/src/dev/dev.tsx +220 -58
- package/src/dev/get-local-persistence-path.tsx +31 -0
- package/src/dev/local.tsx +740 -181
- package/src/dev/remote.tsx +340 -123
- package/src/dev/start-server.ts +543 -0
- package/src/dev/use-esbuild.ts +61 -7
- package/src/dev/validate-dev-props.ts +31 -0
- package/src/dev-registry.tsx +201 -0
- package/src/dev.tsx +614 -258
- package/src/dialogs.tsx +41 -8
- package/src/{worker-namespace.ts → dispatch-namespace.ts} +23 -22
- package/src/docs/index.ts +97 -0
- package/src/entry.ts +3 -2
- package/src/environment-variables/factory.ts +88 -0
- package/src/environment-variables/misc-variables.ts +30 -0
- package/src/generate/index.ts +300 -0
- package/src/git-client.ts +100 -7
- package/src/index.tsx +249 -1560
- package/src/init.ts +626 -150
- package/src/inspect.ts +137 -32
- package/src/{metrics/is-ci.ts → is-ci.ts} +0 -0
- package/src/is-interactive.ts +4 -0
- package/src/jest.d.ts +4 -0
- package/src/{kv.ts → kv/helpers.ts} +3 -3
- package/src/kv/index.ts +596 -0
- package/src/logger.ts +27 -8
- package/src/metrics/index.ts +1 -0
- package/src/metrics/metrics-config.ts +4 -4
- package/src/metrics/metrics-dispatcher.ts +1 -0
- package/src/metrics/metrics-usage-headers.ts +24 -0
- package/src/metrics/send-event.ts +13 -8
- package/src/miniflare-cli/assets.ts +172 -465
- package/src/miniflare-cli/index.ts +149 -24
- package/src/miniflare-cli/tsconfig.json +9 -0
- package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -0
- package/src/miniflare-cli/types.ts +11 -0
- package/src/module-collection.ts +12 -3
- package/src/pages/build.tsx +108 -42
- package/src/pages/constants.ts +11 -0
- package/src/pages/deployment-tails.tsx +284 -0
- package/src/pages/deployments.tsx +9 -31
- package/src/pages/dev.tsx +417 -108
- package/src/pages/errors.ts +66 -0
- package/src/pages/functions/buildPlugin.ts +86 -84
- package/src/pages/functions/buildWorker.ts +121 -106
- package/src/pages/functions/routes-consolidation.test.ts +250 -0
- package/src/pages/functions/routes-consolidation.ts +73 -0
- package/src/pages/functions/routes-transformation.test.ts +282 -0
- package/src/pages/functions/routes-transformation.ts +115 -0
- package/src/pages/functions/routes-validation.test.ts +403 -0
- package/src/pages/functions/routes-validation.ts +202 -0
- package/src/pages/functions/tsconfig.json +8 -0
- package/src/pages/functions/tsconfig.tsbuildinfo +1 -0
- package/src/pages/functions.tsx +82 -0
- package/src/pages/hash.tsx +13 -0
- package/src/pages/index.tsx +73 -55
- package/src/pages/projects.tsx +9 -3
- package/src/pages/prompt-select-project.tsx +31 -0
- package/src/pages/publish.tsx +183 -60
- package/src/pages/types.ts +1 -0
- package/src/pages/upload.tsx +107 -56
- package/src/pages/utils.ts +13 -2
- package/src/paths.ts +49 -4
- package/src/proxy.ts +375 -157
- package/src/publish/index.ts +270 -0
- package/src/{publish.ts → publish/publish.ts} +431 -188
- package/src/pubsub/pubsub-commands.tsx +4 -3
- package/src/queues/cli/commands/consumer/add.ts +71 -0
- package/src/queues/cli/commands/consumer/index.ts +22 -0
- package/src/queues/cli/commands/consumer/remove.ts +38 -0
- package/src/queues/cli/commands/create.ts +25 -0
- package/src/queues/cli/commands/delete.ts +26 -0
- package/src/queues/cli/commands/index.ts +36 -0
- package/src/queues/cli/commands/list.ts +25 -0
- package/src/queues/client.ts +135 -0
- package/src/queues/utils.ts +18 -0
- package/src/r2/constants.ts +4 -0
- package/src/r2/helpers.ts +131 -0
- package/src/r2/index.ts +289 -0
- package/src/routes.ts +140 -0
- package/src/secret/index.ts +379 -0
- package/src/sites.tsx +3 -3
- package/src/tail/createTail.ts +379 -0
- package/src/tail/filters.ts +4 -6
- package/src/tail/index.ts +199 -284
- package/src/tail/printing.ts +43 -3
- package/src/tsconfig-sanity.ts +16 -0
- package/src/type-generation.ts +181 -0
- package/src/user/access.ts +68 -0
- package/src/user/auth-variables.ts +113 -0
- package/src/user/choose-account.tsx +1 -1
- package/src/user/index.ts +0 -1
- package/src/user/user.tsx +116 -49
- package/src/utils/collectKeyValues.ts +14 -0
- package/src/whoami.tsx +80 -2
- package/src/worker.ts +69 -9
- package/src/yargs-types.ts +24 -0
- package/src/zones.ts +124 -9
- 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/__tests__/tsconfig.tsbuildinfo +1 -0
- package/templates/d1-beta-facade.js +205 -0
- package/templates/facade.d.ts +14 -0
- package/templates/first-party-worker-module-facade.ts +19 -0
- package/templates/format-dev-errors.ts +33 -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 +62 -0
- package/templates/middleware/loader-modules.ts +82 -0
- package/templates/middleware/loader-sw.ts +233 -0
- package/templates/middleware/middleware-miniflare3-json-error.ts +20 -0
- package/templates/middleware/middleware-pretty-error.ts +40 -0
- package/templates/middleware/middleware-scheduled.ts +15 -0
- package/templates/new-worker.js +1 -1
- package/templates/pages-dev-pipeline.ts +31 -0
- package/templates/pages-dev-util.ts +52 -0
- package/templates/pages-shim.ts +4 -1
- package/templates/pages-template-plugin.ts +21 -5
- package/templates/pages-template-worker.ts +37 -9
- package/templates/{static-asset-facade.js → serve-static-assets.ts} +23 -7
- package/templates/service-bindings-module-facade.js +54 -0
- package/templates/service-bindings-sw-facade.js +42 -0
- package/templates/tsconfig-sanity.ts +11 -0
- package/templates/tsconfig.init.json +106 -0
- package/templates/tsconfig.json +5 -102
- package/templates/tsconfig.tsbuildinfo +1 -0
- package/wrangler-dist/cli.d.ts +621 -42
- package/wrangler-dist/cli.js +144441 -102606
- package/src/environment-variables.ts +0 -35
- package/src/faye-websocket.d.ts +0 -6
- package/src/generate.ts +0 -33
- package/src/miniflare-cli/enum-keys.ts +0 -17
- package/src/preview.ts +0 -31
- package/src/r2.ts +0 -50
- package/src/user/env-vars.ts +0 -46
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wrangler",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-e1c2f5b9",
|
|
4
4
|
"description": "Command-line interface for all things Cloudflare Workers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"wrangler",
|
|
@@ -28,6 +28,11 @@
|
|
|
28
28
|
"bugs": {
|
|
29
29
|
"url": "https://github.com/cloudflare/wrangler2/issues"
|
|
30
30
|
},
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "https://github.com/cloudflare/wrangler2.git",
|
|
34
|
+
"directory": "packages/wrangler"
|
|
35
|
+
},
|
|
31
36
|
"license": "MIT OR Apache-2.0",
|
|
32
37
|
"author": "wrangler@cloudflare.com",
|
|
33
38
|
"main": "wrangler-dist/cli.js",
|
|
@@ -49,19 +54,20 @@
|
|
|
49
54
|
"Cloudflare_CA.pem"
|
|
50
55
|
],
|
|
51
56
|
"scripts": {
|
|
57
|
+
"assert-git-version": "node -r esbuild-register scripts/assert-git-version.ts",
|
|
52
58
|
"build": "npm run clean && npm run bundle && npm run emit-types",
|
|
53
59
|
"bundle": "node -r esbuild-register scripts/bundle.ts",
|
|
54
|
-
"check:type": "tsc",
|
|
55
|
-
"clean": "
|
|
60
|
+
"check:type": "node -r esbuild-register scripts/tsc-all.ts",
|
|
61
|
+
"clean": "rimraf wrangler-dist miniflare-dist emitted-types",
|
|
56
62
|
"dev": "npm run clean && concurrently -c black,blue --kill-others-on-fail false 'npm run bundle -- --watch' 'npm run check:type -- --watch --preserveWatchOutput'",
|
|
57
63
|
"emit-types": "tsc -p tsconfig.emit.json && node -r esbuild-register scripts/emit-types.ts",
|
|
58
64
|
"prepublishOnly": "SOURCEMAPS=false npm run build",
|
|
59
|
-
"start": "npm run bundle && NODE_OPTIONS=--enable-source-maps ./bin/wrangler.js",
|
|
60
|
-
"test": "jest --silent=false --verbose=true",
|
|
61
|
-
"test-watch": "npm run test -- --runInBand --testTimeout=50000 --watch"
|
|
65
|
+
"start": "npm run bundle && cross-env NODE_OPTIONS=--enable-source-maps ./bin/wrangler.js",
|
|
66
|
+
"test": "npm run assert-git-version && jest --silent=false --verbose=true",
|
|
67
|
+
"test-watch": "npm run test -- --runInBand --testTimeout=50000 --watch",
|
|
68
|
+
"test:ci": "npm run test -- --verbose=true --coverage"
|
|
62
69
|
},
|
|
63
70
|
"jest": {
|
|
64
|
-
"collectCoverage": true,
|
|
65
71
|
"coverageReporters": [
|
|
66
72
|
"json",
|
|
67
73
|
"html",
|
|
@@ -87,27 +93,40 @@
|
|
|
87
93
|
]
|
|
88
94
|
},
|
|
89
95
|
"transformIgnorePatterns": [
|
|
90
|
-
"node_modules/(?!find-up|locate-path|p-locate|p-limit|p-timeout|p-queue|yocto-queue|path-exists|execa|strip-final-newline|npm-run-path|path-key|onetime|mimic-fn|human-signals|is-stream|get-port|supports-color|pretty-bytes)"
|
|
96
|
+
"node_modules/(?!find-up|locate-path|p-locate|p-limit|p-timeout|p-queue|yocto-queue|path-exists|execa|strip-final-newline|npm-run-path|path-key|onetime|mimic-fn|human-signals|is-stream|get-port|supports-color|pretty-bytes|npx-import)"
|
|
91
97
|
]
|
|
92
98
|
},
|
|
93
99
|
"dependencies": {
|
|
94
100
|
"@cloudflare/kv-asset-handler": "^0.2.0",
|
|
95
101
|
"@esbuild-plugins/node-globals-polyfill": "^0.1.1",
|
|
96
102
|
"@esbuild-plugins/node-modules-polyfill": "^0.1.4",
|
|
103
|
+
"@miniflare/core": "2.10.0",
|
|
104
|
+
"@miniflare/d1": "2.10.0",
|
|
105
|
+
"@miniflare/durable-objects": "2.10.0",
|
|
97
106
|
"blake3-wasm": "^2.1.5",
|
|
98
107
|
"chokidar": "^3.5.3",
|
|
99
|
-
"esbuild": "0.14.
|
|
100
|
-
"miniflare": "
|
|
108
|
+
"esbuild": "0.14.51",
|
|
109
|
+
"miniflare": "2.10.0",
|
|
101
110
|
"nanoid": "^3.3.3",
|
|
102
111
|
"path-to-regexp": "^6.2.0",
|
|
103
112
|
"selfsigned": "^2.0.1",
|
|
113
|
+
"source-map": "^0.7.4",
|
|
104
114
|
"xxhash-wasm": "^1.0.1"
|
|
105
115
|
},
|
|
106
116
|
"devDependencies": {
|
|
117
|
+
"@cloudflare/types": "^6.18.4",
|
|
118
|
+
"@cloudflare/workers-types": "^4.20221111.1",
|
|
119
|
+
"@databases/split-sql-query": "^1.0.3",
|
|
120
|
+
"@databases/sql": "^3.2.0",
|
|
107
121
|
"@iarna/toml": "^3.0.0",
|
|
108
122
|
"@microsoft/api-extractor": "^7.28.3",
|
|
123
|
+
"@miniflare/tre": "^3.0.0-next.8",
|
|
124
|
+
"@types/better-sqlite3": "^7.6.0",
|
|
125
|
+
"@types/busboy": "^1.5.0",
|
|
109
126
|
"@types/command-exists": "^1.2.0",
|
|
127
|
+
"@types/express": "^4.17.13",
|
|
110
128
|
"@types/glob-to-regexp": "0.4.1",
|
|
129
|
+
"@types/javascript-time-ago": "^2.0.3",
|
|
111
130
|
"@types/mime": "^2.0.3",
|
|
112
131
|
"@types/prompts": "^2.0.14",
|
|
113
132
|
"@types/react": "^17.0.37",
|
|
@@ -117,6 +136,8 @@
|
|
|
117
136
|
"@types/ws": "^8.5.3",
|
|
118
137
|
"@types/yargs": "^17.0.10",
|
|
119
138
|
"@webcontainer/env": "^1.0.1",
|
|
139
|
+
"body-parser": "^1.20.0",
|
|
140
|
+
"chalk": "^2.4.2",
|
|
120
141
|
"clipboardy": "^3.0.0",
|
|
121
142
|
"cmd-shim": "^4.1.0",
|
|
122
143
|
"command-exists": "^1.2.9",
|
|
@@ -124,7 +145,7 @@
|
|
|
124
145
|
"devtools-protocol": "^0.0.955664",
|
|
125
146
|
"dotenv": "^16.0.0",
|
|
126
147
|
"execa": "^6.1.0",
|
|
127
|
-
"
|
|
148
|
+
"express": "^4.18.1",
|
|
128
149
|
"finalhandler": "^1.2.0",
|
|
129
150
|
"find-up": "^6.3.0",
|
|
130
151
|
"get-port": "^6.1.2",
|
|
@@ -138,22 +159,28 @@
|
|
|
138
159
|
"ink-testing-library": "^2.1.0",
|
|
139
160
|
"ink-text-input": "^4.0.3",
|
|
140
161
|
"is-ci": "^3.0.1",
|
|
162
|
+
"javascript-time-ago": "^2.5.4",
|
|
141
163
|
"jest-fetch-mock": "^3.0.3",
|
|
142
164
|
"jest-websocket-mock": "^2.3.0",
|
|
143
165
|
"mime": "^3.0.0",
|
|
166
|
+
"minimatch": "^5.1.0",
|
|
167
|
+
"msw": "^0.49.1",
|
|
168
|
+
"npx-import": "^1.1.3",
|
|
144
169
|
"open": "^8.4.0",
|
|
145
170
|
"p-queue": "^7.2.0",
|
|
146
171
|
"pretty-bytes": "^6.0.0",
|
|
147
172
|
"prompts": "^2.4.2",
|
|
148
173
|
"react": "^17.0.2",
|
|
149
174
|
"react-error-boundary": "^3.1.4",
|
|
175
|
+
"remove-accents-esm": "^0.0.1",
|
|
176
|
+
"semiver": "^1.1.0",
|
|
150
177
|
"serve-static": "^1.15.0",
|
|
151
178
|
"signal-exit": "^3.0.7",
|
|
152
179
|
"supports-color": "^9.2.2",
|
|
153
180
|
"timeago.js": "^4.0.2",
|
|
154
181
|
"tmp-promise": "^3.0.3",
|
|
155
182
|
"ts-dedent": "^2.2.0",
|
|
156
|
-
"undici": "^5.
|
|
183
|
+
"undici": "^5.11.0",
|
|
157
184
|
"update-check": "^1.5.4",
|
|
158
185
|
"ws": "^8.5.0",
|
|
159
186
|
"xdg-app-paths": "^7.3.0",
|
|
@@ -163,6 +190,6 @@
|
|
|
163
190
|
"fsevents": "~2.3.2"
|
|
164
191
|
},
|
|
165
192
|
"engines": {
|
|
166
|
-
"node": ">=16.
|
|
193
|
+
"node": ">=16.13.0"
|
|
167
194
|
}
|
|
168
195
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { domainUsesAccess, getAccessToken } from "../user/access";
|
|
2
|
+
import { msw, mswAccessHandlers } from "./helpers/msw";
|
|
3
|
+
|
|
4
|
+
describe("access", () => {
|
|
5
|
+
beforeEach(() => {
|
|
6
|
+
msw.use(...mswAccessHandlers);
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
describe("basic", () => {
|
|
10
|
+
it("should correctly detect an access protected domain", async () => {
|
|
11
|
+
expect(await domainUsesAccess("access-protected.com")).toBeTruthy();
|
|
12
|
+
expect(await domainUsesAccess("not-access-protected.com")).toBeFalsy();
|
|
13
|
+
});
|
|
14
|
+
it("should not fail without cloudflared installed", async () => {
|
|
15
|
+
expect(await getAccessToken("not-access-protected.com")).toBeFalsy();
|
|
16
|
+
});
|
|
17
|
+
it("should error without cloudflared installed on an access protected domain", async () => {
|
|
18
|
+
await expect(getAccessToken("access-protected.com")).rejects.toEqual(
|
|
19
|
+
new Error(
|
|
20
|
+
"To use Wrangler with Cloudflare Access, please install `cloudflared` from https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/install-and-setup/installation"
|
|
21
|
+
)
|
|
22
|
+
);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import { Request } from "undici";
|
|
3
|
+
import { unstable_dev } from "../api";
|
|
4
|
+
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
5
|
+
|
|
6
|
+
jest.unmock("undici");
|
|
7
|
+
|
|
8
|
+
describe("unstable_dev", () => {
|
|
9
|
+
it("should return Hello World", async () => {
|
|
10
|
+
const worker = await unstable_dev(
|
|
11
|
+
"src/__tests__/helpers/worker-scripts/hello-world-worker.js",
|
|
12
|
+
{
|
|
13
|
+
experimental: {
|
|
14
|
+
disableExperimentalWarning: true,
|
|
15
|
+
disableDevRegistry: true,
|
|
16
|
+
},
|
|
17
|
+
}
|
|
18
|
+
);
|
|
19
|
+
const resp = await worker.fetch();
|
|
20
|
+
if (resp) {
|
|
21
|
+
const text = await resp.text();
|
|
22
|
+
expect(text).toMatchInlineSnapshot(`"Hello World!"`);
|
|
23
|
+
}
|
|
24
|
+
await worker.stop();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("should return the port that the server started on (1)", async () => {
|
|
28
|
+
const worker = await unstable_dev(
|
|
29
|
+
"src/__tests__/helpers/worker-scripts/hello-world-worker.js",
|
|
30
|
+
{
|
|
31
|
+
experimental: {
|
|
32
|
+
disableExperimentalWarning: true,
|
|
33
|
+
disableDevRegistry: true,
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
);
|
|
37
|
+
expect(worker.port).toBeGreaterThan(0);
|
|
38
|
+
await worker.stop();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("should return the port that the server started on (2)", async () => {
|
|
42
|
+
const worker = await unstable_dev(
|
|
43
|
+
"src/__tests__/helpers/worker-scripts/hello-world-worker.js",
|
|
44
|
+
{
|
|
45
|
+
port: 9191,
|
|
46
|
+
experimental: {
|
|
47
|
+
disableExperimentalWarning: true,
|
|
48
|
+
disableDevRegistry: true,
|
|
49
|
+
},
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
expect(worker.port).toBe(9191);
|
|
53
|
+
await worker.stop();
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe("unstable dev fetch input protocol", () => {
|
|
58
|
+
it("should use http localProtocol", async () => {
|
|
59
|
+
const worker = await unstable_dev(
|
|
60
|
+
"src/__tests__/helpers/worker-scripts/hello-world-worker.js",
|
|
61
|
+
{
|
|
62
|
+
localProtocol: "http",
|
|
63
|
+
experimental: {
|
|
64
|
+
disableExperimentalWarning: true,
|
|
65
|
+
disableDevRegistry: true,
|
|
66
|
+
},
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
const res = await worker.fetch();
|
|
70
|
+
if (res) {
|
|
71
|
+
const text = await res.text();
|
|
72
|
+
expect(text).toMatchInlineSnapshot(`"Hello World!"`);
|
|
73
|
+
}
|
|
74
|
+
await worker.stop();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("should use undefined localProtocol", async () => {
|
|
78
|
+
const worker = await unstable_dev(
|
|
79
|
+
"src/__tests__/helpers/worker-scripts/hello-world-worker.js",
|
|
80
|
+
{
|
|
81
|
+
localProtocol: undefined,
|
|
82
|
+
experimental: {
|
|
83
|
+
disableExperimentalWarning: true,
|
|
84
|
+
disableDevRegistry: true,
|
|
85
|
+
},
|
|
86
|
+
}
|
|
87
|
+
);
|
|
88
|
+
const res = await worker.fetch();
|
|
89
|
+
if (res) {
|
|
90
|
+
const text = await res.text();
|
|
91
|
+
expect(text).toMatchInlineSnapshot(`"Hello World!"`);
|
|
92
|
+
}
|
|
93
|
+
await worker.stop();
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
describe("unstable dev fetch input parsing", () => {
|
|
98
|
+
runInTempDir();
|
|
99
|
+
|
|
100
|
+
it("should pass in a request object unchanged", async () => {
|
|
101
|
+
const scriptContent = `
|
|
102
|
+
export default {
|
|
103
|
+
fetch(request, env, ctx) {
|
|
104
|
+
const url = new URL(request.url);
|
|
105
|
+
if (url.pathname === "/test") {
|
|
106
|
+
if (request.method === "POST") {
|
|
107
|
+
return new Response("requestPOST");
|
|
108
|
+
}
|
|
109
|
+
return new Response("requestGET");
|
|
110
|
+
}
|
|
111
|
+
return new Response('Hello world');
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
`;
|
|
115
|
+
fs.writeFileSync("index.js", scriptContent);
|
|
116
|
+
const port = 21213;
|
|
117
|
+
const worker = await unstable_dev("index.js", {
|
|
118
|
+
port,
|
|
119
|
+
experimental: {
|
|
120
|
+
disableExperimentalWarning: true,
|
|
121
|
+
disableDevRegistry: true,
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
const req = new Request("http://0.0.0.0:21213/test", {
|
|
125
|
+
method: "POST",
|
|
126
|
+
});
|
|
127
|
+
const resp = await worker.fetch(req);
|
|
128
|
+
let text;
|
|
129
|
+
if (resp) text = await resp.text();
|
|
130
|
+
expect(text).toMatchInlineSnapshot(`"requestPOST"`);
|
|
131
|
+
await worker.stop();
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("should strip back to pathname for URL objects", async () => {
|
|
135
|
+
const scriptContent = `
|
|
136
|
+
export default {
|
|
137
|
+
fetch(request, env, ctx) {
|
|
138
|
+
const url = new URL(request.url);
|
|
139
|
+
if (url.pathname === "/test") {
|
|
140
|
+
return new Response("request");
|
|
141
|
+
}
|
|
142
|
+
return new Response('Hello world');
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
`;
|
|
146
|
+
fs.writeFileSync("index.js", scriptContent);
|
|
147
|
+
const worker = await unstable_dev("index.js", {
|
|
148
|
+
experimental: {
|
|
149
|
+
disableExperimentalWarning: true,
|
|
150
|
+
disableDevRegistry: true,
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
const url = new URL("http://localhost:80/test");
|
|
154
|
+
const resp = await worker.fetch(url);
|
|
155
|
+
let text;
|
|
156
|
+
if (resp) text = await resp.text();
|
|
157
|
+
expect(text).toMatchInlineSnapshot(`"request"`);
|
|
158
|
+
await worker.stop();
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("should allow full url passed in string, and stripped back to pathname", async () => {
|
|
162
|
+
const scriptContent = `
|
|
163
|
+
export default {
|
|
164
|
+
fetch(request, env, ctx) {
|
|
165
|
+
const url = new URL(request.url);
|
|
166
|
+
if (url.pathname === "/test") {
|
|
167
|
+
return new Response("request");
|
|
168
|
+
}
|
|
169
|
+
return new Response('Hello world');
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
`;
|
|
173
|
+
fs.writeFileSync("index.js", scriptContent);
|
|
174
|
+
const worker = await unstable_dev("index.js", {
|
|
175
|
+
experimental: {
|
|
176
|
+
disableExperimentalWarning: true,
|
|
177
|
+
disableDevRegistry: true,
|
|
178
|
+
},
|
|
179
|
+
});
|
|
180
|
+
const resp = await worker.fetch("http://example.com/test");
|
|
181
|
+
let text;
|
|
182
|
+
if (resp) text = await resp.text();
|
|
183
|
+
expect(text).toMatchInlineSnapshot(`"request"`);
|
|
184
|
+
await worker.stop();
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it("should allow pathname to be passed in", async () => {
|
|
188
|
+
const scriptContent = `
|
|
189
|
+
export default {
|
|
190
|
+
fetch(request, env, ctx) {
|
|
191
|
+
const url = new URL(request.url);
|
|
192
|
+
if (url.pathname === "/test") {
|
|
193
|
+
return new Response("request");
|
|
194
|
+
}
|
|
195
|
+
return new Response('Hello world');
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
`;
|
|
199
|
+
fs.writeFileSync("index.js", scriptContent);
|
|
200
|
+
const worker = await unstable_dev("index.js", {
|
|
201
|
+
experimental: {
|
|
202
|
+
disableExperimentalWarning: true,
|
|
203
|
+
disableDevRegistry: true,
|
|
204
|
+
},
|
|
205
|
+
});
|
|
206
|
+
const resp = await worker.fetch("/test");
|
|
207
|
+
let text;
|
|
208
|
+
if (resp) text = await resp.text();
|
|
209
|
+
expect(text).toMatchInlineSnapshot(`"request"`);
|
|
210
|
+
await worker.stop();
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it("should allow no input be passed in", async () => {
|
|
214
|
+
const scriptContent = `
|
|
215
|
+
export default {
|
|
216
|
+
fetch(request, env, ctx) {
|
|
217
|
+
const url = new URL(request.url);
|
|
218
|
+
if (url.pathname === "/test") {
|
|
219
|
+
return new Response("request");
|
|
220
|
+
}
|
|
221
|
+
return new Response('Hello world');
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
`;
|
|
225
|
+
fs.writeFileSync("index.js", scriptContent);
|
|
226
|
+
const worker = await unstable_dev("index.js", {
|
|
227
|
+
experimental: {
|
|
228
|
+
disableExperimentalWarning: true,
|
|
229
|
+
disableDevRegistry: true,
|
|
230
|
+
},
|
|
231
|
+
});
|
|
232
|
+
const resp = await worker.fetch("");
|
|
233
|
+
let text;
|
|
234
|
+
if (resp) text = await resp.text();
|
|
235
|
+
expect(text).toMatchInlineSnapshot(`"Hello world"`);
|
|
236
|
+
await worker.stop();
|
|
237
|
+
});
|
|
238
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { unstable_dev } from "../api";
|
|
2
|
+
import { fetch } from "undici";
|
|
3
|
+
|
|
4
|
+
jest.unmock("undici");
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* a huge caveat to how testing multi-worker scripts works:
|
|
8
|
+
* you can't shutdown the first worker you spun up, or it'll kill the devRegistry
|
|
9
|
+
*/
|
|
10
|
+
describe("multi-worker testing", () => {
|
|
11
|
+
let childWorker;
|
|
12
|
+
let parentWorker;
|
|
13
|
+
|
|
14
|
+
beforeAll(async () => {
|
|
15
|
+
childWorker = await unstable_dev(
|
|
16
|
+
"src/__tests__/helpers/worker-scripts/hello-world-worker.js",
|
|
17
|
+
{
|
|
18
|
+
config: "src/__tests__/helpers/worker-scripts/child-wrangler.toml",
|
|
19
|
+
experimental: {
|
|
20
|
+
disableExperimentalWarning: true,
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
);
|
|
24
|
+
parentWorker = await unstable_dev(
|
|
25
|
+
"src/__tests__/helpers/worker-scripts/parent-worker.js",
|
|
26
|
+
{
|
|
27
|
+
config: "src/__tests__/helpers/worker-scripts/parent-wrangler.toml",
|
|
28
|
+
experimental: {
|
|
29
|
+
disableExperimentalWarning: true,
|
|
30
|
+
},
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
afterAll(async () => {
|
|
36
|
+
await childWorker.stop();
|
|
37
|
+
await parentWorker.stop();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("parentWorker and childWorker should be added devRegistry", async () => {
|
|
41
|
+
const resp = await fetch("http://localhost:6284/workers");
|
|
42
|
+
if (resp) {
|
|
43
|
+
const parsedResp = await resp.json();
|
|
44
|
+
expect(parsedResp.parent).toBeTruthy();
|
|
45
|
+
expect(parsedResp.child).toBeTruthy();
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("childWorker should return Hello World itself", async () => {
|
|
50
|
+
const resp = await childWorker.fetch();
|
|
51
|
+
if (resp) {
|
|
52
|
+
const text = await resp.text();
|
|
53
|
+
expect(text).toMatchInlineSnapshot(`"Hello World!"`);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("parentWorker should return Hello World by invoking the child worker", async () => {
|
|
58
|
+
const resp = await parentWorker.fetch();
|
|
59
|
+
if (resp) {
|
|
60
|
+
const parsedResp = await resp.text();
|
|
61
|
+
expect(parsedResp).toEqual("Parent worker sees: Hello World!");
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Request } from "undici";
|
|
2
|
+
import { parseRequestInput } from "../api/dev";
|
|
3
|
+
|
|
4
|
+
describe("parseRequestInput for fetch on unstable dev", () => {
|
|
5
|
+
it("should allow no input to be passed in", () => {
|
|
6
|
+
const [input, _] = parseRequestInput("0.0.0.0", 8080);
|
|
7
|
+
|
|
8
|
+
expect(input).toMatchInlineSnapshot(`"http://0.0.0.0:8080"`);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it("should allow string of pathname to be passed in", () => {
|
|
12
|
+
const [input, _] = parseRequestInput("0.0.0.0", 8080, "/test");
|
|
13
|
+
|
|
14
|
+
expect(input).toMatchInlineSnapshot(`"http://0.0.0.0:8080/test"`);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("should allow full url to be passed in as string and stripped", () => {
|
|
18
|
+
const [input, _] = parseRequestInput(
|
|
19
|
+
"0.0.0.0",
|
|
20
|
+
8080,
|
|
21
|
+
"http://cloudflare.com/test"
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
expect(input).toMatchInlineSnapshot(`"http://0.0.0.0:8080/test"`);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("should allow URL object without pathname to be passed in and stripped", () => {
|
|
28
|
+
const [input, _] = parseRequestInput(
|
|
29
|
+
"0.0.0.0",
|
|
30
|
+
8080,
|
|
31
|
+
new URL("http://cloudflare.com")
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
expect(input).toMatchInlineSnapshot(`"http://0.0.0.0:8080/"`);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("should allow URL object with pathname to be passed in and stripped", () => {
|
|
38
|
+
const [input, _] = parseRequestInput(
|
|
39
|
+
"0.0.0.0",
|
|
40
|
+
8080,
|
|
41
|
+
new URL("http://cloudflare.com/test")
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
expect(input).toMatchInlineSnapshot(`"http://0.0.0.0:8080/test"`);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("should allow request object to be passed in", () => {
|
|
48
|
+
const [input, init] = parseRequestInput(
|
|
49
|
+
"0.0.0.0",
|
|
50
|
+
8080,
|
|
51
|
+
new Request("http://cloudflare.com/test", { method: "POST" })
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
expect(init).toBeUndefined();
|
|
55
|
+
expect(input).toBeInstanceOf(Request);
|
|
56
|
+
// We don't expect the request to be modified
|
|
57
|
+
expect((input as Request).url).toMatchInlineSnapshot(
|
|
58
|
+
`"http://cloudflare.com/test"`
|
|
59
|
+
);
|
|
60
|
+
expect((input as Request).method).toMatchInlineSnapshot(`"POST"`);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("should parse to give https url with localProtocol = https", () => {
|
|
64
|
+
const [input, _] = parseRequestInput("0.0.0.0", 8080, "/test", {}, "https");
|
|
65
|
+
|
|
66
|
+
expect(input).toMatchInlineSnapshot(`"https://0.0.0.0:8080/test"`);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("should parse to give http url with localProtocol = http", () => {
|
|
70
|
+
const [input, _] = parseRequestInput("0.0.0.0", 8080, "/test", {}, "http");
|
|
71
|
+
|
|
72
|
+
expect(input).toMatchInlineSnapshot(`"http://0.0.0.0:8080/test"`);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("should parse to give http url with localProtocol not set", () => {
|
|
76
|
+
const [input, _] = parseRequestInput("0.0.0.0", 8080, "/test", {});
|
|
77
|
+
|
|
78
|
+
expect(input).toMatchInlineSnapshot(`"http://0.0.0.0:8080/test"`);
|
|
79
|
+
});
|
|
80
|
+
});
|