wrangler 0.0.0-e3e3243 → 0.0.0-e4047cab

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.
Files changed (310) hide show
  1. package/Cloudflare_CA.pem +18 -0
  2. package/README.md +47 -14
  3. package/bin/wrangler.js +166 -31
  4. package/kv-asset-handler.js +1 -0
  5. package/miniflare-dist/index.mjs +6263 -21
  6. package/package.json +191 -141
  7. package/src/__tests__/access.test.ts +25 -0
  8. package/src/__tests__/api-dev.test.ts +209 -0
  9. package/src/__tests__/api-devregistry.test.js +56 -0
  10. package/src/__tests__/api.test.ts +80 -0
  11. package/src/__tests__/config-cache-without-cache-dir.test.ts +38 -0
  12. package/src/__tests__/config-cache.test.ts +42 -0
  13. package/src/__tests__/configuration.test.ts +3971 -2810
  14. package/src/__tests__/d1.test.ts +80 -0
  15. package/src/__tests__/delete.test.ts +263 -0
  16. package/src/__tests__/deployments.test.ts +91 -0
  17. package/src/__tests__/dev.test.tsx +1521 -526
  18. package/src/__tests__/dialogs.test.tsx +40 -0
  19. package/src/__tests__/generate.test.ts +235 -0
  20. package/src/__tests__/get-host-from-url.test.ts +16 -0
  21. package/src/__tests__/guess-worker-format.test.ts +74 -57
  22. package/src/__tests__/helpers/cmd-shim.d.ts +6 -6
  23. package/src/__tests__/helpers/mock-account-id.ts +24 -24
  24. package/src/__tests__/helpers/mock-bin.ts +20 -20
  25. package/src/__tests__/helpers/mock-cfetch.ts +219 -93
  26. package/src/__tests__/helpers/mock-console.ts +68 -32
  27. package/src/__tests__/helpers/mock-dialogs.ts +121 -33
  28. package/src/__tests__/helpers/mock-get-zone-from-host.ts +8 -0
  29. package/src/__tests__/helpers/mock-http-server.ts +46 -0
  30. package/src/__tests__/helpers/mock-istty.ts +74 -0
  31. package/src/__tests__/helpers/mock-known-routes.ts +7 -0
  32. package/src/__tests__/helpers/mock-kv.ts +27 -27
  33. package/src/__tests__/helpers/mock-oauth-flow.ts +256 -0
  34. package/src/__tests__/helpers/mock-process.ts +39 -0
  35. package/src/__tests__/helpers/mock-stdin.ts +82 -77
  36. package/src/__tests__/helpers/mock-web-socket.ts +21 -21
  37. package/src/__tests__/helpers/msw/handlers/access.ts +13 -0
  38. package/src/__tests__/helpers/msw/handlers/deployments.ts +59 -0
  39. package/src/__tests__/helpers/msw/handlers/namespaces.ts +104 -0
  40. package/src/__tests__/helpers/msw/handlers/oauth.ts +31 -0
  41. package/src/__tests__/helpers/msw/handlers/r2.ts +80 -0
  42. package/src/__tests__/helpers/msw/handlers/script.ts +75 -0
  43. package/src/__tests__/helpers/msw/handlers/user.ts +63 -0
  44. package/src/__tests__/helpers/msw/handlers/zones.ts +22 -0
  45. package/src/__tests__/helpers/msw/index.ts +21 -0
  46. package/src/__tests__/helpers/run-in-tmp.ts +28 -22
  47. package/src/__tests__/helpers/run-wrangler.ts +8 -8
  48. package/src/__tests__/helpers/worker-scripts/child-wrangler.toml +1 -0
  49. package/src/__tests__/helpers/worker-scripts/hello-world-worker.js +5 -0
  50. package/src/__tests__/helpers/worker-scripts/hello-world-wrangler.toml +1 -0
  51. package/src/__tests__/helpers/worker-scripts/parent-worker.js +8 -0
  52. package/src/__tests__/helpers/worker-scripts/parent-wrangler.toml +5 -0
  53. package/src/__tests__/helpers/write-worker-source.ts +31 -0
  54. package/src/__tests__/helpers/write-wrangler-toml.ts +9 -9
  55. package/src/__tests__/https-options.test.ts +144 -108
  56. package/src/__tests__/index.test.ts +248 -967
  57. package/src/__tests__/init.test.ts +2900 -0
  58. package/src/__tests__/jest.setup.ts +167 -34
  59. package/src/__tests__/kv.test.ts +1661 -1366
  60. package/src/__tests__/logger.test.ts +141 -0
  61. package/src/__tests__/logout.test.ts +36 -41
  62. package/src/__tests__/metrics.test.ts +450 -0
  63. package/src/__tests__/middleware.scheduled.test.ts +135 -0
  64. package/src/__tests__/middleware.test.ts +726 -0
  65. package/src/__tests__/package-manager.test.ts +312 -165
  66. package/src/__tests__/pages-deployment-tail.test.ts +820 -0
  67. package/src/__tests__/pages.test.ts +2437 -77
  68. package/src/__tests__/parse.test.ts +253 -245
  69. package/src/__tests__/paths.test.ts +39 -0
  70. package/src/__tests__/publish.test.ts +7569 -3445
  71. package/src/__tests__/pubsub.test.ts +370 -0
  72. package/src/__tests__/queues.test.ts +522 -0
  73. package/src/__tests__/r2.test.ts +388 -193
  74. package/src/__tests__/route.test.ts +22 -22
  75. package/src/__tests__/secret.test.ts +626 -407
  76. package/src/__tests__/tail.test.ts +779 -442
  77. package/src/__tests__/test-old-node-version.js +31 -0
  78. package/src/__tests__/type-generation.test.ts +226 -0
  79. package/src/__tests__/user.test.ts +129 -0
  80. package/src/__tests__/utils-collectKeyValues.test.ts +47 -0
  81. package/src/__tests__/validate-dev-props.test.ts +56 -0
  82. package/src/__tests__/version.test.ts +35 -0
  83. package/src/__tests__/whoami.test.tsx +266 -88
  84. package/src/__tests__/worker-namespace.test.ts +326 -0
  85. package/src/abort.d.ts +3 -0
  86. package/src/api/dev.ts +210 -0
  87. package/src/api/index.ts +2 -0
  88. package/src/bundle-reporter.tsx +68 -0
  89. package/src/bundle.ts +791 -123
  90. package/src/cfetch/index.ts +123 -67
  91. package/src/cfetch/internal.ts +216 -92
  92. package/src/cli.ts +23 -14
  93. package/src/config/README.md +1 -1
  94. package/src/config/config.ts +236 -179
  95. package/src/config/diagnostics.ts +61 -61
  96. package/src/config/environment.ts +506 -316
  97. package/src/config/index.ts +310 -38
  98. package/src/config/validation-helpers.ts +385 -342
  99. package/src/config/validation.ts +1970 -1099
  100. package/src/config-cache.ts +85 -0
  101. package/src/create-worker-preview.ts +240 -124
  102. package/src/create-worker-upload-form.ts +300 -201
  103. package/src/d1/backups.tsx +223 -0
  104. package/src/d1/constants.ts +2 -0
  105. package/src/d1/create.tsx +63 -0
  106. package/src/d1/delete.tsx +56 -0
  107. package/src/d1/execute.tsx +352 -0
  108. package/src/d1/formatTimeAgo.ts +14 -0
  109. package/src/d1/index.ts +101 -0
  110. package/src/d1/list.tsx +48 -0
  111. package/src/d1/migrations/apply.tsx +184 -0
  112. package/src/d1/migrations/create.tsx +77 -0
  113. package/src/d1/migrations/helpers.ts +147 -0
  114. package/src/d1/migrations/index.tsx +3 -0
  115. package/src/d1/migrations/list.tsx +79 -0
  116. package/src/d1/migrations/options.ts +18 -0
  117. package/src/d1/options.ts +22 -0
  118. package/src/d1/types.tsx +24 -0
  119. package/src/d1/utils.ts +48 -0
  120. package/src/delete.ts +108 -0
  121. package/src/deployments.ts +77 -0
  122. package/src/deprecated/index.ts +438 -0
  123. package/src/dev/dev-vars.ts +39 -0
  124. package/src/dev/dev.tsx +550 -328
  125. package/src/dev/get-local-persistence-path.tsx +31 -0
  126. package/src/dev/local.tsx +871 -213
  127. package/src/dev/remote.tsx +592 -192
  128. package/src/dev/start-server.ts +539 -0
  129. package/src/dev/use-esbuild.ts +184 -84
  130. package/src/dev/validate-dev-props.ts +31 -0
  131. package/src/dev-registry.tsx +201 -0
  132. package/src/dev.tsx +904 -0
  133. package/src/dialogs.tsx +150 -59
  134. package/src/dispatch-namespace.ts +207 -0
  135. package/src/durable.ts +102 -0
  136. package/src/entry.ts +260 -171
  137. package/src/environment-variables.ts +40 -23
  138. package/src/errors.ts +11 -0
  139. package/src/git-client.ts +124 -0
  140. package/src/global-wrangler-config-path.ts +26 -0
  141. package/src/https-options.ts +85 -80
  142. package/src/index.tsx +639 -2341
  143. package/src/init.ts +970 -0
  144. package/src/inspect.ts +707 -557
  145. package/src/intl-polyfill.d.ts +123 -123
  146. package/src/is-ci.ts +14 -0
  147. package/src/is-interactive.ts +16 -0
  148. package/src/kv/helpers.ts +430 -0
  149. package/src/kv/index.ts +596 -0
  150. package/src/logger.ts +92 -0
  151. package/src/metrics/index.ts +5 -0
  152. package/src/metrics/metrics-config.ts +239 -0
  153. package/src/metrics/metrics-dispatcher.ts +96 -0
  154. package/src/metrics/metrics-usage-headers.ts +24 -0
  155. package/src/metrics/send-event.ts +96 -0
  156. package/src/miniflare-cli/assets.ts +220 -0
  157. package/src/miniflare-cli/index.ts +206 -30
  158. package/src/miniflare-cli/request-context.ts +40 -0
  159. package/src/module-collection.ts +222 -213
  160. package/src/open-in-browser.ts +8 -16
  161. package/src/package-manager.ts +183 -90
  162. package/src/pages/build.tsx +270 -0
  163. package/src/pages/constants.ts +18 -0
  164. package/src/pages/deployment-tails.tsx +284 -0
  165. package/src/pages/deployments.tsx +84 -0
  166. package/src/pages/dev.tsx +706 -0
  167. package/src/pages/errors.ts +66 -0
  168. package/src/pages/functions/buildPlugin.ts +107 -0
  169. package/src/pages/functions/buildWorker.ts +166 -0
  170. package/src/pages/functions/filepath-routing.test.ts +234 -0
  171. package/src/pages/functions/filepath-routing.ts +189 -0
  172. package/src/pages/functions/identifiers.ts +78 -0
  173. package/src/pages/functions/routes-consolidation.test.ts +250 -0
  174. package/src/pages/functions/routes-consolidation.ts +73 -0
  175. package/src/pages/functions/routes-transformation.test.ts +282 -0
  176. package/src/pages/functions/routes-transformation.ts +115 -0
  177. package/src/pages/functions/routes-validation.test.ts +403 -0
  178. package/src/pages/functions/routes-validation.ts +202 -0
  179. package/src/pages/functions/routes.ts +151 -0
  180. package/src/pages/functions.tsx +82 -0
  181. package/src/pages/hash.tsx +13 -0
  182. package/src/pages/index.tsx +102 -0
  183. package/src/pages/projects.tsx +169 -0
  184. package/src/pages/prompt-select-project.tsx +31 -0
  185. package/src/pages/publish.tsx +451 -0
  186. package/src/pages/types.ts +41 -0
  187. package/src/pages/upload.tsx +426 -0
  188. package/src/pages/utils.ts +23 -0
  189. package/src/parse.ts +224 -121
  190. package/src/paths.ts +53 -8
  191. package/src/proxy.ts +629 -375
  192. package/src/publish/index.ts +270 -0
  193. package/src/publish/publish.ts +1035 -0
  194. package/src/pubsub/index.ts +286 -0
  195. package/src/pubsub/pubsub-commands.tsx +624 -0
  196. package/src/queues/cli/commands/consumer/add.ts +71 -0
  197. package/src/queues/cli/commands/consumer/index.ts +22 -0
  198. package/src/queues/cli/commands/consumer/remove.ts +38 -0
  199. package/src/queues/cli/commands/create.ts +25 -0
  200. package/src/queues/cli/commands/delete.ts +26 -0
  201. package/src/queues/cli/commands/index.ts +36 -0
  202. package/src/queues/cli/commands/list.ts +25 -0
  203. package/src/queues/client.ts +135 -0
  204. package/src/queues/utils.ts +18 -0
  205. package/src/r2/constants.ts +4 -0
  206. package/src/r2/helpers.ts +131 -0
  207. package/src/r2/index.ts +289 -0
  208. package/src/routes.ts +140 -0
  209. package/src/secret/index.ts +378 -0
  210. package/src/selfsigned.d.ts +23 -23
  211. package/src/sites.tsx +283 -191
  212. package/src/tail/createTail.ts +379 -0
  213. package/src/tail/filters.ts +108 -110
  214. package/src/tail/index.ts +211 -296
  215. package/src/tail/printing.ts +92 -47
  216. package/src/type-generation.ts +173 -0
  217. package/src/update-check.ts +19 -0
  218. package/src/user/access.ts +69 -0
  219. package/src/user/choose-account.tsx +69 -0
  220. package/src/user/env-vars.ts +46 -0
  221. package/src/user/generate-auth-url.ts +33 -0
  222. package/src/user/generate-random-state.ts +16 -0
  223. package/src/user/index.ts +3 -0
  224. package/src/user/user.tsx +1198 -0
  225. package/src/utils/collectKeyValues.ts +14 -0
  226. package/src/whoami.tsx +142 -42
  227. package/src/worker.ts +182 -100
  228. package/src/yargs-types.ts +24 -0
  229. package/src/zones.ts +191 -0
  230. package/templates/__tests__/pages-dev-util.test.ts +128 -0
  231. package/templates/checked-fetch.js +17 -0
  232. package/templates/d1-beta-facade.js +205 -0
  233. package/templates/first-party-worker-module-facade.ts +18 -0
  234. package/templates/format-dev-errors.ts +32 -0
  235. package/templates/gitignore +171 -0
  236. package/templates/init-tests/test-jest-new-worker.js +25 -0
  237. package/templates/init-tests/test-vitest-new-worker.js +26 -0
  238. package/templates/middleware/common.ts +62 -0
  239. package/templates/middleware/loader-modules.ts +84 -0
  240. package/templates/middleware/loader-sw.ts +227 -0
  241. package/templates/middleware/middleware-miniflare3-json-error.ts +20 -0
  242. package/templates/middleware/middleware-pretty-error.ts +40 -0
  243. package/templates/middleware/middleware-scheduled.ts +15 -0
  244. package/templates/new-worker-scheduled.js +17 -0
  245. package/templates/new-worker-scheduled.ts +32 -0
  246. package/templates/new-worker.js +3 -3
  247. package/templates/new-worker.ts +18 -3
  248. package/templates/no-op-worker.js +10 -0
  249. package/templates/pages-dev-pipeline.ts +28 -0
  250. package/templates/pages-dev-util.ts +52 -0
  251. package/templates/pages-shim.ts +9 -0
  252. package/templates/pages-template-plugin.ts +171 -0
  253. package/templates/pages-template-worker.ts +189 -0
  254. package/templates/serve-static-assets.ts +63 -0
  255. package/templates/service-bindings-module-facade.js +54 -0
  256. package/templates/service-bindings-sw-facade.js +42 -0
  257. package/templates/tsconfig.json +96 -95
  258. package/wrangler-dist/cli.d.ts +893 -0
  259. package/wrangler-dist/cli.js +116816 -94969
  260. package/miniflare-dist/index.mjs.map +0 -7
  261. package/pages/functions/buildWorker.ts +0 -62
  262. package/pages/functions/filepath-routing.test.ts +0 -223
  263. package/pages/functions/filepath-routing.ts +0 -181
  264. package/pages/functions/identifiers.ts +0 -78
  265. package/pages/functions/routes.ts +0 -151
  266. package/pages/functions/template-worker.ts +0 -130
  267. package/src/__tests__/helpers/faye-websocket.d.ts +0 -6
  268. package/src/__tests__/sentry.test.ts +0 -146
  269. package/src/kv.ts +0 -319
  270. package/src/miniflare-cli/enum-keys.ts +0 -17
  271. package/src/pages.tsx +0 -1061
  272. package/src/publish.ts +0 -350
  273. package/src/r2.ts +0 -50
  274. package/src/reporting.ts +0 -131
  275. package/src/user.tsx +0 -1127
  276. package/templates/static-asset-facade.js +0 -47
  277. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  278. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  279. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  280. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  281. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  282. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  283. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  284. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  285. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  286. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  287. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  288. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  289. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  290. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  291. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  292. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  293. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  294. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  295. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  296. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  297. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  298. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  299. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  300. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  301. package/vendor/wrangler-mime/LICENSE +0 -21
  302. package/vendor/wrangler-mime/Mime.js +0 -97
  303. package/vendor/wrangler-mime/README.md +0 -187
  304. package/vendor/wrangler-mime/cli.js +0 -46
  305. package/vendor/wrangler-mime/index.js +0 -4
  306. package/vendor/wrangler-mime/lite.js +0 -4
  307. package/vendor/wrangler-mime/package.json +0 -52
  308. package/vendor/wrangler-mime/types/other.js +0 -1
  309. package/vendor/wrangler-mime/types/standard.js +0 -1
  310. package/wrangler-dist/cli.js.map +0 -7
