Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/tests/smoke/convert/convert.ts
12921 views
1
/*
2
* convert.ts
3
*
4
* Copyright (C) 2020-2022 Posit Software, PBC
5
*
6
*/
7
import { existsSync } from "../../../src/deno_ral/fs.ts";
8
import { assert } from "testing/asserts";
9
10
import { outputForInput } from "../../utils.ts";
11
import {
12
ExecuteOutput,
13
TestContext,
14
testQuartoCmd,
15
Verify,
16
} from "../../test.ts";
17
import { verifyPath } from "../../verify.ts";
18
19
const outputConverted = (input: string, to: string): Verify => {
20
return {
21
name: "Output Converted",
22
verify: (outputs: ExecuteOutput[]) => {
23
// Check for output converted message
24
const outputCreatedMsg = outputs.find((outMsg) =>
25
outMsg.msg.startsWith("Converted to")
26
);
27
assert(outputCreatedMsg !== undefined, "No output convertsion message");
28
29
// Check for existence of the output
30
const outputFile = outputForInput(input, to);
31
verifyPath(outputFile.outputPath);
32
return Promise.resolve();
33
},
34
};
35
};
36
37
// currently only converts to ipynb
38
export function testConvert(
39
input: string,
40
addtlVerify?: Verify[],
41
context?: TestContext,
42
args?: string[],
43
) {
44
// Verify that the output was created and
45
// that supporting files are present or missing
46
const verify: Verify[] = [];
47
48
if (!input.endsWith("/")) {
49
verify.push(outputConverted(input, "ipynb"));
50
}
51
if (addtlVerify) {
52
verify.push(...addtlVerify);
53
}
54
context = context || {};
55
56
// Run the command
57
testQuartoCmd(
58
"convert",
59
[input, ...(args || [])],
60
verify,
61
{
62
...context,
63
teardown: async () => {
64
if (context?.teardown) {
65
await context?.teardown();
66
}
67
cleanoutput(input, "ipynb");
68
},
69
},
70
);
71
}
72
73
export function cleanoutput(input: string, to: string) {
74
const out = outputForInput(input, to);
75
if (existsSync(out.outputPath)) {
76
Deno.removeSync(out.outputPath);
77
}
78
if (existsSync(out.supportPath)) {
79
Deno.removeSync(out.supportPath, { recursive: true });
80
}
81
}
82
83