forked from cloudflare/workers-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdialog.test.ts
144 lines (115 loc) · 4.69 KB
/
dialog.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import { afterAll, afterEach, beforeAll, describe, expect, test } from "vitest";
import { collectCLIOutput, normalizeOutput } from "../../../cli/test-util";
import { printSummary, printWelcomeMessage } from "../dialog";
import type { C3Context } from "types";
describe("dialog helpers", () => {
const std = collectCLIOutput();
const originalColumns = process.stdout.columns;
beforeAll(() => {
process.stdout.columns = 60;
});
afterAll(() => {
process.stdout.columns = originalColumns;
});
test("printWelcomeMessage with telemetry disabled", () => {
printWelcomeMessage("0.0.0", false);
expect(normalizeOutput(std.out)).toMatchInlineSnapshot(`
"────────────────────────────────────────────────────────────
👋 Welcome to create-cloudflare v0.0.0!
🧡 Let's get started.
────────────────────────────────────────────────────────────
"
`);
});
test("printWelcomeMessage with telemetry enabled", () => {
printWelcomeMessage("0.0.0", true);
expect(normalizeOutput(std.out)).toMatchInlineSnapshot(`
"────────────────────────────────────────────────────────────
👋 Welcome to create-cloudflare v0.0.0!
🧡 Let's get started.
📊 Cloudflare collects telemetry about your usage of Create-Cloudflare.
Learn more at: https://github.com/cloudflare/workers-sdk/blob/main/packages/create-cloudflare/telemetry.md
────────────────────────────────────────────────────────────
"
`);
});
describe("printSummary", () => {
const ctx: C3Context = {
project: { name: "test-project", path: "./workspace" },
args: {
projectName: "test-project",
},
template: {
configVersion: 1,
id: "test",
displayName: "display-name",
platform: "workers",
},
account: {
id: "account-id",
name: "account-name",
},
deployment: {
url: "https://example.test.workers.dev",
},
originalCWD: "./workspace",
gitRepoAlreadyExisted: false,
};
let originalStdoutColumns: number;
beforeAll(() => {
originalStdoutColumns = process.stdout.columns;
});
afterEach(() => {
process.stdout.columns = originalStdoutColumns;
});
test("with deploy", async () => {
await printSummary(ctx);
expect(normalizeOutput(std.out)).toMatchInlineSnapshot(`
"────────────────────────────────────────────────────────────
🎉 SUCCESS Application deployed successfully!
🔍 View Project
Visit: https://example.test.workers.dev
Dash: https://dash.cloudflare.com/?to=/:account/workers/services/view/test-project
💻 Continue Developing
Start dev server: pnpm run start
Deploy again: pnpm run deploy
📖 Explore Documentation
https://developers.cloudflare.com/workers
🐛 Report an Issue
https://github.com/cloudflare/workers-sdk/issues/new/choose
💬 Join our Community
https://discord.cloudflare.com
────────────────────────────────────────────────────────────
"
`);
});
test("with no deploy", async () => {
await printSummary({
...ctx,
account: undefined,
deployment: {},
project: { name: "test-project", path: "./example" },
template: {
...ctx.template,
platform: "pages",
},
});
expect(normalizeOutput(std.out)).toMatchInlineSnapshot(`
"────────────────────────────────────────────────────────────
🎉 SUCCESS Application created successfully!
💻 Continue Developing
Change directories: cd ../example
Start dev server: pnpm run start
Deploy: pnpm run deploy
📖 Explore Documentation
https://developers.cloudflare.com/pages
🐛 Report an Issue
https://github.com/cloudflare/workers-sdk/issues/new/choose
💬 Join our Community
https://discord.cloudflare.com
────────────────────────────────────────────────────────────
"
`);
});
});
});