@typespec/emitter-framework 0.9.0-dev.1 → 0.9.0-dev.10
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/dist/src/core/components/output.d.ts +4 -4
- package/dist/src/core/components/output.d.ts.map +1 -1
- package/dist/src/core/components/output.js +3 -3
- package/dist/src/core/context/name-policy-context.d.ts +2 -2
- package/dist/src/core/context/name-policy-context.d.ts.map +1 -1
- package/dist/src/core/context/tsp-context.d.ts +2 -2
- package/dist/src/core/context/tsp-context.d.ts.map +1 -1
- package/dist/src/core/transport-name-policy.d.ts +1 -1
- package/dist/src/core/transport-name-policy.d.ts.map +1 -1
- package/dist/src/core/write-output.d.ts +2 -2
- package/dist/src/core/write-output.d.ts.map +1 -1
- package/dist/src/csharp/components/class/declaration.d.ts +13 -0
- package/dist/src/csharp/components/class/declaration.d.ts.map +1 -0
- package/dist/src/csharp/components/class/declaration.js +91 -0
- package/dist/src/csharp/components/class/declaration.test.d.ts +2 -0
- package/dist/src/csharp/components/class/declaration.test.d.ts.map +1 -0
- package/dist/src/csharp/components/class/declaration.test.js +377 -0
- package/dist/src/csharp/components/enum/declaration.d.ts +9 -0
- package/dist/src/csharp/components/enum/declaration.d.ts.map +1 -0
- package/dist/src/csharp/components/enum/declaration.js +55 -0
- package/dist/src/csharp/components/enum/declaration.test.d.ts +2 -0
- package/dist/src/csharp/components/enum/declaration.test.d.ts.map +1 -0
- package/dist/src/csharp/components/enum/declaration.test.js +309 -0
- package/dist/src/csharp/components/index.d.ts +5 -0
- package/dist/src/csharp/components/index.d.ts.map +1 -0
- package/dist/src/csharp/components/index.js +4 -0
- package/dist/src/csharp/components/property/property.d.ts +15 -0
- package/dist/src/csharp/components/property/property.d.ts.map +1 -0
- package/dist/src/csharp/components/property/property.js +85 -0
- package/dist/src/csharp/components/property/property.test.d.ts +2 -0
- package/dist/src/csharp/components/property/property.test.d.ts.map +1 -0
- package/dist/src/csharp/components/property/property.test.js +117 -0
- package/dist/src/csharp/components/type-expression.d.ts +11 -0
- package/dist/src/csharp/components/type-expression.d.ts.map +1 -0
- package/dist/src/csharp/components/type-expression.js +143 -0
- package/dist/src/csharp/components/type-expression.test.d.ts +2 -0
- package/dist/src/csharp/components/type-expression.test.d.ts.map +1 -0
- package/dist/src/csharp/components/type-expression.test.js +128 -0
- package/dist/src/csharp/components/utils/doc-comments.d.ts +14 -0
- package/dist/src/csharp/components/utils/doc-comments.d.ts.map +1 -0
- package/dist/src/csharp/components/utils/doc-comments.js +67 -0
- package/dist/src/csharp/components/utils/refkey.d.ts +23 -0
- package/dist/src/csharp/components/utils/refkey.d.ts.map +1 -0
- package/dist/src/csharp/components/utils/refkey.js +35 -0
- package/dist/src/csharp/index.d.ts +2 -0
- package/dist/src/csharp/index.d.ts.map +1 -0
- package/dist/src/csharp/index.js +1 -0
- package/dist/src/testing/index.d.ts +1 -1
- package/dist/src/testing/index.d.ts.map +1 -1
- 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 +3 -3
- 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/src/typescript/components/array-expression.d.ts +2 -3
- package/dist/src/typescript/components/array-expression.d.ts.map +1 -1
- package/dist/src/typescript/components/array-expression.js +2 -2
- package/dist/src/typescript/components/arrow-function.d.ts +2 -2
- package/dist/src/typescript/components/arrow-function.d.ts.map +1 -1
- package/dist/src/typescript/components/arrow-function.js +2 -1
- package/dist/src/typescript/components/class-method.d.ts +1 -1
- package/dist/src/typescript/components/class-method.d.ts.map +1 -1
- package/dist/src/typescript/components/enum-declaration.d.ts +6 -6
- package/dist/src/typescript/components/enum-declaration.d.ts.map +1 -1
- package/dist/src/typescript/components/enum-declaration.js +2 -2
- package/dist/src/typescript/components/function-declaration.d.ts +1 -1
- package/dist/src/typescript/components/function-declaration.d.ts.map +1 -1
- package/dist/src/typescript/components/function-expression.d.ts +2 -2
- package/dist/src/typescript/components/function-expression.d.ts.map +1 -1
- package/dist/src/typescript/components/function-expression.js +2 -1
- package/dist/src/typescript/components/function-type.d.ts +2 -2
- package/dist/src/typescript/components/function-type.d.ts.map +1 -1
- package/dist/src/typescript/components/function-type.js +2 -1
- package/dist/src/typescript/components/interface-declaration.d.ts +4 -4
- package/dist/src/typescript/components/interface-declaration.d.ts.map +1 -1
- package/dist/src/typescript/components/interface-declaration.js +3 -4
- package/dist/src/typescript/components/interface-member.d.ts +2 -2
- package/dist/src/typescript/components/interface-member.d.ts.map +1 -1
- package/dist/src/typescript/components/interface-method.d.ts +2 -2
- package/dist/src/typescript/components/interface-method.d.ts.map +1 -1
- package/dist/src/typescript/components/record-expression.d.ts +1 -1
- package/dist/src/typescript/components/record-expression.d.ts.map +1 -1
- package/dist/src/typescript/components/type-alias-declaration.d.ts +1 -1
- package/dist/src/typescript/components/type-alias-declaration.d.ts.map +1 -1
- package/dist/src/typescript/components/type-declaration.d.ts +1 -1
- package/dist/src/typescript/components/type-declaration.d.ts.map +1 -1
- package/dist/src/typescript/components/type-expression.d.ts +1 -1
- package/dist/src/typescript/components/type-expression.d.ts.map +1 -1
- package/dist/src/typescript/components/type-transform.d.ts +2 -2
- package/dist/src/typescript/components/type-transform.d.ts.map +1 -1
- package/dist/src/typescript/components/union-declaration.d.ts +2 -2
- package/dist/src/typescript/components/union-declaration.d.ts.map +1 -1
- package/dist/src/typescript/components/union-expression.d.ts +3 -4
- package/dist/src/typescript/components/union-expression.d.ts.map +1 -1
- package/dist/src/typescript/components/union-expression.js +3 -3
- package/dist/src/typescript/components/value-expression.d.ts +2 -2
- package/dist/src/typescript/components/value-expression.d.ts.map +1 -1
- package/dist/src/typescript/utils/operation.d.ts +2 -2
- package/dist/src/typescript/utils/operation.d.ts.map +1 -1
- package/dist/test/test-host.d.ts +2 -0
- package/dist/test/test-host.d.ts.map +1 -0
- package/dist/test/test-host.js +5 -0
- 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/dist/test/typescript/components/member-expression.test.js +5 -5
- package/dist/test/typescript/test-host.d.ts +1 -1
- package/dist/test/typescript/test-host.d.ts.map +1 -1
- package/dist/test/utils.d.ts +2 -2
- package/dist/test/utils.d.ts.map +1 -1
- package/dist/test/vitest.setup.d.ts +2 -0
- package/dist/test/vitest.setup.d.ts.map +1 -0
- package/dist/test/vitest.setup.js +1 -0
- package/package.json +26 -8
- package/src/core/components/output.tsx +9 -5
- package/src/core/context/name-policy-context.ts +2 -2
- package/src/core/context/tsp-context.ts +2 -2
- package/src/core/transport-name-policy.ts +1 -1
- package/src/core/write-output.ts +2 -2
- package/src/csharp/components/class/declaration.test.tsx +339 -0
- package/src/csharp/components/class/declaration.tsx +86 -0
- package/src/csharp/components/enum/declaration.test.tsx +267 -0
- package/src/csharp/components/enum/declaration.tsx +56 -0
- package/src/csharp/components/index.ts +4 -0
- package/src/csharp/components/property/property.test.tsx +97 -0
- package/src/csharp/components/property/property.tsx +62 -0
- package/src/csharp/components/type-expression.test.tsx +133 -0
- package/src/csharp/components/type-expression.tsx +119 -0
- package/src/csharp/components/utils/doc-comments.tsx +58 -0
- package/src/csharp/components/utils/refkey.ts +36 -0
- package/src/csharp/index.ts +1 -0
- package/src/testing/index.ts +1 -1
- 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 +92 -237
- package/src/testing/scenario-test/index.ts +0 -1
- package/src/testing/scenario-test/snippet-extractor.ts +1 -1
- package/src/typescript/components/array-expression.tsx +3 -3
- package/src/typescript/components/arrow-function.tsx +2 -2
- package/src/typescript/components/class-method.tsx +1 -1
- package/src/typescript/components/enum-declaration.tsx +6 -6
- package/src/typescript/components/function-declaration.tsx +1 -1
- package/src/typescript/components/function-expression.tsx +2 -2
- package/src/typescript/components/function-type.tsx +2 -2
- package/src/typescript/components/interface-declaration.tsx +11 -12
- package/src/typescript/components/interface-member.tsx +2 -2
- package/src/typescript/components/interface-method.tsx +2 -2
- package/src/typescript/components/record-expression.tsx +1 -1
- package/src/typescript/components/type-alias-declaration.tsx +1 -1
- package/src/typescript/components/type-declaration.tsx +1 -1
- package/src/typescript/components/type-expression.tsx +2 -2
- package/src/typescript/components/type-transform.tsx +3 -3
- package/src/typescript/components/union-declaration.tsx +2 -2
- package/src/typescript/components/union-expression.tsx +12 -7
- package/src/typescript/components/value-expression.tsx +2 -2
- package/src/typescript/utils/operation.ts +2 -2
- package/test/test-host.ts +4 -0
- package/test/testing/snippet-extractor-csharp.test.ts +4 -4
- package/test/testing/snippet-extractor-java.test.ts +4 -4
- package/test/testing/snippet-extractor-python.test.ts +3 -3
- package/test/testing/snippet-extractor-typescript.test.ts +4 -4
- package/test/typescript/components/arrow-function.test.tsx +2 -2
- package/test/typescript/components/enum-declaration.test.tsx +1 -1
- package/test/typescript/components/function-declaration.test.tsx +1 -1
- package/test/typescript/components/function-expression.test.tsx +2 -2
- package/test/typescript/components/function-type.test.tsx +2 -2
- package/test/typescript/components/interface-declaration.test.tsx +1 -1
- package/test/typescript/components/interface-method.test.tsx +2 -2
- package/test/typescript/components/member-expression.test.tsx +10 -10
- package/test/typescript/components/type-alias-declaration.test.tsx +1 -1
- package/test/typescript/components/type-transform.test.tsx +2 -2
- package/test/typescript/components/union-declaration.test.tsx +2 -2
- package/test/typescript/components/value-expression.test.tsx +6 -6
- package/test/typescript/test-host.ts +1 -1
- package/test/utils.ts +2 -2
- package/test/vitest.setup.ts +1 -0
- package/tsconfig.json +3 -1
- package/vitest.config.ts +2 -1
- 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 { CompilerOptions, Diagnostic } from "@typespec/compiler";
|
|
2
|
-
import {
|
|
3
|
-
BasicTestRunner,
|
|
4
|
-
createTestHost,
|
|
5
|
-
createTestWrapper,
|
|
6
|
-
TestHostConfig,
|
|
7
|
-
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
|
-
}
|