forked from microsoft/typespec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-utils.ts
27 lines (25 loc) · 880 Bytes
/
test-utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { ok } from "assert";
import type { Diagnostic } from "../src/index.js";
import { expectDiagnosticEmpty } from "../src/testing/expect.js";
export interface Test<I extends unknown[], R> {
compile(...args: I): Promise<R>;
compileAndDiagnose(...args: I): Promise<[R | undefined, readonly Diagnostic[]]>;
diagnose(...args: I): Promise<readonly Diagnostic[]>;
}
export function defineTest<T extends unknown[], R>(
fn: (...args: T) => Promise<[R | undefined, readonly Diagnostic[]]>,
): Test<T, R> {
return {
compileAndDiagnose: fn,
compile: async (...args) => {
const [called, diagnostics] = await fn(...args);
expectDiagnosticEmpty(diagnostics);
ok(called, "Decorator was not called");
return called;
},
diagnose: async (...args) => {
const [_, diagnostics] = await fn(...args);
return diagnostics;
},
};
}