wrangler 0.0.0-e7a0cd5b → 0.0.0-e87ad068
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 +3 -3
- package/bin/wrangler.js +30 -10
- package/miniflare-dist/index.mjs +254 -128
- package/package.json +27 -19
- package/src/__tests__/api-dev.test.ts +65 -36
- package/src/__tests__/api-devregistry.test.ts +121 -0
- package/src/__tests__/api.test.ts +27 -5
- package/src/__tests__/configuration.test.ts +797 -98
- package/src/__tests__/constellation.test.ts +371 -0
- package/src/__tests__/d1/d1.test.ts +82 -0
- package/src/__tests__/d1/execute.test.ts +66 -0
- package/src/__tests__/d1/migrate.test.ts +257 -0
- package/src/__tests__/d1/splitter.test.ts +255 -0
- package/src/__tests__/delete.test.ts +91 -49
- package/src/__tests__/deployments.test.ts +330 -56
- package/src/__tests__/dev.test.tsx +198 -90
- package/src/__tests__/generate.test.ts +12 -10
- package/src/__tests__/guess-worker-format.test.ts +35 -0
- package/src/__tests__/helpers/end-event-loop.ts +6 -0
- package/src/__tests__/helpers/mock-auth-domain.ts +20 -0
- package/src/__tests__/helpers/mock-console.ts +6 -0
- package/src/__tests__/helpers/mock-dialogs.ts +71 -85
- package/src/__tests__/helpers/mock-get-pages-upload-token.ts +25 -0
- package/src/__tests__/helpers/mock-get-zone-from-host.ts +8 -5
- package/src/__tests__/helpers/mock-known-routes.ts +7 -2
- package/src/__tests__/helpers/mock-kv.ts +29 -16
- package/src/__tests__/helpers/mock-oauth-flow.ts +103 -92
- package/src/__tests__/helpers/mock-process.ts +8 -13
- package/src/__tests__/helpers/mock-set-timeout.ts +16 -0
- package/src/__tests__/helpers/msw/blob-worker.cjs +19 -0
- package/src/__tests__/helpers/msw/handlers/deployments.ts +128 -27
- package/src/__tests__/helpers/msw/handlers/namespaces.ts +18 -41
- package/src/__tests__/helpers/msw/handlers/oauth.ts +13 -18
- package/src/__tests__/helpers/msw/handlers/r2.ts +14 -34
- package/src/__tests__/helpers/msw/handlers/script.ts +9 -28
- package/src/__tests__/helpers/msw/handlers/user.ts +13 -24
- package/src/__tests__/helpers/msw/handlers/zones.ts +6 -8
- package/src/__tests__/helpers/msw/index.ts +32 -1
- package/src/__tests__/helpers/msw/read-file-sync.js +61 -0
- package/src/__tests__/helpers/string-dynamic-values-matcher.ts +28 -0
- package/src/__tests__/helpers/worker-scripts/parent-worker.js +4 -1
- package/src/__tests__/index.test.ts +92 -72
- package/src/__tests__/init.test.ts +1033 -631
- package/src/__tests__/jest.setup.ts +19 -42
- package/src/__tests__/kv.test.ts +355 -231
- package/src/__tests__/logger.test.ts +68 -2
- package/src/__tests__/logout.test.ts +47 -0
- package/src/__tests__/metrics.test.ts +94 -51
- package/src/__tests__/middleware.scheduled.test.ts +42 -32
- package/src/__tests__/middleware.test.ts +212 -122
- package/src/__tests__/mtls-certificates.test.ts +589 -0
- package/src/__tests__/pages/deployment-list.test.ts +80 -0
- package/src/__tests__/pages/functions-build.test.ts +529 -0
- package/src/__tests__/pages/pages.test.ts +81 -0
- package/src/__tests__/pages/project-create.test.ts +63 -0
- package/src/__tests__/pages/project-list.test.ts +110 -0
- package/src/__tests__/pages/project-upload.test.ts +500 -0
- package/src/__tests__/pages/publish.test.ts +2864 -0
- package/src/__tests__/pages-deployment-tail.test.ts +957 -0
- package/src/__tests__/parse.test.ts +106 -0
- package/src/__tests__/publish.test.ts +2227 -1005
- package/src/__tests__/pubsub.test.ts +226 -100
- package/src/__tests__/queues.test.ts +238 -77
- package/src/__tests__/r2.test.ts +55 -57
- package/src/__tests__/secret.test.ts +179 -130
- package/src/__tests__/tail.test.ts +313 -113
- package/src/__tests__/test-old-node-version.js +3 -3
- package/src/__tests__/traverse-module-graph.test.ts +220 -0
- 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 +43 -26
- package/src/__tests__/unstableDev.test.ts +61 -0
- package/src/__tests__/user.test.ts +35 -72
- package/src/__tests__/whoami.test.tsx +8 -114
- package/src/__tests__/worker-namespace.test.ts +83 -69
- package/src/api/dev.ts +180 -60
- package/src/api/index.ts +10 -1
- package/src/api/mtls-certificate.ts +148 -0
- package/src/api/pages/create-worker-bundle-contents.ts +80 -0
- package/src/api/pages/index.ts +5 -0
- package/src/api/pages/publish.tsx +371 -0
- package/src/bundle.ts +315 -148
- package/src/cfetch/index.ts +0 -2
- package/src/cfetch/internal.ts +33 -33
- package/src/cli.ts +4 -4
- package/src/config/config.ts +14 -7
- package/src/config/environment.ts +120 -24
- package/src/config/index.ts +117 -35
- package/src/config/validation-helpers.ts +1 -1
- package/src/config/validation.ts +430 -19
- package/src/constellation/createProject.tsx +51 -0
- package/src/constellation/deleteProject.ts +51 -0
- package/src/constellation/deleteProjectModel.ts +76 -0
- package/src/constellation/index.ts +75 -0
- package/src/constellation/listCatalog.tsx +35 -0
- package/src/constellation/listModel.tsx +49 -0
- package/src/constellation/listProject.tsx +28 -0
- package/src/constellation/listRuntime.tsx +28 -0
- package/src/constellation/options.ts +17 -0
- package/src/constellation/types.ts +17 -0
- package/src/constellation/uploadModel.tsx +84 -0
- package/src/constellation/utils.ts +90 -0
- package/src/create-worker-preview.ts +19 -8
- package/src/create-worker-upload-form.ts +81 -18
- package/src/d1/backups.tsx +47 -46
- package/src/d1/constants.ts +5 -0
- package/src/d1/create.tsx +85 -37
- package/src/d1/{delete.tsx → delete.ts} +12 -15
- package/src/d1/execute.tsx +228 -156
- package/src/d1/index.ts +31 -7
- package/src/d1/list.tsx +27 -13
- package/src/d1/migrations/apply.tsx +235 -0
- package/src/d1/migrations/create.tsx +79 -0
- package/src/d1/migrations/helpers.ts +171 -0
- package/src/d1/migrations/index.ts +3 -0
- package/src/d1/migrations/list.tsx +95 -0
- package/src/d1/migrations/options.ts +23 -0
- package/src/d1/options.ts +12 -2
- package/src/d1/splitter.ts +161 -0
- package/src/d1/types.ts +32 -0
- package/src/d1/utils.ts +12 -2
- package/src/delete.ts +8 -16
- package/src/deployments.ts +340 -46
- package/src/deprecated/index.ts +8 -302
- package/src/dev/dev.tsx +66 -46
- package/src/dev/local.tsx +339 -104
- package/src/dev/remote.tsx +36 -3
- package/src/dev/start-server.ts +146 -101
- package/src/dev/use-esbuild.ts +82 -56
- package/src/dev/validate-dev-props.ts +9 -0
- package/src/{dev-registry.tsx → dev-registry.ts} +13 -1
- package/src/dev.tsx +202 -125
- package/src/dialogs.ts +136 -0
- package/src/dispatch-namespace.ts +21 -17
- package/src/docs/helpers.ts +50 -0
- package/src/docs/index.ts +54 -0
- package/src/entry.ts +26 -11
- package/src/environment-variables/factory.ts +89 -0
- package/src/environment-variables/misc-variables.ts +30 -0
- package/src/generate/index.ts +303 -0
- package/src/git-client.ts +15 -4
- package/src/{index.tsx → index.ts} +148 -63
- package/src/init.ts +301 -197
- package/src/inspect.ts +122 -6
- package/src/jest.d.ts +4 -0
- package/src/kv/helpers.ts +7 -4
- package/src/kv/index.ts +15 -17
- package/src/logger.ts +36 -5
- package/src/metrics/metrics-config.ts +3 -3
- package/src/metrics/send-event.ts +6 -1
- package/src/miniflare-cli/assets.ts +64 -28
- package/src/miniflare-cli/index.ts +6 -9
- 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 +92 -26
- package/src/mtls-certificate/cli.ts +155 -0
- package/src/pages/build.ts +423 -0
- package/src/pages/buildFunctions.ts +140 -0
- package/src/pages/deployment-tails.ts +281 -0
- package/src/pages/deployments.tsx +11 -33
- package/src/pages/{dev.tsx → dev.ts} +192 -126
- package/src/pages/errors.ts +1 -0
- package/src/pages/functions/buildPlugin.ts +73 -69
- package/src/pages/functions/buildWorker.ts +342 -117
- package/src/pages/functions/tsconfig.json +8 -0
- package/src/pages/functions/tsconfig.tsbuildinfo +1 -0
- package/src/pages/{functions.tsx → functions.ts} +8 -4
- package/src/pages/{index.tsx → index.ts} +11 -3
- package/src/pages/projects.tsx +12 -22
- package/src/pages/prompt-select-project.tsx +31 -0
- package/src/pages/publish.tsx +45 -214
- package/src/pages/types.ts +6 -9
- package/src/pages/upload.tsx +58 -14
- package/src/pages/utils.ts +14 -3
- package/src/parse.ts +23 -1
- package/src/paths.ts +1 -1
- package/src/proxy.ts +5 -0
- package/src/publish/index.ts +20 -16
- package/src/publish/publish.ts +81 -48
- package/src/pubsub/{pubsub-commands.tsx → pubsub-commands.ts} +19 -20
- package/src/queues/cli/commands/consumer/add.ts +24 -24
- package/src/queues/cli/commands/consumer/index.ts +3 -6
- package/src/queues/cli/commands/consumer/remove.ts +11 -18
- package/src/queues/cli/commands/create.ts +8 -8
- package/src/queues/cli/commands/delete.ts +8 -8
- package/src/queues/cli/commands/index.ts +6 -4
- package/src/queues/cli/commands/list.ts +8 -8
- package/src/queues/client.ts +1 -0
- package/src/queues/utils.ts +18 -0
- package/src/r2/constants.ts +4 -0
- package/src/r2/helpers.ts +1 -0
- package/src/r2/index.ts +40 -28
- package/src/secret/index.ts +18 -17
- package/src/{sites.tsx → sites.ts} +165 -53
- package/src/tail/createTail.ts +103 -3
- package/src/tail/filters.ts +1 -1
- package/src/tail/index.ts +8 -11
- package/src/tail/printing.ts +27 -0
- package/src/traverse-module-graph.ts +54 -0
- package/src/tsconfig-sanity.ts +16 -0
- package/src/type-generation.ts +85 -57
- package/src/user/access.ts +0 -1
- package/src/user/auth-variables.ts +113 -0
- package/src/user/choose-account.tsx +1 -31
- package/src/user/index.ts +0 -1
- package/src/user/{user.tsx → user.ts} +124 -82
- package/src/utils/render.ts +93 -0
- package/src/{whoami.tsx → whoami.ts} +37 -71
- package/src/worker.ts +61 -3
- package/src/yargs-types.ts +22 -5
- package/templates/__tests__/tsconfig-sanity.ts +12 -0
- package/templates/__tests__/tsconfig.json +8 -0
- package/templates/__tests__/tsconfig.tsbuildinfo +1 -0
- package/templates/checked-fetch.js +9 -3
- package/templates/d1-beta-facade.js +95 -25
- package/templates/facade.d.ts +14 -0
- package/templates/first-party-worker-module-facade.ts +4 -3
- package/templates/format-dev-errors.ts +8 -6
- package/templates/gitignore +1 -0
- package/templates/init-tests/test-jest-new-worker.js +3 -5
- package/templates/init-tests/test-vitest-new-worker.js +3 -5
- package/templates/init-tests/test-vitest-new-worker.ts +25 -0
- package/templates/middleware/loader-modules.ts +2 -2
- package/templates/middleware/loader-sw.ts +51 -31
- package/templates/middleware/middleware-miniflare3-json-error.ts +32 -0
- package/templates/new-worker.ts +3 -0
- package/templates/pages-dev-pipeline.ts +4 -1
- package/templates/pages-dev-util.ts +4 -1
- package/templates/pages-shim.ts +4 -1
- package/templates/pages-template-plugin.ts +19 -10
- package/templates/serve-static-assets.ts +17 -14
- package/templates/service-bindings-module-facade.js +1 -0
- package/templates/tsconfig-sanity.ts +11 -0
- package/templates/tsconfig.init.json +105 -0
- package/templates/tsconfig.json +5 -103
- package/templates/tsconfig.tsbuildinfo +1 -0
- package/wrangler-dist/cli.d.ts +902 -77
- package/wrangler-dist/cli.js +131685 -140615
- package/wrangler-dist/wasm-sync.wasm +0 -0
- package/src/__tests__/api-devregistry.test.js +0 -57
- package/src/__tests__/d1.test.ts +0 -72
- package/src/__tests__/dialogs.test.tsx +0 -40
- package/src/__tests__/helpers/mock-cfetch.ts +0 -333
- package/src/__tests__/pages.test.ts +0 -2223
- package/src/d1/types.tsx +0 -14
- package/src/dialogs.tsx +0 -163
- package/src/environment-variables.ts +0 -50
- package/src/pages/build.tsx +0 -238
- package/src/user/env-vars.ts +0 -46
- package/templates/experimental-local-cache-stubs.js +0 -27
- /package/src/{bundle-reporter.tsx → bundle-reporter.ts} +0 -0
- /package/src/dev/{get-local-persistence-path.tsx → get-local-persistence-path.ts} +0 -0
- /package/src/pages/{hash.tsx → hash.ts} +0 -0
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
2
|
import getPort from "get-port";
|
|
3
|
+
import { rest } from "msw";
|
|
3
4
|
import patchConsole from "patch-console";
|
|
4
5
|
import dedent from "ts-dedent";
|
|
5
6
|
import Dev from "../dev/dev";
|
|
7
|
+
import { CI } from "../is-ci";
|
|
6
8
|
import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
|
|
7
|
-
import { setMockResponse, unsetAllMocks } from "./helpers/mock-cfetch";
|
|
8
9
|
import { mockConsoleMethods } from "./helpers/mock-console";
|
|
9
10
|
import {
|
|
10
11
|
msw,
|
|
@@ -32,7 +33,23 @@ describe("wrangler dev", () => {
|
|
|
32
33
|
afterEach(() => {
|
|
33
34
|
(Dev as jest.Mock).mockClear();
|
|
34
35
|
patchConsole(() => {});
|
|
35
|
-
|
|
36
|
+
msw.resetHandlers();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe("authorization", () => {
|
|
40
|
+
mockApiToken({ apiToken: null });
|
|
41
|
+
const isCISpy = jest.spyOn(CI, "isCI").mockReturnValue(true);
|
|
42
|
+
|
|
43
|
+
it("should kick you to the login flow when running wrangler dev in remote mode without authorization", async () => {
|
|
44
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
45
|
+
await expect(
|
|
46
|
+
runWrangler("dev index.js")
|
|
47
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
48
|
+
`"You must be logged in to use wrangler dev in remote mode. Try logging in, or run wrangler dev --local."`
|
|
49
|
+
);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
isCISpy.mockClear();
|
|
36
53
|
});
|
|
37
54
|
|
|
38
55
|
describe("compatibility-date", () => {
|
|
@@ -119,7 +136,7 @@ describe("wrangler dev", () => {
|
|
|
119
136
|
|
|
120
137
|
expect(std.out).toMatchInlineSnapshot(`
|
|
121
138
|
"
|
|
122
|
-
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/
|
|
139
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose[0m"
|
|
123
140
|
`);
|
|
124
141
|
expect(std.err).toMatchInlineSnapshot(`
|
|
125
142
|
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mMissing entry-point: The entry-point should be specified via the command line (e.g. \`wrangler dev path/to/script\`) or the \`main\` config field.[0m
|
|
@@ -422,16 +439,44 @@ describe("wrangler dev", () => {
|
|
|
422
439
|
main: "index.js",
|
|
423
440
|
});
|
|
424
441
|
fs.writeFileSync("index.js", `export default {};`);
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
442
|
+
|
|
443
|
+
msw.use(
|
|
444
|
+
rest.get("*/zones", (req, res, ctx) => {
|
|
445
|
+
let zone: [] | [{ id: "some-zone-id" }] = [];
|
|
446
|
+
if (
|
|
447
|
+
req.url.searchParams.get("name") === "111.222.333.some-host.com"
|
|
448
|
+
) {
|
|
449
|
+
zone = [];
|
|
450
|
+
} else if (
|
|
451
|
+
req.url.searchParams.get("name") === "222.333.some-host.com"
|
|
452
|
+
) {
|
|
453
|
+
zone = [];
|
|
454
|
+
} else if (req.url.searchParams.get("name") === "333.some-host.com") {
|
|
455
|
+
zone = [{ id: "some-zone-id" }];
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
return res(
|
|
459
|
+
ctx.status(200),
|
|
460
|
+
ctx.json({
|
|
461
|
+
success: true,
|
|
462
|
+
errors: [],
|
|
463
|
+
messages: [],
|
|
464
|
+
result: zone,
|
|
465
|
+
})
|
|
466
|
+
);
|
|
433
467
|
})
|
|
434
468
|
);
|
|
469
|
+
|
|
470
|
+
await runWrangler("dev --host 111.222.333.some-host.com");
|
|
471
|
+
|
|
472
|
+
const devMockCall = (Dev as jest.Mock).mock.calls[0][0];
|
|
473
|
+
|
|
474
|
+
expect(devMockCall).toHaveProperty("host", "111.222.333.some-host.com");
|
|
475
|
+
expect(devMockCall).toHaveProperty(
|
|
476
|
+
"localUpstream",
|
|
477
|
+
"111.222.333.some-host.com"
|
|
478
|
+
);
|
|
479
|
+
expect(devMockCall).toHaveProperty("zone", "some-zone-id");
|
|
435
480
|
});
|
|
436
481
|
|
|
437
482
|
it("should, in order, use args.host/config.dev.host/args.routes/(config.route|config.routes)", async () => {
|
|
@@ -590,7 +635,7 @@ describe("wrangler dev", () => {
|
|
|
590
635
|
it("should run a custom build before starting `dev`", async () => {
|
|
591
636
|
writeWranglerToml({
|
|
592
637
|
build: {
|
|
593
|
-
command: `node -e "
|
|
638
|
+
command: `node -e "4+4; require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')"`,
|
|
594
639
|
},
|
|
595
640
|
});
|
|
596
641
|
|
|
@@ -603,12 +648,12 @@ describe("wrangler dev", () => {
|
|
|
603
648
|
// and the command would pass through
|
|
604
649
|
expect((Dev as jest.Mock).mock.calls[0][0].build).toEqual({
|
|
605
650
|
command:
|
|
606
|
-
"node -e \"
|
|
651
|
+
"node -e \"4+4; require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')\"",
|
|
607
652
|
cwd: undefined,
|
|
608
653
|
watch_dir: "src",
|
|
609
654
|
});
|
|
610
655
|
expect(std.out).toMatchInlineSnapshot(
|
|
611
|
-
`"Running custom build: node -e \\"
|
|
656
|
+
`"Running custom build: node -e \\"4+4; require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')\\""`
|
|
612
657
|
);
|
|
613
658
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
614
659
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
@@ -618,7 +663,7 @@ describe("wrangler dev", () => {
|
|
|
618
663
|
it("should run a custom build of multiple steps combined by && before starting `dev`", async () => {
|
|
619
664
|
writeWranglerToml({
|
|
620
665
|
build: {
|
|
621
|
-
command: `echo "
|
|
666
|
+
command: `echo "export default { fetch(){ return new Response(123) } }" > index.js`,
|
|
622
667
|
},
|
|
623
668
|
});
|
|
624
669
|
|
|
@@ -630,7 +675,7 @@ describe("wrangler dev", () => {
|
|
|
630
675
|
`);
|
|
631
676
|
|
|
632
677
|
expect(std.out).toMatchInlineSnapshot(
|
|
633
|
-
`"Running custom build: echo \\"
|
|
678
|
+
`"Running custom build: echo \\"export default { fetch(){ return new Response(123) } }\\" > index.js"`
|
|
634
679
|
);
|
|
635
680
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
636
681
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
@@ -641,27 +686,27 @@ describe("wrangler dev", () => {
|
|
|
641
686
|
writeWranglerToml({
|
|
642
687
|
main: "index.js",
|
|
643
688
|
build: {
|
|
644
|
-
command: `node -e "
|
|
689
|
+
command: `node -e "4+4;"`,
|
|
645
690
|
},
|
|
646
691
|
});
|
|
647
692
|
|
|
648
693
|
await expect(runWrangler("dev")).rejects
|
|
649
694
|
.toThrowErrorMatchingInlineSnapshot(`
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
695
|
+
"The expected output file at \\"index.js\\" was not found after running custom build: node -e \\"4+4;\\".
|
|
696
|
+
The \`main\` property in wrangler.toml should point to the file generated by the custom build."
|
|
697
|
+
`);
|
|
653
698
|
expect(std.out).toMatchInlineSnapshot(`
|
|
654
|
-
|
|
699
|
+
"Running custom build: node -e \\"4+4;\\"
|
|
655
700
|
|
|
656
|
-
|
|
657
|
-
|
|
701
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose[0m"
|
|
702
|
+
`);
|
|
658
703
|
expect(std.err).toMatchInlineSnapshot(`
|
|
659
|
-
|
|
704
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mThe expected output file at \\"index.js\\" was not found after running custom build: node -e \\"4+4;\\".[0m
|
|
660
705
|
|
|
661
|
-
|
|
706
|
+
The \`main\` property in wrangler.toml should point to the file generated by the custom build.
|
|
662
707
|
|
|
663
|
-
|
|
664
|
-
|
|
708
|
+
"
|
|
709
|
+
`);
|
|
665
710
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
666
711
|
});
|
|
667
712
|
|
|
@@ -729,7 +774,7 @@ describe("wrangler dev", () => {
|
|
|
729
774
|
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mSetting upstream-protocol to http is not currently implemented.[0m
|
|
730
775
|
|
|
731
776
|
If this is required in your project, please add your use case to the following issue:
|
|
732
|
-
[4mhttps://github.com/cloudflare/
|
|
777
|
+
[4mhttps://github.com/cloudflare/workers-sdk/issues/583[0m.
|
|
733
778
|
|
|
734
779
|
"
|
|
735
780
|
`);
|
|
@@ -792,7 +837,7 @@ describe("wrangler dev", () => {
|
|
|
792
837
|
});
|
|
793
838
|
fs.writeFileSync("index.js", `export default {};`);
|
|
794
839
|
await runWrangler("dev");
|
|
795
|
-
expect((Dev as jest.Mock).mock.calls[0][0].
|
|
840
|
+
expect((Dev as jest.Mock).mock.calls[0][0].initialIp).toEqual("0.0.0.0");
|
|
796
841
|
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
797
842
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
798
843
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
@@ -807,7 +852,7 @@ describe("wrangler dev", () => {
|
|
|
807
852
|
});
|
|
808
853
|
fs.writeFileSync("index.js", `export default {};`);
|
|
809
854
|
await runWrangler("dev");
|
|
810
|
-
expect((Dev as jest.Mock).mock.calls[0][0].
|
|
855
|
+
expect((Dev as jest.Mock).mock.calls[0][0].initialIp).toEqual("1.2.3.4");
|
|
811
856
|
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
812
857
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
813
858
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
@@ -822,7 +867,7 @@ describe("wrangler dev", () => {
|
|
|
822
867
|
});
|
|
823
868
|
fs.writeFileSync("index.js", `export default {};`);
|
|
824
869
|
await runWrangler("dev --ip=5.6.7.8");
|
|
825
|
-
expect((Dev as jest.Mock).mock.calls[0][0].
|
|
870
|
+
expect((Dev as jest.Mock).mock.calls[0][0].initialIp).toEqual("5.6.7.8");
|
|
826
871
|
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
827
872
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
828
873
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
@@ -830,6 +875,32 @@ describe("wrangler dev", () => {
|
|
|
830
875
|
});
|
|
831
876
|
|
|
832
877
|
describe("inspector port", () => {
|
|
878
|
+
it("should connect WebSocket server with --experimental-local", async () => {
|
|
879
|
+
writeWranglerToml({
|
|
880
|
+
main: "./index.js",
|
|
881
|
+
});
|
|
882
|
+
fs.writeFileSync(
|
|
883
|
+
"index.js",
|
|
884
|
+
`export default {
|
|
885
|
+
async fetch(request, env, ctx ){
|
|
886
|
+
console.log('Hello World LOGGING');
|
|
887
|
+
},
|
|
888
|
+
};`
|
|
889
|
+
);
|
|
890
|
+
await runWrangler("dev --experimental-local");
|
|
891
|
+
|
|
892
|
+
expect((Dev as jest.Mock).mock.calls[0][0].inspectorPort).toEqual(9229);
|
|
893
|
+
expect(std).toMatchInlineSnapshot(`
|
|
894
|
+
Object {
|
|
895
|
+
"debug": "",
|
|
896
|
+
"err": "",
|
|
897
|
+
"info": "",
|
|
898
|
+
"out": "",
|
|
899
|
+
"warn": "",
|
|
900
|
+
}
|
|
901
|
+
`);
|
|
902
|
+
});
|
|
903
|
+
|
|
833
904
|
it("should use 9229 as the default port", async () => {
|
|
834
905
|
writeWranglerToml({
|
|
835
906
|
main: "index.js",
|
|
@@ -841,6 +912,7 @@ describe("wrangler dev", () => {
|
|
|
841
912
|
Object {
|
|
842
913
|
"debug": "",
|
|
843
914
|
"err": "",
|
|
915
|
+
"info": "",
|
|
844
916
|
"out": "",
|
|
845
917
|
"warn": "",
|
|
846
918
|
}
|
|
@@ -858,6 +930,7 @@ describe("wrangler dev", () => {
|
|
|
858
930
|
Object {
|
|
859
931
|
"debug": "",
|
|
860
932
|
"err": "",
|
|
933
|
+
"info": "",
|
|
861
934
|
"out": "",
|
|
862
935
|
"warn": "",
|
|
863
936
|
}
|
|
@@ -878,6 +951,7 @@ describe("wrangler dev", () => {
|
|
|
878
951
|
Object {
|
|
879
952
|
"debug": "",
|
|
880
953
|
"err": "",
|
|
954
|
+
"info": "",
|
|
881
955
|
"out": "",
|
|
882
956
|
"warn": "",
|
|
883
957
|
}
|
|
@@ -908,7 +982,7 @@ describe("wrangler dev", () => {
|
|
|
908
982
|
});
|
|
909
983
|
fs.writeFileSync("index.js", `export default {};`);
|
|
910
984
|
await runWrangler("dev");
|
|
911
|
-
expect((Dev as jest.Mock).mock.calls[0][0].
|
|
985
|
+
expect((Dev as jest.Mock).mock.calls[0][0].initialPort).toEqual(8787);
|
|
912
986
|
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
913
987
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
914
988
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
@@ -926,7 +1000,7 @@ describe("wrangler dev", () => {
|
|
|
926
1000
|
(getPort as jest.Mock).mockResolvedValue(98765);
|
|
927
1001
|
|
|
928
1002
|
await runWrangler("dev");
|
|
929
|
-
expect((Dev as jest.Mock).mock.calls[0][0].
|
|
1003
|
+
expect((Dev as jest.Mock).mock.calls[0][0].initialPort).toEqual(8888);
|
|
930
1004
|
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
931
1005
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
932
1006
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
@@ -960,7 +1034,7 @@ describe("wrangler dev", () => {
|
|
|
960
1034
|
(getPort as jest.Mock).mockResolvedValue(98765);
|
|
961
1035
|
|
|
962
1036
|
await runWrangler("dev --port=9999");
|
|
963
|
-
expect((Dev as jest.Mock).mock.calls[0][0].
|
|
1037
|
+
expect((Dev as jest.Mock).mock.calls[0][0].initialPort).toEqual(9999);
|
|
964
1038
|
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
965
1039
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
966
1040
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
@@ -975,7 +1049,7 @@ describe("wrangler dev", () => {
|
|
|
975
1049
|
(getPort as jest.Mock).mockResolvedValue(98765);
|
|
976
1050
|
|
|
977
1051
|
await runWrangler("dev");
|
|
978
|
-
expect((Dev as jest.Mock).mock.calls[0][0].
|
|
1052
|
+
expect((Dev as jest.Mock).mock.calls[0][0].initialPort).toEqual(98765);
|
|
979
1053
|
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
980
1054
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
981
1055
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
@@ -1005,7 +1079,7 @@ describe("wrangler dev", () => {
|
|
|
1005
1079
|
});
|
|
1006
1080
|
fs.writeFileSync("index.js", `export default {};`);
|
|
1007
1081
|
await runWrangler("dev");
|
|
1008
|
-
expect((Dev as jest.Mock).mock.calls[0][0].
|
|
1082
|
+
expect((Dev as jest.Mock).mock.calls[0][0].initialIp).toEqual("0.0.0.0");
|
|
1009
1083
|
expect(std.out).toMatchInlineSnapshot(`
|
|
1010
1084
|
"Your worker has access to the following bindings:
|
|
1011
1085
|
- Durable Objects:
|
|
@@ -1139,6 +1213,7 @@ describe("wrangler dev", () => {
|
|
|
1139
1213
|
"err": "[31mX [41;31m[[41;97mERROR[41;31m][0m [1mNot enough arguments following: site[0m
|
|
1140
1214
|
|
|
1141
1215
|
",
|
|
1216
|
+
"info": "",
|
|
1142
1217
|
"out": "
|
|
1143
1218
|
wrangler dev [script]
|
|
1144
1219
|
|
|
@@ -1148,10 +1223,11 @@ describe("wrangler dev", () => {
|
|
|
1148
1223
|
script The path to an entry point for your worker [string]
|
|
1149
1224
|
|
|
1150
1225
|
Flags:
|
|
1151
|
-
-
|
|
1152
|
-
-
|
|
1153
|
-
-
|
|
1154
|
-
-
|
|
1226
|
+
-j, --experimental-json-config Experimental: Support wrangler.json [boolean]
|
|
1227
|
+
-c, --config Path to .toml configuration file [string]
|
|
1228
|
+
-e, --env Environment to use for operations and .env files [string]
|
|
1229
|
+
-h, --help Show help [boolean]
|
|
1230
|
+
-v, --version Show version number [boolean]
|
|
1155
1231
|
|
|
1156
1232
|
Options:
|
|
1157
1233
|
--name Name of the worker [string]
|
|
@@ -1178,10 +1254,12 @@ describe("wrangler dev", () => {
|
|
|
1178
1254
|
--tsconfig Path to a custom tsconfig.json file [string]
|
|
1179
1255
|
-l, --local Run on my machine [boolean] [default: false]
|
|
1180
1256
|
--experimental-local Run on my machine using the Cloudflare Workers runtime [boolean] [default: false]
|
|
1257
|
+
--experimental-local-remote-kv Read/write KV data from/to real namespaces on the Cloudflare network [boolean] [default: false]
|
|
1181
1258
|
--minify Minify the script [boolean]
|
|
1182
|
-
--node-compat Enable
|
|
1259
|
+
--node-compat Enable Node.js compatibility [boolean]
|
|
1183
1260
|
--persist Enable persistence for local mode, using default path: .wrangler/state [boolean]
|
|
1184
1261
|
--persist-to Specify directory to use for local persistence (implies --persist) [string]
|
|
1262
|
+
--live-reload Auto reload HTML pages when change is detected in local mode [boolean]
|
|
1185
1263
|
--test-scheduled Test scheduled events by visiting /__scheduled in browser [boolean] [default: false]
|
|
1186
1264
|
--log-level Specify logging level [choices: \\"debug\\", \\"info\\", \\"log\\", \\"warn\\", \\"error\\", \\"none\\"] [default: \\"log\\"]",
|
|
1187
1265
|
"warn": "",
|
|
@@ -1270,15 +1348,16 @@ describe("wrangler dev", () => {
|
|
|
1270
1348
|
|
|
1271
1349
|
await runWrangler('dev --assets "./assets"');
|
|
1272
1350
|
expect(std).toMatchInlineSnapshot(`
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1351
|
+
Object {
|
|
1352
|
+
"debug": "",
|
|
1353
|
+
"err": "",
|
|
1354
|
+
"info": "",
|
|
1355
|
+
"out": "",
|
|
1356
|
+
"warn": "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mThe --assets argument is experimental and may change or break at any time[0m
|
|
1357
|
+
|
|
1358
|
+
",
|
|
1359
|
+
}
|
|
1360
|
+
`);
|
|
1282
1361
|
});
|
|
1283
1362
|
|
|
1284
1363
|
it("should warn if config.assets is used", async () => {
|
|
@@ -1291,17 +1370,18 @@ describe("wrangler dev", () => {
|
|
|
1291
1370
|
|
|
1292
1371
|
await runWrangler("dev");
|
|
1293
1372
|
expect(std).toMatchInlineSnapshot(`
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1373
|
+
Object {
|
|
1374
|
+
"debug": "",
|
|
1375
|
+
"err": "",
|
|
1376
|
+
"info": "",
|
|
1377
|
+
"out": "",
|
|
1378
|
+
"warn": "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mProcessing wrangler.toml configuration:[0m
|
|
1299
1379
|
|
|
1300
|
-
|
|
1380
|
+
- \\"assets\\" fields are experimental and may change or break at any time.
|
|
1301
1381
|
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1382
|
+
",
|
|
1383
|
+
}
|
|
1384
|
+
`);
|
|
1305
1385
|
});
|
|
1306
1386
|
});
|
|
1307
1387
|
|
|
@@ -1310,15 +1390,16 @@ describe("wrangler dev", () => {
|
|
|
1310
1390
|
fs.writeFileSync("index.js", `export default {};`);
|
|
1311
1391
|
await runWrangler("dev index.js --inspect");
|
|
1312
1392
|
expect(std).toMatchInlineSnapshot(`
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1393
|
+
Object {
|
|
1394
|
+
"debug": "",
|
|
1395
|
+
"err": "",
|
|
1396
|
+
"info": "",
|
|
1397
|
+
"out": "",
|
|
1398
|
+
"warn": "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mPassing --inspect is unnecessary, now you can always connect to devtools.[0m
|
|
1399
|
+
|
|
1400
|
+
",
|
|
1401
|
+
}
|
|
1402
|
+
`);
|
|
1322
1403
|
});
|
|
1323
1404
|
|
|
1324
1405
|
it("should default to true, without a warning", async () => {
|
|
@@ -1329,6 +1410,7 @@ describe("wrangler dev", () => {
|
|
|
1329
1410
|
Object {
|
|
1330
1411
|
"debug": "",
|
|
1331
1412
|
"err": "",
|
|
1413
|
+
"info": "",
|
|
1332
1414
|
"out": "",
|
|
1333
1415
|
"warn": "",
|
|
1334
1416
|
}
|
|
@@ -1343,6 +1425,7 @@ describe("wrangler dev", () => {
|
|
|
1343
1425
|
Object {
|
|
1344
1426
|
"debug": "",
|
|
1345
1427
|
"err": "",
|
|
1428
|
+
"info": "",
|
|
1346
1429
|
"out": "",
|
|
1347
1430
|
"warn": "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mPassing --inspect is unnecessary, now you can always connect to devtools.[0m
|
|
1348
1431
|
|
|
@@ -1359,6 +1442,7 @@ describe("wrangler dev", () => {
|
|
|
1359
1442
|
Object {
|
|
1360
1443
|
"debug": "",
|
|
1361
1444
|
"err": "",
|
|
1445
|
+
"info": "",
|
|
1362
1446
|
"out": "",
|
|
1363
1447
|
"warn": "",
|
|
1364
1448
|
}
|
|
@@ -1374,6 +1458,7 @@ describe("wrangler dev", () => {
|
|
|
1374
1458
|
Object {
|
|
1375
1459
|
"debug": "",
|
|
1376
1460
|
"err": "",
|
|
1461
|
+
"info": "",
|
|
1377
1462
|
"out": "",
|
|
1378
1463
|
"warn": "",
|
|
1379
1464
|
}
|
|
@@ -1387,6 +1472,7 @@ describe("wrangler dev", () => {
|
|
|
1387
1472
|
Object {
|
|
1388
1473
|
"debug": "",
|
|
1389
1474
|
"err": "",
|
|
1475
|
+
"info": "",
|
|
1390
1476
|
"out": "",
|
|
1391
1477
|
"warn": "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mPassing --inspect is unnecessary, now you can always connect to devtools.[0m
|
|
1392
1478
|
|
|
@@ -1443,23 +1529,24 @@ describe("wrangler dev", () => {
|
|
|
1443
1529
|
fs.writeFileSync("index.js", `export default {};`);
|
|
1444
1530
|
await runWrangler("dev index.js");
|
|
1445
1531
|
expect(std).toMatchInlineSnapshot(`
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1532
|
+
Object {
|
|
1533
|
+
"debug": "",
|
|
1534
|
+
"err": "",
|
|
1535
|
+
"info": "",
|
|
1536
|
+
"out": "Your worker has access to the following bindings:
|
|
1537
|
+
- Services:
|
|
1538
|
+
- WorkerA: A
|
|
1539
|
+
- WorkerB: B - staging",
|
|
1540
|
+
"warn": "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mProcessing wrangler.toml configuration:[0m
|
|
1454
1541
|
|
|
1455
|
-
|
|
1542
|
+
- \\"services\\" fields are experimental and may change or break at any time.
|
|
1456
1543
|
|
|
1457
1544
|
|
|
1458
|
-
|
|
1545
|
+
[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mThis worker is bound to live services: WorkerA (A), WorkerB (B@staging)[0m
|
|
1459
1546
|
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1547
|
+
",
|
|
1548
|
+
}
|
|
1549
|
+
`);
|
|
1463
1550
|
});
|
|
1464
1551
|
|
|
1465
1552
|
it("should mask vars that were overriden in .dev.vars", async () => {
|
|
@@ -1482,6 +1569,7 @@ describe("wrangler dev", () => {
|
|
|
1482
1569
|
Object {
|
|
1483
1570
|
"debug": "",
|
|
1484
1571
|
"err": "",
|
|
1572
|
+
"info": "",
|
|
1485
1573
|
"out": "Using vars defined in .dev.vars
|
|
1486
1574
|
Your worker has access to the following bindings:
|
|
1487
1575
|
- Vars:
|
|
@@ -1493,17 +1581,37 @@ describe("wrangler dev", () => {
|
|
|
1493
1581
|
`);
|
|
1494
1582
|
});
|
|
1495
1583
|
});
|
|
1584
|
+
|
|
1585
|
+
describe("`nodejs_compat` compatibility flag", () => {
|
|
1586
|
+
it("should conflict with the --node-compat option", async () => {
|
|
1587
|
+
writeWranglerToml();
|
|
1588
|
+
fs.writeFileSync("index.js", `export default {};`);
|
|
1589
|
+
|
|
1590
|
+
await expect(
|
|
1591
|
+
runWrangler(
|
|
1592
|
+
"dev index.js --compatibility-flag=nodejs_compat --node-compat"
|
|
1593
|
+
)
|
|
1594
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
1595
|
+
`"The \`nodejs_compat\` compatibility flag cannot be used in conjunction with the legacy \`--node-compat\` flag. If you want to use the Workers runtime Node.js compatibility features, please remove the \`--node-compat\` argument from your CLI command or \`node_compat = true\` from your config file."`
|
|
1596
|
+
);
|
|
1597
|
+
});
|
|
1598
|
+
});
|
|
1496
1599
|
});
|
|
1497
1600
|
|
|
1498
1601
|
function mockGetZones(domain: string, zones: { id: string }[] = []) {
|
|
1499
|
-
|
|
1500
|
-
"
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1602
|
+
msw.use(
|
|
1603
|
+
rest.get("*/zones", (req, res, ctx) => {
|
|
1604
|
+
expect([...req.url.searchParams.entries()]).toEqual([["name", domain]]);
|
|
1605
|
+
|
|
1606
|
+
return res(
|
|
1607
|
+
ctx.status(200),
|
|
1608
|
+
ctx.json({
|
|
1609
|
+
success: true,
|
|
1610
|
+
errors: [],
|
|
1611
|
+
messages: [],
|
|
1612
|
+
result: zones,
|
|
1613
|
+
})
|
|
1614
|
+
);
|
|
1615
|
+
})
|
|
1508
1616
|
);
|
|
1509
1617
|
}
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { mockConsoleMethods } from "./helpers/mock-console";
|
|
4
|
-
import { mockConfirm
|
|
4
|
+
import { mockConfirm } from "./helpers/mock-dialogs";
|
|
5
|
+
import { useMockIsTTY } from "./helpers/mock-istty";
|
|
5
6
|
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
6
7
|
import { runWrangler } from "./helpers/run-wrangler";
|
|
7
8
|
|
|
8
9
|
describe("generate", () => {
|
|
9
10
|
runInTempDir();
|
|
11
|
+
const { setIsTTY } = useMockIsTTY();
|
|
10
12
|
const std = mockConsoleMethods();
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
setIsTTY(true);
|
|
15
|
+
});
|
|
11
16
|
|
|
12
17
|
describe("cli functionality", () => {
|
|
13
|
-
afterEach(() => {
|
|
14
|
-
clearConfirmMocks();
|
|
15
|
-
});
|
|
18
|
+
afterEach(() => {});
|
|
16
19
|
|
|
17
20
|
it("defers to `wrangler init` when no template is given", async () => {
|
|
18
21
|
mockConfirm(
|
|
@@ -55,7 +58,7 @@ describe("generate", () => {
|
|
|
55
58
|
`);
|
|
56
59
|
});
|
|
57
60
|
|
|
58
|
-
it("auto-increments the worker directory name", async () => {
|
|
61
|
+
it.skip("auto-increments the worker directory name", async () => {
|
|
59
62
|
fs.mkdirSync("my-worker");
|
|
60
63
|
|
|
61
64
|
expect(fs.existsSync("my-worker-1")).toBe(false);
|
|
@@ -113,10 +116,9 @@ describe("generate", () => {
|
|
|
113
116
|
".git": expect.any(Object),
|
|
114
117
|
".gitignore": expect.any(String),
|
|
115
118
|
"README.md": expect.stringContaining("Template: worker-typescript"),
|
|
116
|
-
"jest.config.json": expect.any(String),
|
|
117
119
|
"package.json": expect.stringContaining("@cloudflare/workers-types"),
|
|
118
|
-
src: expect.objectContaining({
|
|
119
|
-
|
|
120
|
+
src: expect.objectContaining({
|
|
121
|
+
"index.ts": expect.any(String),
|
|
120
122
|
"index.test.ts": expect.any(String),
|
|
121
123
|
}),
|
|
122
124
|
"tsconfig.json": expect.any(String),
|
|
@@ -128,7 +130,7 @@ describe("generate", () => {
|
|
|
128
130
|
// was harder than i thought, leaving this for now.
|
|
129
131
|
it.todo("clones a cloudflare template with full checkouts");
|
|
130
132
|
|
|
131
|
-
it("clones a user/repo template", async () => {
|
|
133
|
+
it.skip("clones a user/repo template", async () => {
|
|
132
134
|
await expect(
|
|
133
135
|
runWrangler("generate my-worker caass/wrangler-generate-test-template")
|
|
134
136
|
).resolves.toBeUndefined();
|
|
@@ -143,7 +145,7 @@ describe("generate", () => {
|
|
|
143
145
|
});
|
|
144
146
|
});
|
|
145
147
|
|
|
146
|
-
it("clones a user/repo/path/to/subdirectory template", async () => {
|
|
148
|
+
it.skip("clones a user/repo/path/to/subdirectory template", async () => {
|
|
147
149
|
await expect(
|
|
148
150
|
runWrangler("generate my-worker cloudflare/templates/worker-typescript")
|
|
149
151
|
).resolves.toBeUndefined();
|
|
@@ -32,6 +32,41 @@ describe("guess worker format", () => {
|
|
|
32
32
|
expect(guess).toBe("service-worker");
|
|
33
33
|
});
|
|
34
34
|
|
|
35
|
+
it('should detect a "service-worker" worker using `typeof module`', async () => {
|
|
36
|
+
await writeFile("./index.ts", "typeof module");
|
|
37
|
+
const guess = await guessWorkerFormat(
|
|
38
|
+
path.join(process.cwd(), "./index.ts"),
|
|
39
|
+
process.cwd(),
|
|
40
|
+
undefined
|
|
41
|
+
);
|
|
42
|
+
expect(guess).toBe("service-worker");
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should detect a "service-worker" worker using imports', async () => {
|
|
46
|
+
await writeFile(
|
|
47
|
+
"./dep.ts",
|
|
48
|
+
`
|
|
49
|
+
const value = 'thing';
|
|
50
|
+
export default value;
|
|
51
|
+
`
|
|
52
|
+
);
|
|
53
|
+
await writeFile(
|
|
54
|
+
"./index.ts",
|
|
55
|
+
`
|
|
56
|
+
import value from './dep.ts';
|
|
57
|
+
addEventListener('fetch', (event) => {
|
|
58
|
+
event.respondWith(new Response(value));
|
|
59
|
+
});
|
|
60
|
+
`
|
|
61
|
+
);
|
|
62
|
+
const guess = await guessWorkerFormat(
|
|
63
|
+
path.join(process.cwd(), "./index.ts"),
|
|
64
|
+
process.cwd(),
|
|
65
|
+
undefined
|
|
66
|
+
);
|
|
67
|
+
expect(guess).toBe("service-worker");
|
|
68
|
+
});
|
|
69
|
+
|
|
35
70
|
it("should throw an error when the hint doesn't match the guess (modules - service-worker)", async () => {
|
|
36
71
|
await writeFile("./index.ts", "export default {};");
|
|
37
72
|
await expect(
|