tangled
alpha
login
or
join now
besaid.zone
/
create-atproto-app
2
fork
atom
A CLI for scaffolding ATProto web applications
2
fork
atom
overview
issues
pulls
pipelines
tests: add some more tests
besaid.zone
1 month ago
b38875c9
978fe71f
verified
This commit was signed with the committer's
known signature
.
besaid.zone
SSH Key Fingerprint:
SHA256:Q4dc5PTI8DNTxJbH2bWsDeY6BXzfq0ce1XSA4H5Y3iI=
2/2
test.yml
success
42s
typecheck.yml
success
37s
+101
-7
2 changed files
expand all
collapse all
unified
split
__tests__
cli.test.ts
src
commands
init.ts
+98
-6
__tests__/cli.test.ts
reviewed
···
1
1
import type { SyncOptions } from "execa";
2
2
3
3
import { execaCommandSync } from "execa";
4
4
+
import {
5
5
+
existsSync,
6
6
+
mkdirSync,
7
7
+
readdirSync,
8
8
+
rmSync,
9
9
+
writeFileSync,
10
10
+
} from "node:fs";
4
11
import { join } from "node:path";
5
5
-
import { expect, test } from "vitest";
12
12
+
import { afterEach, beforeAll, expect, test } from "vitest";
6
13
7
14
const CLI_PATH = join(import.meta.dirname, "..");
15
15
+
const DEFAULT_APP_NAME = "my-app";
16
16
+
const appPath = join(import.meta.dirname, "..", DEFAULT_APP_NAME);
8
17
9
18
async function run(args: string[], options?: SyncOptions) {
10
19
return execaCommandSync(`node ${CLI_PATH} ${args.join(" ")}`, {
11
20
env: { ...process.env, _VITE_TEST_CLI: "true" },
21
21
+
reject: false,
12
22
...options,
13
23
});
14
24
}
15
25
26
26
+
function createExistingProject() {
27
27
+
mkdirSync(DEFAULT_APP_NAME, { recursive: true });
28
28
+
const pkgJson = join(DEFAULT_APP_NAME, "package.json");
29
29
+
writeFileSync(pkgJson, '{"name": "my-app"}');
30
30
+
}
31
31
+
32
32
+
function cleanUpTestFolders() {
33
33
+
if (existsSync(appPath)) {
34
34
+
rmSync(appPath, { recursive: true, force: true });
35
35
+
}
36
36
+
}
37
37
+
38
38
+
beforeAll(() => cleanUpTestFolders());
39
39
+
afterEach(() => cleanUpTestFolders());
40
40
+
16
41
test("should prompt for project name", async () => {
17
42
const { stdout } = await run(["init"]);
18
43
expect(stdout).toContain("Please provide a name for this project:");
19
44
});
20
45
21
46
test("should prompt framework", async () => {
22
22
-
const { stdout } = await run(["init", "my-app"]);
47
47
+
const { stdout } = await run(["init", DEFAULT_APP_NAME]);
23
48
expect(stdout).toContain("Select a framework:");
24
49
});
25
50
26
51
test("should prompt variant", async () => {
27
27
-
const { stdout } = await run(["init", "my-app", "--framework", "react"]);
52
52
+
const { stdout } = await run([
53
53
+
"init",
54
54
+
DEFAULT_APP_NAME,
55
55
+
"--framework",
56
56
+
"react",
57
57
+
]);
28
58
expect(stdout).toContain("Select a framework variant:");
29
59
});
30
60
31
31
-
test.skip("should fail if no command is specified", async () => {
32
32
-
const { stdout } = await run([]);
33
33
-
expect(stdout).toContain("USAGE create-atproto-app create");
61
61
+
test("should fail if no command is specified", async () => {
62
62
+
const { stderr } = await run([]);
63
63
+
expect(stderr).toContain("No command specified.");
64
64
+
});
65
65
+
66
66
+
test("should successfully create a project", async () => {
67
67
+
const { stdout } = await run([
68
68
+
"init",
69
69
+
"--name",
70
70
+
DEFAULT_APP_NAME,
71
71
+
"--framework",
72
72
+
"react",
73
73
+
"--variant",
74
74
+
"react-ts",
75
75
+
]);
76
76
+
77
77
+
expect(stdout).toContain("Done!");
78
78
+
});
79
79
+
80
80
+
test("should warn if project name already exists", async () => {
81
81
+
createExistingProject();
82
82
+
const { stdout } = await run([
83
83
+
"init",
84
84
+
"--name",
85
85
+
DEFAULT_APP_NAME,
86
86
+
"--framework",
87
87
+
"react",
88
88
+
"--variant",
89
89
+
"react-ts",
90
90
+
]);
91
91
+
expect(stdout).toContain("A project with the name of");
92
92
+
});
93
93
+
94
94
+
test("should successfully scaffold a react project", async () => {
95
95
+
const { stdout } = await run([
96
96
+
"init",
97
97
+
"--name",
98
98
+
DEFAULT_APP_NAME,
99
99
+
"--framework",
100
100
+
"react",
101
101
+
"--variant",
102
102
+
"react-ts",
103
103
+
]);
104
104
+
expect(stdout).toContain("Project created!");
105
105
+
expect(
106
106
+
readdirSync(join(appPath, "src")).some((files) => files.endsWith(".tsx")),
107
107
+
);
108
108
+
});
109
109
+
110
110
+
test("should successfully scaffold a svelte project", async () => {
111
111
+
const { stdout } = await run([
112
112
+
"init",
113
113
+
"--name",
114
114
+
DEFAULT_APP_NAME,
115
115
+
"--framework",
116
116
+
"svelte",
117
117
+
"--variant",
118
118
+
"svelte-ts",
119
119
+
]);
120
120
+
expect(stdout).toContain("Project created!");
121
121
+
expect(
122
122
+
readdirSync(join(appPath, "src")).some((files) =>
123
123
+
files.endsWith(".svelte"),
124
124
+
),
125
125
+
);
34
126
});
+3
-1
src/commands/init.ts
reviewed
···
168
168
169
169
execSync(templateCommand);
170
170
171
171
-
removeViteTemplateFiles(root, removableTemplateFiles(variant));
171
171
+
const files = removableTemplateFiles(variant);
172
172
+
173
173
+
removeViteTemplateFiles(root, files);
172
174
173
175
for (const file of readdirSync(templateDir)) {
174
176
const sourceTemplateFiles = resolve(templateDir, file);