-
Notifications
You must be signed in to change notification settings - Fork 182
Expand file tree
/
Copy pathsimple-docs.test.ts
More file actions
100 lines (81 loc) · 3.9 KB
/
Copy pathsimple-docs.test.ts
File metadata and controls
100 lines (81 loc) · 3.9 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
// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
import * as vscode from "vscode";
import { tinymist } from "../../lsp";
import type { Context } from ".";
export async function getTests(ctx: Context) {
// await ctx.openWorkspace("simple-docs");
await ctx.suite("starts Client", async (suite) => {
vscode.window.showInformationMessage("Start all tests.");
// const workspaceUri = ctx.workspaceUri();
const workspaceUri = ctx.getWorkspace("simple-docs");
console.log("Start all tests on ", workspaceUri.fsPath);
const completionLabel = (item: vscode.CompletionItem) => {
if (typeof item.label === "string") {
return item.label;
}
return item.label.label;
};
suite.addTest("starts Client", async () => {
const mainTyp = await ctx.openDocument(
vscode.Uri.joinPath(workspaceUri, "completion-base.typ"),
);
const pong = await ctx.completion<vscode.CompletionList>(
mainTyp.document.uri,
new vscode.Position(7, 2),
);
ctx.expect(pong.items.map(completionLabel)).to.include.members(["aa", "aab", "aabc"]);
// close the editor
await vscode.commands.executeCommand("workbench.action.closeActiveEditor");
});
suite.addTest("starts Preview", async () => {
await ctx.openDocument(vscode.Uri.joinPath(workspaceUri, "preview-skyzh-cv.typ"));
let resp = (await vscode.commands.executeCommand("typst-preview.preview")) as any;
ctx.expect(resp).to.have.property("taskId");
const { taskId } = resp;
let previewState: any = await vscode.commands.executeCommand(
"tinymist.doInspectPreviewState",
);
ctx.expect(previewState.tasks).to.have.lengthOf(1);
ctx.expect(previewState.tasks[0].taskId).to.be.equal(taskId);
ctx.expect(!!previewState.tasks[0].panel).to.be.equal(true);
await ctx.openDocument(vscode.Uri.joinPath(workspaceUri, "preview-hello-world.typ"));
resp = await vscode.commands.executeCommand("typst-preview.preview");
ctx.expect(resp).to.have.property("taskId");
const { taskId: taskId2 } = resp;
previewState = await vscode.commands.executeCommand("tinymist.doInspectPreviewState");
ctx.expect(previewState.tasks).to.have.lengthOf(2);
await ctx.openDocument(vscode.Uri.joinPath(workspaceUri, "preview-skyzh-cv.typ"));
resp = await vscode.commands.executeCommand("typst-preview.preview");
ctx.expect(resp.message).to.be.equal("existed");
await vscode.commands.executeCommand("tinymist.doDisposePreview", { taskId });
await vscode.commands.executeCommand("tinymist.doDisposePreview", { taskId: taskId2 });
previewState = await vscode.commands.executeCommand("tinymist.doInspectPreviewState");
ctx.expect(previewState.tasks).to.have.lengthOf(0);
// close the editor
await vscode.commands.executeCommand("workbench.action.closeActiveEditor");
});
suite.addTest("restart server", async () => {
const _mainTyp = await ctx.openDocument(
vscode.Uri.joinPath(workspaceUri, "completion-base.typ"),
);
await vscode.commands.executeCommand("tinymist.restartServer");
// close the editor
await vscode.commands.executeCommand("workbench.action.closeActiveEditor");
});
suite.addTest("get recent log text", async () => {
const marker = `agent-log-marker-${Date.now()}`;
tinymist.outputChannel.append(marker);
const logs = await vscode.commands.executeCommand<string>("tinymist.getLogText");
ctx.expect(logs).to.include(marker);
const none = await vscode.commands.executeCommand<string>("tinymist.getLogText", {
maxChars: 0,
});
ctx.expect(none).to.equal("");
const tail = await vscode.commands.executeCommand<string>("tinymist.getLogText", {
maxChars: 16,
});
ctx.expect(tail.length).to.be.lessThanOrEqual(16);
});
});
}