wrangler 2.8.1 → 2.9.1
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/miniflare-dist/index.mjs +1 -14
- package/package.json +2 -2
- package/src/__tests__/d1/d1.test.ts +11 -56
- package/src/__tests__/d1/migrate.test.ts +141 -0
- package/src/__tests__/dev.test.tsx +5 -4
- package/src/__tests__/generate.test.ts +1 -1
- package/src/__tests__/helpers/end-event-loop.ts +6 -0
- package/src/__tests__/helpers/mock-get-pages-upload-token.ts +25 -0
- package/src/__tests__/helpers/mock-set-timeout.ts +16 -0
- package/src/__tests__/index.test.ts +36 -32
- package/src/__tests__/init.test.ts +1 -1
- package/src/__tests__/kv.test.ts +55 -44
- package/src/__tests__/pages/deployment-list.test.ts +78 -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 +108 -0
- package/src/__tests__/pages/project-upload.test.ts +481 -0
- package/src/__tests__/pages/publish.test.ts +2221 -0
- package/src/__tests__/parse.test.ts +106 -0
- package/src/__tests__/pubsub.test.ts +15 -12
- package/src/__tests__/queues.test.ts +35 -28
- package/src/__tests__/r2.test.ts +25 -20
- package/src/__tests__/tsconfig.tsbuildinfo +1 -1
- package/src/__tests__/worker-namespace.test.ts +26 -21
- package/src/api/dev.ts +80 -11
- package/src/api/pages/publish.tsx +7 -4
- package/src/bundle.ts +1 -1
- package/src/config/config.ts +7 -0
- package/src/config/index.ts +24 -20
- package/src/d1/backups.tsx +20 -24
- package/src/d1/create.tsx +6 -5
- package/src/d1/delete.ts +7 -10
- package/src/d1/execute.tsx +83 -85
- package/src/d1/index.ts +5 -6
- package/src/d1/list.tsx +21 -9
- package/src/d1/migrations/apply.tsx +13 -9
- package/src/d1/migrations/create.tsx +9 -10
- package/src/d1/migrations/list.tsx +19 -9
- package/src/d1/migrations/options.ts +2 -2
- package/src/d1/options.ts +3 -3
- package/src/delete.ts +5 -8
- package/src/deprecated/index.ts +7 -8
- package/src/dev.tsx +42 -80
- package/src/dispatch-namespace.ts +20 -16
- package/src/docs/index.ts +7 -8
- package/src/generate/index.ts +5 -7
- package/src/index.ts +22 -21
- package/src/init.ts +5 -7
- package/src/kv/index.ts +15 -17
- package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -1
- package/src/pages/build.ts +6 -4
- package/src/pages/deployment-tails.ts +7 -10
- package/src/pages/deployments.tsx +6 -4
- package/src/pages/dev.ts +15 -17
- package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
- package/src/pages/functions.ts +8 -4
- package/src/pages/index.ts +3 -3
- package/src/pages/projects.tsx +7 -12
- package/src/pages/publish.tsx +6 -4
- package/src/pages/types.ts +5 -0
- package/src/pages/upload.tsx +6 -4
- package/src/parse.ts +23 -1
- package/src/publish/index.ts +19 -15
- package/src/publish/publish.ts +2 -2
- package/src/pubsub/pubsub-commands.ts +18 -19
- package/src/queues/cli/commands/consumer/add.ts +18 -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 +3 -4
- package/src/queues/cli/commands/list.ts +8 -8
- package/src/r2/index.ts +28 -28
- package/src/secret/index.ts +9 -14
- package/src/tail/index.ts +6 -8
- package/src/yargs-types.ts +18 -5
- package/templates/checked-fetch.js +9 -1
- package/templates/tsconfig.init.json +1 -1
- package/templates/tsconfig.tsbuildinfo +1 -1
- package/wrangler-dist/cli.js +2180 -1799
- package/src/__tests__/pages.test.ts +0 -2898
package/src/__tests__/kv.test.ts
CHANGED
|
@@ -63,10 +63,11 @@ describe("wrangler", () => {
|
|
|
63
63
|
namespace The name of the new namespace [string] [required]
|
|
64
64
|
|
|
65
65
|
Flags:
|
|
66
|
-
-
|
|
67
|
-
-
|
|
68
|
-
-
|
|
69
|
-
-
|
|
66
|
+
-j, --experimental-json-config Experimental: Support wrangler.json [boolean]
|
|
67
|
+
-c, --config Path to .toml configuration file [string]
|
|
68
|
+
-e, --env Environment to use for operations and .env files [string]
|
|
69
|
+
-h, --help Show help [boolean]
|
|
70
|
+
-v, --version Show version number [boolean]
|
|
70
71
|
|
|
71
72
|
Options:
|
|
72
73
|
--preview Interact with a preview namespace [boolean]"
|
|
@@ -94,10 +95,11 @@ describe("wrangler", () => {
|
|
|
94
95
|
namespace The name of the new namespace [string] [required]
|
|
95
96
|
|
|
96
97
|
Flags:
|
|
97
|
-
-
|
|
98
|
-
-
|
|
99
|
-
-
|
|
100
|
-
-
|
|
98
|
+
-j, --experimental-json-config Experimental: Support wrangler.json [boolean]
|
|
99
|
+
-c, --config Path to .toml configuration file [string]
|
|
100
|
+
-e, --env Environment to use for operations and .env files [string]
|
|
101
|
+
-h, --help Show help [boolean]
|
|
102
|
+
-v, --version Show version number [boolean]
|
|
101
103
|
|
|
102
104
|
Options:
|
|
103
105
|
--preview Interact with a preview namespace [boolean]"
|
|
@@ -126,10 +128,11 @@ describe("wrangler", () => {
|
|
|
126
128
|
namespace The name of the new namespace [string] [required]
|
|
127
129
|
|
|
128
130
|
Flags:
|
|
129
|
-
-
|
|
130
|
-
-
|
|
131
|
-
-
|
|
132
|
-
-
|
|
131
|
+
-j, --experimental-json-config Experimental: Support wrangler.json [boolean]
|
|
132
|
+
-c, --config Path to .toml configuration file [string]
|
|
133
|
+
-e, --env Environment to use for operations and .env files [string]
|
|
134
|
+
-h, --help Show help [boolean]
|
|
135
|
+
-v, --version Show version number [boolean]
|
|
133
136
|
|
|
134
137
|
Options:
|
|
135
138
|
--preview Interact with a preview namespace [boolean]"
|
|
@@ -552,10 +555,11 @@ describe("wrangler", () => {
|
|
|
552
555
|
value The value to write [string]
|
|
553
556
|
|
|
554
557
|
Flags:
|
|
555
|
-
-
|
|
556
|
-
-
|
|
557
|
-
-
|
|
558
|
-
-
|
|
558
|
+
-j, --experimental-json-config Experimental: Support wrangler.json [boolean]
|
|
559
|
+
-c, --config Path to .toml configuration file [string]
|
|
560
|
+
-e, --env Environment to use for operations and .env files [string]
|
|
561
|
+
-h, --help Show help [boolean]
|
|
562
|
+
-v, --version Show version number [boolean]
|
|
559
563
|
|
|
560
564
|
Options:
|
|
561
565
|
--binding The binding of the namespace to write to [string]
|
|
@@ -591,10 +595,11 @@ describe("wrangler", () => {
|
|
|
591
595
|
value The value to write [string]
|
|
592
596
|
|
|
593
597
|
Flags:
|
|
594
|
-
-
|
|
595
|
-
-
|
|
596
|
-
-
|
|
597
|
-
-
|
|
598
|
+
-j, --experimental-json-config Experimental: Support wrangler.json [boolean]
|
|
599
|
+
-c, --config Path to .toml configuration file [string]
|
|
600
|
+
-e, --env Environment to use for operations and .env files [string]
|
|
601
|
+
-h, --help Show help [boolean]
|
|
602
|
+
-v, --version Show version number [boolean]
|
|
598
603
|
|
|
599
604
|
Options:
|
|
600
605
|
--binding The binding of the namespace to write to [string]
|
|
@@ -630,10 +635,11 @@ describe("wrangler", () => {
|
|
|
630
635
|
value The value to write [string]
|
|
631
636
|
|
|
632
637
|
Flags:
|
|
633
|
-
-
|
|
634
|
-
-
|
|
635
|
-
-
|
|
636
|
-
-
|
|
638
|
+
-j, --experimental-json-config Experimental: Support wrangler.json [boolean]
|
|
639
|
+
-c, --config Path to .toml configuration file [string]
|
|
640
|
+
-e, --env Environment to use for operations and .env files [string]
|
|
641
|
+
-h, --help Show help [boolean]
|
|
642
|
+
-v, --version Show version number [boolean]
|
|
637
643
|
|
|
638
644
|
Options:
|
|
639
645
|
--binding The binding of the namespace to write to [string]
|
|
@@ -669,10 +675,11 @@ describe("wrangler", () => {
|
|
|
669
675
|
value The value to write [string]
|
|
670
676
|
|
|
671
677
|
Flags:
|
|
672
|
-
-
|
|
673
|
-
-
|
|
674
|
-
-
|
|
675
|
-
-
|
|
678
|
+
-j, --experimental-json-config Experimental: Support wrangler.json [boolean]
|
|
679
|
+
-c, --config Path to .toml configuration file [string]
|
|
680
|
+
-e, --env Environment to use for operations and .env files [string]
|
|
681
|
+
-h, --help Show help [boolean]
|
|
682
|
+
-v, --version Show version number [boolean]
|
|
676
683
|
|
|
677
684
|
Options:
|
|
678
685
|
--binding The binding of the namespace to write to [string]
|
|
@@ -708,10 +715,11 @@ describe("wrangler", () => {
|
|
|
708
715
|
value The value to write [string]
|
|
709
716
|
|
|
710
717
|
Flags:
|
|
711
|
-
-
|
|
712
|
-
-
|
|
713
|
-
-
|
|
714
|
-
-
|
|
718
|
+
-j, --experimental-json-config Experimental: Support wrangler.json [boolean]
|
|
719
|
+
-c, --config Path to .toml configuration file [string]
|
|
720
|
+
-e, --env Environment to use for operations and .env files [string]
|
|
721
|
+
-h, --help Show help [boolean]
|
|
722
|
+
-v, --version Show version number [boolean]
|
|
715
723
|
|
|
716
724
|
Options:
|
|
717
725
|
--binding The binding of the namespace to write to [string]
|
|
@@ -1083,10 +1091,11 @@ describe("wrangler", () => {
|
|
|
1083
1091
|
key The key value to get. [string] [required]
|
|
1084
1092
|
|
|
1085
1093
|
Flags:
|
|
1086
|
-
-
|
|
1087
|
-
-
|
|
1088
|
-
-
|
|
1089
|
-
-
|
|
1094
|
+
-j, --experimental-json-config Experimental: Support wrangler.json [boolean]
|
|
1095
|
+
-c, --config Path to .toml configuration file [string]
|
|
1096
|
+
-e, --env Environment to use for operations and .env files [string]
|
|
1097
|
+
-h, --help Show help [boolean]
|
|
1098
|
+
-v, --version Show version number [boolean]
|
|
1090
1099
|
|
|
1091
1100
|
Options:
|
|
1092
1101
|
--binding The name of the namespace to get from [string]
|
|
@@ -1117,10 +1126,11 @@ describe("wrangler", () => {
|
|
|
1117
1126
|
key The key value to get. [string] [required]
|
|
1118
1127
|
|
|
1119
1128
|
Flags:
|
|
1120
|
-
-
|
|
1121
|
-
-
|
|
1122
|
-
-
|
|
1123
|
-
-
|
|
1129
|
+
-j, --experimental-json-config Experimental: Support wrangler.json [boolean]
|
|
1130
|
+
-c, --config Path to .toml configuration file [string]
|
|
1131
|
+
-e, --env Environment to use for operations and .env files [string]
|
|
1132
|
+
-h, --help Show help [boolean]
|
|
1133
|
+
-v, --version Show version number [boolean]
|
|
1124
1134
|
|
|
1125
1135
|
Options:
|
|
1126
1136
|
--binding The name of the namespace to get from [string]
|
|
@@ -1152,10 +1162,11 @@ describe("wrangler", () => {
|
|
|
1152
1162
|
key The key value to get. [string] [required]
|
|
1153
1163
|
|
|
1154
1164
|
Flags:
|
|
1155
|
-
-
|
|
1156
|
-
-
|
|
1157
|
-
-
|
|
1158
|
-
-
|
|
1165
|
+
-j, --experimental-json-config Experimental: Support wrangler.json [boolean]
|
|
1166
|
+
-c, --config Path to .toml configuration file [string]
|
|
1167
|
+
-e, --env Environment to use for operations and .env files [string]
|
|
1168
|
+
-h, --help Show help [boolean]
|
|
1169
|
+
-v, --version Show version number [boolean]
|
|
1159
1170
|
|
|
1160
1171
|
Options:
|
|
1161
1172
|
--binding The name of the namespace to get from [string]
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { rest } from "msw";
|
|
2
|
+
import { endEventLoop } from "../helpers/end-event-loop";
|
|
3
|
+
import { mockAccountId, mockApiToken } from "./../helpers/mock-account-id";
|
|
4
|
+
import { msw } from "./../helpers/msw";
|
|
5
|
+
import { runInTempDir } from "./../helpers/run-in-tmp";
|
|
6
|
+
import { runWrangler } from "./../helpers/run-wrangler";
|
|
7
|
+
import type { Deployment } from "./../../pages/types";
|
|
8
|
+
|
|
9
|
+
describe("deployment list", () => {
|
|
10
|
+
runInTempDir();
|
|
11
|
+
mockAccountId();
|
|
12
|
+
mockApiToken();
|
|
13
|
+
|
|
14
|
+
afterEach(async () => {
|
|
15
|
+
// Force a tick to ensure that all promises resolve
|
|
16
|
+
await endEventLoop();
|
|
17
|
+
// Reset MSW after tick to ensure that all requests have been handled
|
|
18
|
+
msw.resetHandlers();
|
|
19
|
+
msw.restoreHandlers();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("should make request to list deployments", async () => {
|
|
23
|
+
const deployments: Deployment[] = [
|
|
24
|
+
{
|
|
25
|
+
id: "87bbc8fe-16be-45cd-81e0-63d722e82cdf",
|
|
26
|
+
url: "https://87bbc8fe.images.pages.dev",
|
|
27
|
+
environment: "preview",
|
|
28
|
+
created_on: "2021-11-17T14:52:26.133835Z",
|
|
29
|
+
latest_stage: {
|
|
30
|
+
ended_on: "2021-11-17T14:52:26.133835Z",
|
|
31
|
+
status: "success",
|
|
32
|
+
},
|
|
33
|
+
deployment_trigger: {
|
|
34
|
+
metadata: {
|
|
35
|
+
branch: "main",
|
|
36
|
+
commit_hash: "c7649364c4cb32ad4f65b530b9424e8be5bec9d6",
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
project_name: "images",
|
|
40
|
+
},
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
const requests = mockDeploymentListRequest(deployments);
|
|
44
|
+
await runWrangler("pages deployment list --project-name=images");
|
|
45
|
+
|
|
46
|
+
expect(requests.count).toBe(1);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
/* -------------------------------------------------- */
|
|
51
|
+
/* Helper Functions */
|
|
52
|
+
/* -------------------------------------------------- */
|
|
53
|
+
|
|
54
|
+
function mockDeploymentListRequest(deployments: unknown[]) {
|
|
55
|
+
const requests = { count: 0 };
|
|
56
|
+
msw.use(
|
|
57
|
+
rest.get(
|
|
58
|
+
"*/accounts/:accountId/pages/projects/:project/deployments",
|
|
59
|
+
(req, res, ctx) => {
|
|
60
|
+
requests.count++;
|
|
61
|
+
|
|
62
|
+
expect(req.params.project).toEqual("images");
|
|
63
|
+
expect(req.params.accountId).toEqual("some-account-id");
|
|
64
|
+
|
|
65
|
+
return res.once(
|
|
66
|
+
ctx.status(200),
|
|
67
|
+
ctx.json({
|
|
68
|
+
success: true,
|
|
69
|
+
errors: [],
|
|
70
|
+
messages: [],
|
|
71
|
+
result: deployments,
|
|
72
|
+
})
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
)
|
|
76
|
+
);
|
|
77
|
+
return requests;
|
|
78
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { endEventLoop } from "../helpers/end-event-loop";
|
|
2
|
+
import { mockConsoleMethods } from "../helpers/mock-console";
|
|
3
|
+
import { runInTempDir } from "../helpers/run-in-tmp";
|
|
4
|
+
import { runWrangler } from "../helpers/run-wrangler";
|
|
5
|
+
|
|
6
|
+
describe("pages", () => {
|
|
7
|
+
const std = mockConsoleMethods();
|
|
8
|
+
|
|
9
|
+
runInTempDir();
|
|
10
|
+
|
|
11
|
+
afterEach(async () => {
|
|
12
|
+
// Force a tick to ensure that all promises resolve
|
|
13
|
+
await endEventLoop();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("should display a list of available subcommands, for pages with no subcommand", async () => {
|
|
17
|
+
await runWrangler("pages");
|
|
18
|
+
await endEventLoop();
|
|
19
|
+
|
|
20
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
21
|
+
"wrangler pages
|
|
22
|
+
|
|
23
|
+
⚡️ Configure Cloudflare Pages
|
|
24
|
+
|
|
25
|
+
Commands:
|
|
26
|
+
wrangler pages dev [directory] [-- command..] 🧑💻 Develop your full-stack Pages application locally
|
|
27
|
+
wrangler pages project ⚡️ Interact with your Pages projects
|
|
28
|
+
wrangler pages deployment 🚀 Interact with the deployments of a project
|
|
29
|
+
wrangler pages publish [directory] 🆙 Publish a directory of static assets as a Pages deployment
|
|
30
|
+
|
|
31
|
+
Flags:
|
|
32
|
+
-j, --experimental-json-config Experimental: Support wrangler.json [boolean]
|
|
33
|
+
-c, --config Path to .toml configuration file [string]
|
|
34
|
+
-e, --env Environment to use for operations and .env files [string]
|
|
35
|
+
-h, --help Show help [boolean]
|
|
36
|
+
-v, --version Show version number [boolean]
|
|
37
|
+
|
|
38
|
+
🚧 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/wrangler2/issues/new/choose"
|
|
39
|
+
`);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe("beta message for subcommands", () => {
|
|
43
|
+
it("should display for pages:dev", async () => {
|
|
44
|
+
await expect(
|
|
45
|
+
runWrangler("pages dev")
|
|
46
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
47
|
+
`"Must specify a directory of static assets to serve or a command to run or a proxy port."`
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
51
|
+
"🚧 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/wrangler2/issues/new/choose
|
|
52
|
+
|
|
53
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose[0m"
|
|
54
|
+
`);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("should display for pages:functions:build", async () => {
|
|
58
|
+
await expect(runWrangler("pages functions build")).rejects.toThrowError();
|
|
59
|
+
|
|
60
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
61
|
+
"🚧 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/wrangler2/issues/new/choose
|
|
62
|
+
|
|
63
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose[0m"
|
|
64
|
+
`);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("should display for pages:functions:optimize-routes", async () => {
|
|
68
|
+
await expect(
|
|
69
|
+
runWrangler(
|
|
70
|
+
'pages functions optimize-routes --routes-path="/build/_routes.json" --output-routes-path="/build/_optimized-routes.json"'
|
|
71
|
+
)
|
|
72
|
+
).rejects.toThrowError();
|
|
73
|
+
|
|
74
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
75
|
+
"🚧 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/wrangler2/issues/new/choose
|
|
76
|
+
|
|
77
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose[0m"
|
|
78
|
+
`);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { rest } from "msw";
|
|
2
|
+
import { endEventLoop } from "../helpers/end-event-loop";
|
|
3
|
+
import { mockAccountId, mockApiToken } from "./../helpers/mock-account-id";
|
|
4
|
+
import { mockConsoleMethods } from "./../helpers/mock-console";
|
|
5
|
+
import { msw } from "./../helpers/msw";
|
|
6
|
+
import { runInTempDir } from "./../helpers/run-in-tmp";
|
|
7
|
+
import { runWrangler } from "./../helpers/run-wrangler";
|
|
8
|
+
|
|
9
|
+
describe("project create", () => {
|
|
10
|
+
const std = mockConsoleMethods();
|
|
11
|
+
|
|
12
|
+
runInTempDir();
|
|
13
|
+
mockAccountId();
|
|
14
|
+
mockApiToken();
|
|
15
|
+
|
|
16
|
+
afterEach(async () => {
|
|
17
|
+
// Force a tick to ensure that all promises resolve
|
|
18
|
+
await endEventLoop();
|
|
19
|
+
// Reset MSW after tick to ensure that all requests have been handled
|
|
20
|
+
msw.resetHandlers();
|
|
21
|
+
msw.restoreHandlers();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("should create a project with a production branch", async () => {
|
|
25
|
+
msw.use(
|
|
26
|
+
rest.post(
|
|
27
|
+
"*/accounts/:accountId/pages/projects",
|
|
28
|
+
async (req, res, ctx) => {
|
|
29
|
+
const body = await req.json();
|
|
30
|
+
|
|
31
|
+
expect(req.params.accountId).toEqual("some-account-id");
|
|
32
|
+
expect(body).toEqual({
|
|
33
|
+
name: "a-new-project",
|
|
34
|
+
production_branch: "main",
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
return res.once(
|
|
38
|
+
ctx.status(200),
|
|
39
|
+
ctx.json({
|
|
40
|
+
success: true,
|
|
41
|
+
errors: [],
|
|
42
|
+
messages: [],
|
|
43
|
+
result: {
|
|
44
|
+
name: "a-new-project",
|
|
45
|
+
subdomain: "a-new-project.pages.dev",
|
|
46
|
+
production_branch: "main",
|
|
47
|
+
},
|
|
48
|
+
})
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
)
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
await runWrangler(
|
|
55
|
+
"pages project create a-new-project --production-branch=main"
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
59
|
+
"✨ Successfully created the 'a-new-project' project. It will be available at https://a-new-project.pages.dev/ once you create your first deployment.
|
|
60
|
+
To deploy a folder of assets, run 'wrangler pages publish [directory]'."
|
|
61
|
+
`);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { rest } from "msw";
|
|
2
|
+
import { endEventLoop } from "../helpers/end-event-loop";
|
|
3
|
+
import { mockAccountId, mockApiToken } from "./../helpers/mock-account-id";
|
|
4
|
+
import { msw } from "./../helpers/msw";
|
|
5
|
+
import { runInTempDir } from "./../helpers/run-in-tmp";
|
|
6
|
+
import { runWrangler } from "./../helpers/run-wrangler";
|
|
7
|
+
import type { Project } from "./../../pages/types";
|
|
8
|
+
|
|
9
|
+
describe("project list", () => {
|
|
10
|
+
runInTempDir();
|
|
11
|
+
mockAccountId();
|
|
12
|
+
mockApiToken();
|
|
13
|
+
|
|
14
|
+
afterEach(async () => {
|
|
15
|
+
// Force a tick to ensure that all promises resolve
|
|
16
|
+
await endEventLoop();
|
|
17
|
+
// Reset MSW after tick to ensure that all requests have been handled
|
|
18
|
+
msw.resetHandlers();
|
|
19
|
+
msw.restoreHandlers();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("should make request to list projects", async () => {
|
|
23
|
+
const projects: Project[] = [
|
|
24
|
+
{
|
|
25
|
+
name: "dogs",
|
|
26
|
+
subdomain: "docs.pages.dev",
|
|
27
|
+
domains: ["dogs.pages.dev"],
|
|
28
|
+
source: {
|
|
29
|
+
type: "github",
|
|
30
|
+
},
|
|
31
|
+
latest_deployment: {
|
|
32
|
+
modified_on: "2021-11-17T14:52:26.133835Z",
|
|
33
|
+
},
|
|
34
|
+
created_on: "2021-11-17T14:52:26.133835Z",
|
|
35
|
+
production_branch: "main",
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: "cats",
|
|
39
|
+
subdomain: "cats.pages.dev",
|
|
40
|
+
domains: ["cats.pages.dev", "kitten.com"],
|
|
41
|
+
latest_deployment: {
|
|
42
|
+
modified_on: "2021-11-17T14:52:26.133835Z",
|
|
43
|
+
},
|
|
44
|
+
created_on: "2021-11-17T14:52:26.133835Z",
|
|
45
|
+
production_branch: "main",
|
|
46
|
+
},
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
const requests = mockProjectListRequest(projects);
|
|
50
|
+
await runWrangler("pages project list");
|
|
51
|
+
|
|
52
|
+
expect(requests.count).toBe(1);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("should make multiple requests for paginated results", async () => {
|
|
56
|
+
const projects: Project[] = [];
|
|
57
|
+
for (let i = 0; i < 15; i++) {
|
|
58
|
+
projects.push({
|
|
59
|
+
name: "dogs" + i,
|
|
60
|
+
subdomain: i + "dogs.pages.dev",
|
|
61
|
+
domains: [i + "dogs.pages.dev"],
|
|
62
|
+
source: {
|
|
63
|
+
type: "github",
|
|
64
|
+
},
|
|
65
|
+
latest_deployment: {
|
|
66
|
+
modified_on: "2021-11-17T14:52:26.133835Z",
|
|
67
|
+
},
|
|
68
|
+
created_on: "2021-11-17T14:52:26.133835Z",
|
|
69
|
+
production_branch: "main",
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
const requests = mockProjectListRequest(projects);
|
|
73
|
+
await runWrangler("pages project list");
|
|
74
|
+
expect(requests.count).toEqual(2);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
/* -------------------------------------------------- */
|
|
79
|
+
/* Helper Functions */
|
|
80
|
+
/* -------------------------------------------------- */
|
|
81
|
+
|
|
82
|
+
function mockProjectListRequest(projects: unknown[]) {
|
|
83
|
+
const requests = { count: 0 };
|
|
84
|
+
msw.use(
|
|
85
|
+
rest.get("*/accounts/:accountId/pages/projects", async (req, res, ctx) => {
|
|
86
|
+
requests.count++;
|
|
87
|
+
const pageSize = Number(req.url.searchParams.get("per_page"));
|
|
88
|
+
const page = Number(req.url.searchParams.get("page"));
|
|
89
|
+
const expectedPageSize = 10;
|
|
90
|
+
const expectedPage = requests.count;
|
|
91
|
+
expect(req.params.accountId).toEqual("some-account-id");
|
|
92
|
+
expect(pageSize).toEqual(expectedPageSize);
|
|
93
|
+
expect(page).toEqual(expectedPage);
|
|
94
|
+
expect(await req.text()).toEqual("");
|
|
95
|
+
|
|
96
|
+
return res(
|
|
97
|
+
ctx.status(200),
|
|
98
|
+
ctx.json({
|
|
99
|
+
success: true,
|
|
100
|
+
errors: [],
|
|
101
|
+
messages: [],
|
|
102
|
+
result: projects.slice((page - 1) * pageSize, page * pageSize),
|
|
103
|
+
})
|
|
104
|
+
);
|
|
105
|
+
})
|
|
106
|
+
);
|
|
107
|
+
return requests;
|
|
108
|
+
}
|