Skip to content

Commit 00630c4

Browse files
diyaayayjdesrosiers
authored andcommitted
Added deprecated tests
1 parent fdb019c commit 00630c4

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import { afterEach, beforeEach, describe, expect, test } from "vitest";
2+
import { DiagnosticSeverity, DiagnosticTag, PublishDiagnosticsNotification } from "vscode-languageserver";
3+
import { TestClient } from "../test-client.js";
4+
import documentSettings from "./document-settings.js";
5+
import semanticTokens from "./semantic-tokens.js";
6+
import schemaRegistry from "./schema-registry.js";
7+
import workspace from "./workspace.js";
8+
import DeprecatedFeature from "./deprecated.js";
9+
10+
import type { Diagnostic } from "vscode-languageserver";
11+
import type { DocumentSettings } from "./document-settings.js";
12+
13+
14+
describe("Feature - Deprecated", () => {
15+
let client: TestClient<DocumentSettings>;
16+
17+
beforeEach(async () => {
18+
client = new TestClient([
19+
workspace,
20+
documentSettings,
21+
semanticTokens,
22+
schemaRegistry,
23+
DeprecatedFeature
24+
]);
25+
await client.start();
26+
});
27+
28+
afterEach(async () => {
29+
await client.stop();
30+
});
31+
32+
test("test deprecated 2020-12", async () => {
33+
const diagnosticsPromise = new Promise<Diagnostic[]>((resolve) => {
34+
client.onNotification(PublishDiagnosticsNotification.type, (params) => {
35+
resolve(params.diagnostics);
36+
});
37+
});
38+
39+
await client.openDocument("./subject.schema.json", `{
40+
"$schema": "https://json-schema.org/draft/2020-12/schema",
41+
"definitions": {}
42+
}`);
43+
44+
const diagnostics = await diagnosticsPromise;
45+
expect(diagnostics[0].message).to.eql("Use '$defs'. 'definitions' was replaced with '$defs' in 2019-09");
46+
});
47+
48+
test("test deprecated 2019-09", async () => {
49+
const diagnosticsPromise = new Promise<Diagnostic[]>((resolve) => {
50+
client.onNotification(PublishDiagnosticsNotification.type, (params) => {
51+
resolve(params.diagnostics);
52+
});
53+
});
54+
55+
await client.openDocument("./subject.schema.json", `{
56+
"$schema": "https://json-schema.org/draft/2019-09/schema",
57+
"definitions": {}
58+
}`);
59+
60+
const diagnostics = await diagnosticsPromise;
61+
expect(diagnostics[0].message).to.eql("Use '$defs'. 'definitions' was replaced with '$defs' in 2019-09");
62+
});
63+
64+
test("test diganostics type", async () => {
65+
const diagnosticsPromise = new Promise<Diagnostic[]>((resolve) => {
66+
client.onNotification(PublishDiagnosticsNotification.type, (params) => {
67+
resolve(params.diagnostics);
68+
});
69+
});
70+
71+
await client.openDocument("./subject.schema.json", `{
72+
"$schema": "https://json-schema.org/draft/2019-09/schema",
73+
"definitions": {}
74+
}`);
75+
76+
const diagnostics = await diagnosticsPromise;
77+
expect(diagnostics[0].severity).to.eql(DiagnosticSeverity.Warning);
78+
});
79+
80+
test("test diganostics tag", async () => {
81+
const diagnosticsPromise = new Promise<Diagnostic[]>((resolve) => {
82+
client.onNotification(PublishDiagnosticsNotification.type, (params) => {
83+
resolve(params.diagnostics);
84+
});
85+
});
86+
87+
await client.openDocument("./subject.schema.json", `{
88+
"$schema": "https://json-schema.org/draft/2019-09/schema",
89+
"definitions": {}
90+
}`);
91+
92+
const diagnostics = await diagnosticsPromise;
93+
expect(diagnostics[0].tags).to.eql([DiagnosticTag.Deprecated]);
94+
});
95+
96+
test("test diganostics range", async () => {
97+
const diagnosticsPromise = new Promise<Diagnostic[]>((resolve) => {
98+
client.onNotification(PublishDiagnosticsNotification.type, (params) => {
99+
resolve(params.diagnostics);
100+
});
101+
});
102+
103+
await client.openDocument("./subject.schema.json", `{
104+
"$schema": "https://json-schema.org/draft/2019-09/schema",
105+
"definitions": {}
106+
}`);
107+
108+
const diagnostics = await diagnosticsPromise;
109+
const range = {
110+
"start": { "line": 2, "character": 4 },
111+
"end": { "line": 2, "character": 21 }
112+
};
113+
114+
expect(diagnostics[0].range).to.eql(range);
115+
});
116+
});

0 commit comments

Comments
 (0)