-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup-project.test.js
More file actions
83 lines (74 loc) · 3.06 KB
/
Copy pathsetup-project.test.js
File metadata and controls
83 lines (74 loc) · 3.06 KB
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
import { describe, it, expect } from "vitest";
import { execFileSync } from "child_process";
import { join, dirname } from "path";
import { fileURLToPath } from "url";
const __dirname = dirname(fileURLToPath(import.meta.url));
const SCRIPT = join(__dirname, "..", "setup-project.sh");
const PROJECT_ROOT = join(__dirname, "..", "..");
/**
* Tests for setup-project.sh
*
* These exercise the non-destructive paths only: --help and --dry-run. The
* --dry-run path resolves the renderer (validating it against the registry and
* reading manifest.template) and prints the scaffold plan without invoking any
* `pnpm create` / network calls, which keeps the test hermetic and fast.
*/
function run(args = []) {
try {
const stdout = execFileSync("bash", [SCRIPT, ...args], {
encoding: "utf-8",
timeout: 60000,
cwd: PROJECT_ROOT,
});
return { stdout, exitCode: 0 };
} catch (err) {
return { stdout: err.stdout || "", stderr: err.stderr || "", exitCode: err.status };
}
}
describe("setup-project.sh", () => {
it("--help documents --renderer and lists registry renderers", () => {
const r = run(["--help"]);
expect(r.exitCode).toBe(0);
expect(r.stdout).toMatch(/--renderer <name>/);
// The renderer list is sourced from the registry.
expect(r.stdout).toMatch(/Available renderers:.*astro/);
expect(r.stdout).toMatch(/Available renderers:.*nextjs/);
});
it("--renderer astro resolves to the astro template via the registry", () => {
const r = run(["my-app", "--renderer", "astro", "--dry-run"]);
expect(r.exitCode).toBe(0);
expect(r.stdout).toMatch(/Renderer: astro/);
expect(r.stdout).toMatch(/template:\s+templates\/astro/);
// Dry-run must not create anything.
expect(r.stdout).toMatch(/\[dry-run\] No project created/);
});
it("--next alias maps to the nextjs renderer", () => {
const r = run(["my-app", "--next", "--dry-run"]);
expect(r.exitCode).toBe(0);
expect(r.stdout).toMatch(/Renderer: nextjs/);
expect(r.stdout).toMatch(/template:\s+templates\/nextjs/);
});
it("--svelte alias maps to the sveltekit renderer", () => {
const r = run(["my-app", "--svelte", "--dry-run"]);
expect(r.exitCode).toBe(0);
expect(r.stdout).toMatch(/Renderer: sveltekit/);
expect(r.stdout).toMatch(/template:\s+templates\/sveltekit/);
});
it("--astro alias maps to the astro renderer", () => {
const r = run(["my-app", "--astro", "--dry-run"]);
expect(r.exitCode).toBe(0);
expect(r.stdout).toMatch(/Renderer: astro/);
expect(r.stdout).toMatch(/template:\s+templates\/astro/);
});
it("exits non-zero on an unknown renderer", () => {
const r = run(["my-app", "--renderer", "does-not-exist", "--dry-run"]);
expect(r.exitCode).not.toBe(0);
expect(r.stderr).toMatch(/unknown renderer/i);
});
it("preserves the legacy --react path (no registry renderer)", () => {
const r = run(["my-app", "--react", "--dry-run"]);
expect(r.exitCode).toBe(0);
expect(r.stdout).toMatch(/Framework: react/);
expect(r.stdout).toMatch(/template:\s+templates\/vite/);
});
});