@typespec/emitter-framework 0.11.0-dev.1 → 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.
Files changed (190) hide show
  1. package/dist/src/core/components/index.js +2 -1
  2. package/dist/src/core/components/index.js.map +1 -0
  3. package/dist/src/core/components/output.js +2 -1
  4. package/dist/src/core/components/output.js.map +1 -0
  5. package/dist/src/core/components/overrides/component-overrides.js +2 -1
  6. package/dist/src/core/components/overrides/component-overrides.js.map +1 -0
  7. package/dist/src/core/components/overrides/config.js +2 -1
  8. package/dist/src/core/components/overrides/config.js.map +1 -0
  9. package/dist/src/core/components/overrides/context.js +2 -1
  10. package/dist/src/core/components/overrides/context.js.map +1 -0
  11. package/dist/src/core/context/index.js +2 -1
  12. package/dist/src/core/context/index.js.map +1 -0
  13. package/dist/src/core/context/name-policy-context.js +2 -1
  14. package/dist/src/core/context/name-policy-context.js.map +1 -0
  15. package/dist/src/core/context/tsp-context.js +2 -1
  16. package/dist/src/core/context/tsp-context.js.map +1 -0
  17. package/dist/src/core/index.js +2 -1
  18. package/dist/src/core/index.js.map +1 -0
  19. package/dist/src/core/transport-name-policy.js +2 -1
  20. package/dist/src/core/transport-name-policy.js.map +1 -0
  21. package/dist/src/core/write-output.d.ts.map +1 -1
  22. package/dist/src/core/write-output.js +4 -3
  23. package/dist/src/core/write-output.js.map +1 -0
  24. package/dist/src/csharp/components/class/declaration.d.ts +1 -1
  25. package/dist/src/csharp/components/class/declaration.d.ts.map +1 -1
  26. package/dist/src/csharp/components/class/declaration.js +14 -5
  27. package/dist/src/csharp/components/class/declaration.js.map +1 -0
  28. package/dist/src/csharp/components/class/declaration.test.js +65 -105
  29. package/dist/src/csharp/components/class/declaration.test.js.map +1 -0
  30. package/dist/src/csharp/components/enum/declaration.js +2 -1
  31. package/dist/src/csharp/components/enum/declaration.js.map +1 -0
  32. package/dist/src/csharp/components/enum/declaration.test.js +52 -88
  33. package/dist/src/csharp/components/enum/declaration.test.js.map +1 -0
  34. package/dist/src/csharp/components/index.js +2 -1
  35. package/dist/src/csharp/components/index.js.map +1 -0
  36. package/dist/src/csharp/components/property/property.d.ts.map +1 -1
  37. package/dist/src/csharp/components/property/property.js +40 -14
  38. package/dist/src/csharp/components/property/property.js.map +1 -0
  39. package/dist/src/csharp/components/property/property.test.js +129 -29
  40. package/dist/src/csharp/components/property/property.test.js.map +1 -0
  41. package/dist/src/csharp/components/type-expression.d.ts.map +1 -1
  42. package/dist/src/csharp/components/type-expression.js +22 -3
  43. package/dist/src/csharp/components/type-expression.js.map +1 -0
  44. package/dist/src/csharp/components/type-expression.test.js +87 -54
  45. package/dist/src/csharp/components/type-expression.test.js.map +1 -0
  46. package/dist/src/csharp/components/utils/doc-comments.js +2 -1
  47. package/dist/src/csharp/components/utils/doc-comments.js.map +1 -0
  48. package/dist/src/csharp/components/utils/nullable-util.d.ts +4 -0
  49. package/dist/src/csharp/components/utils/nullable-util.d.ts.map +1 -0
  50. package/dist/src/csharp/components/utils/nullable-util.js +27 -0
  51. package/dist/src/csharp/components/utils/nullable-util.js.map +1 -0
  52. package/dist/src/csharp/components/utils/refkey.js +2 -1
  53. package/dist/src/csharp/components/utils/refkey.js.map +1 -0
  54. package/dist/src/csharp/index.js +2 -1
  55. package/dist/src/csharp/index.js.map +1 -0
  56. package/dist/src/lib.js +2 -1
  57. package/dist/src/lib.js.map +1 -0
  58. package/dist/src/testing/index.js +2 -1
  59. package/dist/src/testing/index.js.map +1 -0
  60. package/dist/src/testing/scenario-test/code-block-expectation.js +2 -1
  61. package/dist/src/testing/scenario-test/code-block-expectation.js.map +1 -0
  62. package/dist/src/testing/scenario-test/code-block-expectation.test.js +2 -1
  63. package/dist/src/testing/scenario-test/code-block-expectation.test.js.map +1 -0
  64. package/dist/src/testing/scenario-test/harness.js +2 -1
  65. package/dist/src/testing/scenario-test/harness.js.map +1 -0
  66. package/dist/src/testing/scenario-test/index.js +2 -1
  67. package/dist/src/testing/scenario-test/index.js.map +1 -0
  68. package/dist/src/testing/scenario-test/snippet-extractor.js +2 -1
  69. package/dist/src/testing/scenario-test/snippet-extractor.js.map +1 -0
  70. package/dist/src/typescript/components/array-expression.js +2 -1
  71. package/dist/src/typescript/components/array-expression.js.map +1 -0
  72. package/dist/src/typescript/components/arrow-function.js +2 -1
  73. package/dist/src/typescript/components/arrow-function.js.map +1 -0
  74. package/dist/src/typescript/components/class-method.js +2 -1
  75. package/dist/src/typescript/components/class-method.js.map +1 -0
  76. package/dist/src/typescript/components/enum-declaration.js +2 -1
  77. package/dist/src/typescript/components/enum-declaration.js.map +1 -0
  78. package/dist/src/typescript/components/function-declaration.js +2 -1
  79. package/dist/src/typescript/components/function-declaration.js.map +1 -0
  80. package/dist/src/typescript/components/function-expression.js +2 -1
  81. package/dist/src/typescript/components/function-expression.js.map +1 -0
  82. package/dist/src/typescript/components/function-type.js +2 -1
  83. package/dist/src/typescript/components/function-type.js.map +1 -0
  84. package/dist/src/typescript/components/index.js +2 -1
  85. package/dist/src/typescript/components/index.js.map +1 -0
  86. package/dist/src/typescript/components/interface-declaration.js +2 -1
  87. package/dist/src/typescript/components/interface-declaration.js.map +1 -0
  88. package/dist/src/typescript/components/interface-member.js +2 -1
  89. package/dist/src/typescript/components/interface-member.js.map +1 -0
  90. package/dist/src/typescript/components/interface-method.js +2 -1
  91. package/dist/src/typescript/components/interface-method.js.map +1 -0
  92. package/dist/src/typescript/components/record-expression.js +2 -1
  93. package/dist/src/typescript/components/record-expression.js.map +1 -0
  94. package/dist/src/typescript/components/static-serializers.js +2 -1
  95. package/dist/src/typescript/components/static-serializers.js.map +1 -0
  96. package/dist/src/typescript/components/type-alias-declaration.js +2 -1
  97. package/dist/src/typescript/components/type-alias-declaration.js.map +1 -0
  98. package/dist/src/typescript/components/type-declaration.js +2 -1
  99. package/dist/src/typescript/components/type-declaration.js.map +1 -0
  100. package/dist/src/typescript/components/type-expression.js +2 -1
  101. package/dist/src/typescript/components/type-expression.js.map +1 -0
  102. package/dist/src/typescript/components/type-transform.js +2 -1
  103. package/dist/src/typescript/components/type-transform.js.map +1 -0
  104. package/dist/src/typescript/components/union/declaration.js +2 -1
  105. package/dist/src/typescript/components/union/declaration.js.map +1 -0
  106. package/dist/src/typescript/components/union/declaration.test.js +2 -1
  107. package/dist/src/typescript/components/union/declaration.test.js.map +1 -0
  108. package/dist/src/typescript/components/union/expression.js +2 -1
  109. package/dist/src/typescript/components/union/expression.js.map +1 -0
  110. package/dist/src/typescript/components/union/expression.test.js +2 -1
  111. package/dist/src/typescript/components/union/expression.test.js.map +1 -0
  112. package/dist/src/typescript/components/value-expression.js +2 -1
  113. package/dist/src/typescript/components/value-expression.js.map +1 -0
  114. package/dist/src/typescript/index.js +2 -1
  115. package/dist/src/typescript/index.js.map +1 -0
  116. package/dist/src/typescript/lib.js +2 -1
  117. package/dist/src/typescript/lib.js.map +1 -0
  118. package/dist/src/typescript/utils/index.js +2 -1
  119. package/dist/src/typescript/utils/index.js.map +1 -0
  120. package/dist/src/typescript/utils/operation.js +2 -1
  121. package/dist/src/typescript/utils/operation.js.map +1 -0
  122. package/dist/src/typescript/utils/refkey.js +2 -1
  123. package/dist/src/typescript/utils/refkey.js.map +1 -0
  124. package/dist/test/test-host.js +2 -1
  125. package/dist/test/test-host.js.map +1 -0
  126. package/dist/test/testing/snippet-extractor-csharp.test.js +2 -1
  127. package/dist/test/testing/snippet-extractor-csharp.test.js.map +1 -0
  128. package/dist/test/testing/snippet-extractor-java.test.js +2 -1
  129. package/dist/test/testing/snippet-extractor-java.test.js.map +1 -0
  130. package/dist/test/testing/snippet-extractor-python.test.js +2 -1
  131. package/dist/test/testing/snippet-extractor-python.test.js.map +1 -0
  132. package/dist/test/testing/snippet-extractor-typescript.test.js +2 -1
  133. package/dist/test/testing/snippet-extractor-typescript.test.js.map +1 -0
  134. package/dist/test/typescript/components/arrow-function.test.js +18 -22
  135. package/dist/test/typescript/components/arrow-function.test.js.map +1 -0
  136. package/dist/test/typescript/components/component-override.test.js +3 -2
  137. package/dist/test/typescript/components/component-override.test.js.map +1 -0
  138. package/dist/test/typescript/components/enum-declaration.test.js +2 -1
  139. package/dist/test/typescript/components/enum-declaration.test.js.map +1 -0
  140. package/dist/test/typescript/components/function-declaration.test.js +3 -2
  141. package/dist/test/typescript/components/function-declaration.test.js.map +1 -0
  142. package/dist/test/typescript/components/function-expression.test.js +18 -22
  143. package/dist/test/typescript/components/function-expression.test.js.map +1 -0
  144. package/dist/test/typescript/components/function-type.test.js +18 -22
  145. package/dist/test/typescript/components/function-type.test.js.map +1 -0
  146. package/dist/test/typescript/components/interface-declaration.test.js +3 -2
  147. package/dist/test/typescript/components/interface-declaration.test.js.map +1 -0
  148. package/dist/test/typescript/components/interface-method.test.js +37 -45
  149. package/dist/test/typescript/components/interface-method.test.js.map +1 -0
  150. package/dist/test/typescript/components/member-expression.test.js +2 -1
  151. package/dist/test/typescript/components/member-expression.test.js.map +1 -0
  152. package/dist/test/typescript/components/type-alias-declaration.test.js +8 -5
  153. package/dist/test/typescript/components/type-alias-declaration.test.js.map +1 -0
  154. package/dist/test/typescript/components/type-transform.test.js +29 -27
  155. package/dist/test/typescript/components/type-transform.test.js.map +1 -0
  156. package/dist/test/typescript/components/value-expression.test.js +3 -2
  157. package/dist/test/typescript/components/value-expression.test.js.map +1 -0
  158. package/dist/test/typescript/utils.js +2 -1
  159. package/dist/test/typescript/utils.js.map +1 -0
  160. package/dist/test/utils.d.ts +1 -0
  161. package/dist/test/utils.d.ts.map +1 -1
  162. package/dist/test/utils.js +13 -3
  163. package/dist/test/utils.js.map +1 -0
  164. package/dist/test/vitest.setup.js +2 -1
  165. package/dist/test/vitest.setup.js.map +1 -0
  166. package/package.json +8 -8
  167. package/src/core/write-output.ts +2 -2
  168. package/src/csharp/components/class/declaration.test.tsx +64 -102
  169. package/src/csharp/components/class/declaration.tsx +13 -3
  170. package/src/csharp/components/enum/declaration.test.tsx +47 -78
  171. package/src/csharp/components/property/property.test.tsx +108 -25
  172. package/src/csharp/components/property/property.tsx +43 -11
  173. package/src/csharp/components/type-expression.test.tsx +84 -69
  174. package/src/csharp/components/type-expression.tsx +25 -4
  175. package/src/csharp/components/utils/nullable-util.ts +25 -0
  176. package/test/typescript/components/arrow-function.test.tsx +23 -42
  177. package/test/typescript/components/component-override.test.tsx +1 -1
  178. package/test/typescript/components/function-declaration.test.tsx +2 -1
  179. package/test/typescript/components/function-expression.test.tsx +23 -42
  180. package/test/typescript/components/function-type.test.tsx +22 -40
  181. package/test/typescript/components/interface-declaration.test.tsx +1 -1
  182. package/test/typescript/components/interface-method.test.tsx +50 -92
  183. package/test/typescript/components/type-alias-declaration.test.tsx +8 -6
  184. package/test/typescript/components/type-transform.test.tsx +37 -37
  185. package/test/typescript/components/value-expression.test.tsx +1 -1
  186. package/test/utils.ts +10 -3
  187. package/dist/test/typescript/test-host.d.ts +0 -12
  188. package/dist/test/typescript/test-host.d.ts.map +0 -1
  189. package/dist/test/typescript/test-host.js +0 -29
  190. package/test/typescript/test-host.ts +0 -37
