Path: blob/main/tests/unit/schema-validation/error-location.test.ts
6451 views
/*1* error-location.test.ts2*3* Copyright (C) 2021-2022 Posit Software, PBC4*5*/67import { unitTest } from "../../test.ts";89//import { schemaTestFile } from "./utils.ts";10//import { cleanoutput } from "../../smoke/render/render.ts";11//import { validateDocumentFromSource } from "../../../src/core/schema/validate-document.ts";1213unitTest("schema-validation-error-location", async () => {14/*15FIXME: we're temporarily disabling this test since it relies on format16checks failing, and our format schema is disabled on `main` to avoid17user breakage at the moment.1819const {20input21} = schemaTestFile("good-validation-fail.qmd", "html");2223const src = Deno.readTextFileSync(input);24const ignore = (_foo: string) => {};25const errors = await validateDocumentFromSource(src, ignore, ignore);2627// check that it found all bad instances28const badInstancesGroundTruth = ["/format/html/dpi", "/echo"];29assert(errors.length === 2);30const badInstancesSeen = errors.map(error => error.instancePath);31assert(badInstancesSeen.every(seen => badInstancesGroundTruth.indexOf(seen) !== -1));3233// check that the instances are reported in the right location34const error1 = errors.filter(error => error.instancePath === "/format/html/dpi")[0];35const error2 = errors.filter(error => error.instancePath === "/echo")[0];3637// lines and columns are zero-based38assert(error1.start!.line === 4);39assert(error1.start!.column === 9);40assert(error1.end!.line === 4);41assert(error1.end!.column === 15);4243assert(error2.start!.line === 8);44assert(error2.start!.column === 9);45assert(error2.end!.line === 8);46assert(error2.end!.column === 15);4748cleanoutput("good-validation-fail.qmd", "html");49*/50});515253