Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/tests/smoke/yaml-intelligence/yaml-intelligence.test.ts
6434 views
1
/*
2
* yaml-intelligence.test.ts
3
*
4
* Copyright (C) 2022 Posit Software, PBC
5
*
6
*/
7
8
import { expandGlobSync } from "../../../src/core/deno/expand-glob.ts";
9
import { unitTest } from "../../test.ts";
10
11
import { assert, assertEquals } from "testing/asserts";
12
13
import { initYamlIntelligenceResourcesFromFilesystem } from "../../../src/core/schema/utils.ts";
14
import {
15
initState,
16
setInitializer,
17
} from "../../../src/core/lib/yaml-validation/state.ts";
18
import {
19
CompletionResult,
20
getAutomation,
21
} from "../../../src/core/lib/yaml-intelligence/yaml-intelligence.ts";
22
23
async function fullInit() {
24
await initYamlIntelligenceResourcesFromFilesystem();
25
}
26
27
unitTest("yaml-intelligence-smoke-regression", async () => {
28
setInitializer(fullInit);
29
await initState();
30
31
for (
32
const { path: fileName } of expandGlobSync(
33
"smoke/yaml-intelligence/crashes/*.json",
34
)
35
) {
36
const { kind, context } = JSON.parse(Deno.readTextFileSync(fileName));
37
try {
38
await getAutomation(kind, context);
39
} catch (e) {
40
console.error("\n\n");
41
console.error("Regression failure, case:", fileName);
42
console.error(e);
43
assert(false, "Smoke assertion failed");
44
}
45
}
46
});
47
48
unitTest("yaml-intelligence-unit-regression", async () => {
49
setInitializer(fullInit);
50
await initState();
51
52
for (
53
const { path: fileName } of expandGlobSync(
54
"smoke/yaml-intelligence/checks/*.json",
55
)
56
) {
57
const input = JSON.parse(Deno.readTextFileSync(fileName));
58
const { kind, context, expected, expectedLength } = input;
59
const result = await getAutomation(kind, context);
60
61
assert(result !== null);
62
63
try {
64
if (expected !== undefined) {
65
assertEquals(result, expected);
66
}
67
68
if (kind === "completions") {
69
if (expectedLength !== undefined) {
70
assertEquals(
71
(result as CompletionResult).completions.length,
72
expectedLength,
73
);
74
}
75
}
76
} catch (e) {
77
console.error("\n\nRegression failure, case:", fileName);
78
throw e;
79
}
80
}
81
});
82
83