microsoft/typespec
Publicmirrored from https://github.com/microsoft/typespecAvailable
packages/compiler/testing/types.ts
47lines · modecode
| 1 | import { CompilerHost, Diagnostic, Program, Type } from "../core/index.js"; |
| 2 | import { CompilerOptions } from "../core/options.js"; |
| 3 | |
| 4 | export interface TestFileSystem { |
| 5 | compilerHost: CompilerHost; |
| 6 | fs: Map<string, string>; |
| 7 | |
| 8 | addCadlFile(path: string, contents: string): void; |
| 9 | addJsFile(path: string, contents: Record<string, any>): void; |
| 10 | addRealCadlFile(path: string, realPath: string): Promise<void>; |
| 11 | addRealJsFile(path: string, realPath: string): Promise<void>; |
| 12 | addCadlLibrary(testLibrary: CadlTestLibrary): Promise<void>; |
| 13 | } |
| 14 | |
| 15 | export interface TestHost extends TestFileSystem { |
| 16 | program: Program; |
| 17 | testTypes: Record<string, Type>; |
| 18 | |
| 19 | compile(main: string, options?: CompilerOptions): Promise<Record<string, Type>>; |
| 20 | diagnose(main: string, options?: CompilerOptions): Promise<readonly Diagnostic[]>; |
| 21 | compileAndDiagnose( |
| 22 | main: string, |
| 23 | options?: CompilerOptions |
| 24 | ): Promise<[Record<string, Type>, readonly Diagnostic[]]>; |
| 25 | } |
| 26 | |
| 27 | export interface TestFiles { |
| 28 | realDir: string; |
| 29 | pattern: string; |
| 30 | virtualPath: string; |
| 31 | } |
| 32 | |
| 33 | export interface CadlTestLibrary { |
| 34 | name: string; |
| 35 | packageRoot: string; |
| 36 | files: TestFiles[]; |
| 37 | } |
| 38 | |
| 39 | export interface TestHostConfig { |
| 40 | libraries?: CadlTestLibrary[]; |
| 41 | } |
| 42 | |
| 43 | export class TestHostError extends Error { |
| 44 | constructor(message: string, public code: "ENOENT" | "ERR_MODULE_NOT_FOUND") { |
| 45 | super(message); |
| 46 | } |
| 47 | } |
| 48 | |