@typespec/emitter-framework 0.9.0-dev.8 → 0.10.0-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/dist/src/testing/scenario-test/code-block-expectation.d.ts +33 -0
- package/dist/src/testing/scenario-test/code-block-expectation.d.ts.map +1 -0
- package/dist/src/testing/scenario-test/code-block-expectation.js +69 -0
- package/dist/src/testing/scenario-test/code-block-expectation.test.d.ts +2 -0
- package/dist/src/testing/scenario-test/code-block-expectation.test.d.ts.map +1 -0
- package/dist/src/testing/scenario-test/code-block-expectation.test.js +80 -0
- package/dist/src/testing/scenario-test/harness.d.ts +2 -2
- package/dist/src/testing/scenario-test/harness.d.ts.map +1 -1
- package/dist/src/testing/scenario-test/harness.js +69 -158
- package/dist/src/testing/scenario-test/index.d.ts +0 -1
- package/dist/src/testing/scenario-test/index.d.ts.map +1 -1
- package/dist/src/testing/scenario-test/index.js +1 -2
- package/dist/src/testing/scenario-test/snippet-extractor.d.ts +1 -1
- package/dist/src/testing/scenario-test/snippet-extractor.js +1 -1
- package/dist/test/testing/snippet-extractor-csharp.test.js +3 -3
- package/dist/test/testing/snippet-extractor-java.test.js +3 -3
- package/dist/test/testing/snippet-extractor-python.test.js +2 -2
- package/dist/test/testing/snippet-extractor-typescript.test.js +3 -3
- package/package.json +20 -12
- package/src/testing/scenario-test/code-block-expectation.test.ts +95 -0
- package/src/testing/scenario-test/code-block-expectation.ts +115 -0
- package/src/testing/scenario-test/harness.ts +91 -236
- package/src/testing/scenario-test/index.ts +0 -1
- package/src/testing/scenario-test/snippet-extractor.ts +1 -1
- package/test/testing/snippet-extractor-csharp.test.ts +3 -3
- package/test/testing/snippet-extractor-java.test.ts +3 -3
- package/test/testing/snippet-extractor-python.test.ts +2 -2
- package/test/testing/snippet-extractor-typescript.test.ts +3 -3
- package/dist/src/testing/scenario-test/test-host.d.ts +0 -8
- package/dist/src/testing/scenario-test/test-host.d.ts.map +0 -1
- package/dist/src/testing/scenario-test/test-host.js +0 -49
- package/src/testing/scenario-test/test-host.ts +0 -83
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import type { CompilerOptions, Diagnostic } from "@typespec/compiler";
|
|
2
|
-
import {
|
|
3
|
-
type BasicTestRunner,
|
|
4
|
-
createTestHost,
|
|
5
|
-
createTestWrapper,
|
|
6
|
-
type TestHostConfig,
|
|
7
|
-
type TypeSpecTestLibrary,
|
|
8
|
-
} from "@typespec/compiler/testing";
|
|
9
|
-
import { HttpTestLibrary } from "@typespec/http/testing";
|
|
10
|
-
import { RestTestLibrary } from "@typespec/rest/testing";
|
|
11
|
-
import { join, relative } from "path";
|
|
12
|
-
|
|
13
|
-
export interface EmittedFile {
|
|
14
|
-
path: string;
|
|
15
|
-
content: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async function createEmitterTestRunner(
|
|
19
|
-
testLibrary: TypeSpecTestLibrary,
|
|
20
|
-
options: {
|
|
21
|
-
testHostConfig?: TestHostConfig;
|
|
22
|
-
autoImports?: string[];
|
|
23
|
-
autoUsings?: string[];
|
|
24
|
-
compilerOptions?: CompilerOptions;
|
|
25
|
-
} = {},
|
|
26
|
-
) {
|
|
27
|
-
const libraries = options.testHostConfig?.libraries ?? [
|
|
28
|
-
testLibrary,
|
|
29
|
-
HttpTestLibrary,
|
|
30
|
-
RestTestLibrary,
|
|
31
|
-
];
|
|
32
|
-
const host = await createTestHost({ libraries });
|
|
33
|
-
|
|
34
|
-
return createTestWrapper(host, {
|
|
35
|
-
autoImports: options.autoImports ?? ["@typespec/http", "@typespec/rest"],
|
|
36
|
-
autoUsings: options.autoUsings ?? ["TypeSpec.Http", "TypeSpec.Rest"],
|
|
37
|
-
compilerOptions: options.compilerOptions ?? {
|
|
38
|
-
noEmit: false,
|
|
39
|
-
emit: [testLibrary.name],
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export async function emitWithDiagnostics(
|
|
45
|
-
testLibrary: TypeSpecTestLibrary,
|
|
46
|
-
emitterOutputDir: string,
|
|
47
|
-
code: string,
|
|
48
|
-
): Promise<[EmittedFile[], readonly Diagnostic[]]> {
|
|
49
|
-
const runner = await createEmitterTestRunner(testLibrary);
|
|
50
|
-
await runner.compileAndDiagnose(code, {
|
|
51
|
-
outputDir: "tsp-output",
|
|
52
|
-
});
|
|
53
|
-
const result = await readFilesRecursively(emitterOutputDir, emitterOutputDir, runner);
|
|
54
|
-
return [result, runner.program.diagnostics];
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async function readFilesRecursively(
|
|
58
|
-
currentDir: string,
|
|
59
|
-
emitterOutputDir: string,
|
|
60
|
-
runner: BasicTestRunner,
|
|
61
|
-
): Promise<EmittedFile[]> {
|
|
62
|
-
const entries = await runner.program.host.readDir(currentDir);
|
|
63
|
-
const result: EmittedFile[] = [];
|
|
64
|
-
|
|
65
|
-
for (const entry of entries) {
|
|
66
|
-
const fullPath = join(currentDir, entry);
|
|
67
|
-
const stat = await runner.program.host.stat(fullPath);
|
|
68
|
-
|
|
69
|
-
if (stat.isDirectory()) {
|
|
70
|
-
// Recursively read files in the directory
|
|
71
|
-
const nestedFiles = await readFilesRecursively(fullPath, emitterOutputDir, runner);
|
|
72
|
-
result.push(...nestedFiles);
|
|
73
|
-
} else if (stat.isFile()) {
|
|
74
|
-
// Read the file
|
|
75
|
-
// Read the file and store it with a relative path
|
|
76
|
-
const relativePath = relative(emitterOutputDir, fullPath);
|
|
77
|
-
const fileContent = await runner.program.host.readFile(fullPath);
|
|
78
|
-
result.push({ path: relativePath, content: fileContent.text });
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return result;
|
|
83
|
-
}
|