wrangler 0.0.0-ece06ea → 0.0.0-ed08df4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cloudflare_CA.pem +18 -0
- package/README.md +27 -14
- package/bin/wrangler.js +34 -2
- package/miniflare-dist/index.mjs +4886 -0
- package/package.json +71 -36
- package/pages/functions/buildPlugin.ts +92 -0
- package/pages/functions/buildWorker.ts +138 -0
- package/pages/functions/filepath-routing.test.ts +234 -0
- package/pages/functions/filepath-routing.ts +189 -0
- package/pages/functions/identifiers.ts +78 -0
- package/pages/functions/routes.ts +156 -0
- package/pages/functions/template-plugin.ts +147 -0
- package/pages/functions/template-worker.ts +143 -0
- package/src/__tests__/config-cache.test.ts +36 -0
- package/src/__tests__/configuration.test.ts +3125 -0
- package/src/__tests__/dev.test.tsx +829 -0
- package/src/__tests__/guess-worker-format.test.ts +85 -0
- package/src/__tests__/{clipboardy-mock.js → helpers/clipboardy-mock.js} +0 -0
- package/src/__tests__/helpers/cmd-shim.d.ts +11 -0
- package/src/__tests__/helpers/faye-websocket.d.ts +6 -0
- package/src/__tests__/helpers/mock-account-id.ts +48 -0
- package/src/__tests__/helpers/mock-bin.ts +36 -0
- package/src/__tests__/helpers/mock-cfetch.ts +211 -0
- package/src/__tests__/helpers/mock-console.ts +87 -0
- package/src/__tests__/helpers/mock-dialogs.ts +90 -0
- package/src/__tests__/helpers/mock-http-server.ts +46 -0
- package/src/__tests__/helpers/mock-istty.ts +27 -0
- package/src/__tests__/helpers/mock-kv.ts +33 -0
- package/src/__tests__/helpers/mock-oauth-flow.ts +255 -0
- package/src/__tests__/helpers/mock-stdin.ts +103 -0
- package/src/__tests__/helpers/mock-web-socket.ts +29 -0
- package/src/__tests__/helpers/run-in-tmp.ts +39 -0
- package/src/__tests__/helpers/run-wrangler.ts +16 -0
- package/src/__tests__/helpers/write-worker-source.ts +31 -0
- package/src/__tests__/helpers/write-wrangler-toml.ts +17 -0
- package/src/__tests__/https-options.test.ts +130 -0
- package/src/__tests__/index.test.ts +221 -132
- package/src/__tests__/init.test.ts +1516 -0
- package/src/__tests__/jest.setup.ts +77 -0
- package/src/__tests__/kv.test.ts +1481 -0
- package/src/__tests__/logger.test.ts +115 -0
- package/src/__tests__/package-manager.test.ts +206 -0
- package/src/__tests__/pages.test.ts +327 -0
- package/src/__tests__/parse.test.ts +326 -0
- package/src/__tests__/publish.test.ts +4996 -0
- package/src/__tests__/r2.test.ts +210 -0
- package/src/__tests__/route.test.ts +45 -0
- package/src/__tests__/secret.test.ts +446 -0
- package/src/__tests__/tail.test.ts +690 -0
- package/src/__tests__/user.test.ts +131 -0
- package/src/__tests__/whoami.test.tsx +105 -0
- package/src/bundle.ts +169 -0
- package/src/cfetch/index.ts +104 -0
- package/src/cfetch/internal.ts +140 -0
- package/src/cli.ts +10 -7
- package/src/config/README.md +107 -0
- package/src/config/config.ts +234 -0
- package/src/config/diagnostics.ts +80 -0
- package/src/config/environment.ts +394 -0
- package/src/config/index.ts +63 -0
- package/src/config/validation-helpers.ts +575 -0
- package/src/config/validation.ts +1424 -0
- package/src/config-cache.ts +45 -0
- package/src/create-worker-preview.ts +175 -0
- package/src/create-worker-upload-form.ts +240 -0
- package/src/dev/dev-vars.ts +36 -0
- package/src/dev/dev.tsx +421 -0
- package/src/dev/local.tsx +312 -0
- package/src/dev/remote.tsx +213 -0
- package/src/dev/use-esbuild.ts +118 -0
- package/src/dialogs.tsx +22 -20
- package/src/entry.ts +322 -0
- package/src/environment-variables.ts +35 -0
- package/src/errors.ts +11 -0
- package/src/https-options.ts +123 -0
- package/src/index.tsx +1869 -1020
- package/src/inspect.ts +623 -0
- package/src/intl-polyfill.d.ts +139 -0
- package/src/kv.ts +344 -0
- package/src/logger.ts +66 -0
- package/src/miniflare-cli/README.md +30 -0
- package/src/miniflare-cli/enum-keys.ts +17 -0
- package/src/miniflare-cli/index.ts +41 -0
- package/src/miniflare-cli/request-context.ts +40 -0
- package/src/module-collection.ts +258 -0
- package/src/open-in-browser.ts +26 -0
- package/src/package-manager.ts +127 -0
- package/src/pages.tsx +1756 -218
- package/src/parse.ts +185 -0
- package/src/paths.ts +26 -0
- package/src/proxy.ts +449 -0
- package/src/publish.ts +377 -262
- package/src/r2.ts +50 -0
- package/src/selfsigned.d.ts +29 -0
- package/src/sites.tsx +237 -59
- package/src/tail/filters.ts +279 -0
- package/src/tail/index.ts +299 -0
- package/src/tail/printing.ts +67 -0
- package/src/update-check.ts +19 -0
- package/src/user.tsx +395 -221
- package/src/whoami.tsx +70 -0
- package/src/worker.ts +172 -0
- package/templates/gitignore +171 -0
- package/templates/new-worker.js +15 -0
- package/templates/new-worker.ts +15 -0
- package/{static-asset-facade.js → templates/static-asset-facade.js} +1 -1
- package/templates/tsconfig.json +105 -0
- package/wrangler-dist/cli.js +108921 -132528
- package/src/__tests__/fixtures/init/.gitkeep +0 -0
- package/src/__tests__/mock-cfetch.js +0 -46
- package/src/api/form_data.ts +0 -158
- package/src/api/inspect.ts +0 -441
- package/src/api/preview.ts +0 -123
- package/src/api/worker.ts +0 -161
- package/src/cfetch.ts +0 -72
- package/src/config.ts +0 -124
- package/src/dev.tsx +0 -736
- package/src/kv.tsx +0 -211
- package/src/tail.tsx +0 -71
- package/src/util/fetch.ts +0 -74
- package/wrangler-dist/cli.js.map +0 -7
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { logger } from "../logger";
|
|
2
|
+
import { mockConsoleMethods } from "./helpers/mock-console";
|
|
3
|
+
|
|
4
|
+
describe("logger", () => {
|
|
5
|
+
const std = mockConsoleMethods();
|
|
6
|
+
|
|
7
|
+
it("should add colored markers to error and warning messages", () => {
|
|
8
|
+
logger.loggerLevel = "debug";
|
|
9
|
+
logger.debug("This is a debug message");
|
|
10
|
+
logger.log("This is a log message");
|
|
11
|
+
logger.warn("This is a warn message");
|
|
12
|
+
logger.error("This is a error message");
|
|
13
|
+
|
|
14
|
+
expect(std.debug).toMatchInlineSnapshot(`"This is a debug message"`);
|
|
15
|
+
expect(std.out).toMatchInlineSnapshot(`"This is a log message"`);
|
|
16
|
+
expect(std.warn).toMatchInlineSnapshot(`
|
|
17
|
+
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mThis is a warn message[0m
|
|
18
|
+
|
|
19
|
+
"
|
|
20
|
+
`);
|
|
21
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
22
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mThis is a error message[0m
|
|
23
|
+
|
|
24
|
+
"
|
|
25
|
+
`);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe("loggerLevel=debug", () => {
|
|
29
|
+
it("should render messages that are at or above the log level set in the logger", () => {
|
|
30
|
+
logger.loggerLevel = "debug";
|
|
31
|
+
logger.debug("This is a debug message");
|
|
32
|
+
logger.log("This is a log message");
|
|
33
|
+
logger.warn("This is a warn message");
|
|
34
|
+
logger.error("This is a error message");
|
|
35
|
+
|
|
36
|
+
expect(std.debug).toMatchInlineSnapshot(`"This is a debug message"`);
|
|
37
|
+
expect(std.out).toMatchInlineSnapshot(`"This is a log message"`);
|
|
38
|
+
expect(std.warn).toMatchInlineSnapshot(`
|
|
39
|
+
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mThis is a warn message[0m
|
|
40
|
+
|
|
41
|
+
"
|
|
42
|
+
`);
|
|
43
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
44
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mThis is a error message[0m
|
|
45
|
+
|
|
46
|
+
"
|
|
47
|
+
`);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe("loggerLevel=log", () => {
|
|
52
|
+
it("should render messages that are at or above the log level set in the logger", () => {
|
|
53
|
+
logger.loggerLevel = "log";
|
|
54
|
+
logger.debug("This is a debug message");
|
|
55
|
+
logger.log("This is a log message");
|
|
56
|
+
logger.warn("This is a warn message");
|
|
57
|
+
logger.error("This is a error message");
|
|
58
|
+
|
|
59
|
+
expect(std.debug).toMatchInlineSnapshot(`""`);
|
|
60
|
+
expect(std.out).toMatchInlineSnapshot(`"This is a log message"`);
|
|
61
|
+
expect(std.warn).toMatchInlineSnapshot(`
|
|
62
|
+
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mThis is a warn message[0m
|
|
63
|
+
|
|
64
|
+
"
|
|
65
|
+
`);
|
|
66
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
67
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mThis is a error message[0m
|
|
68
|
+
|
|
69
|
+
"
|
|
70
|
+
`);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
describe("loggerLevel=warn", () => {
|
|
75
|
+
it("should render messages that are at or above the log level set in the logger", () => {
|
|
76
|
+
logger.loggerLevel = "warn";
|
|
77
|
+
logger.debug("This is a debug message");
|
|
78
|
+
logger.log("This is a log message");
|
|
79
|
+
logger.warn("This is a warn message");
|
|
80
|
+
logger.error("This is a error message");
|
|
81
|
+
|
|
82
|
+
expect(std.debug).toMatchInlineSnapshot(`""`);
|
|
83
|
+
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
84
|
+
expect(std.warn).toMatchInlineSnapshot(`
|
|
85
|
+
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mThis is a warn message[0m
|
|
86
|
+
|
|
87
|
+
"
|
|
88
|
+
`);
|
|
89
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
90
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mThis is a error message[0m
|
|
91
|
+
|
|
92
|
+
"
|
|
93
|
+
`);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
describe("loggerLevel=error", () => {
|
|
98
|
+
it("should render messages that are at or above the log level set in the logger", () => {
|
|
99
|
+
logger.loggerLevel = "error";
|
|
100
|
+
logger.debug("This is a debug message");
|
|
101
|
+
logger.log("This is a log message");
|
|
102
|
+
logger.warn("This is a warn message");
|
|
103
|
+
logger.error("This is a error message");
|
|
104
|
+
|
|
105
|
+
expect(std.debug).toMatchInlineSnapshot(`""`);
|
|
106
|
+
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
107
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
108
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
109
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mThis is a error message[0m
|
|
110
|
+
|
|
111
|
+
"
|
|
112
|
+
`);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
});
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { writeFileSync } from "node:fs";
|
|
2
|
+
import { mockBinary } from "./helpers/mock-bin";
|
|
3
|
+
import { mockConsoleMethods } from "./helpers/mock-console";
|
|
4
|
+
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
5
|
+
|
|
6
|
+
const { getPackageManager, getPackageManagerName } =
|
|
7
|
+
jest.requireActual("../package-manager");
|
|
8
|
+
interface TestCase {
|
|
9
|
+
npm: boolean;
|
|
10
|
+
yarn: boolean;
|
|
11
|
+
npmLockFile: boolean;
|
|
12
|
+
yarnLockFile: boolean;
|
|
13
|
+
expectedPackageManager: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const testCases: TestCase[] = [
|
|
17
|
+
// npm binary - no yarn binary
|
|
18
|
+
{
|
|
19
|
+
npm: true,
|
|
20
|
+
yarn: false,
|
|
21
|
+
npmLockFile: false,
|
|
22
|
+
yarnLockFile: false,
|
|
23
|
+
expectedPackageManager: "npm",
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
npm: true,
|
|
27
|
+
yarn: false,
|
|
28
|
+
npmLockFile: true,
|
|
29
|
+
yarnLockFile: false,
|
|
30
|
+
expectedPackageManager: "npm",
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
npm: true,
|
|
34
|
+
yarn: false,
|
|
35
|
+
npmLockFile: false,
|
|
36
|
+
yarnLockFile: true,
|
|
37
|
+
expectedPackageManager: "npm",
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
npm: true,
|
|
41
|
+
yarn: false,
|
|
42
|
+
npmLockFile: true,
|
|
43
|
+
yarnLockFile: true,
|
|
44
|
+
expectedPackageManager: "npm",
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
// yarn binary - no npm binary
|
|
48
|
+
{
|
|
49
|
+
npm: false,
|
|
50
|
+
yarn: true,
|
|
51
|
+
npmLockFile: false,
|
|
52
|
+
yarnLockFile: false,
|
|
53
|
+
expectedPackageManager: "yarn",
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
npm: false,
|
|
57
|
+
yarn: true,
|
|
58
|
+
npmLockFile: true,
|
|
59
|
+
yarnLockFile: false,
|
|
60
|
+
expectedPackageManager: "yarn",
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
npm: false,
|
|
64
|
+
yarn: true,
|
|
65
|
+
npmLockFile: false,
|
|
66
|
+
yarnLockFile: true,
|
|
67
|
+
expectedPackageManager: "yarn",
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
npm: false,
|
|
71
|
+
yarn: true,
|
|
72
|
+
npmLockFile: true,
|
|
73
|
+
yarnLockFile: true,
|
|
74
|
+
expectedPackageManager: "yarn",
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
// npm and yarn binaries
|
|
78
|
+
{
|
|
79
|
+
npm: true,
|
|
80
|
+
yarn: true,
|
|
81
|
+
npmLockFile: false,
|
|
82
|
+
yarnLockFile: false,
|
|
83
|
+
expectedPackageManager: "npm",
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
npm: true,
|
|
87
|
+
yarn: true,
|
|
88
|
+
npmLockFile: true,
|
|
89
|
+
yarnLockFile: false,
|
|
90
|
+
expectedPackageManager: "npm",
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
npm: true,
|
|
94
|
+
yarn: true,
|
|
95
|
+
npmLockFile: false,
|
|
96
|
+
yarnLockFile: true,
|
|
97
|
+
expectedPackageManager: "yarn",
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
npm: true,
|
|
101
|
+
yarn: true,
|
|
102
|
+
npmLockFile: true,
|
|
103
|
+
yarnLockFile: true,
|
|
104
|
+
expectedPackageManager: "npm",
|
|
105
|
+
},
|
|
106
|
+
];
|
|
107
|
+
|
|
108
|
+
describe("getPackageManager()", () => {
|
|
109
|
+
runInTempDir();
|
|
110
|
+
mockConsoleMethods();
|
|
111
|
+
|
|
112
|
+
describe("no supported package manager", () => {
|
|
113
|
+
mockYarn(false);
|
|
114
|
+
mockNpm(false);
|
|
115
|
+
|
|
116
|
+
it("should throw an error", async () => {
|
|
117
|
+
await expect(() =>
|
|
118
|
+
getPackageManager(process.cwd())
|
|
119
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
120
|
+
`"Unable to find a package manager. Supported managers are: npm and yarn."`
|
|
121
|
+
);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
for (const {
|
|
126
|
+
npm,
|
|
127
|
+
yarn,
|
|
128
|
+
npmLockFile,
|
|
129
|
+
yarnLockFile,
|
|
130
|
+
expectedPackageManager,
|
|
131
|
+
} of testCases) {
|
|
132
|
+
describe(
|
|
133
|
+
getTestCaseDescription(npm, yarn, npmLockFile, yarnLockFile),
|
|
134
|
+
() => {
|
|
135
|
+
mockYarn(yarn);
|
|
136
|
+
mockNpm(npm);
|
|
137
|
+
mockLockFiles(npmLockFile, yarnLockFile);
|
|
138
|
+
|
|
139
|
+
it(`should return the ${expectedPackageManager} package manager`, async () => {
|
|
140
|
+
const actualPackageManager = await getPackageManager(process.cwd());
|
|
141
|
+
expect(getPackageManagerName(actualPackageManager)).toEqual(
|
|
142
|
+
expectedPackageManager
|
|
143
|
+
);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Create a fake yarn binary
|
|
152
|
+
*/
|
|
153
|
+
function mockYarn(succeed: boolean): void {
|
|
154
|
+
let unMock: () => void;
|
|
155
|
+
beforeEach(async () => {
|
|
156
|
+
unMock = await mockBinary("yarn", `process.exit(${succeed ? 0 : 1})`);
|
|
157
|
+
});
|
|
158
|
+
afterEach(() => unMock());
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Create a fake npm binary
|
|
163
|
+
*/
|
|
164
|
+
function mockNpm(succeed: boolean): void {
|
|
165
|
+
let unMock: () => void;
|
|
166
|
+
beforeEach(async () => {
|
|
167
|
+
unMock = await mockBinary("npm", `process.exit(${succeed ? 0 : 1})`);
|
|
168
|
+
});
|
|
169
|
+
afterEach(() => unMock());
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Create a fake lock files.
|
|
174
|
+
*/
|
|
175
|
+
function mockLockFiles(npmLockFile: boolean, yarnLockFile: boolean) {
|
|
176
|
+
beforeEach(() => {
|
|
177
|
+
if (npmLockFile) {
|
|
178
|
+
writeFileSync("package-lock.json", "");
|
|
179
|
+
}
|
|
180
|
+
if (yarnLockFile) {
|
|
181
|
+
writeFileSync("yarn.lock", "");
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function getTestCaseDescription(
|
|
187
|
+
npm: boolean,
|
|
188
|
+
yarn: boolean,
|
|
189
|
+
npmLockFile: boolean,
|
|
190
|
+
yarnLockFile: boolean
|
|
191
|
+
): string {
|
|
192
|
+
const criteria: string[] = [];
|
|
193
|
+
if (npm) {
|
|
194
|
+
criteria.push("npm");
|
|
195
|
+
}
|
|
196
|
+
if (npmLockFile) {
|
|
197
|
+
criteria.push("package-lock.json");
|
|
198
|
+
}
|
|
199
|
+
if (yarn) {
|
|
200
|
+
criteria.push("yarn");
|
|
201
|
+
}
|
|
202
|
+
if (yarnLockFile) {
|
|
203
|
+
criteria.push("yarn.lock");
|
|
204
|
+
}
|
|
205
|
+
return "using " + criteria.join("; ");
|
|
206
|
+
}
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import { writeFileSync } from "node:fs";
|
|
2
|
+
import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
|
|
3
|
+
import { setMockResponse, unsetAllMocks } from "./helpers/mock-cfetch";
|
|
4
|
+
import { mockConsoleMethods } from "./helpers/mock-console";
|
|
5
|
+
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
6
|
+
import { runWrangler } from "./helpers/run-wrangler";
|
|
7
|
+
import type { Project, Deployment } from "../pages";
|
|
8
|
+
import type { File, FormData } from "undici";
|
|
9
|
+
|
|
10
|
+
describe("pages", () => {
|
|
11
|
+
runInTempDir();
|
|
12
|
+
const std = mockConsoleMethods();
|
|
13
|
+
function endEventLoop() {
|
|
14
|
+
return new Promise((resolve) => setImmediate(resolve));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
it("should should display a list of available subcommands, for pages with no subcommand", async () => {
|
|
18
|
+
await runWrangler("pages");
|
|
19
|
+
await endEventLoop();
|
|
20
|
+
|
|
21
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
22
|
+
"wrangler pages
|
|
23
|
+
|
|
24
|
+
⚡️ Configure Cloudflare Pages
|
|
25
|
+
|
|
26
|
+
Commands:
|
|
27
|
+
wrangler pages dev [directory] [-- command] 🧑💻 Develop your full-stack Pages application locally
|
|
28
|
+
wrangler pages project ⚡️ Interact with your Pages projects
|
|
29
|
+
wrangler pages deployment 🚀 Interact with the deployments of a project
|
|
30
|
+
wrangler pages publish [directory] 🆙 Publish a directory of static assets as a Pages deployment
|
|
31
|
+
|
|
32
|
+
Flags:
|
|
33
|
+
-c, --config Path to .toml configuration file [string]
|
|
34
|
+
-h, --help Show help [boolean]
|
|
35
|
+
-v, --version Show version number [boolean]
|
|
36
|
+
|
|
37
|
+
🚧 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/wrangler2/issues/new/choose"
|
|
38
|
+
`);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
describe("beta message for subcommands", () => {
|
|
42
|
+
it("should display for pages:dev", async () => {
|
|
43
|
+
await expect(
|
|
44
|
+
runWrangler("pages dev")
|
|
45
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
46
|
+
`"Must specify a directory of static assets to serve or a command to run."`
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
50
|
+
"🚧 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/wrangler2/issues/new/choose
|
|
51
|
+
|
|
52
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new.[0m"
|
|
53
|
+
`);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("should display for pages:functions:build", async () => {
|
|
57
|
+
await expect(runWrangler("pages functions build")).rejects.toThrowError();
|
|
58
|
+
|
|
59
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
60
|
+
"🚧 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/wrangler2/issues/new/choose
|
|
61
|
+
|
|
62
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new.[0m"
|
|
63
|
+
`);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe("project list", () => {
|
|
68
|
+
mockAccountId();
|
|
69
|
+
mockApiToken();
|
|
70
|
+
|
|
71
|
+
afterEach(() => {
|
|
72
|
+
unsetAllMocks();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
function mockListRequest(projects: unknown[]) {
|
|
76
|
+
const requests = { count: 0 };
|
|
77
|
+
setMockResponse(
|
|
78
|
+
"/accounts/:accountId/pages/projects",
|
|
79
|
+
([_url, accountId], init, query) => {
|
|
80
|
+
requests.count++;
|
|
81
|
+
expect(accountId).toEqual("some-account-id");
|
|
82
|
+
expect(query.get("per_page")).toEqual("10");
|
|
83
|
+
expect(query.get("page")).toEqual(`${requests.count}`);
|
|
84
|
+
expect(init).toEqual({});
|
|
85
|
+
const pageSize = Number(query.get("per_page"));
|
|
86
|
+
const page = Number(query.get("page"));
|
|
87
|
+
return projects.slice((page - 1) * pageSize, page * pageSize);
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
return requests;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
it("should make request to list projects", async () => {
|
|
94
|
+
const projects: Project[] = [
|
|
95
|
+
{
|
|
96
|
+
name: "dogs",
|
|
97
|
+
subdomain: "docs.pages.dev",
|
|
98
|
+
domains: ["dogs.pages.dev"],
|
|
99
|
+
source: {
|
|
100
|
+
type: "github",
|
|
101
|
+
},
|
|
102
|
+
latest_deployment: {
|
|
103
|
+
modified_on: "2021-11-17T14:52:26.133835Z",
|
|
104
|
+
},
|
|
105
|
+
created_on: "2021-11-17T14:52:26.133835Z",
|
|
106
|
+
production_branch: "main",
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
name: "cats",
|
|
110
|
+
subdomain: "cats.pages.dev",
|
|
111
|
+
domains: ["cats.pages.dev", "kitten.com"],
|
|
112
|
+
latest_deployment: {
|
|
113
|
+
modified_on: "2021-11-17T14:52:26.133835Z",
|
|
114
|
+
},
|
|
115
|
+
created_on: "2021-11-17T14:52:26.133835Z",
|
|
116
|
+
production_branch: "main",
|
|
117
|
+
},
|
|
118
|
+
];
|
|
119
|
+
|
|
120
|
+
const requests = mockListRequest(projects);
|
|
121
|
+
await runWrangler("pages project list");
|
|
122
|
+
|
|
123
|
+
expect(requests.count).toBe(1);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("should make multiple requests for paginated results", async () => {
|
|
127
|
+
const projects: Project[] = [];
|
|
128
|
+
for (let i = 0; i < 15; i++) {
|
|
129
|
+
projects.push({
|
|
130
|
+
name: "dogs" + i,
|
|
131
|
+
subdomain: i + "dogs.pages.dev",
|
|
132
|
+
domains: [i + "dogs.pages.dev"],
|
|
133
|
+
source: {
|
|
134
|
+
type: "github",
|
|
135
|
+
},
|
|
136
|
+
latest_deployment: {
|
|
137
|
+
modified_on: "2021-11-17T14:52:26.133835Z",
|
|
138
|
+
},
|
|
139
|
+
created_on: "2021-11-17T14:52:26.133835Z",
|
|
140
|
+
production_branch: "main",
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
const requests = mockListRequest(projects);
|
|
144
|
+
await runWrangler("pages project list");
|
|
145
|
+
expect(requests.count).toEqual(2);
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
describe("project create", () => {
|
|
150
|
+
mockAccountId();
|
|
151
|
+
mockApiToken();
|
|
152
|
+
|
|
153
|
+
afterEach(() => {
|
|
154
|
+
unsetAllMocks();
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it("should create a project with a production branch", async () => {
|
|
158
|
+
setMockResponse(
|
|
159
|
+
"/accounts/:accountId/pages/projects",
|
|
160
|
+
([_url, accountId], init) => {
|
|
161
|
+
expect(accountId).toEqual("some-account-id");
|
|
162
|
+
expect(init.method).toEqual("POST");
|
|
163
|
+
const body = JSON.parse(init.body as string);
|
|
164
|
+
expect(body).toEqual({
|
|
165
|
+
name: "a-new-project",
|
|
166
|
+
production_branch: "main",
|
|
167
|
+
});
|
|
168
|
+
return {
|
|
169
|
+
name: "a-new-project",
|
|
170
|
+
subdomain: "a-new-project.pages.dev",
|
|
171
|
+
production_branch: "main",
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
);
|
|
175
|
+
await runWrangler(
|
|
176
|
+
"pages project create a-new-project --production-branch=main"
|
|
177
|
+
);
|
|
178
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
179
|
+
"✨ Successfully created the 'a-new-project' project. It will be available at https://a-new-project.pages.dev/ once you create your first deployment.
|
|
180
|
+
To deploy a folder of assets, run 'wrangler pages publish [directory]'."
|
|
181
|
+
`);
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
describe("deployment list", () => {
|
|
186
|
+
mockAccountId();
|
|
187
|
+
mockApiToken();
|
|
188
|
+
|
|
189
|
+
afterEach(() => {
|
|
190
|
+
unsetAllMocks();
|
|
191
|
+
});
|
|
192
|
+
function mockListRequest(deployments: unknown[]) {
|
|
193
|
+
const requests = { count: 0 };
|
|
194
|
+
setMockResponse(
|
|
195
|
+
"/accounts/:accountId/pages/projects/:project/deployments",
|
|
196
|
+
([_url, accountId, project]) => {
|
|
197
|
+
requests.count++;
|
|
198
|
+
expect(project).toEqual("images");
|
|
199
|
+
expect(accountId).toEqual("some-account-id");
|
|
200
|
+
return deployments;
|
|
201
|
+
}
|
|
202
|
+
);
|
|
203
|
+
return requests;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
it("should make request to list deployments", async () => {
|
|
207
|
+
const deployments: Deployment[] = [
|
|
208
|
+
{
|
|
209
|
+
id: "87bbc8fe-16be-45cd-81e0-63d722e82cdf",
|
|
210
|
+
url: "https://87bbc8fe.images.pages.dev",
|
|
211
|
+
environment: "preview",
|
|
212
|
+
latest_stage: {
|
|
213
|
+
ended_on: "2021-11-17T14:52:26.133835Z",
|
|
214
|
+
status: "success",
|
|
215
|
+
},
|
|
216
|
+
deployment_trigger: {
|
|
217
|
+
metadata: {
|
|
218
|
+
branch: "main",
|
|
219
|
+
commit_hash: "c7649364c4cb32ad4f65b530b9424e8be5bec9d6",
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
project_name: "images",
|
|
223
|
+
},
|
|
224
|
+
];
|
|
225
|
+
|
|
226
|
+
const requests = mockListRequest(deployments);
|
|
227
|
+
await runWrangler("pages deployment list --project-name=images");
|
|
228
|
+
|
|
229
|
+
expect(requests.count).toBe(1);
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
describe("deployment create", () => {
|
|
234
|
+
let actualProcessEnvCI: string | undefined;
|
|
235
|
+
|
|
236
|
+
mockAccountId();
|
|
237
|
+
mockApiToken();
|
|
238
|
+
runInTempDir();
|
|
239
|
+
|
|
240
|
+
beforeEach(() => {
|
|
241
|
+
actualProcessEnvCI = process.env.CI;
|
|
242
|
+
process.env.CI = "true";
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
afterEach(() => {
|
|
246
|
+
unsetAllMocks();
|
|
247
|
+
process.env.CI = actualProcessEnvCI;
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it("should be aliased with 'wrangler pages publish'", async () => {
|
|
251
|
+
await runWrangler("pages publish --help");
|
|
252
|
+
await endEventLoop();
|
|
253
|
+
|
|
254
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
255
|
+
"wrangler pages publish [directory]
|
|
256
|
+
|
|
257
|
+
🆙 Publish a directory of static assets as a Pages deployment
|
|
258
|
+
|
|
259
|
+
Positionals:
|
|
260
|
+
directory The directory of static files to upload [string]
|
|
261
|
+
|
|
262
|
+
Flags:
|
|
263
|
+
-c, --config Path to .toml configuration file [string]
|
|
264
|
+
-h, --help Show help [boolean]
|
|
265
|
+
-v, --version Show version number [boolean]
|
|
266
|
+
|
|
267
|
+
Options:
|
|
268
|
+
--project-name The name of the project you want to deploy to [string]
|
|
269
|
+
--branch The name of the branch you want to deploy to [string]
|
|
270
|
+
--commit-hash The SHA to attach to this deployment [string]
|
|
271
|
+
--commit-message The commit message to attach to this deployment [string]
|
|
272
|
+
--commit-dirty Whether or not the workspace should be considered dirty for this deployment [boolean]
|
|
273
|
+
|
|
274
|
+
🚧 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/wrangler2/issues/new/choose"
|
|
275
|
+
`);
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
it("should upload a directory of files", async () => {
|
|
279
|
+
writeFileSync("logo.png", "foobar");
|
|
280
|
+
|
|
281
|
+
setMockResponse(
|
|
282
|
+
"/accounts/:accountId/pages/projects/foo/file",
|
|
283
|
+
async ([_url, accountId], init) => {
|
|
284
|
+
expect(accountId).toEqual("some-account-id");
|
|
285
|
+
expect(init.method).toEqual("POST");
|
|
286
|
+
const body = init.body as FormData;
|
|
287
|
+
const logoPNGFile = body.get("file") as File;
|
|
288
|
+
expect(await logoPNGFile.text()).toEqual("foobar");
|
|
289
|
+
expect(logoPNGFile.name).toEqual("logo.png");
|
|
290
|
+
|
|
291
|
+
return {
|
|
292
|
+
id: "2082190357cfd3617ccfe04f340c6247",
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
);
|
|
296
|
+
|
|
297
|
+
setMockResponse(
|
|
298
|
+
"/accounts/:accountId/pages/projects/foo/deployments",
|
|
299
|
+
async ([_url, accountId], init) => {
|
|
300
|
+
expect(accountId).toEqual("some-account-id");
|
|
301
|
+
expect(init.method).toEqual("POST");
|
|
302
|
+
const body = init.body as FormData;
|
|
303
|
+
const manifest = JSON.parse(body.get("manifest") as string);
|
|
304
|
+
expect(manifest).toMatchInlineSnapshot(`
|
|
305
|
+
Object {
|
|
306
|
+
"/logo.png": "2082190357cfd3617ccfe04f340c6247",
|
|
307
|
+
}
|
|
308
|
+
`);
|
|
309
|
+
|
|
310
|
+
return {
|
|
311
|
+
url: "https://abcxyz.foo.pages.dev/",
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
);
|
|
315
|
+
|
|
316
|
+
await runWrangler("pages publish . --project-name=foo");
|
|
317
|
+
|
|
318
|
+
// TODO: Unmounting somehow loses this output
|
|
319
|
+
|
|
320
|
+
// expect(std.out).toMatchInlineSnapshot(`
|
|
321
|
+
// "✨ Success! Uploaded 1 files (TIMINGS)
|
|
322
|
+
|
|
323
|
+
// ✨ Deployment complete! Take a peek over at https://abcxyz.foo.pages.dev/"
|
|
324
|
+
// `);
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
});
|