Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/tests/smoke/project/common.ts
12925 views
1
/*
2
* common.ts
3
*
4
* Copyright (C) 2020-2022 Posit Software, PBC
5
*
6
*/
7
import { existsSync } from "../../../src/deno_ral/fs.ts";
8
import { join, dirname } from "../../../src/deno_ral/path.ts";
9
import { Verify, testQuartoCmd } from "../../test.ts";
10
import { outputForInput } from "../../utils.ts";
11
import { fileExists, noErrorsOrWarnings, noSupportingFiles } from "../../verify.ts";
12
13
export const kProjectWorkingDir = "simple-test";
14
export const kQuartoProjectFile = join(kProjectWorkingDir, "_quarto.yml");
15
16
export async function cleanWorking() {
17
if (existsSync(kProjectWorkingDir)) {
18
await Deno.remove(kProjectWorkingDir, { recursive: true });
19
}
20
}
21
22
export type OutputVerify = (outputDir: string) => Verify[];
23
24
// This is similar to testSite.
25
// It tests a project render, and allow to verify output directory assertions
26
export const testProjectRender = (
27
input: string,
28
to: string,
29
outputVerify: OutputVerify = (_outDir: string): Verify[] => [],
30
) => {
31
32
const output = outputForInput(input, to);
33
const outDir = dirname(output.outputPath);
34
const outVerify = outputVerify(outDir);
35
36
const verifyTests = [noErrorsOrWarnings, fileExists(output.supportPath)];
37
verifyTests.push(...outVerify);
38
39
// Run the command
40
testQuartoCmd(
41
"render",
42
[input],
43
verifyTests,
44
{
45
teardown: async () => {
46
const siteDir = dirname(output.outputPath);
47
if (existsSync(siteDir)) {
48
await Deno.remove(siteDir, { recursive: true });
49
}
50
},
51
},
52
);
53
};
54
55