@@ -1,148 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.sleep = exports.mockGlobal = exports.mockCaches = exports.mockManifest = exports.mockKV = exports.getEvent = void 0;
13
- const makeServiceWorkerEnv = require('service-worker-mock');
14
- const HASH = '123HASHBROWN';
15
- const getEvent = (request) => {
16
- const waitUntil = (callback) => __awaiter(void 0, void 0, void 0, function* () {
17
- yield callback;
18
- });
19
- return {
20
- request,
21
- waitUntil,
22
- };
23
- };
24
- exports.getEvent = getEvent;
25
- const store = {
26
- 'key1.123HASHBROWN.txt': 'val1',
27
- 'key1.123HASHBROWN.png': 'val1',
28
- 'index.123HASHBROWN.html': 'index.html',
29
- 'cache.123HASHBROWN.html': 'cache me if you can',
30
- '测试.123HASHBROWN.html': 'My filename is non-ascii',
31
- '%not-really-percent-encoded.123HASHBROWN.html': 'browser percent encoded',
32
- '%2F.123HASHBROWN.html': 'user percent encoded',
33
- '你好.123HASHBROWN.html': 'I shouldnt be served',
34
- '%E4%BD%A0%E5%A5%BD.123HASHBROWN.html': 'Im important',
35
- 'nohash.txt': 'no hash but still got some result',
36
- 'sub/blah.123HASHBROWN.png': 'picturedis',
37
- 'sub/index.123HASHBROWN.html': 'picturedis',
38
- 'client.123HASHBROWN': 'important file',
39
- 'client.123HASHBROWN/index.html': 'Im here but serve my big bro above',
40
- '你好/index.123HASHBROWN.html': 'My path is non-ascii',
41
- };
42
- const mockKV = (store) => {
43
- return {
44
- get: (path) => store[path] || null,
45
- };
46
- };
47
- exports.mockKV = mockKV;
48
- const mockManifest = () => {
49
- return JSON.stringify({
50
- 'key1.txt': `key1.${HASH}.txt`,
51
- 'key1.png': `key1.${HASH}.png`,
52
- 'cache.html': `cache.${HASH}.html`,
53
- '测试.html': `测试.${HASH}.html`,
54
- '你好.html': `你好.${HASH}.html`,
55
- '%not-really-percent-encoded.html': `%not-really-percent-encoded.${HASH}.html`,
56
- '%2F.html': `%2F.${HASH}.html`,
57
- '%E4%BD%A0%E5%A5%BD.html': `%E4%BD%A0%E5%A5%BD.${HASH}.html`,
58
- 'index.html': `index.${HASH}.html`,
59
- 'sub/blah.png': `sub/blah.${HASH}.png`,
60
- 'sub/index.html': `sub/index.${HASH}.html`,
61
- client: `client.${HASH}`,
62
- 'client/index.html': `client.${HASH}`,
63
- '你好/index.html': `你好/index.${HASH}.html`,
64
- });
65
- };
66
- exports.mockManifest = mockManifest;
67
- let cacheStore = new Map();
68
- const mockCaches = () => {
69
- return {
70
- default: {
71
- match(key) {
72
- return __awaiter(this, void 0, void 0, function* () {
73
- let cacheKey = {
74
- url: key.url,
75
- headers: {},
76
- };
77
- let response;
78
- if (key.headers.has('if-none-match')) {
79
- let makeStrongEtag = key.headers.get('if-none-match').replace('W/', '');
80
- Reflect.set(cacheKey.headers, 'etag', makeStrongEtag);
81
- response = cacheStore.get(JSON.stringify(cacheKey));
82
- }
83
- else {
84
- // if client doesn't send if-none-match, we need to iterate through these keys
85
- // and just test the URL
86
- const activeCacheKeys = Array.from(cacheStore.keys());
87
- for (const cacheStoreKey of activeCacheKeys) {
88
- if (JSON.parse(cacheStoreKey).url === key.url) {
89
- response = cacheStore.get(cacheStoreKey);
90
- }
91
- }
92
- }
93
- // TODO: write test to accomodate for rare scenarios with where range requests accomodate etags
94
- if (response && !key.headers.has('if-none-match')) {
95
- // this appears overly verbose, but is necessary to document edge cache behavior
96
- // The Range request header triggers the response header Content-Range ...
97
- const range = key.headers.get('range');
98
- if (range) {
99
- response.headers.set('content-range', `bytes ${range.split('=').pop()}/${response.headers.get('content-length')}`);
100
- }
101
- // ... which we are using in this repository to set status 206
102
- if (response.headers.has('content-range')) {
103
- response.status = 206;
104
- }
105
- else {
106
- response.status = 200;
107
- }
108
- let etag = response.headers.get('etag');
109
- if (etag && !etag.includes('W/')) {
110
- response.headers.set('etag', `W/${etag}`);
111
- }
112
- }
113
- return response;
114
- });
115
- },
116
- put(key, val) {
117
- return __awaiter(this, void 0, void 0, function* () {
118
- let headers = new Headers(val.headers);
119
- let url = new URL(key.url);
120
- let resWithBody = new Response(val.body, { headers, status: 200 });
121
- let resNoBody = new Response(null, { headers, status: 304 });
122
- let cacheKey = {
123
- url: key.url,
124
- headers: {
125
- etag: `"${url.pathname.replace('/', '')}"`,
126
- },
127
- };
128
- cacheStore.set(JSON.stringify(cacheKey), resNoBody);
129
- cacheKey.headers = {};
130
- cacheStore.set(JSON.stringify(cacheKey), resWithBody);
131
- return;
132
- });
133
- },
134
- },
135
- };
136
- };
137
- exports.mockCaches = mockCaches;
138
- function mockGlobal() {
139
- Object.assign(global, makeServiceWorkerEnv());
140
- Object.assign(global, { __STATIC_CONTENT_MANIFEST: exports.mockManifest() });
141
- Object.assign(global, { __STATIC_CONTENT: exports.mockKV(store) });
142
- Object.assign(global, { caches: exports.mockCaches() });
143
- }
144
- exports.mockGlobal = mockGlobal;
145
- const sleep = (milliseconds) => {
146
- return new Promise((resolve) => setTimeout(resolve, milliseconds));
147
- };
148
- exports.sleep = sleep;
@@ -1,436 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const ava_1 = require("ava");
13
- const mocks_1 = require("../mocks");
14
- const index_1 = require("../index");
15
- ava_1.default('getAssetFromKV return correct val from KV and default caching', (t) => __awaiter(void 0, void 0, void 0, function* () {
16
- mocks_1.mockGlobal();
17
- const event = mocks_1.getEvent(new Request('https://blah.com/key1.txt'));
18
- const res = yield index_1.getAssetFromKV(event);
19
- if (res) {
20
- t.is(res.headers.get('cache-control'), null);
21
- t.is(res.headers.get('cf-cache-status'), 'MISS');
22
- t.is(yield res.text(), 'val1');
23
- t.true(res.headers.get('content-type').includes('text'));
24
- }
25
- else {
26
- t.fail('Response was undefined');
27
- }
28
- }));
29
- ava_1.default('getAssetFromKV evaluated the file matching the extensionless path first /client/ -> client', (t) => __awaiter(void 0, void 0, void 0, function* () {
30
- mocks_1.mockGlobal();
31
- const event = mocks_1.getEvent(new Request(`https://foo.com/client/`));
32
- const res = yield index_1.getAssetFromKV(event);
33
- t.is(yield res.text(), 'important file');
34
- t.true(res.headers.get('content-type').includes('text'));
35
- }));
36
- ava_1.default('getAssetFromKV evaluated the file matching the extensionless path first /client -> client', (t) => __awaiter(void 0, void 0, void 0, function* () {
37
- mocks_1.mockGlobal();
38
- const event = mocks_1.getEvent(new Request(`https://foo.com/client`));
39
- const res = yield index_1.getAssetFromKV(event);
40
- t.is(yield res.text(), 'important file');
41
- t.true(res.headers.get('content-type').includes('text'));
42
- }));
43
- ava_1.default('getAssetFromKV if not in asset manifest still returns nohash.txt', (t) => __awaiter(void 0, void 0, void 0, function* () {
44
- mocks_1.mockGlobal();
45
- const event = mocks_1.getEvent(new Request('https://blah.com/nohash.txt'));
46
- const res = yield index_1.getAssetFromKV(event);
47
- if (res) {
48
- t.is(yield res.text(), 'no hash but still got some result');
49
- t.true(res.headers.get('content-type').includes('text'));
50
- }
51
- else {
52
- t.fail('Response was undefined');
53
- }
54
- }));
55
- ava_1.default('getAssetFromKV if no asset manifest /client -> client fails', (t) => __awaiter(void 0, void 0, void 0, function* () {
56
- mocks_1.mockGlobal();
57
- const event = mocks_1.getEvent(new Request(`https://foo.com/client`));
58
- const error = yield t.throwsAsync(index_1.getAssetFromKV(event, { ASSET_MANIFEST: {} }));
59
- t.is(error.status, 404);
60
- }));
61
- ava_1.default('getAssetFromKV if sub/ -> sub/index.html served', (t) => __awaiter(void 0, void 0, void 0, function* () {
62
- mocks_1.mockGlobal();
63
- const event = mocks_1.getEvent(new Request(`https://foo.com/sub`));
64
- const res = yield index_1.getAssetFromKV(event);
65
- if (res) {
66
- t.is(yield res.text(), 'picturedis');
67
- }
68
- else {
69
- t.fail('Response was undefined');
70
- }
71
- }));
72
- ava_1.default('getAssetFromKV gets index.html by default for / requests', (t) => __awaiter(void 0, void 0, void 0, function* () {
73
- mocks_1.mockGlobal();
74
- const event = mocks_1.getEvent(new Request('https://blah.com/'));
75
- const res = yield index_1.getAssetFromKV(event);
76
- if (res) {
77
- t.is(yield res.text(), 'index.html');
78
- t.true(res.headers.get('content-type').includes('html'));
79
- }
80
- else {
81
- t.fail('Response was undefined');
82
- }
83
- }));
84
- ava_1.default('getAssetFromKV non ASCII path support', (t) => __awaiter(void 0, void 0, void 0, function* () {
85
- mocks_1.mockGlobal();
86
- const event = mocks_1.getEvent(new Request('https://blah.com/测试.html'));
87
- const res = yield index_1.getAssetFromKV(event);
88
- if (res) {
89
- t.is(yield res.text(), 'My filename is non-ascii');
90
- }
91
- else {
92
- t.fail('Response was undefined');
93
- }
94
- }));
95
- ava_1.default('getAssetFromKV supports browser percent encoded URLs', (t) => __awaiter(void 0, void 0, void 0, function* () {
96
- mocks_1.mockGlobal();
97
- const event = mocks_1.getEvent(new Request('https://example.com/%not-really-percent-encoded.html'));
98
- const res = yield index_1.getAssetFromKV(event);
99
- if (res) {
100
- t.is(yield res.text(), 'browser percent encoded');
101
- }
102
- else {
103
- t.fail('Response was undefined');
104
- }
105
- }));
106
- ava_1.default('getAssetFromKV supports user percent encoded URLs', (t) => __awaiter(void 0, void 0, void 0, function* () {
107
- mocks_1.mockGlobal();
108
- const event = mocks_1.getEvent(new Request('https://blah.com/%2F.html'));
109
- const res = yield index_1.getAssetFromKV(event);
110
- if (res) {
111
- t.is(yield res.text(), 'user percent encoded');
112
- }
113
- else {
114
- t.fail('Response was undefined');
115
- }
116
- }));
117
- ava_1.default('getAssetFromKV only decode URL when necessary', (t) => __awaiter(void 0, void 0, void 0, function* () {
118
- mocks_1.mockGlobal();
119
- const event1 = mocks_1.getEvent(new Request('https://blah.com/%E4%BD%A0%E5%A5%BD.html'));
120
- const event2 = mocks_1.getEvent(new Request('https://blah.com/你好.html'));
121
- const res1 = yield index_1.getAssetFromKV(event1);
122
- const res2 = yield index_1.getAssetFromKV(event2);
123
- if (res1 && res2) {
124
- t.is(yield res1.text(), 'Im important');
125
- t.is(yield res2.text(), 'Im important');
126
- }
127
- else {
128
- t.fail('Response was undefined');
129
- }
130
- }));
131
- ava_1.default('getAssetFromKV Support for user decode url path', (t) => __awaiter(void 0, void 0, void 0, function* () {
132
- mocks_1.mockGlobal();
133
- const event1 = mocks_1.getEvent(new Request('https://blah.com/%E4%BD%A0%E5%A5%BD/'));
134
- const event2 = mocks_1.getEvent(new Request('https://blah.com/你好/'));
135
- const res1 = yield index_1.getAssetFromKV(event1);
136
- const res2 = yield index_1.getAssetFromKV(event2);
137
- if (res1 && res2) {
138
- t.is(yield res1.text(), 'My path is non-ascii');
139
- t.is(yield res2.text(), 'My path is non-ascii');
140
- }
141
- else {
142
- t.fail('Response was undefined');
143
- }
144
- }));
145
- ava_1.default('getAssetFromKV custom key modifier', (t) => __awaiter(void 0, void 0, void 0, function* () {
146
- mocks_1.mockGlobal();
147
- const event = mocks_1.getEvent(new Request('https://blah.com/docs/sub/blah.png'));
148
- const customRequestMapper = (request) => {
149
- let defaultModifiedRequest = index_1.mapRequestToAsset(request);
150
- let url = new URL(defaultModifiedRequest.url);
151
- url.pathname = url.pathname.replace('/docs', '');
152
- return new Request(url.toString(), request);
153
- };
154
- const res = yield index_1.getAssetFromKV(event, { mapRequestToAsset: customRequestMapper });
155
- if (res) {
156
- t.is(yield res.text(), 'picturedis');
157
- }
158
- else {
159
- t.fail('Response was undefined');
160
- }
161
- }));
162
- ava_1.default('getAssetFromKV when setting browser caching', (t) => __awaiter(void 0, void 0, void 0, function* () {
163
- mocks_1.mockGlobal();
164
- const event = mocks_1.getEvent(new Request('https://blah.com/'));
165
- const res = yield index_1.getAssetFromKV(event, { cacheControl: { browserTTL: 22 } });
166
- if (res) {
167
- t.is(res.headers.get('cache-control'), 'max-age=22');
168
- }
169
- else {
170
- t.fail('Response was undefined');
171
- }
172
- }));
173
- ava_1.default('getAssetFromKV when setting custom cache setting', (t) => __awaiter(void 0, void 0, void 0, function* () {
174
- mocks_1.mockGlobal();
175
- const event1 = mocks_1.getEvent(new Request('https://blah.com/'));
176
- const event2 = mocks_1.getEvent(new Request('https://blah.com/key1.png?blah=34'));
177
- const cacheOnlyPngs = (req) => {
178
- if (new URL(req.url).pathname.endsWith('.png'))
179
- return {
180
- browserTTL: 720,
181
- edgeTTL: 720,
182
- };
183
- else
184
- return {
185
- bypassCache: true,
186
- };
187
- };
188
- const res1 = yield index_1.getAssetFromKV(event1, { cacheControl: cacheOnlyPngs });
189
- const res2 = yield index_1.getAssetFromKV(event2, { cacheControl: cacheOnlyPngs });
190
- if (res1 && res2) {
191
- t.is(res1.headers.get('cache-control'), null);
192
- t.true(res2.headers.get('content-type').includes('png'));
193
- t.is(res2.headers.get('cache-control'), 'max-age=720');
194
- t.is(res2.headers.get('cf-cache-status'), 'MISS');
195
- }
196
- else {
197
- t.fail('Response was undefined');
198
- }
199
- }));
200
- ava_1.default('getAssetFromKV caches on two sequential requests', (t) => __awaiter(void 0, void 0, void 0, function* () {
201
- mocks_1.mockGlobal();
202
- const resourceKey = 'cache.html';
203
- const resourceVersion = JSON.parse(mocks_1.mockManifest())[resourceKey];
204
- const event1 = mocks_1.getEvent(new Request(`https://blah.com/${resourceKey}`));
205
- const event2 = mocks_1.getEvent(new Request(`https://blah.com/${resourceKey}`, {
206
- headers: {
207
- 'if-none-match': `"${resourceVersion}"`,
208
- },
209
- }));
210
- const res1 = yield index_1.getAssetFromKV(event1, { cacheControl: { edgeTTL: 720, browserTTL: 720 } });
211
- yield mocks_1.sleep(1);
212
- const res2 = yield index_1.getAssetFromKV(event2);
213
- if (res1 && res2) {
214
- t.is(res1.headers.get('cf-cache-status'), 'MISS');
215
- t.is(res1.headers.get('cache-control'), 'max-age=720');
216
- t.is(res2.headers.get('cf-cache-status'), 'REVALIDATED');
217
- }
218
- else {
219
- t.fail('Response was undefined');
220
- }
221
- }));
222
- ava_1.default('getAssetFromKV does not store max-age on two sequential requests', (t) => __awaiter(void 0, void 0, void 0, function* () {
223
- mocks_1.mockGlobal();
224
- const resourceKey = 'cache.html';
225
- const resourceVersion = JSON.parse(mocks_1.mockManifest())[resourceKey];
226
- const event1 = mocks_1.getEvent(new Request(`https://blah.com/${resourceKey}`));
227
- const event2 = mocks_1.getEvent(new Request(`https://blah.com/${resourceKey}`, {
228
- headers: {
229
- 'if-none-match': `"${resourceVersion}"`,
230
- },
231
- }));
232
- const res1 = yield index_1.getAssetFromKV(event1, { cacheControl: { edgeTTL: 720 } });
233
- yield mocks_1.sleep(100);
234
- const res2 = yield index_1.getAssetFromKV(event2);
235
- if (res1 && res2) {
236
- t.is(res1.headers.get('cf-cache-status'), 'MISS');
237
- t.is(res1.headers.get('cache-control'), null);
238
- t.is(res2.headers.get('cf-cache-status'), 'REVALIDATED');
239
- t.is(res2.headers.get('cache-control'), null);
240
- }
241
- else {
242
- t.fail('Response was undefined');
243
- }
244
- }));
245
- ava_1.default('getAssetFromKV does not cache on Cloudflare when bypass cache set', (t) => __awaiter(void 0, void 0, void 0, function* () {
246
- mocks_1.mockGlobal();
247
- const event = mocks_1.getEvent(new Request('https://blah.com/'));
248
- const res = yield index_1.getAssetFromKV(event, { cacheControl: { bypassCache: true } });
249
- if (res) {
250
- t.is(res.headers.get('cache-control'), null);
251
- t.is(res.headers.get('cf-cache-status'), null);
252
- }
253
- else {
254
- t.fail('Response was undefined');
255
- }
256
- }));
257
- ava_1.default('getAssetFromKV with no trailing slash on root', (t) => __awaiter(void 0, void 0, void 0, function* () {
258
- mocks_1.mockGlobal();
259
- const event = mocks_1.getEvent(new Request('https://blah.com'));
260
- const res = yield index_1.getAssetFromKV(event);
261
- if (res) {
262
- t.is(yield res.text(), 'index.html');
263
- }
264
- else {
265
- t.fail('Response was undefined');
266
- }
267
- }));
268
- ava_1.default('getAssetFromKV with no trailing slash on a subdirectory', (t) => __awaiter(void 0, void 0, void 0, function* () {
269
- mocks_1.mockGlobal();
270
- const event = mocks_1.getEvent(new Request('https://blah.com/sub/blah.png'));
271
- const res = yield index_1.getAssetFromKV(event);
272
- if (res) {
273
- t.is(yield res.text(), 'picturedis');
274
- }
275
- else {
276
- t.fail('Response was undefined');
277
- }
278
- }));
279
- ava_1.default('getAssetFromKV no result throws an error', (t) => __awaiter(void 0, void 0, void 0, function* () {
280
- mocks_1.mockGlobal();
281
- const event = mocks_1.getEvent(new Request('https://blah.com/random'));
282
- const error = yield t.throwsAsync(index_1.getAssetFromKV(event));
283
- t.is(error.status, 404);
284
- }));
285
- ava_1.default('getAssetFromKV TTls set to null should not cache on browser or edge', (t) => __awaiter(void 0, void 0, void 0, function* () {
286
- mocks_1.mockGlobal();
287
- const event = mocks_1.getEvent(new Request('https://blah.com/'));
288
- const res1 = yield index_1.getAssetFromKV(event, { cacheControl: { browserTTL: null, edgeTTL: null } });
289
- yield mocks_1.sleep(100);
290
- const res2 = yield index_1.getAssetFromKV(event, { cacheControl: { browserTTL: null, edgeTTL: null } });
291
- if (res1 && res2) {
292
- t.is(res1.headers.get('cf-cache-status'), null);
293
- t.is(res1.headers.get('cache-control'), null);
294
- t.is(res2.headers.get('cf-cache-status'), null);
295
- t.is(res2.headers.get('cache-control'), null);
296
- }
297
- else {
298
- t.fail('Response was undefined');
299
- }
300
- }));
301
- ava_1.default('getAssetFromKV passing in a custom NAMESPACE serves correct asset', (t) => __awaiter(void 0, void 0, void 0, function* () {
302
- mocks_1.mockGlobal();
303
- let CUSTOM_NAMESPACE = mocks_1.mockKV({
304
- 'key1.123HASHBROWN.txt': 'val1',
305
- });
306
- Object.assign(global, { CUSTOM_NAMESPACE });
307
- const event = mocks_1.getEvent(new Request('https://blah.com/'));
308
- const res = yield index_1.getAssetFromKV(event);
309
- if (res) {
310
- t.is(yield res.text(), 'index.html');
311
- t.true(res.headers.get('content-type').includes('html'));
312
- }
313
- else {
314
- t.fail('Response was undefined');
315
- }
316
- }));
317
- ava_1.default('getAssetFromKV when custom namespace without the asset should fail', (t) => __awaiter(void 0, void 0, void 0, function* () {
318
- mocks_1.mockGlobal();
319
- let CUSTOM_NAMESPACE = mocks_1.mockKV({
320
- 'key5.123HASHBROWN.txt': 'customvalu',
321
- });
322
- const event = mocks_1.getEvent(new Request('https://blah.com'));
323
- const error = yield t.throwsAsync(index_1.getAssetFromKV(event, { ASSET_NAMESPACE: CUSTOM_NAMESPACE }));
324
- t.is(error.status, 404);
325
- }));
326
- ava_1.default('getAssetFromKV when namespace not bound fails', (t) => __awaiter(void 0, void 0, void 0, function* () {
327
- mocks_1.mockGlobal();
328
- var MY_CUSTOM_NAMESPACE = undefined;
329
- Object.assign(global, { MY_CUSTOM_NAMESPACE });
330
- const event = mocks_1.getEvent(new Request('https://blah.com/'));
331
- const error = yield t.throwsAsync(index_1.getAssetFromKV(event, { ASSET_NAMESPACE: MY_CUSTOM_NAMESPACE }));
332
- t.is(error.status, 500);
333
- }));
334
- ava_1.default('getAssetFromKV when if-none-match === active resource version, should revalidate', (t) => __awaiter(void 0, void 0, void 0, function* () {
335
- mocks_1.mockGlobal();
336
- const resourceKey = 'key1.png';
337
- const resourceVersion = JSON.parse(mocks_1.mockManifest())[resourceKey];
338
- const event1 = mocks_1.getEvent(new Request(`https://blah.com/${resourceKey}`));
339
- const event2 = mocks_1.getEvent(new Request(`https://blah.com/${resourceKey}`, {
340
- headers: {
341
- 'if-none-match': `W/"${resourceVersion}"`,
342
- },
343
- }));
344
- const res1 = yield index_1.getAssetFromKV(event1, { cacheControl: { edgeTTL: 720 } });
345
- yield mocks_1.sleep(100);
346
- const res2 = yield index_1.getAssetFromKV(event2);
347
- if (res1 && res2) {
348
- t.is(res1.headers.get('cf-cache-status'), 'MISS');
349
- t.is(res2.headers.get('cf-cache-status'), 'REVALIDATED');
350
- }
351
- else {
352
- t.fail('Response was undefined');
353
- }
354
- }));
355
- ava_1.default('getAssetFromKV when if-none-match equals etag of stale resource then should bypass cache', (t) => __awaiter(void 0, void 0, void 0, function* () {
356
- mocks_1.mockGlobal();
357
- const resourceKey = 'key1.png';
358
- const resourceVersion = JSON.parse(mocks_1.mockManifest())[resourceKey];
359
- const req1 = new Request(`https://blah.com/${resourceKey}`, {
360
- headers: {
361
- 'if-none-match': `"${resourceVersion}"`,
362
- },
363
- });
364
- const req2 = new Request(`https://blah.com/${resourceKey}`, {
365
- headers: {
366
- 'if-none-match': `"${resourceVersion}-another-version"`,
367
- },
368
- });
369
- const event = mocks_1.getEvent(req1);
370
- const event2 = mocks_1.getEvent(req2);
371
- const res1 = yield index_1.getAssetFromKV(event, { cacheControl: { edgeTTL: 720 } });
372
- const res2 = yield index_1.getAssetFromKV(event);
373
- const res3 = yield index_1.getAssetFromKV(event2);
374
- if (res1 && res2 && res3) {
375
- t.is(res1.headers.get('cf-cache-status'), 'MISS');
376
- t.is(res2.headers.get('etag'), `W/${req1.headers.get('if-none-match')}`);
377
- t.is(res2.headers.get('cf-cache-status'), 'REVALIDATED');
378
- t.not(res3.headers.get('etag'), req2.headers.get('if-none-match'));
379
- t.is(res3.headers.get('cf-cache-status'), 'MISS');
380
- }
381
- else {
382
- t.fail('Response was undefined');
383
- }
384
- }));
385
- ava_1.default('getAssetFromKV when resource in cache, etag should be weakened before returned to eyeball', (t) => __awaiter(void 0, void 0, void 0, function* () {
386
- mocks_1.mockGlobal();
387
- const resourceKey = 'key1.png';
388
- const resourceVersion = JSON.parse(mocks_1.mockManifest())[resourceKey];
389
- const req1 = new Request(`https://blah.com/${resourceKey}`, {
390
- headers: {
391
- 'if-none-match': `"${resourceVersion}"`,
392
- },
393
- });
394
- const event = mocks_1.getEvent(req1);
395
- const res1 = yield index_1.getAssetFromKV(event, { cacheControl: { edgeTTL: 720 } });
396
- const res2 = yield index_1.getAssetFromKV(event);
397
- if (res1 && res2) {
398
- t.is(res1.headers.get('cf-cache-status'), 'MISS');
399
- t.is(res2.headers.get('etag'), `W/${req1.headers.get('if-none-match')}`);
400
- }
401
- else {
402
- t.fail('Response was undefined');
403
- }
404
- }));
405
- ava_1.default('getAssetFromKV if-none-match not sent but resource in cache, should return cache hit 200 OK', (t) => __awaiter(void 0, void 0, void 0, function* () {
406
- const resourceKey = 'cache.html';
407
- const event = mocks_1.getEvent(new Request(`https://blah.com/${resourceKey}`));
408
- const res1 = yield index_1.getAssetFromKV(event, { cacheControl: { edgeTTL: 720 } });
409
- yield mocks_1.sleep(1);
410
- const res2 = yield index_1.getAssetFromKV(event);
411
- if (res1 && res2) {
412
- t.is(res1.headers.get('cf-cache-status'), 'MISS');
413
- t.is(res1.headers.get('cache-control'), null);
414
- t.is(res2.status, 200);
415
- t.is(res2.headers.get('cf-cache-status'), 'HIT');
416
- }
417
- else {
418
- t.fail('Response was undefined');
419
- }
420
- }));
421
- ava_1.default('getAssetFromKV if range request submitted and resource in cache, request fulfilled', (t) => __awaiter(void 0, void 0, void 0, function* () {
422
- const resourceKey = 'cache.html';
423
- const event1 = mocks_1.getEvent(new Request(`https://blah.com/${resourceKey}`));
424
- const event2 = mocks_1.getEvent(new Request(`https://blah.com/${resourceKey}`, { headers: { range: 'bytes=0-10' } }));
425
- const res1 = index_1.getAssetFromKV(event1, { cacheControl: { edgeTTL: 720 } });
426
- yield res1;
427
- yield mocks_1.sleep(2);
428
- const res2 = yield index_1.getAssetFromKV(event2);
429
- if (res2.headers.has('content-range')) {
430
- t.is(res2.status, 206);
431
- }
432
- else {
433
- t.fail('Response was undefined');
434
- }
435
- }));
436
- ava_1.default.todo('getAssetFromKV when body not empty, should invoke .cancel()');
@@ -1,40 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const ava_1 = require("ava");
13
- const mocks_1 = require("../mocks");
14
- const index_1 = require("../index");
15
- ava_1.default('mapRequestToAsset() correctly changes /about -> /about/index.html', (t) => __awaiter(void 0, void 0, void 0, function* () {
16
- mocks_1.mockGlobal();
17
- let path = '/about';
18
- let request = new Request(`https://foo.com${path}`);
19
- let newRequest = index_1.mapRequestToAsset(request);
20
- t.is(newRequest.url, request.url + '/index.html');
21
- }));
22
- ava_1.default('mapRequestToAsset() correctly changes /about/ -> /about/index.html', (t) => __awaiter(void 0, void 0, void 0, function* () {
23
- let path = '/about/';
24
- let request = new Request(`https://foo.com${path}`);
25
- let newRequest = index_1.mapRequestToAsset(request);
26
- t.is(newRequest.url, request.url + 'index.html');
27
- }));
28
- ava_1.default('mapRequestToAsset() correctly changes /about.me/ -> /about.me/index.html', (t) => __awaiter(void 0, void 0, void 0, function* () {
29
- let path = '/about.me/';
30
- let request = new Request(`https://foo.com${path}`);
31
- let newRequest = index_1.mapRequestToAsset(request);
32
- t.is(newRequest.url, request.url + 'index.html');
33
- }));
34
- ava_1.default('mapRequestToAsset() correctly changes /about -> /about/default.html', (t) => __awaiter(void 0, void 0, void 0, function* () {
35
- mocks_1.mockGlobal();
36
- let path = '/about';
37
- let request = new Request(`https://foo.com${path}`);
38
- let newRequest = index_1.mapRequestToAsset(request, { defaultDocument: 'default.html' });
39
- t.is(newRequest.url, request.url + '/default.html');
40
- }));