Path: blob/main/tests/smoke/yaml-intelligence/yaml-intelligence.test.ts
6434 views
/*1* yaml-intelligence.test.ts2*3* Copyright (C) 2022 Posit Software, PBC4*5*/67import { expandGlobSync } from "../../../src/core/deno/expand-glob.ts";8import { unitTest } from "../../test.ts";910import { assert, assertEquals } from "testing/asserts";1112import { initYamlIntelligenceResourcesFromFilesystem } from "../../../src/core/schema/utils.ts";13import {14initState,15setInitializer,16} from "../../../src/core/lib/yaml-validation/state.ts";17import {18CompletionResult,19getAutomation,20} from "../../../src/core/lib/yaml-intelligence/yaml-intelligence.ts";2122async function fullInit() {23await initYamlIntelligenceResourcesFromFilesystem();24}2526unitTest("yaml-intelligence-smoke-regression", async () => {27setInitializer(fullInit);28await initState();2930for (31const { path: fileName } of expandGlobSync(32"smoke/yaml-intelligence/crashes/*.json",33)34) {35const { kind, context } = JSON.parse(Deno.readTextFileSync(fileName));36try {37await getAutomation(kind, context);38} catch (e) {39console.error("\n\n");40console.error("Regression failure, case:", fileName);41console.error(e);42assert(false, "Smoke assertion failed");43}44}45});4647unitTest("yaml-intelligence-unit-regression", async () => {48setInitializer(fullInit);49await initState();5051for (52const { path: fileName } of expandGlobSync(53"smoke/yaml-intelligence/checks/*.json",54)55) {56const input = JSON.parse(Deno.readTextFileSync(fileName));57const { kind, context, expected, expectedLength } = input;58const result = await getAutomation(kind, context);5960assert(result !== null);6162try {63if (expected !== undefined) {64assertEquals(result, expected);65}6667if (kind === "completions") {68if (expectedLength !== undefined) {69assertEquals(70(result as CompletionResult).completions.length,71expectedLength,72);73}74}75} catch (e) {76console.error("\n\nRegression failure, case:", fileName);77throw e;78}79}80});818283