-
Notifications
You must be signed in to change notification settings - Fork 431
Expand file tree
/
Copy pathinstall.test.ts
More file actions
191 lines (177 loc) · 4.85 KB
/
install.test.ts
File metadata and controls
191 lines (177 loc) · 4.85 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import { noErrorsOrWarnings } from "../../verify.ts";
import { join } from "../../../src/deno_ral/path.ts";
import { ExecuteOutput, testQuartoCmd, Verify } from "../../test.ts";
import { assert } from "testing/asserts";
import { ensureDirSync, existsSync } from "../../../src/deno_ral/fs.ts";
import { docs } from "../../utils.ts";
import { isLinux } from "../../../src/deno_ral/platform.ts";
const verifySubDirCount = (dir: string, count: number): Verify => {
return {
name: "Verify number of directories",
verify: (_outputs: ExecuteOutput[]) => {
const contents = Deno.readDirSync(dir);
let subDirCount = 0;
for (const content of contents) {
if (content.isDirectory) {
subDirCount = subDirCount + 1;
}
}
assert(count === subDirCount, "Incorrect number of subdirectories");
return Promise.resolve();
},
};
};
const verifySubDirName = (dir: string, name: string): Verify => {
return {
name: "Verify name of the directory",
verify: (_outputs: ExecuteOutput[]) => {
assert(
existsSync(join(dir, name)),
"Expected subdirectory doesn't exist",
);
return Promise.resolve();
},
};
};
const workingDir = Deno.makeTempDirSync();
// Verify installation using a remote github repo
testQuartoCmd(
"install",
["extension", "quarto-ext/lightbox", "--no-prompt"],
[
noErrorsOrWarnings,
verifySubDirCount("_extensions", 1),
verifySubDirName("_extensions", "quarto-ext"),
],
{
cwd: () => {
return workingDir;
},
teardown: () => {
Deno.removeSync("_extensions", { recursive: true });
return Promise.resolve();
},
},
);
// Verify install using urls
const extUrls = [
"quarto-ext/lightbox",
"quarto-ext/lightbox@cool",
"quarto-ext/lightbox@v0.1.4",
"quarto-ext/lightbox@test/use-in-quarto-cli",
"quarto-ext/lightbox@a738ff253fd46dd0cdd6aa992178cb7561b70251",
"quarto-ext/lightbox@a738ff2",
"https://github.com/quarto-ext/lightbox/archive/refs/tags/v0.1.4.tar.gz",
"https://github.com/quarto-ext/lightbox/archive/refs/heads/main.tar.gz",
"https://github.com/quarto-ext/lightbox/archive/refs/heads/cool.tar.gz",
"https://github.com/quarto-ext/lightbox/archive/a738ff253fd46dd0cdd6aa992178cb7561b70251.tar.gz",
];
if (!isLinux) {
extUrls.push(
...[
"https://github.com/quarto-ext/lightbox/archive/refs/tags/v0.1.4.zip",
"https://github.com/quarto-ext/lightbox/archive/refs/heads/main.zip",
"https://github.com/quarto-ext/lightbox/archive/refs/heads/cool.zip",
"https://github.com/quarto-ext/lightbox/archive/a738ff253fd46dd0cdd6aa992178cb7561b70251.zip",
],
);
}
for (const extUrl of extUrls) {
// Verify installation using a remote github repo
testQuartoCmd(
"add",
[extUrl, "--no-prompt"],
[
noErrorsOrWarnings,
verifySubDirCount("_extensions", 1),
verifySubDirName("_extensions", "quarto-ext"),
],
{
cwd: () => {
return workingDir;
},
teardown: () => {
Deno.removeSync("_extensions", { recursive: true });
return Promise.resolve();
},
sanitize: {
resources: false,
},
},
);
}
// Verify use template using a remote github repo
const templateDir = join(workingDir, "template");
ensureDirSync(templateDir);
testQuartoCmd(
"use",
["template", "quarto-journals/jss", "--no-prompt"],
[
noErrorsOrWarnings,
verifySubDirCount("_extensions", 1),
verifySubDirName("_extensions", "quarto-journals"),
],
{
cwd: () => {
return templateDir;
},
teardown: () => {
Deno.chdir("..");
Deno.removeSync(templateDir, { recursive: true });
return Promise.resolve();
},
},
);
// Verify installation using a local zip file
const testDir = docs("extensions");
const testDirAbs = join(Deno.cwd(), testDir);
const zipFiles = [
{
path: "owned-multiple.tar.gz",
count: 3,
names: ["acm", "acs", "coolster"],
},
{
path: "unowned-multiple.tar.gz",
count: 3,
names: ["acm", "acs", "coolster"],
},
{
path: "rootdir.tar.gz",
count: 1,
names: ["latex-environments"],
},
{
path: "subdir.tar.gz",
count: 1,
names: ["latex-environments"],
},
];
for (const zipFile of zipFiles) {
const verification = [
noErrorsOrWarnings,
verifySubDirCount("_extensions", zipFile.count),
];
for (const name of zipFile.names) {
verification.push(verifySubDirName("_extensions", name));
}
const zipPath = join(testDirAbs, "ext-repo", zipFile.path);
testQuartoCmd(
"install",
["extension", zipPath, "--no-prompt"],
verification,
{
cwd: () => {
return workingDir;
},
teardown: () => {
try {
Deno.removeSync("_extensions", { recursive: true });
} catch {
// Weird flex but ok
}
return Promise.resolve();
},
},
);
}