2022-01-20 02:10:16 -05:00
|
|
|
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
2021-11-23 11:45:18 -05:00
|
|
|
import { assert } from "./test_util.ts";
|
2020-02-24 14:48:14 -05:00
|
|
|
|
2021-11-23 11:45:18 -05:00
|
|
|
Deno.test(function formatDiagnosticBasic() {
|
2020-09-12 05:53:57 -04:00
|
|
|
const fixture: Deno.Diagnostic[] = [
|
2020-02-24 14:48:14 -05:00
|
|
|
{
|
2020-09-12 05:53:57 -04:00
|
|
|
start: {
|
|
|
|
line: 0,
|
|
|
|
character: 0,
|
|
|
|
},
|
|
|
|
end: {
|
|
|
|
line: 0,
|
|
|
|
character: 7,
|
|
|
|
},
|
|
|
|
fileName: "test.ts",
|
|
|
|
messageText:
|
|
|
|
"Cannot find name 'console'. Do you need to change your target library? Try changing the `lib` compiler option to include 'dom'.",
|
|
|
|
sourceLine: `console.log("a");`,
|
|
|
|
category: 1,
|
|
|
|
code: 2584,
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2020-02-24 14:48:14 -05:00
|
|
|
];
|
|
|
|
const out = Deno.formatDiagnostics(fixture);
|
2020-09-12 05:53:57 -04:00
|
|
|
assert(out.includes("Cannot find name"));
|
|
|
|
assert(out.includes("test.ts"));
|
2020-02-24 14:48:14 -05:00
|
|
|
});
|
|
|
|
|
2021-11-23 11:45:18 -05:00
|
|
|
Deno.test(function formatDiagnosticError() {
|
2020-02-24 14:48:14 -05:00
|
|
|
let thrown = false;
|
2020-11-03 10:19:29 -05:00
|
|
|
// deno-lint-ignore no-explicit-any
|
2020-09-12 05:53:57 -04:00
|
|
|
const bad = ([{ hello: 123 }] as any) as Deno.Diagnostic[];
|
2020-02-24 14:48:14 -05:00
|
|
|
try {
|
|
|
|
Deno.formatDiagnostics(bad);
|
|
|
|
} catch (e) {
|
2020-05-05 12:23:15 -04:00
|
|
|
assert(e instanceof Deno.errors.InvalidData);
|
2020-02-24 14:48:14 -05:00
|
|
|
thrown = true;
|
|
|
|
}
|
|
|
|
assert(thrown);
|
|
|
|
});
|