Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/tests/smoke/extensions/install.test.ts
12925 views
1
import { noErrorsOrWarnings } from "../../verify.ts";
2
import { join } from "../../../src/deno_ral/path.ts";
3
import { ExecuteOutput, testQuartoCmd, Verify } from "../../test.ts";
4
import { assert } from "testing/asserts";
5
import { ensureDirSync, existsSync } from "../../../src/deno_ral/fs.ts";
6
import { docs } from "../../utils.ts";
7
import { isLinux } from "../../../src/deno_ral/platform.ts";
8
9
const verifySubDirCount = (dir: string, count: number): Verify => {
10
return {
11
name: "Verify number of directories",
12
verify: (_outputs: ExecuteOutput[]) => {
13
const contents = Deno.readDirSync(dir);
14
15
let subDirCount = 0;
16
for (const content of contents) {
17
if (content.isDirectory) {
18
subDirCount = subDirCount + 1;
19
}
20
}
21
22
assert(count === subDirCount, "Incorrect number of subdirectories");
23
return Promise.resolve();
24
},
25
};
26
};
27
28
const verifySubDirName = (dir: string, name: string): Verify => {
29
return {
30
name: "Verify name of the directory",
31
verify: (_outputs: ExecuteOutput[]) => {
32
assert(
33
existsSync(join(dir, name)),
34
"Expected subdirectory doesn't exist",
35
);
36
return Promise.resolve();
37
},
38
};
39
};
40
41
const workingDir = Deno.makeTempDirSync();
42
43
// Verify installation using a remote github repo
44
testQuartoCmd(
45
"install",
46
["extension", "quarto-ext/lightbox", "--no-prompt"],
47
[
48
noErrorsOrWarnings,
49
verifySubDirCount("_extensions", 1),
50
verifySubDirName("_extensions", "quarto-ext"),
51
],
52
{
53
cwd: () => {
54
return workingDir;
55
},
56
teardown: () => {
57
Deno.removeSync("_extensions", { recursive: true });
58
return Promise.resolve();
59
},
60
},
61
);
62
63
// Verify install using urls
64
const extUrls = [
65
"quarto-ext/lightbox",
66
"quarto-ext/lightbox@cool",
67
"quarto-ext/[email protected]",
68
"quarto-ext/lightbox@test/use-in-quarto-cli",
69
"https://github.com/quarto-ext/lightbox/archive/refs/tags/v0.1.4.tar.gz",
70
"https://github.com/quarto-ext/lightbox/archive/refs/heads/main.tar.gz",
71
"https://github.com/quarto-ext/lightbox/archive/refs/heads/cool.tar.gz",
72
];
73
74
if (!isLinux) {
75
extUrls.push(
76
...[
77
"https://github.com/quarto-ext/lightbox/archive/refs/tags/v0.1.4.zip",
78
"https://github.com/quarto-ext/lightbox/archive/refs/heads/main.zip",
79
"https://github.com/quarto-ext/lightbox/archive/refs/heads/cool.zip",
80
],
81
);
82
}
83
84
for (const extUrl of extUrls) {
85
// Verify installation using a remote github repo
86
testQuartoCmd(
87
"add",
88
[extUrl, "--no-prompt"],
89
[
90
noErrorsOrWarnings,
91
verifySubDirCount("_extensions", 1),
92
verifySubDirName("_extensions", "quarto-ext"),
93
],
94
{
95
cwd: () => {
96
return workingDir;
97
},
98
teardown: () => {
99
Deno.removeSync("_extensions", { recursive: true });
100
return Promise.resolve();
101
},
102
sanitize: {
103
resources: false,
104
},
105
},
106
);
107
}
108
109
// Verify use template using a remote github repo
110
const templateDir = join(workingDir, "template");
111
ensureDirSync(templateDir);
112
testQuartoCmd(
113
"use",
114
["template", "quarto-journals/jss", "--no-prompt"],
115
[
116
noErrorsOrWarnings,
117
verifySubDirCount("_extensions", 1),
118
verifySubDirName("_extensions", "quarto-journals"),
119
],
120
{
121
cwd: () => {
122
return templateDir;
123
},
124
teardown: () => {
125
Deno.chdir("..");
126
Deno.removeSync(templateDir, { recursive: true });
127
return Promise.resolve();
128
},
129
},
130
);
131
132
// Verify installation using a local zip file
133
const testDir = docs("extensions");
134
const testDirAbs = join(Deno.cwd(), testDir);
135
136
const zipFiles = [
137
{
138
path: "owned-multiple.tar.gz",
139
count: 3,
140
names: ["acm", "acs", "coolster"],
141
},
142
{
143
path: "unowned-multiple.tar.gz",
144
count: 3,
145
names: ["acm", "acs", "coolster"],
146
},
147
{
148
path: "rootdir.tar.gz",
149
count: 1,
150
names: ["latex-environments"],
151
},
152
{
153
path: "subdir.tar.gz",
154
count: 1,
155
names: ["latex-environments"],
156
},
157
];
158
159
for (const zipFile of zipFiles) {
160
const verification = [
161
noErrorsOrWarnings,
162
verifySubDirCount("_extensions", zipFile.count),
163
];
164
for (const name of zipFile.names) {
165
verification.push(verifySubDirName("_extensions", name));
166
}
167
168
const zipPath = join(testDirAbs, "ext-repo", zipFile.path);
169
testQuartoCmd(
170
"install",
171
["extension", zipPath, "--no-prompt"],
172
verification,
173
{
174
cwd: () => {
175
return workingDir;
176
},
177
teardown: () => {
178
try {
179
Deno.removeSync("_extensions", { recursive: true });
180
} catch {
181
// Weird flex but ok
182
}
183
return Promise.resolve();
184
},
185
},
186
);
187
}
188
189