@@ -1,27 +1,25 @@
1
- import { render } from "@alloy-js/core";
2
- import { d } from "@alloy-js/core/testing";
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 { BasicTestRunner } from "@typespec/compiler/testing";
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: BasicTestRunner;
11
+ let runner: TesterInstance;
14
12
 
15
13
  beforeEach(async () => {
16
- runner = await createEmitterFrameworkTestRunner();
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
- const res = render(
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 } = (await runner.compile(`
46
- @test op getName(id: string): string;
47
- `)) as { getName: Operation };
38
+ const { getName } = await runner.compile(t.code`
39
+ @test op ${t.op("getName")}(id: string): string;
40
+ `);
48
41
 
49
- const res = render(
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 } = (await runner.compile(`
71
- @test op getName(id: string): string;
72
- `)) as { getName: Operation };
58
+ const { getName } = await runner.compile(t.code`
59
+ @test op ${t.op("getName")}(id: string): string;
60
+ `);
73
61
 
74
- const res = render(
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 } = (await runner.compile(`
100
- @test op getName(id: string): string;
101
- `)) as { getName: Operation };
82
+ const { getName } = await runner.compile(t.code`
83
+ @test op ${t.op("getName")}(id: string): string;
84
+ `);
102
85
 
103
- const res = render(
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 } = (await runner.compile(`
129
- @test op getName(id: string): string;
130
- `)) as { getName: Operation };
106
+ const { getName } = await runner.compile(t.code`
107
+ @test op ${t.op("getName")}(id: string): string;
108
+ `);
131
109
 
132
- const res = render(
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 } = (await runner.compile(`
161
- @test op getName(id: string): string;
162
- `)) as { getName: Operation };
133
+ const { getName } = await runner.compile(t.code`
134
+ @test op ${t.op("getName")}(id: string): string;
135
+ `);
163
136
 
164
- const res = render(
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 } = (await runner.compile(`
186
- @test op getName(id: string): string;
187
- `)) as { getName: Operation };
153
+ const { getName } = await runner.compile(t.code`
154
+ @test op ${t.op("getName")}(id: string): string;
155
+ `);
188
156
 
189
- const res = render(
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
- const res = render(
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, Operation } from "@typespec/compiler";
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 createEmitterFrameworkTestRunner();
140
- const { getName } = (await runner.compile(`
141
- @test op getName(id: string): string;
142
- `)) as { getName: Operation };
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 { BasicTestRunner } from "@typespec/compiler/testing";
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: BasicTestRunner;
22
+ let testRunner: TesterInstance;
23
23
  const namePolicy = ts.createTSNamePolicy();
24
24
  beforeEach(async () => {
25
- testRunner = await createEmitterFrameworkTestRunner();
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 } = (await testRunner.compile(spec)) as { Widget: Model };
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 } = (await testRunner.compile(spec)) as { Widget: Model };
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 } = (await testRunner.compile(spec)) as { Widget: Model };
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 } = (await testRunner.compile(spec)) as { Widget: Model };
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 } = (await testRunner.compile(spec)) as { Widget: Model };
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 } = (await testRunner.compile(spec)) as { Widget: Model };
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 } = (await testRunner.compile(spec)) as { Widget: Model };
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 } = (await testRunner.compile(`
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
- `)) as { Pet: Model; Cat: Model; Dog: Model };
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 } = (await testRunner.compile(`
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
- `)) as { Pet: Model; Cat: Model; Dog: Model };
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
- const res = render(Output().children(SourceFile({ path: "test.ts" }).children(cb(program))));
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,12 +0,0 @@
1
- import type { Program } from "@typespec/compiler";
2
- export declare function createTypespecCliTestHost(): Promise<import("@typespec/compiler/testing").TestHost>;
3
- export declare function createEmitterFrameworkTestRunner(options?: {
4
- autoUsings?: string[];
5
- }): Promise<import("@typespec/compiler/testing").BasicTestRunner>;
6
- export declare function getProgram(code: string): Promise<Program>;
7
- /**
8
- * Initializes an empty program in the compiler.
9
- * This is useful when you want to initialize the default TypeKits without any code.
10
- */
11
- export declare function initEmptyProgram(): Promise<void>;
12
- //# 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;AAOlD,wBAAsB,yBAAyB,2DAE9C;AAED,wBAAsB,gCAAgC,CAAC,OAAO,GAAE;IAAE,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;CAAO,iEAK7F;AAED,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAU/D;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAEtD"}
@@ -1,29 +0,0 @@
1
- import { createTestHost, createTestWrapper, expectDiagnosticEmpty } from "@typespec/compiler/testing";
2
- export async function createTypespecCliTestHost() {
3
- return createTestHost({});
4
- }
5
- export async function createEmitterFrameworkTestRunner(options = {}) {
6
- const host = await createTypespecCliTestHost();
7
- return createTestWrapper(host, {
8
- autoUsings: options.autoUsings
9
- });
10
- }
11
- export async function getProgram(code) {
12
- const host = await createTypespecCliTestHost();
13
- const wrapper = createTestWrapper(host, {
14
- compilerOptions: {
15
- noEmit: true
16
- }
17
- });
18
- const [_, diagnostics] = await wrapper.compileAndDiagnose(code);
19
- expectDiagnosticEmpty(diagnostics);
20
- return wrapper.program;
21
- }
22
-
23
- /**
24
- * Initializes an empty program in the compiler.
25
- * This is useful when you want to initialize the default TypeKits without any code.
26
- */
27
- export async function initEmptyProgram() {
28
- await getProgram("");
29
- }
@@ -1,37 +0,0 @@
1
- import type { Program } from "@typespec/compiler";
2
- import {
3
- createTestHost,
4
- createTestWrapper,
5
- expectDiagnosticEmpty,
6
- } from "@typespec/compiler/testing";
7
-
8
- export async function createTypespecCliTestHost() {
9
- return createTestHost({});
10
- }
11
-
12
- export async function createEmitterFrameworkTestRunner(options: { autoUsings?: string[] } = {}) {
13
- const host = await createTypespecCliTestHost();
14
- return createTestWrapper(host, {
15
- autoUsings: options.autoUsings,
16
- });
17
- }
18
-
19
- export async function getProgram(code: string): Promise<Program> {
20
- const host = await createTypespecCliTestHost();
21
- const wrapper = createTestWrapper(host, {
22
- compilerOptions: {
23
- noEmit: true,
24
- },
25
- });
26
- const [_, diagnostics] = await wrapper.compileAndDiagnose(code);
27
- expectDiagnosticEmpty(diagnostics);
28
- return wrapper.program;
29
- }
30
-
31
- /**
32
- * Initializes an empty program in the compiler.
33
- * This is useful when you want to initialize the default TypeKits without any code.
34
- */
35
- export async function initEmptyProgram(): Promise<void> {
36
- await getProgram("");
37
- }