Skip to content

Commit 75dca02

Browse files
committed
Reorganize test files by feature instead of origin
Dissolve design-doc-examples.test.ts, coverage-gaps.test.ts, emitter.test.ts, and diagnostics.test.ts — distribute their tests into feature-focused files. Create new files for unions, enums, arrays, deprecation, circular references, and doc comments. 197 tests across 17 files (was 197 across 15).
1 parent a0869c7 commit 75dca02

18 files changed

Lines changed: 1166 additions & 1199 deletions
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { strictEqual } from "node:assert";
2+
import { describe, it } from "vitest";
3+
import { emitSingleSchema } from "./test-host.js";
4+
5+
describe("arrays", () => {
6+
it("supports array types", async () => {
7+
const code = `
8+
@schema
9+
namespace TestNamespace {
10+
model Tag {
11+
name: string;
12+
color: string;
13+
}
14+
15+
model Article {
16+
id: string;
17+
title: string;
18+
tags: Tag[];
19+
categories: string[];
20+
}
21+
22+
@query
23+
op getArticle(id: string): Article;
24+
25+
@query
26+
op listArticles(): Article[];
27+
}
28+
`;
29+
30+
const result = await emitSingleSchema(code, {});
31+
32+
strictEqual(result.includes("tags: [Tag!]!"), true);
33+
strictEqual(result.includes("categories: [String!]!"), true);
34+
strictEqual(result.includes("listArticles: [Article!]"), true);
35+
});
36+
37+
it("emits list types for array properties", async () => {
38+
const code = `
39+
@schema
40+
namespace TestNamespace {
41+
model User {
42+
id: string;
43+
tags: string[];
44+
}
45+
46+
@query
47+
op getUser(): User;
48+
}
49+
`;
50+
51+
const result = await emitSingleSchema(code, {});
52+
strictEqual(result.includes("tags: [String!]!"), true);
53+
});
54+
55+
it("emits nullable list items for optional element types", async () => {
56+
const code = `
57+
@schema
58+
namespace TestNamespace {
59+
model User {
60+
id: string;
61+
tags: (string | null)[];
62+
}
63+
64+
@query
65+
op getUser(): User;
66+
}
67+
`;
68+
69+
const result = await emitSingleSchema(code, {});
70+
strictEqual(result.includes("tags: [String]!"), true);
71+
});
72+
});
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { strictEqual } from "node:assert";
2+
import { describe, it } from "vitest";
3+
import { emitSingleSchema } from "./test-host.js";
4+
5+
describe("circular references", () => {
6+
it("handles circular references between models", async () => {
7+
const code = `
8+
@schema
9+
namespace TestNamespace {
10+
model User {
11+
id: string;
12+
name: string;
13+
posts: Post[];
14+
}
15+
16+
model Post {
17+
id: string;
18+
title: string;
19+
author: User;
20+
comments: Comment[];
21+
}
22+
23+
model Comment {
24+
id: string;
25+
text: string;
26+
author: User;
27+
post: Post;
28+
}
29+
30+
@query
31+
op getUser(id: string): User;
32+
33+
@query
34+
op getPost(id: string): Post;
35+
}
36+
`;
37+
38+
const result = await emitSingleSchema(code, {});
39+
40+
strictEqual(result.includes("type User {"), true);
41+
strictEqual(result.includes("posts: [Post!]!"), true);
42+
strictEqual(result.includes("type Post {"), true);
43+
strictEqual(result.includes("author: User!"), true);
44+
strictEqual(result.includes("comments: [Comment!]!"), true);
45+
strictEqual(result.includes("type Comment {"), true);
46+
});
47+
});

packages/graphql/test/coverage-gaps.test.ts

Lines changed: 0 additions & 210 deletions
This file was deleted.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { strictEqual } from "node:assert";
2+
import { describe, it } from "vitest";
3+
import { emitSingleSchema } from "./test-host.js";
4+
5+
describe("deprecation", () => {
6+
it("supports @deprecated directive", async () => {
7+
const code = `
8+
@schema
9+
namespace TestNamespace {
10+
model User {
11+
id: string;
12+
name: string;
13+
#deprecated "Use email instead"
14+
username: string;
15+
}
16+
17+
@query
18+
op getUser(id: string): User;
19+
20+
#deprecated "Use getUserById instead"
21+
@query
22+
op findUser(id: string): User;
23+
}
24+
`;
25+
26+
const result = await emitSingleSchema(code, {});
27+
28+
strictEqual(result.includes('@deprecated(reason: "Use email instead")'), true);
29+
strictEqual(result.includes('@deprecated(reason: "Use getUserById instead")'), true);
30+
});
31+
});

0 commit comments

Comments
 (0)