microsoft/typespec

Public

mirrored from https://github.com/microsoft/typespecAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
e966efd30e552f4e84d5ae7224515199738ddd8e

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

packages/compiler/testing/types.ts

47lines · modecode

1import { CompilerHost, Diagnostic, Program, Type } from "../core/index.js";
2import { CompilerOptions } from "../core/options.js";
3
4export 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
15export 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
27export interface TestFiles {
28 realDir: string;
29 pattern: string;
30 virtualPath: string;
31}
32
33export interface CadlTestLibrary {
34 name: string;
35 packageRoot: string;
36 files: TestFiles[];
37}
38
39export interface TestHostConfig {
40 libraries?: CadlTestLibrary[];
41}
42
43export class TestHostError extends Error {
44 constructor(message: string, public code: "ENOENT" | "ERR_MODULE_NOT_FOUND") {
45 super(message);
46 }
47}
48