Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/tests/smoke/typst-gather/typst-gather.test.ts
6466 views
1
import { testQuartoCmd, Verify } from "../../test.ts";
2
import { assert } from "testing/asserts";
3
import { existsSync } from "../../../src/deno_ral/fs.ts";
4
5
// Test 1: Auto-detection from _extension.yml
6
const verifyPackagesCreated: Verify = {
7
name: "Verify typst/packages directory was created",
8
verify: async () => {
9
const packagesDir = "_extensions/test-format/typst/packages";
10
assert(
11
existsSync(packagesDir),
12
`Expected typst/packages directory not found: ${packagesDir}`,
13
);
14
},
15
};
16
17
const verifyExamplePackageCached: Verify = {
18
name: "Verify @preview/example package was cached",
19
verify: async () => {
20
const packageDir =
21
"_extensions/test-format/typst/packages/preview/example/0.1.0";
22
assert(
23
existsSync(packageDir),
24
`Expected cached package not found: ${packageDir}`,
25
);
26
27
// Verify typst.toml exists in the package
28
const manifestPath = `${packageDir}/typst.toml`;
29
assert(
30
existsSync(manifestPath),
31
`Expected package manifest not found: ${manifestPath}`,
32
);
33
},
34
};
35
36
testQuartoCmd(
37
"call",
38
["typst-gather"],
39
[verifyPackagesCreated, verifyExamplePackageCached],
40
{
41
cwd: () => "smoke/typst-gather",
42
},
43
"typst-gather caches preview packages from extension templates",
44
);
45
46
// Test 2: Config file with rootdir
47
const verifyConfigPackagesCreated: Verify = {
48
name: "Verify typst/packages directory was created via config",
49
verify: async () => {
50
const packagesDir = "_extensions/config-format/typst/packages";
51
assert(
52
existsSync(packagesDir),
53
`Expected typst/packages directory not found: ${packagesDir}`,
54
);
55
},
56
};
57
58
const verifyConfigExamplePackageCached: Verify = {
59
name: "Verify @preview/example package was cached via config",
60
verify: async () => {
61
const packageDir =
62
"_extensions/config-format/typst/packages/preview/example/0.1.0";
63
assert(
64
existsSync(packageDir),
65
`Expected cached package not found: ${packageDir}`,
66
);
67
68
const manifestPath = `${packageDir}/typst.toml`;
69
assert(
70
existsSync(manifestPath),
71
`Expected package manifest not found: ${manifestPath}`,
72
);
73
},
74
};
75
76
testQuartoCmd(
77
"call",
78
["typst-gather"],
79
[verifyConfigPackagesCreated, verifyConfigExamplePackageCached],
80
{
81
cwd: () => "smoke/typst-gather/with-config",
82
},
83
"typst-gather uses rootdir from config file",
84
);
85
86
// Test 3: --init-config generates config file
87
const verifyInitConfigCreated: Verify = {
88
name: "Verify typst-gather.toml was created",
89
verify: async () => {
90
assert(
91
existsSync("typst-gather.toml"),
92
"Expected typst-gather.toml to be created",
93
);
94
95
// Read and verify content has rootdir
96
const content = Deno.readTextFileSync("typst-gather.toml");
97
assert(
98
content.includes("rootdir"),
99
"Expected typst-gather.toml to contain rootdir",
100
);
101
assert(
102
content.includes("_extensions/test-format"),
103
"Expected rootdir to point to extension directory",
104
);
105
},
106
};
107
108
testQuartoCmd(
109
"call",
110
["typst-gather", "--init-config"],
111
[verifyInitConfigCreated],
112
{
113
cwd: () => "smoke/typst-gather",
114
teardown: async () => {
115
// Clean up generated config file
116
try {
117
Deno.removeSync("typst-gather.toml");
118
} catch {
119
// Ignore if already removed
120
}
121
},
122
},
123
"typst-gather --init-config generates config with rootdir",
124
);
125
126
// Test 4: @local package is copied when [local] section is configured
127
const verifyLocalPackageCopied: Verify = {
128
name: "Verify @local/my-local-pkg was copied",
129
verify: async () => {
130
const packageDir =
131
"_extensions/local-format/typst/packages/local/my-local-pkg/0.1.0";
132
assert(
133
existsSync(packageDir),
134
`Expected local package not found: ${packageDir}`,
135
);
136
137
const manifestPath = `${packageDir}/typst.toml`;
138
assert(
139
existsSync(manifestPath),
140
`Expected package manifest not found: ${manifestPath}`,
141
);
142
143
const libPath = `${packageDir}/lib.typ`;
144
assert(existsSync(libPath), `Expected lib.typ not found: ${libPath}`);
145
},
146
};
147
148
testQuartoCmd(
149
"call",
150
["typst-gather"],
151
[verifyLocalPackageCopied],
152
{
153
cwd: () => "smoke/typst-gather/with-local",
154
teardown: async () => {
155
// Clean up copied packages
156
try {
157
Deno.removeSync("_extensions/local-format/typst", { recursive: true });
158
} catch {
159
// Ignore if already removed
160
}
161
},
162
},
163
"typst-gather copies @local packages when configured",
164
);
165
166
// Test 5: --init-config detects @local imports and generates [local] section
167
const verifyInitConfigWithLocal: Verify = {
168
name: "Verify --init-config detects @local imports",
169
verify: async () => {
170
assert(
171
existsSync("typst-gather.toml"),
172
"Expected typst-gather.toml to be created",
173
);
174
175
const content = Deno.readTextFileSync("typst-gather.toml");
176
assert(
177
content.includes("[local]"),
178
"Expected typst-gather.toml to contain [local] section",
179
);
180
assert(
181
content.includes("my-local-pkg"),
182
"Expected typst-gather.toml to reference my-local-pkg",
183
);
184
assert(
185
content.includes("@local/my-local-pkg"),
186
"Expected typst-gather.toml to show found @local import",
187
);
188
},
189
};
190
191
testQuartoCmd(
192
"call",
193
["typst-gather", "--init-config"],
194
[verifyInitConfigWithLocal],
195
{
196
cwd: () => "smoke/typst-gather/with-local",
197
setup: async () => {
198
// Remove existing config so --init-config can run
199
try {
200
Deno.renameSync("typst-gather.toml", "typst-gather.toml.bak");
201
} catch {
202
// Ignore if doesn't exist
203
}
204
},
205
teardown: async () => {
206
// Restore original config and clean up generated one
207
try {
208
Deno.removeSync("typst-gather.toml");
209
} catch {
210
// Ignore
211
}
212
try {
213
Deno.renameSync("typst-gather.toml.bak", "typst-gather.toml");
214
} catch {
215
// Ignore
216
}
217
},
218
},
219
"typst-gather --init-config detects @local imports",
220
);
221
222