-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathcompile.test.ts
More file actions
141 lines (122 loc) · 4.45 KB
/
compile.test.ts
File metadata and controls
141 lines (122 loc) · 4.45 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
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
import { execSync } from "child_process";
import * as fs from "fs";
import * as os from "os";
import * as path from "path";
import { expect, test, describe } from "vitest";
const runZeroBuildSchema = async (testName: string) => {
const schemaPath = path.join(
process.cwd(),
"tests",
"schemas",
`${testName}.zero.ts`,
);
const tmpDir = path.join(os.tmpdir(), "zero-build-schema-test", testName);
try {
fs.mkdirSync(tmpDir, { recursive: true });
const outputPath = path.join(tmpDir, "schema.json");
execSync(`pnpm exec zero-build-schema -p ${schemaPath} -o ${outputPath}`, {
encoding: "utf-8",
});
const output = fs.readFileSync(outputPath, { encoding: "utf-8" });
return JSON.parse(output);
} catch (error) {
if (error instanceof Error) {
console.error("Command execution failed:", error.message);
}
throw error;
} finally {
// Clean up temporary files
fs.rmSync(tmpDir, { recursive: true, force: true });
}
};
describe.concurrent("compile", () => {
test("compile - no-relations", async () => {
const result = await runZeroBuildSchema("no-relations");
expect(result.schema.tables.user).toBeTruthy();
expect(Object.keys(result.schema.tables)).toStrictEqual([
"profile_info",
"user",
]);
});
test("compile - one-to-one-2", async () => {
const result = await runZeroBuildSchema("one-to-one-2");
expect(result.schema.tables.user).toBeTruthy();
expect(Object.keys(result.schema.tables)).toStrictEqual([
"medium",
"message",
"user",
]);
});
test("compile - one-to-one", async () => {
const result = await runZeroBuildSchema("one-to-one");
expect(result.schema.tables.user).toBeTruthy();
expect(Object.keys(result.schema.tables)).toStrictEqual([
"profile_info",
"user",
]);
});
test("compile - one-to-one-subset", async () => {
const result = await runZeroBuildSchema("one-to-one-subset");
expect(result.schema.tables.user).toBeTruthy();
expect(Object.keys(result.schema.tables)).toStrictEqual(["user"]);
});
test("compile - one-to-one-foreign-key", async () => {
const result = await runZeroBuildSchema("one-to-one-foreign-key");
expect(result.schema.tables.users).toBeTruthy();
expect(Object.keys(result.schema.tables)).toStrictEqual(["posts", "users"]);
});
test("compile - one-to-one-self", async () => {
const result = await runZeroBuildSchema("one-to-one-self");
expect(result.schema.tables.user).toBeTruthy();
expect(Object.keys(result.schema.tables)).toStrictEqual(["user"]);
});
test("compile - one-to-many", async () => {
const result = await runZeroBuildSchema("one-to-many");
expect(result.schema.tables.user).toBeTruthy();
expect(Object.keys(result.schema.tables)).toStrictEqual([
"comment",
"post",
"user",
]);
});
test("compile - one-to-many-named", async () => {
const result = await runZeroBuildSchema("one-to-many-named");
expect(result.schema.tables.users).toBeTruthy();
expect(Object.keys(result.schema.tables)).toStrictEqual(["posts", "users"]);
});
test("compile - many-to-many", async () => {
const result = await runZeroBuildSchema("many-to-many");
expect(result.schema.tables.user).toBeTruthy();
expect(Object.keys(result.schema.tables)).toStrictEqual([
"group",
"user",
"users_to_group",
]);
});
test("compile - many-to-many-subset", async () => {
const result = await runZeroBuildSchema("many-to-many-subset");
expect(result.schema.tables.user).toBeTruthy();
expect(Object.keys(result.schema.tables)).toStrictEqual(["user"]);
});
test("compile - many-to-many-subset-2", async () => {
const result = await runZeroBuildSchema("many-to-many-subset-2");
expect(result.schema.tables.user).toBeTruthy();
expect(Object.keys(result.schema.tables)).toStrictEqual([
"user",
"users_to_group",
]);
});
test("compile - many-to-many-self-referential", async () => {
const result = await runZeroBuildSchema("many-to-many-self-referential");
expect(result.schema.tables.user).toBeTruthy();
expect(Object.keys(result.schema.tables)).toStrictEqual([
"friendship",
"user",
]);
});
test("compile - custom-schema", async () => {
const result = await runZeroBuildSchema("custom-schema");
expect(result.schema.tables.user).toBeTruthy();
expect(Object.keys(result.schema.tables)).toStrictEqual(["user"]);
});
});