@typespec/emitter-framework 0.11.0-dev.0 → 0.11.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/index.d.ts +2 -0
- package/dist/src/core/components/index.d.ts.map +1 -1
- package/dist/src/core/components/index.js +4 -1
- package/dist/src/core/components/index.js.map +1 -0
- package/dist/src/core/components/output.js +2 -1
- package/dist/src/core/components/output.js.map +1 -0
- package/dist/src/core/components/overrides/component-overrides.d.ts +64 -0
- package/dist/src/core/components/overrides/component-overrides.d.ts.map +1 -0
- package/dist/src/core/components/overrides/component-overrides.js +41 -0
- package/dist/src/core/components/overrides/component-overrides.js.map +1 -0
- package/dist/src/core/components/overrides/config.d.ts +28 -0
- package/dist/src/core/components/overrides/config.d.ts.map +1 -0
- package/dist/src/core/components/overrides/config.js +55 -0
- package/dist/src/core/components/overrides/config.js.map +1 -0
- package/dist/src/core/components/overrides/context.d.ts +11 -0
- package/dist/src/core/components/overrides/context.d.ts.map +1 -0
- package/dist/src/core/components/overrides/context.js +9 -0
- package/dist/src/core/components/overrides/context.js.map +1 -0
- package/dist/src/core/context/index.js +2 -1
- package/dist/src/core/context/index.js.map +1 -0
- package/dist/src/core/context/name-policy-context.js +2 -1
- package/dist/src/core/context/name-policy-context.js.map +1 -0
- package/dist/src/core/context/tsp-context.js +2 -1
- package/dist/src/core/context/tsp-context.js.map +1 -0
- package/dist/src/core/index.js +2 -1
- package/dist/src/core/index.js.map +1 -0
- package/dist/src/core/transport-name-policy.js +2 -1
- package/dist/src/core/transport-name-policy.js.map +1 -0
- package/dist/src/core/write-output.d.ts.map +1 -1
- package/dist/src/core/write-output.js +4 -3
- package/dist/src/core/write-output.js.map +1 -0
- package/dist/src/csharp/components/class/declaration.d.ts +1 -1
- package/dist/src/csharp/components/class/declaration.d.ts.map +1 -1
- package/dist/src/csharp/components/class/declaration.js +14 -5
- package/dist/src/csharp/components/class/declaration.js.map +1 -0
- package/dist/src/csharp/components/class/declaration.test.js +125 -92
- package/dist/src/csharp/components/class/declaration.test.js.map +1 -0
- package/dist/src/csharp/components/enum/declaration.js +2 -1
- package/dist/src/csharp/components/enum/declaration.js.map +1 -0
- package/dist/src/csharp/components/enum/declaration.test.js +52 -88
- package/dist/src/csharp/components/enum/declaration.test.js.map +1 -0
- package/dist/src/csharp/components/index.js +2 -1
- package/dist/src/csharp/components/index.js.map +1 -0
- package/dist/src/csharp/components/property/property.d.ts.map +1 -1
- package/dist/src/csharp/components/property/property.js +40 -14
- package/dist/src/csharp/components/property/property.js.map +1 -0
- package/dist/src/csharp/components/property/property.test.js +129 -29
- package/dist/src/csharp/components/property/property.test.js.map +1 -0
- package/dist/src/csharp/components/type-expression.d.ts.map +1 -1
- package/dist/src/csharp/components/type-expression.js +34 -6
- package/dist/src/csharp/components/type-expression.js.map +1 -0
- package/dist/src/csharp/components/type-expression.test.js +87 -54
- package/dist/src/csharp/components/type-expression.test.js.map +1 -0
- package/dist/src/csharp/components/utils/doc-comments.js +2 -1
- package/dist/src/csharp/components/utils/doc-comments.js.map +1 -0
- package/dist/src/csharp/components/utils/nullable-util.d.ts +4 -0
- package/dist/src/csharp/components/utils/nullable-util.d.ts.map +1 -0
- package/dist/src/csharp/components/utils/nullable-util.js +27 -0
- package/dist/src/csharp/components/utils/nullable-util.js.map +1 -0
- package/dist/src/csharp/components/utils/refkey.js +2 -1
- package/dist/src/csharp/components/utils/refkey.js.map +1 -0
- package/dist/src/csharp/index.js +2 -1
- package/dist/src/csharp/index.js.map +1 -0
- package/dist/src/lib.js +2 -1
- package/dist/src/lib.js.map +1 -0
- package/dist/src/testing/index.js +2 -1
- package/dist/src/testing/index.js.map +1 -0
- package/dist/src/testing/scenario-test/code-block-expectation.js +2 -1
- package/dist/src/testing/scenario-test/code-block-expectation.js.map +1 -0
- package/dist/src/testing/scenario-test/code-block-expectation.test.js +2 -1
- package/dist/src/testing/scenario-test/code-block-expectation.test.js.map +1 -0
- package/dist/src/testing/scenario-test/harness.js +8 -2
- package/dist/src/testing/scenario-test/harness.js.map +1 -0
- package/dist/src/testing/scenario-test/index.js +2 -1
- package/dist/src/testing/scenario-test/index.js.map +1 -0
- package/dist/src/testing/scenario-test/snippet-extractor.js +2 -1
- package/dist/src/testing/scenario-test/snippet-extractor.js.map +1 -0
- package/dist/src/typescript/components/array-expression.js +2 -1
- package/dist/src/typescript/components/array-expression.js.map +1 -0
- package/dist/src/typescript/components/arrow-function.js +2 -1
- package/dist/src/typescript/components/arrow-function.js.map +1 -0
- package/dist/src/typescript/components/class-method.js +2 -1
- package/dist/src/typescript/components/class-method.js.map +1 -0
- package/dist/src/typescript/components/enum-declaration.js +2 -1
- package/dist/src/typescript/components/enum-declaration.js.map +1 -0
- package/dist/src/typescript/components/function-declaration.js +2 -1
- package/dist/src/typescript/components/function-declaration.js.map +1 -0
- package/dist/src/typescript/components/function-expression.js +2 -1
- package/dist/src/typescript/components/function-expression.js.map +1 -0
- package/dist/src/typescript/components/function-type.js +2 -1
- package/dist/src/typescript/components/function-type.js.map +1 -0
- package/dist/src/typescript/components/index.js +2 -1
- package/dist/src/typescript/components/index.js.map +1 -0
- package/dist/src/typescript/components/interface-declaration.js +2 -1
- package/dist/src/typescript/components/interface-declaration.js.map +1 -0
- package/dist/src/typescript/components/interface-member.d.ts.map +1 -1
- package/dist/src/typescript/components/interface-member.js +13 -20
- package/dist/src/typescript/components/interface-member.js.map +1 -0
- package/dist/src/typescript/components/interface-method.js +2 -1
- package/dist/src/typescript/components/interface-method.js.map +1 -0
- package/dist/src/typescript/components/record-expression.js +2 -1
- package/dist/src/typescript/components/record-expression.js.map +1 -0
- package/dist/src/typescript/components/static-serializers.js +2 -1
- package/dist/src/typescript/components/static-serializers.js.map +1 -0
- package/dist/src/typescript/components/type-alias-declaration.js +2 -1
- package/dist/src/typescript/components/type-alias-declaration.js.map +1 -0
- package/dist/src/typescript/components/type-declaration.js +2 -1
- package/dist/src/typescript/components/type-declaration.js.map +1 -0
- package/dist/src/typescript/components/type-expression.d.ts +0 -1
- package/dist/src/typescript/components/type-expression.d.ts.map +1 -1
- package/dist/src/typescript/components/type-expression.js +13 -12
- package/dist/src/typescript/components/type-expression.js.map +1 -0
- package/dist/src/typescript/components/type-transform.d.ts.map +1 -1
- package/dist/src/typescript/components/type-transform.js +5 -4
- package/dist/src/typescript/components/type-transform.js.map +1 -0
- package/dist/src/typescript/components/union/declaration.js +2 -1
- package/dist/src/typescript/components/union/declaration.js.map +1 -0
- package/dist/src/typescript/components/union/declaration.test.js +2 -1
- package/dist/src/typescript/components/union/declaration.test.js.map +1 -0
- package/dist/src/typescript/components/union/expression.js +2 -1
- package/dist/src/typescript/components/union/expression.js.map +1 -0
- package/dist/src/typescript/components/union/expression.test.js +2 -1
- package/dist/src/typescript/components/union/expression.test.js.map +1 -0
- package/dist/src/typescript/components/value-expression.js +2 -1
- package/dist/src/typescript/components/value-expression.js.map +1 -0
- package/dist/src/typescript/index.js +2 -1
- package/dist/src/typescript/index.js.map +1 -0
- package/dist/src/typescript/lib.js +2 -1
- package/dist/src/typescript/lib.js.map +1 -0
- package/dist/src/typescript/utils/index.js +2 -1
- package/dist/src/typescript/utils/index.js.map +1 -0
- package/dist/src/typescript/utils/operation.js +2 -1
- package/dist/src/typescript/utils/operation.js.map +1 -0
- package/dist/src/typescript/utils/refkey.js +2 -1
- package/dist/src/typescript/utils/refkey.js.map +1 -0
- package/dist/test/test-host.js +2 -1
- package/dist/test/test-host.js.map +1 -0
- package/dist/test/testing/snippet-extractor-csharp.test.js +2 -1
- package/dist/test/testing/snippet-extractor-csharp.test.js.map +1 -0
- package/dist/test/testing/snippet-extractor-java.test.js +2 -1
- package/dist/test/testing/snippet-extractor-java.test.js.map +1 -0
- package/dist/test/testing/snippet-extractor-python.test.js +2 -1
- package/dist/test/testing/snippet-extractor-python.test.js.map +1 -0
- package/dist/test/testing/snippet-extractor-typescript.test.js +2 -1
- package/dist/test/testing/snippet-extractor-typescript.test.js.map +1 -0
- package/dist/test/typescript/components/arrow-function.test.js +18 -22
- package/dist/test/typescript/components/arrow-function.test.js.map +1 -0
- package/dist/test/typescript/components/component-override.test.d.ts +2 -0
- package/dist/test/typescript/components/component-override.test.d.ts.map +1 -0
- package/dist/test/typescript/components/component-override.test.js +78 -0
- package/dist/test/typescript/components/component-override.test.js.map +1 -0
- package/dist/test/typescript/components/enum-declaration.test.js +2 -1
- package/dist/test/typescript/components/enum-declaration.test.js.map +1 -0
- package/dist/test/typescript/components/function-declaration.test.js +3 -2
- package/dist/test/typescript/components/function-declaration.test.js.map +1 -0
- package/dist/test/typescript/components/function-expression.test.js +18 -22
- package/dist/test/typescript/components/function-expression.test.js.map +1 -0
- package/dist/test/typescript/components/function-type.test.js +18 -22
- package/dist/test/typescript/components/function-type.test.js.map +1 -0
- package/dist/test/typescript/components/interface-declaration.test.js +3 -2
- package/dist/test/typescript/components/interface-declaration.test.js.map +1 -0
- package/dist/test/typescript/components/interface-method.test.js +37 -45
- package/dist/test/typescript/components/interface-method.test.js.map +1 -0
- package/dist/test/typescript/components/member-expression.test.js +2 -1
- package/dist/test/typescript/components/member-expression.test.js.map +1 -0
- package/dist/test/typescript/components/type-alias-declaration.test.js +8 -5
- package/dist/test/typescript/components/type-alias-declaration.test.js.map +1 -0
- package/dist/test/typescript/components/type-transform.test.js +29 -27
- package/dist/test/typescript/components/type-transform.test.js.map +1 -0
- package/dist/test/typescript/components/value-expression.test.js +3 -2
- package/dist/test/typescript/components/value-expression.test.js.map +1 -0
- package/dist/test/typescript/utils.js +2 -1
- package/dist/test/typescript/utils.js.map +1 -0
- package/dist/test/utils.d.ts +1 -0
- package/dist/test/utils.d.ts.map +1 -1
- package/dist/test/utils.js +13 -3
- package/dist/test/utils.js.map +1 -0
- package/dist/test/vitest.setup.js +2 -1
- package/dist/test/vitest.setup.js.map +1 -0
- package/package.json +9 -13
- package/src/core/components/index.tsx +2 -0
- package/src/core/components/overrides/component-overrides.tsx +134 -0
- package/src/core/components/overrides/config.ts +85 -0
- package/src/core/components/overrides/context.ts +14 -0
- package/src/core/write-output.ts +2 -2
- package/src/csharp/components/class/declaration.test.tsx +114 -88
- package/src/csharp/components/class/declaration.tsx +13 -3
- package/src/csharp/components/enum/declaration.test.tsx +47 -78
- package/src/csharp/components/property/property.test.tsx +108 -25
- package/src/csharp/components/property/property.tsx +43 -11
- package/src/csharp/components/type-expression.test.tsx +84 -69
- package/src/csharp/components/type-expression.tsx +31 -5
- package/src/csharp/components/utils/nullable-util.ts +25 -0
- package/src/testing/scenario-test/harness.ts +6 -1
- package/src/typescript/components/interface-member.tsx +8 -14
- package/src/typescript/components/type-expression.tsx +7 -8
- package/src/typescript/components/type-transform.tsx +3 -7
- package/test/typescript/components/arrow-function.test.tsx +23 -42
- package/test/typescript/components/component-override.test.tsx +71 -0
- package/test/typescript/components/function-declaration.test.tsx +2 -1
- package/test/typescript/components/function-expression.test.tsx +23 -42
- package/test/typescript/components/function-type.test.tsx +22 -40
- package/test/typescript/components/interface-declaration.test.tsx +1 -1
- package/test/typescript/components/interface-method.test.tsx +50 -92
- package/test/typescript/components/type-alias-declaration.test.tsx +8 -6
- package/test/typescript/components/type-transform.test.tsx +37 -37
- package/test/typescript/components/value-expression.test.tsx +1 -1
- package/test/utils.ts +10 -3
- package/dist/test/typescript/test-host.d.ts +0 -16
- package/dist/test/typescript/test-host.d.ts.map +0 -1
- package/dist/test/typescript/test-host.js +0 -40
- package/test/typescript/test-host.ts +0 -49
|
@@ -1,27 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Tester } from "#test/test-host.js";
|
|
2
|
+
import { getProgram } from "#test/utils.js";
|
|
3
3
|
import { InterfaceDeclaration, SourceFile } from "@alloy-js/typescript";
|
|
4
4
|
import type { Operation } from "@typespec/compiler";
|
|
5
|
-
import type
|
|
6
|
-
import { beforeEach, describe, it } from "vitest";
|
|
5
|
+
import { t, type TesterInstance } from "@typespec/compiler/testing";
|
|
6
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
7
7
|
import { Output } from "../../../src/core/components/output.jsx";
|
|
8
8
|
import { InterfaceMethod } from "../../../src/typescript/components/interface-method.jsx";
|
|
9
|
-
import { assertFileContents } from "../../utils.js";
|
|
10
|
-
import { createEmitterFrameworkTestRunner, getProgram } from "../test-host.js";
|
|
11
9
|
|
|
12
10
|
describe("interface methods with a `type` prop", () => {
|
|
13
|
-
let runner:
|
|
11
|
+
let runner: TesterInstance;
|
|
14
12
|
|
|
15
13
|
beforeEach(async () => {
|
|
16
|
-
runner = await
|
|
14
|
+
runner = await Tester.createInstance();
|
|
17
15
|
});
|
|
18
16
|
|
|
19
17
|
it("creates a interface method", async () => {
|
|
20
|
-
const { getName } = (await runner.compile(`
|
|
21
|
-
@test op getName(id: string): string;
|
|
18
|
+
const { getName } = (await runner.compile(t.code`
|
|
19
|
+
@test op ${t.op("getName")}(id: string): string;
|
|
22
20
|
`)) as { getName: Operation };
|
|
23
21
|
|
|
24
|
-
|
|
22
|
+
expect(
|
|
25
23
|
<Output program={runner.program}>
|
|
26
24
|
<SourceFile path="test.ts">
|
|
27
25
|
<InterfaceDeclaration name="basicInterface">
|
|
@@ -29,24 +27,19 @@ describe("interface methods with a `type` prop", () => {
|
|
|
29
27
|
</InterfaceDeclaration>
|
|
30
28
|
</SourceFile>
|
|
31
29
|
</Output>,
|
|
32
|
-
)
|
|
33
|
-
|
|
34
|
-
assertFileContents(
|
|
35
|
-
res,
|
|
36
|
-
d`
|
|
30
|
+
).toRenderTo(`
|
|
37
31
|
interface basicInterface {
|
|
38
32
|
getName(id: string): string
|
|
39
33
|
}
|
|
40
|
-
|
|
41
|
-
);
|
|
34
|
+
`);
|
|
42
35
|
});
|
|
43
36
|
|
|
44
37
|
it("creates an async interface function", async () => {
|
|
45
|
-
const { getName } =
|
|
46
|
-
@test op getName(id: string): string;
|
|
47
|
-
`)
|
|
38
|
+
const { getName } = await runner.compile(t.code`
|
|
39
|
+
@test op ${t.op("getName")}(id: string): string;
|
|
40
|
+
`);
|
|
48
41
|
|
|
49
|
-
|
|
42
|
+
expect(
|
|
50
43
|
<Output program={runner.program}>
|
|
51
44
|
<SourceFile path="test.ts">
|
|
52
45
|
<InterfaceDeclaration name="basicInterface">
|
|
@@ -54,24 +47,19 @@ describe("interface methods with a `type` prop", () => {
|
|
|
54
47
|
</InterfaceDeclaration>
|
|
55
48
|
</SourceFile>
|
|
56
49
|
</Output>,
|
|
57
|
-
)
|
|
58
|
-
|
|
59
|
-
assertFileContents(
|
|
60
|
-
res,
|
|
61
|
-
d`
|
|
50
|
+
).toRenderTo(`
|
|
62
51
|
interface basicInterface {
|
|
63
52
|
getName(id: string): Promise<string>
|
|
64
53
|
}
|
|
65
|
-
|
|
66
|
-
);
|
|
54
|
+
`);
|
|
67
55
|
});
|
|
68
56
|
|
|
69
57
|
it("can append extra parameters with raw params provided", async () => {
|
|
70
|
-
const { getName } =
|
|
71
|
-
@test op getName(id: string): string;
|
|
72
|
-
`)
|
|
58
|
+
const { getName } = await runner.compile(t.code`
|
|
59
|
+
@test op ${t.op("getName")}(id: string): string;
|
|
60
|
+
`);
|
|
73
61
|
|
|
74
|
-
|
|
62
|
+
expect(
|
|
75
63
|
<Output program={runner.program}>
|
|
76
64
|
<SourceFile path="test.ts">
|
|
77
65
|
<InterfaceDeclaration name="basicInterface">
|
|
@@ -83,24 +71,19 @@ describe("interface methods with a `type` prop", () => {
|
|
|
83
71
|
</InterfaceDeclaration>
|
|
84
72
|
</SourceFile>
|
|
85
73
|
</Output>,
|
|
86
|
-
)
|
|
87
|
-
|
|
88
|
-
assertFileContents(
|
|
89
|
-
res,
|
|
90
|
-
d`
|
|
74
|
+
).toRenderTo(`
|
|
91
75
|
interface basicInterface {
|
|
92
76
|
getName(id: string, foo: string): string
|
|
93
77
|
}
|
|
94
|
-
|
|
95
|
-
);
|
|
78
|
+
`);
|
|
96
79
|
});
|
|
97
80
|
|
|
98
81
|
it("can prepend extra parameters with raw params provided", async () => {
|
|
99
|
-
const { getName } =
|
|
100
|
-
@test op getName(id: string): string;
|
|
101
|
-
`)
|
|
82
|
+
const { getName } = await runner.compile(t.code`
|
|
83
|
+
@test op ${t.op("getName")}(id: string): string;
|
|
84
|
+
`);
|
|
102
85
|
|
|
103
|
-
|
|
86
|
+
expect(
|
|
104
87
|
<Output program={runner.program}>
|
|
105
88
|
<SourceFile path="test.ts">
|
|
106
89
|
<InterfaceDeclaration name="basicInterface">
|
|
@@ -112,24 +95,19 @@ describe("interface methods with a `type` prop", () => {
|
|
|
112
95
|
</InterfaceDeclaration>
|
|
113
96
|
</SourceFile>
|
|
114
97
|
</Output>,
|
|
115
|
-
)
|
|
116
|
-
|
|
117
|
-
assertFileContents(
|
|
118
|
-
res,
|
|
119
|
-
d`
|
|
98
|
+
).toRenderTo(`
|
|
120
99
|
interface basicInterface {
|
|
121
100
|
getName(foo: string, id: string): string
|
|
122
101
|
}
|
|
123
|
-
|
|
124
|
-
);
|
|
102
|
+
`);
|
|
125
103
|
});
|
|
126
104
|
|
|
127
105
|
it("can replace parameters with raw params provided", async () => {
|
|
128
|
-
const { getName } =
|
|
129
|
-
@test op getName(id: string): string;
|
|
130
|
-
`)
|
|
106
|
+
const { getName } = await runner.compile(t.code`
|
|
107
|
+
@test op ${t.op("getName")}(id: string): string;
|
|
108
|
+
`);
|
|
131
109
|
|
|
132
|
-
|
|
110
|
+
expect(
|
|
133
111
|
<Output program={runner.program}>
|
|
134
112
|
<SourceFile path="test.ts">
|
|
135
113
|
<InterfaceDeclaration name="basicInterface">
|
|
@@ -144,24 +122,19 @@ describe("interface methods with a `type` prop", () => {
|
|
|
144
122
|
</InterfaceDeclaration>
|
|
145
123
|
</SourceFile>
|
|
146
124
|
</Output>,
|
|
147
|
-
)
|
|
148
|
-
|
|
149
|
-
assertFileContents(
|
|
150
|
-
res,
|
|
151
|
-
d`
|
|
125
|
+
).toRenderTo(`
|
|
152
126
|
interface basicInterface {
|
|
153
127
|
getName(foo: string, bar: number): string
|
|
154
128
|
}
|
|
155
|
-
|
|
156
|
-
);
|
|
129
|
+
`);
|
|
157
130
|
});
|
|
158
131
|
|
|
159
132
|
it("can override return type", async () => {
|
|
160
|
-
const { getName } =
|
|
161
|
-
@test op getName(id: string): string;
|
|
162
|
-
`)
|
|
133
|
+
const { getName } = await runner.compile(t.code`
|
|
134
|
+
@test op ${t.op("getName")}(id: string): string;
|
|
135
|
+
`);
|
|
163
136
|
|
|
164
|
-
|
|
137
|
+
expect(
|
|
165
138
|
<Output program={runner.program}>
|
|
166
139
|
<SourceFile path="test.ts">
|
|
167
140
|
<InterfaceDeclaration name="basicInterface">
|
|
@@ -169,24 +142,19 @@ describe("interface methods with a `type` prop", () => {
|
|
|
169
142
|
</InterfaceDeclaration>
|
|
170
143
|
</SourceFile>
|
|
171
144
|
</Output>,
|
|
172
|
-
)
|
|
173
|
-
|
|
174
|
-
assertFileContents(
|
|
175
|
-
res,
|
|
176
|
-
d`
|
|
145
|
+
).toRenderTo(`
|
|
177
146
|
interface basicInterface {
|
|
178
147
|
getName(id: string): Promise<Record<string, unknown>>
|
|
179
148
|
}
|
|
180
|
-
|
|
181
|
-
);
|
|
149
|
+
`);
|
|
182
150
|
});
|
|
183
151
|
|
|
184
152
|
it("can override method name", async () => {
|
|
185
|
-
const { getName } =
|
|
186
|
-
@test op getName(id: string): string;
|
|
187
|
-
`)
|
|
153
|
+
const { getName } = await runner.compile(t.code`
|
|
154
|
+
@test op ${t.op("getName")}(id: string): string;
|
|
155
|
+
`);
|
|
188
156
|
|
|
189
|
-
|
|
157
|
+
expect(
|
|
190
158
|
<Output program={runner.program}>
|
|
191
159
|
<SourceFile path="test.ts">
|
|
192
160
|
<InterfaceDeclaration name="basicInterface">
|
|
@@ -194,23 +162,18 @@ describe("interface methods with a `type` prop", () => {
|
|
|
194
162
|
</InterfaceDeclaration>
|
|
195
163
|
</SourceFile>
|
|
196
164
|
</Output>,
|
|
197
|
-
)
|
|
198
|
-
|
|
199
|
-
assertFileContents(
|
|
200
|
-
res,
|
|
201
|
-
d`
|
|
165
|
+
).toRenderTo(`
|
|
202
166
|
interface basicInterface {
|
|
203
167
|
getNameCustom(id: string): string
|
|
204
168
|
}
|
|
205
|
-
|
|
206
|
-
);
|
|
169
|
+
`);
|
|
207
170
|
});
|
|
208
171
|
});
|
|
209
172
|
|
|
210
173
|
describe("interface methods without a `type` prop", () => {
|
|
211
174
|
it("renders a plain interface method", async () => {
|
|
212
175
|
const program = await getProgram("");
|
|
213
|
-
|
|
176
|
+
expect(
|
|
214
177
|
<Output program={program}>
|
|
215
178
|
<SourceFile path="test.ts">
|
|
216
179
|
<InterfaceDeclaration name="basicInterface">
|
|
@@ -222,15 +185,10 @@ describe("interface methods without a `type` prop", () => {
|
|
|
222
185
|
</InterfaceDeclaration>
|
|
223
186
|
</SourceFile>
|
|
224
187
|
</Output>,
|
|
225
|
-
)
|
|
226
|
-
|
|
227
|
-
assertFileContents(
|
|
228
|
-
res,
|
|
229
|
-
d`
|
|
188
|
+
).toRenderTo(`
|
|
230
189
|
interface basicInterface {
|
|
231
190
|
plainMethod(param1: string): number
|
|
232
191
|
}
|
|
233
|
-
|
|
234
|
-
);
|
|
192
|
+
`);
|
|
235
193
|
});
|
|
236
194
|
});
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { Tester } from "#test/test-host.js";
|
|
2
|
+
import { getProgram } from "#test/utils.js";
|
|
1
3
|
import { SourceFile } from "@alloy-js/typescript";
|
|
2
|
-
import type { Namespace
|
|
4
|
+
import type { Namespace } from "@typespec/compiler";
|
|
5
|
+
import { t } from "@typespec/compiler/testing";
|
|
3
6
|
import { describe, expect, it } from "vitest";
|
|
4
7
|
import { Output } from "../../../src/core/components/output.jsx";
|
|
5
8
|
import { TypeAliasDeclaration } from "../../../src/typescript/components/type-alias-declaration.jsx";
|
|
6
|
-
import { createEmitterFrameworkTestRunner, getProgram } from "../test-host.js";
|
|
7
9
|
|
|
8
10
|
describe("Typescript Type Alias Declaration", () => {
|
|
9
11
|
describe("Type Alias bound to Typespec Scalar", () => {
|
|
@@ -136,10 +138,10 @@ describe("Typescript Type Alias Declaration", () => {
|
|
|
136
138
|
});
|
|
137
139
|
|
|
138
140
|
it("creates a type alias of a function", async () => {
|
|
139
|
-
const runner = await
|
|
140
|
-
const { getName } =
|
|
141
|
-
@test op
|
|
142
|
-
`)
|
|
141
|
+
const runner = await Tester.createInstance();
|
|
142
|
+
const { getName } = await runner.compile(t.code`
|
|
143
|
+
@test op ${t.op("getName")}(id: string): string;
|
|
144
|
+
`);
|
|
143
145
|
|
|
144
146
|
expect(
|
|
145
147
|
<Output program={runner.program}>
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { Tester } from "#test/test-host.js";
|
|
1
2
|
import { code, Output } from "@alloy-js/core";
|
|
2
3
|
import * as ts from "@alloy-js/typescript";
|
|
3
4
|
import { SourceFile } from "@alloy-js/typescript";
|
|
4
5
|
import type { Model } from "@typespec/compiler";
|
|
5
|
-
import type
|
|
6
|
+
import { t, type TesterInstance } from "@typespec/compiler/testing";
|
|
6
7
|
import { beforeEach, describe, expect, it } from "vitest";
|
|
7
8
|
import {
|
|
8
9
|
ArraySerializer,
|
|
@@ -16,27 +17,26 @@ import {
|
|
|
16
17
|
TypeTransformDeclaration,
|
|
17
18
|
} from "../../../src/typescript/components/type-transform.js";
|
|
18
19
|
import { TypeDeclaration } from "../../../src/typescript/index.js";
|
|
19
|
-
import { createEmitterFrameworkTestRunner } from "../test-host.js";
|
|
20
20
|
|
|
21
21
|
describe.skip("Typescript Type Transform", () => {
|
|
22
|
-
let testRunner:
|
|
22
|
+
let testRunner: TesterInstance;
|
|
23
23
|
const namePolicy = ts.createTSNamePolicy();
|
|
24
24
|
beforeEach(async () => {
|
|
25
|
-
testRunner = await
|
|
25
|
+
testRunner = await Tester.createInstance();
|
|
26
26
|
});
|
|
27
27
|
describe("Model Transforms", () => {
|
|
28
28
|
describe("ModelTransformExpression", () => {
|
|
29
29
|
it("should render a transform expression to client", async () => {
|
|
30
|
-
const spec = `
|
|
30
|
+
const spec = t.code`
|
|
31
31
|
namespace DemoService;
|
|
32
|
-
@test model Widget {
|
|
32
|
+
@test model ${t.model("Widget")} {
|
|
33
33
|
id: string;
|
|
34
34
|
birth_year: int32;
|
|
35
35
|
color: "blue" | "red";
|
|
36
36
|
}
|
|
37
37
|
`;
|
|
38
38
|
|
|
39
|
-
const { Widget } =
|
|
39
|
+
const { Widget } = await testRunner.compile(spec);
|
|
40
40
|
|
|
41
41
|
expect(
|
|
42
42
|
<Output namePolicy={namePolicy}>
|
|
@@ -62,16 +62,16 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
62
62
|
});
|
|
63
63
|
|
|
64
64
|
it("should render a transform expression to wire", async () => {
|
|
65
|
-
const spec = `
|
|
65
|
+
const spec = t.code`
|
|
66
66
|
namespace DemoService;
|
|
67
|
-
@test model Widget {
|
|
67
|
+
@test model ${t.model("Widget")} {
|
|
68
68
|
id: string;
|
|
69
69
|
birth_year: int32;
|
|
70
70
|
color: "blue" | "red";
|
|
71
71
|
}
|
|
72
72
|
`;
|
|
73
73
|
|
|
74
|
-
const { Widget } =
|
|
74
|
+
const { Widget } = await testRunner.compile(spec);
|
|
75
75
|
|
|
76
76
|
expect(
|
|
77
77
|
<Output namePolicy={namePolicy}>
|
|
@@ -97,9 +97,9 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
97
97
|
});
|
|
98
98
|
|
|
99
99
|
it("should render a transform expression that contains a utcDateTime to client", async () => {
|
|
100
|
-
const spec = `
|
|
100
|
+
const spec = t.code`
|
|
101
101
|
namespace DemoService;
|
|
102
|
-
@test model Widget {
|
|
102
|
+
@test model ${t.model("Widget")} {
|
|
103
103
|
id: string;
|
|
104
104
|
birth_date: utcDateTime;
|
|
105
105
|
color: "blue" | "red";
|
|
@@ -139,9 +139,9 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
139
139
|
|
|
140
140
|
describe("TypeTransformDeclaration", () => {
|
|
141
141
|
it("should render a transform functions for a model containing array", async () => {
|
|
142
|
-
const spec = `
|
|
142
|
+
const spec = t.code`
|
|
143
143
|
namespace DemoService;
|
|
144
|
-
@test model Widget {
|
|
144
|
+
@test model ${t.model("Widget")} {
|
|
145
145
|
id: string;
|
|
146
146
|
my_color: "blue" | "red";
|
|
147
147
|
simple?: string[];
|
|
@@ -151,7 +151,7 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
151
151
|
}
|
|
152
152
|
`;
|
|
153
153
|
|
|
154
|
-
const { Widget } =
|
|
154
|
+
const { Widget } = await testRunner.compile(spec);
|
|
155
155
|
|
|
156
156
|
expect(
|
|
157
157
|
<Output namePolicy={namePolicy}>
|
|
@@ -198,9 +198,9 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
198
198
|
`);
|
|
199
199
|
});
|
|
200
200
|
it("should render a transform functions for a model containing record", async () => {
|
|
201
|
-
const spec = `
|
|
201
|
+
const spec = t.code`
|
|
202
202
|
namespace DemoService;
|
|
203
|
-
@test model Widget {
|
|
203
|
+
@test model ${t.model("Widget")} {
|
|
204
204
|
id: string;
|
|
205
205
|
my_color: "blue" | "red";
|
|
206
206
|
simple: Record<string>;
|
|
@@ -209,7 +209,7 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
209
209
|
}
|
|
210
210
|
`;
|
|
211
211
|
|
|
212
|
-
const { Widget } =
|
|
212
|
+
const { Widget } = await testRunner.compile(spec);
|
|
213
213
|
|
|
214
214
|
expect(
|
|
215
215
|
<Output namePolicy={namePolicy}>
|
|
@@ -253,15 +253,15 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
253
253
|
`);
|
|
254
254
|
});
|
|
255
255
|
it("should render a transform functions for a model", async () => {
|
|
256
|
-
const spec = `
|
|
256
|
+
const spec = t.code`
|
|
257
257
|
namespace DemoService;
|
|
258
|
-
@test model Widget {
|
|
258
|
+
@test model ${t.model("Widget")} {
|
|
259
259
|
id: string;
|
|
260
260
|
my_color: "blue" | "red";
|
|
261
261
|
}
|
|
262
262
|
`;
|
|
263
263
|
|
|
264
|
-
const { Widget } =
|
|
264
|
+
const { Widget } = await testRunner.compile(spec);
|
|
265
265
|
|
|
266
266
|
expect(
|
|
267
267
|
<Output namePolicy={namePolicy}>
|
|
@@ -293,14 +293,14 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
293
293
|
});
|
|
294
294
|
describe("Calling a model transform functions", () => {
|
|
295
295
|
it("should collapse a model with single property", async () => {
|
|
296
|
-
const spec = `
|
|
296
|
+
const spec = t.code`
|
|
297
297
|
namespace DemoService;
|
|
298
|
-
@test model Widget {
|
|
298
|
+
@test model ${t.model("Widget")} {
|
|
299
299
|
id: string;
|
|
300
300
|
}
|
|
301
301
|
`;
|
|
302
302
|
|
|
303
|
-
const { Widget } =
|
|
303
|
+
const { Widget } = await testRunner.compile(spec);
|
|
304
304
|
|
|
305
305
|
expect(
|
|
306
306
|
<Output namePolicy={namePolicy}>
|
|
@@ -318,15 +318,15 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
318
318
|
});
|
|
319
319
|
|
|
320
320
|
it("should call transform functions for a model", async () => {
|
|
321
|
-
const spec = `
|
|
321
|
+
const spec = t.code`
|
|
322
322
|
namespace DemoService;
|
|
323
|
-
@test model Widget {
|
|
323
|
+
@test model ${t.model("Widget")} {
|
|
324
324
|
id: string;
|
|
325
325
|
my_color: "blue" | "red";
|
|
326
326
|
}
|
|
327
327
|
`;
|
|
328
328
|
|
|
329
|
-
const { Widget } =
|
|
329
|
+
const { Widget } = await testRunner.compile(spec);
|
|
330
330
|
|
|
331
331
|
expect(
|
|
332
332
|
<Output namePolicy={namePolicy}>
|
|
@@ -356,20 +356,20 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
356
356
|
|
|
357
357
|
describe("Discriminated Model Transforms", () => {
|
|
358
358
|
it("should handle a discriminated union", async () => {
|
|
359
|
-
const { Pet, Cat, Dog } =
|
|
359
|
+
const { Pet, Cat, Dog } = await testRunner.compile(t.code`
|
|
360
360
|
@discriminator("kind")
|
|
361
|
-
@test model Pet {
|
|
361
|
+
@test model ${t.model("Pet")} {
|
|
362
362
|
kind: string;
|
|
363
363
|
}
|
|
364
364
|
|
|
365
|
-
@test model Cat extends Pet {
|
|
365
|
+
@test model ${t.model("Cat")} extends Pet {
|
|
366
366
|
kind: "cat";
|
|
367
367
|
}
|
|
368
368
|
|
|
369
|
-
@test model Dog extends Pet {
|
|
369
|
+
@test model ${t.model("Dog")} extends Pet {
|
|
370
370
|
kind: "dog";
|
|
371
371
|
}
|
|
372
|
-
`)
|
|
372
|
+
`);
|
|
373
373
|
|
|
374
374
|
expect(
|
|
375
375
|
<Output namePolicy={namePolicy}>
|
|
@@ -436,21 +436,21 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
436
436
|
});
|
|
437
437
|
describe("Discriminated Union Transforms", () => {
|
|
438
438
|
it("should handle a discriminated union", async () => {
|
|
439
|
-
const { Pet, Cat, Dog } =
|
|
439
|
+
const { Pet, Cat, Dog } = await testRunner.compile(t.code`
|
|
440
440
|
@discriminator("kind")
|
|
441
|
-
@test union Pet
|
|
441
|
+
@test union ${t.union("Pet")}{
|
|
442
442
|
cat: Cat;
|
|
443
443
|
dog: Dog;
|
|
444
444
|
}
|
|
445
445
|
|
|
446
|
-
@test model Cat
|
|
446
|
+
@test model ${t.model("Cat")} {
|
|
447
447
|
kind: "cat";
|
|
448
448
|
}
|
|
449
449
|
|
|
450
|
-
@test model Dog {
|
|
450
|
+
@test model ${t.model("Dog")} {
|
|
451
451
|
kind: "dog";
|
|
452
452
|
}
|
|
453
|
-
`)
|
|
453
|
+
`);
|
|
454
454
|
|
|
455
455
|
expect(
|
|
456
456
|
<Output namePolicy={namePolicy}>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getProgram } from "#test/utils.js";
|
|
1
2
|
import { Output } from "@alloy-js/core";
|
|
2
3
|
import { dedent } from "@alloy-js/core/testing";
|
|
3
4
|
import { SourceFile } from "@alloy-js/typescript";
|
|
@@ -13,7 +14,6 @@ import {
|
|
|
13
14
|
import { $ } from "@typespec/compiler/typekit";
|
|
14
15
|
import { assert, beforeAll, describe, expect, it } from "vitest";
|
|
15
16
|
import { ValueExpression } from "../../../src/typescript/components/value-expression.js";
|
|
16
|
-
import { getProgram } from "../test-host.js";
|
|
17
17
|
|
|
18
18
|
let program: Program;
|
|
19
19
|
beforeAll(async () => {
|
package/test/utils.ts
CHANGED
|
@@ -1,19 +1,26 @@
|
|
|
1
|
+
import { Tester } from "#test/test-host.js";
|
|
1
2
|
import { type Children, type OutputDirectory, render } from "@alloy-js/core";
|
|
2
3
|
import { Output } from "@alloy-js/core/stc";
|
|
3
4
|
import { SourceFile } from "@alloy-js/typescript/stc";
|
|
4
5
|
import type { Program } from "@typespec/compiler";
|
|
5
6
|
import { assert } from "vitest";
|
|
6
|
-
import { getProgram } from "./typescript/test-host.js";
|
|
7
7
|
|
|
8
8
|
export async function getEmitOutput(tspCode: string, cb: (program: Program) => Children) {
|
|
9
9
|
const program = await getProgram(tspCode);
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
const res = render(Output().children(SourceFile({ path: "test.ts" }).children(cb(program))), {
|
|
11
|
+
insertFinalNewLine: false,
|
|
12
|
+
});
|
|
12
13
|
const testFile = res.contents.find((file) => file.path === "test.ts")!;
|
|
13
14
|
assert("contents" in testFile, "test.ts file does not have contents");
|
|
14
15
|
return testFile.contents;
|
|
15
16
|
}
|
|
16
17
|
|
|
18
|
+
export async function getProgram(tspCode: string) {
|
|
19
|
+
const runner = await Tester.createInstance();
|
|
20
|
+
const { program } = await runner.compile(tspCode);
|
|
21
|
+
return program;
|
|
22
|
+
}
|
|
23
|
+
|
|
17
24
|
export function assertFileContents(res: OutputDirectory, contents: string) {
|
|
18
25
|
const testFile = res.contents.find((file) => file.path === "test.ts")!;
|
|
19
26
|
assert(testFile, "test.ts file not rendered");
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { Program } from "@typespec/compiler";
|
|
2
|
-
export declare function createTypespecCliTestHost(options?: {
|
|
3
|
-
libraries: "Http"[];
|
|
4
|
-
}): Promise<import("@typespec/compiler/testing").TestHost>;
|
|
5
|
-
export declare function createEmitterFrameworkTestRunner(options?: {
|
|
6
|
-
autoUsings?: string[];
|
|
7
|
-
}): Promise<import("@typespec/compiler/testing").BasicTestRunner>;
|
|
8
|
-
export declare function getProgram(code: string, options?: {
|
|
9
|
-
libraries: "Http"[];
|
|
10
|
-
}): Promise<Program>;
|
|
11
|
-
/**
|
|
12
|
-
* Initializes an empty program in the compiler.
|
|
13
|
-
* This is useful when you want to initialize the default TypeKits without any code.
|
|
14
|
-
*/
|
|
15
|
-
export declare function initEmptyProgram(): Promise<void>;
|
|
16
|
-
//# sourceMappingURL=test-host.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"test-host.d.ts","sourceRoot":"","sources":["../../../test/typescript/test-host.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAQlD,wBAAsB,yBAAyB,CAC7C,OAAO,GAAE;IAAE,SAAS,EAAE,MAAM,EAAE,CAAA;CAAsB,0DASrD;AAED,wBAAsB,gCAAgC,CAAC,OAAO,GAAE;IAAE,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;CAAO,iEAK7F;AAED,wBAAsB,UAAU,CAC9B,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE;IAAE,SAAS,EAAE,MAAM,EAAE,CAAA;CAAsB,GACnD,OAAO,CAAC,OAAO,CAAC,CAUlB;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAEtD"}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { createTestHost, createTestWrapper, expectDiagnosticEmpty } from "@typespec/compiler/testing";
|
|
2
|
-
import { HttpTestLibrary } from "@typespec/http/testing";
|
|
3
|
-
export async function createTypespecCliTestHost(options = {
|
|
4
|
-
libraries: []
|
|
5
|
-
}) {
|
|
6
|
-
const libraries = [];
|
|
7
|
-
if (options.libraries.includes("Http")) {
|
|
8
|
-
libraries.push(HttpTestLibrary);
|
|
9
|
-
}
|
|
10
|
-
return createTestHost({
|
|
11
|
-
libraries
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
export async function createEmitterFrameworkTestRunner(options = {}) {
|
|
15
|
-
const host = await createTypespecCliTestHost();
|
|
16
|
-
return createTestWrapper(host, {
|
|
17
|
-
autoUsings: options.autoUsings
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
export async function getProgram(code, options = {
|
|
21
|
-
libraries: []
|
|
22
|
-
}) {
|
|
23
|
-
const host = await createTypespecCliTestHost(options);
|
|
24
|
-
const wrapper = createTestWrapper(host, {
|
|
25
|
-
compilerOptions: {
|
|
26
|
-
noEmit: true
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
const [_, diagnostics] = await wrapper.compileAndDiagnose(code);
|
|
30
|
-
expectDiagnosticEmpty(diagnostics);
|
|
31
|
-
return wrapper.program;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Initializes an empty program in the compiler.
|
|
36
|
-
* This is useful when you want to initialize the default TypeKits without any code.
|
|
37
|
-
*/
|
|
38
|
-
export async function initEmptyProgram() {
|
|
39
|
-
await getProgram("");
|
|
40
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type { Program } from "@typespec/compiler";
|
|
2
|
-
import {
|
|
3
|
-
createTestHost,
|
|
4
|
-
createTestWrapper,
|
|
5
|
-
expectDiagnosticEmpty,
|
|
6
|
-
} from "@typespec/compiler/testing";
|
|
7
|
-
import { HttpTestLibrary } from "@typespec/http/testing";
|
|
8
|
-
|
|
9
|
-
export async function createTypespecCliTestHost(
|
|
10
|
-
options: { libraries: "Http"[] } = { libraries: [] },
|
|
11
|
-
) {
|
|
12
|
-
const libraries = [];
|
|
13
|
-
if (options.libraries.includes("Http")) {
|
|
14
|
-
libraries.push(HttpTestLibrary);
|
|
15
|
-
}
|
|
16
|
-
return createTestHost({
|
|
17
|
-
libraries,
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export async function createEmitterFrameworkTestRunner(options: { autoUsings?: string[] } = {}) {
|
|
22
|
-
const host = await createTypespecCliTestHost();
|
|
23
|
-
return createTestWrapper(host, {
|
|
24
|
-
autoUsings: options.autoUsings,
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export async function getProgram(
|
|
29
|
-
code: string,
|
|
30
|
-
options: { libraries: "Http"[] } = { libraries: [] },
|
|
31
|
-
): Promise<Program> {
|
|
32
|
-
const host = await createTypespecCliTestHost(options);
|
|
33
|
-
const wrapper = createTestWrapper(host, {
|
|
34
|
-
compilerOptions: {
|
|
35
|
-
noEmit: true,
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
const [_, diagnostics] = await wrapper.compileAndDiagnose(code);
|
|
39
|
-
expectDiagnosticEmpty(diagnostics);
|
|
40
|
-
return wrapper.program;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Initializes an empty program in the compiler.
|
|
45
|
-
* This is useful when you want to initialize the default TypeKits without any code.
|
|
46
|
-
*/
|
|
47
|
-
export async function initEmptyProgram(): Promise<void> {
|
|
48
|
-
await getProgram("");
|
|
49
|
-
}
|