@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.
Files changed (212) hide show
  1. package/dist/src/core/components/index.d.ts +2 -0
  2. package/dist/src/core/components/index.d.ts.map +1 -1
  3. package/dist/src/core/components/index.js +4 -1
  4. package/dist/src/core/components/index.js.map +1 -0
  5. package/dist/src/core/components/output.js +2 -1
  6. package/dist/src/core/components/output.js.map +1 -0
  7. package/dist/src/core/components/overrides/component-overrides.d.ts +64 -0
  8. package/dist/src/core/components/overrides/component-overrides.d.ts.map +1 -0
  9. package/dist/src/core/components/overrides/component-overrides.js +41 -0
  10. package/dist/src/core/components/overrides/component-overrides.js.map +1 -0
  11. package/dist/src/core/components/overrides/config.d.ts +28 -0
  12. package/dist/src/core/components/overrides/config.d.ts.map +1 -0
  13. package/dist/src/core/components/overrides/config.js +55 -0
  14. package/dist/src/core/components/overrides/config.js.map +1 -0
  15. package/dist/src/core/components/overrides/context.d.ts +11 -0
  16. package/dist/src/core/components/overrides/context.d.ts.map +1 -0
  17. package/dist/src/core/components/overrides/context.js +9 -0
  18. package/dist/src/core/components/overrides/context.js.map +1 -0
  19. package/dist/src/core/context/index.js +2 -1
  20. package/dist/src/core/context/index.js.map +1 -0
  21. package/dist/src/core/context/name-policy-context.js +2 -1
  22. package/dist/src/core/context/name-policy-context.js.map +1 -0
  23. package/dist/src/core/context/tsp-context.js +2 -1
  24. package/dist/src/core/context/tsp-context.js.map +1 -0
  25. package/dist/src/core/index.js +2 -1
  26. package/dist/src/core/index.js.map +1 -0
  27. package/dist/src/core/transport-name-policy.js +2 -1
  28. package/dist/src/core/transport-name-policy.js.map +1 -0
  29. package/dist/src/core/write-output.d.ts.map +1 -1
  30. package/dist/src/core/write-output.js +4 -3
  31. package/dist/src/core/write-output.js.map +1 -0
  32. package/dist/src/csharp/components/class/declaration.d.ts +1 -1
  33. package/dist/src/csharp/components/class/declaration.d.ts.map +1 -1
  34. package/dist/src/csharp/components/class/declaration.js +14 -5
  35. package/dist/src/csharp/components/class/declaration.js.map +1 -0
  36. package/dist/src/csharp/components/class/declaration.test.js +125 -92
  37. package/dist/src/csharp/components/class/declaration.test.js.map +1 -0
  38. package/dist/src/csharp/components/enum/declaration.js +2 -1
  39. package/dist/src/csharp/components/enum/declaration.js.map +1 -0
  40. package/dist/src/csharp/components/enum/declaration.test.js +52 -88
  41. package/dist/src/csharp/components/enum/declaration.test.js.map +1 -0
  42. package/dist/src/csharp/components/index.js +2 -1
  43. package/dist/src/csharp/components/index.js.map +1 -0
  44. package/dist/src/csharp/components/property/property.d.ts.map +1 -1
  45. package/dist/src/csharp/components/property/property.js +40 -14
  46. package/dist/src/csharp/components/property/property.js.map +1 -0
  47. package/dist/src/csharp/components/property/property.test.js +129 -29
  48. package/dist/src/csharp/components/property/property.test.js.map +1 -0
  49. package/dist/src/csharp/components/type-expression.d.ts.map +1 -1
  50. package/dist/src/csharp/components/type-expression.js +34 -6
  51. package/dist/src/csharp/components/type-expression.js.map +1 -0
  52. package/dist/src/csharp/components/type-expression.test.js +87 -54
  53. package/dist/src/csharp/components/type-expression.test.js.map +1 -0
  54. package/dist/src/csharp/components/utils/doc-comments.js +2 -1
  55. package/dist/src/csharp/components/utils/doc-comments.js.map +1 -0
  56. package/dist/src/csharp/components/utils/nullable-util.d.ts +4 -0
  57. package/dist/src/csharp/components/utils/nullable-util.d.ts.map +1 -0
  58. package/dist/src/csharp/components/utils/nullable-util.js +27 -0
  59. package/dist/src/csharp/components/utils/nullable-util.js.map +1 -0
  60. package/dist/src/csharp/components/utils/refkey.js +2 -1
  61. package/dist/src/csharp/components/utils/refkey.js.map +1 -0
  62. package/dist/src/csharp/index.js +2 -1
  63. package/dist/src/csharp/index.js.map +1 -0
  64. package/dist/src/lib.js +2 -1
  65. package/dist/src/lib.js.map +1 -0
  66. package/dist/src/testing/index.js +2 -1
  67. package/dist/src/testing/index.js.map +1 -0
  68. package/dist/src/testing/scenario-test/code-block-expectation.js +2 -1
  69. package/dist/src/testing/scenario-test/code-block-expectation.js.map +1 -0
  70. package/dist/src/testing/scenario-test/code-block-expectation.test.js +2 -1
  71. package/dist/src/testing/scenario-test/code-block-expectation.test.js.map +1 -0
  72. package/dist/src/testing/scenario-test/harness.js +8 -2
  73. package/dist/src/testing/scenario-test/harness.js.map +1 -0
  74. package/dist/src/testing/scenario-test/index.js +2 -1
  75. package/dist/src/testing/scenario-test/index.js.map +1 -0
  76. package/dist/src/testing/scenario-test/snippet-extractor.js +2 -1
  77. package/dist/src/testing/scenario-test/snippet-extractor.js.map +1 -0
  78. package/dist/src/typescript/components/array-expression.js +2 -1
  79. package/dist/src/typescript/components/array-expression.js.map +1 -0
  80. package/dist/src/typescript/components/arrow-function.js +2 -1
  81. package/dist/src/typescript/components/arrow-function.js.map +1 -0
  82. package/dist/src/typescript/components/class-method.js +2 -1
  83. package/dist/src/typescript/components/class-method.js.map +1 -0
  84. package/dist/src/typescript/components/enum-declaration.js +2 -1
  85. package/dist/src/typescript/components/enum-declaration.js.map +1 -0
  86. package/dist/src/typescript/components/function-declaration.js +2 -1
  87. package/dist/src/typescript/components/function-declaration.js.map +1 -0
  88. package/dist/src/typescript/components/function-expression.js +2 -1
  89. package/dist/src/typescript/components/function-expression.js.map +1 -0
  90. package/dist/src/typescript/components/function-type.js +2 -1
  91. package/dist/src/typescript/components/function-type.js.map +1 -0
  92. package/dist/src/typescript/components/index.js +2 -1
  93. package/dist/src/typescript/components/index.js.map +1 -0
  94. package/dist/src/typescript/components/interface-declaration.js +2 -1
  95. package/dist/src/typescript/components/interface-declaration.js.map +1 -0
  96. package/dist/src/typescript/components/interface-member.d.ts.map +1 -1
  97. package/dist/src/typescript/components/interface-member.js +13 -20
  98. package/dist/src/typescript/components/interface-member.js.map +1 -0
  99. package/dist/src/typescript/components/interface-method.js +2 -1
  100. package/dist/src/typescript/components/interface-method.js.map +1 -0
  101. package/dist/src/typescript/components/record-expression.js +2 -1
  102. package/dist/src/typescript/components/record-expression.js.map +1 -0
  103. package/dist/src/typescript/components/static-serializers.js +2 -1
  104. package/dist/src/typescript/components/static-serializers.js.map +1 -0
  105. package/dist/src/typescript/components/type-alias-declaration.js +2 -1
  106. package/dist/src/typescript/components/type-alias-declaration.js.map +1 -0
  107. package/dist/src/typescript/components/type-declaration.js +2 -1
  108. package/dist/src/typescript/components/type-declaration.js.map +1 -0
  109. package/dist/src/typescript/components/type-expression.d.ts +0 -1
  110. package/dist/src/typescript/components/type-expression.d.ts.map +1 -1
  111. package/dist/src/typescript/components/type-expression.js +13 -12
  112. package/dist/src/typescript/components/type-expression.js.map +1 -0
  113. package/dist/src/typescript/components/type-transform.d.ts.map +1 -1
  114. package/dist/src/typescript/components/type-transform.js +5 -4
  115. package/dist/src/typescript/components/type-transform.js.map +1 -0
  116. package/dist/src/typescript/components/union/declaration.js +2 -1
  117. package/dist/src/typescript/components/union/declaration.js.map +1 -0
  118. package/dist/src/typescript/components/union/declaration.test.js +2 -1
  119. package/dist/src/typescript/components/union/declaration.test.js.map +1 -0
  120. package/dist/src/typescript/components/union/expression.js +2 -1
  121. package/dist/src/typescript/components/union/expression.js.map +1 -0
  122. package/dist/src/typescript/components/union/expression.test.js +2 -1
  123. package/dist/src/typescript/components/union/expression.test.js.map +1 -0
  124. package/dist/src/typescript/components/value-expression.js +2 -1
  125. package/dist/src/typescript/components/value-expression.js.map +1 -0
  126. package/dist/src/typescript/index.js +2 -1
  127. package/dist/src/typescript/index.js.map +1 -0
  128. package/dist/src/typescript/lib.js +2 -1
  129. package/dist/src/typescript/lib.js.map +1 -0
  130. package/dist/src/typescript/utils/index.js +2 -1
  131. package/dist/src/typescript/utils/index.js.map +1 -0
  132. package/dist/src/typescript/utils/operation.js +2 -1
  133. package/dist/src/typescript/utils/operation.js.map +1 -0
  134. package/dist/src/typescript/utils/refkey.js +2 -1
  135. package/dist/src/typescript/utils/refkey.js.map +1 -0
  136. package/dist/test/test-host.js +2 -1
  137. package/dist/test/test-host.js.map +1 -0
  138. package/dist/test/testing/snippet-extractor-csharp.test.js +2 -1
  139. package/dist/test/testing/snippet-extractor-csharp.test.js.map +1 -0
  140. package/dist/test/testing/snippet-extractor-java.test.js +2 -1
  141. package/dist/test/testing/snippet-extractor-java.test.js.map +1 -0
  142. package/dist/test/testing/snippet-extractor-python.test.js +2 -1
  143. package/dist/test/testing/snippet-extractor-python.test.js.map +1 -0
  144. package/dist/test/testing/snippet-extractor-typescript.test.js +2 -1
  145. package/dist/test/testing/snippet-extractor-typescript.test.js.map +1 -0
  146. package/dist/test/typescript/components/arrow-function.test.js +18 -22
  147. package/dist/test/typescript/components/arrow-function.test.js.map +1 -0
  148. package/dist/test/typescript/components/component-override.test.d.ts +2 -0
  149. package/dist/test/typescript/components/component-override.test.d.ts.map +1 -0
  150. package/dist/test/typescript/components/component-override.test.js +78 -0
  151. package/dist/test/typescript/components/component-override.test.js.map +1 -0
  152. package/dist/test/typescript/components/enum-declaration.test.js +2 -1
  153. package/dist/test/typescript/components/enum-declaration.test.js.map +1 -0
  154. package/dist/test/typescript/components/function-declaration.test.js +3 -2
  155. package/dist/test/typescript/components/function-declaration.test.js.map +1 -0
  156. package/dist/test/typescript/components/function-expression.test.js +18 -22
  157. package/dist/test/typescript/components/function-expression.test.js.map +1 -0
  158. package/dist/test/typescript/components/function-type.test.js +18 -22
  159. package/dist/test/typescript/components/function-type.test.js.map +1 -0
  160. package/dist/test/typescript/components/interface-declaration.test.js +3 -2
  161. package/dist/test/typescript/components/interface-declaration.test.js.map +1 -0
  162. package/dist/test/typescript/components/interface-method.test.js +37 -45
  163. package/dist/test/typescript/components/interface-method.test.js.map +1 -0
  164. package/dist/test/typescript/components/member-expression.test.js +2 -1
  165. package/dist/test/typescript/components/member-expression.test.js.map +1 -0
  166. package/dist/test/typescript/components/type-alias-declaration.test.js +8 -5
  167. package/dist/test/typescript/components/type-alias-declaration.test.js.map +1 -0
  168. package/dist/test/typescript/components/type-transform.test.js +29 -27
  169. package/dist/test/typescript/components/type-transform.test.js.map +1 -0
  170. package/dist/test/typescript/components/value-expression.test.js +3 -2
  171. package/dist/test/typescript/components/value-expression.test.js.map +1 -0
  172. package/dist/test/typescript/utils.js +2 -1
  173. package/dist/test/typescript/utils.js.map +1 -0
  174. package/dist/test/utils.d.ts +1 -0
  175. package/dist/test/utils.d.ts.map +1 -1
  176. package/dist/test/utils.js +13 -3
  177. package/dist/test/utils.js.map +1 -0
  178. package/dist/test/vitest.setup.js +2 -1
  179. package/dist/test/vitest.setup.js.map +1 -0
  180. package/package.json +9 -13
  181. package/src/core/components/index.tsx +2 -0
  182. package/src/core/components/overrides/component-overrides.tsx +134 -0
  183. package/src/core/components/overrides/config.ts +85 -0
  184. package/src/core/components/overrides/context.ts +14 -0
  185. package/src/core/write-output.ts +2 -2
  186. package/src/csharp/components/class/declaration.test.tsx +114 -88
  187. package/src/csharp/components/class/declaration.tsx +13 -3
  188. package/src/csharp/components/enum/declaration.test.tsx +47 -78
  189. package/src/csharp/components/property/property.test.tsx +108 -25
  190. package/src/csharp/components/property/property.tsx +43 -11
  191. package/src/csharp/components/type-expression.test.tsx +84 -69
  192. package/src/csharp/components/type-expression.tsx +31 -5
  193. package/src/csharp/components/utils/nullable-util.ts +25 -0
  194. package/src/testing/scenario-test/harness.ts +6 -1
  195. package/src/typescript/components/interface-member.tsx +8 -14
  196. package/src/typescript/components/type-expression.tsx +7 -8
  197. package/src/typescript/components/type-transform.tsx +3 -7
  198. package/test/typescript/components/arrow-function.test.tsx +23 -42
  199. package/test/typescript/components/component-override.test.tsx +71 -0
  200. package/test/typescript/components/function-declaration.test.tsx +2 -1
  201. package/test/typescript/components/function-expression.test.tsx +23 -42
  202. package/test/typescript/components/function-type.test.tsx +22 -40
  203. package/test/typescript/components/interface-declaration.test.tsx +1 -1
  204. package/test/typescript/components/interface-method.test.tsx +50 -92
  205. package/test/typescript/components/type-alias-declaration.test.tsx +8 -6
  206. package/test/typescript/components/type-transform.test.tsx +37 -37
  207. package/test/typescript/components/value-expression.test.tsx +1 -1
  208. package/test/utils.ts +10 -3
  209. package/dist/test/typescript/test-host.d.ts +0 -16
  210. package/dist/test/typescript/test-host.d.ts.map +0 -1
  211. package/dist/test/typescript/test-host.js +0 -40
  212. package/test/typescript/test-host.ts +0 -49
@@ -1,71 +1,57 @@
1
- import { render } from "@alloy-js/core";
2
- import { d } from "@alloy-js/core/testing";
1
+ import { Tester } from "#test/test-host.js";
3
2
  import { SourceFile } from "@alloy-js/typescript";
4
- import type { Operation } from "@typespec/compiler";
5
- import type { BasicTestRunner } from "@typespec/compiler/testing";
6
- import { beforeEach, describe, it } from "vitest";
3
+ import { type TesterInstance, t } from "@typespec/compiler/testing";
4
+ import { beforeEach, describe, expect, it } from "vitest";
7
5
  import { Output } from "../../../src/core/components/output.jsx";
8
6
  import { ArrowFunction } from "../../../src/typescript/components/arrow-function.jsx";
9
- import { assertFileContents } from "../../utils.js";
10
- import { createEmitterFrameworkTestRunner } from "../test-host.js";
11
7
 
12
8
  describe("arrow functions with a `type` prop", () => {
13
- let runner: BasicTestRunner;
9
+ let runner: TesterInstance;
14
10
 
15
11
  beforeEach(async () => {
16
- runner = await createEmitterFrameworkTestRunner();
12
+ runner = await Tester.createInstance();
17
13
  });
18
14
 
19
15
  it("creates a function", async () => {
20
- const { getName } = (await runner.compile(`
21
- @test op getName(id: string): string;
22
- `)) as { getName: Operation };
16
+ const { getName } = await runner.compile(t.code`
17
+ @test op ${t.op("getName")}(id: string): string;
18
+ `);
23
19
 
24
- const res = render(
20
+ expect(
25
21
  <Output program={runner.program}>
26
22
  <SourceFile path="test.ts">
27
23
  <ArrowFunction type={getName}>console.log("Hello!");</ArrowFunction>
28
24
  </SourceFile>
29
25
  </Output>,
30
- );
31
-
32
- assertFileContents(
33
- res,
34
- d`
26
+ ).toRenderTo(`
35
27
  (id: string): string => {
36
28
  console.log("Hello!");
37
29
  }
38
- `,
39
- );
30
+ `);
40
31
  });
41
32
 
42
33
  it("creates an async function", async () => {
43
- const { getName } = (await runner.compile(`
44
- @test op getName(id: string): string;
45
- `)) as { getName: Operation };
34
+ const { getName } = await runner.compile(t.code`
35
+ @test op ${t.op("getName")}(id: string): string;
36
+ `);
46
37
 
47
- const res = render(
38
+ expect(
48
39
  <Output program={runner.program}>
49
40
  <SourceFile path="test.ts">
50
41
  <ArrowFunction async type={getName} />
51
42
  </SourceFile>
52
43
  </Output>,
53
- );
54
-
55
- assertFileContents(
56
- res,
57
- d`
44
+ ).toRenderTo(`
58
45
  async (id: string): Promise<string> => {}
59
- `,
60
- );
46
+ `);
61
47
  });
62
48
 
63
49
  it("can append extra parameters with raw params provided", async () => {
64
- const { getName } = (await runner.compile(`
65
- @test op getName(id: string): string;
66
- `)) as { getName: Operation };
50
+ const { getName } = await runner.compile(t.code`
51
+ @test op ${t.op("getName")}(id: string): string;
52
+ `);
67
53
 
68
- const res = render(
54
+ expect(
69
55
  <Output program={runner.program}>
70
56
  <SourceFile path="test.ts">
71
57
  <ArrowFunction
@@ -74,13 +60,8 @@ describe("arrow functions with a `type` prop", () => {
74
60
  />
75
61
  </SourceFile>
76
62
  </Output>,
77
- );
78
-
79
- assertFileContents(
80
- res,
81
- d`
63
+ ).toRenderTo(`
82
64
  (additionalParam: number, id: string): string => {}
83
- `,
84
- );
65
+ `);
85
66
  });
86
67
  });
@@ -0,0 +1,71 @@
1
+ import {
2
+ Experimental_ComponentOverrides,
3
+ Experimental_ComponentOverridesConfig,
4
+ } from "#core/index.js";
5
+ import { Tester } from "#test/test-host.js";
6
+ import { FunctionDeclaration } from "#typescript/index.js";
7
+ import { For, List, type Children } from "@alloy-js/core";
8
+ import { d } from "@alloy-js/core/testing";
9
+ import { SourceFile } from "@alloy-js/typescript";
10
+ import type { Namespace } from "@typespec/compiler";
11
+ import { expect, it } from "vitest";
12
+ import { Output } from "../../../src/core/components/output.jsx";
13
+ import { InterfaceDeclaration } from "../../../src/typescript/components/interface-declaration.jsx";
14
+
15
+ it("uses overridden component", async () => {
16
+ const { program } = await Tester.compile(`
17
+ namespace DemoService;
18
+ model Foo {
19
+ knownProp: string;
20
+ }
21
+
22
+ op foo(): Foo;
23
+
24
+ `);
25
+
26
+ const [namespace] = program.resolveTypeReference("DemoService");
27
+ const models = Array.from((namespace as Namespace).models.values());
28
+ const operations = Array.from((namespace as Namespace).operations.values());
29
+
30
+ expect(
31
+ <Output program={program}>
32
+ <TestClientOverrides>
33
+ <SourceFile path="test.ts">
34
+ <List hardline>
35
+ {models.map((model) => (
36
+ <InterfaceDeclaration export type={model} />
37
+ ))}
38
+ </List>
39
+ <hbr />
40
+ <For each={operations}>
41
+ {(operation) => <FunctionDeclaration export type={operation} />}
42
+ </For>
43
+ </SourceFile>
44
+ </TestClientOverrides>
45
+ </Output>,
46
+ ).toRenderTo(
47
+ d`
48
+ export interface Foo {
49
+ knownProp: string;
50
+ }
51
+ export function foo(): unknown {}
52
+ `,
53
+ );
54
+ });
55
+
56
+ function TestClientOverrides(props: { children?: Children }) {
57
+ const overrides = Experimental_ComponentOverridesConfig().forTypeKind("Model", {
58
+ reference: (props) => {
59
+ if (props.type.name === "Foo") {
60
+ return "unknown";
61
+ } else {
62
+ return props.default;
63
+ }
64
+ },
65
+ });
66
+ return (
67
+ <Experimental_ComponentOverrides overrides={overrides}>
68
+ {props.children}
69
+ </Experimental_ComponentOverrides>
70
+ );
71
+ }
@@ -1,3 +1,4 @@
1
+ import { getProgram } from "#test/utils.js";
1
2
  import { code } from "@alloy-js/core";
2
3
  import { d } from "@alloy-js/core/testing";
3
4
  import { SourceFile } from "@alloy-js/typescript";
@@ -5,7 +6,7 @@ import type { Namespace } from "@typespec/compiler";
5
6
  import { describe, expect, it } from "vitest";
6
7
  import { Output } from "../../../src/core/components/output.jsx";
7
8
  import { FunctionDeclaration } from "../../../src/typescript/components/function-declaration.js";
8
- import { getProgram } from "../test-host.js";
9
+
9
10
  describe("Typescript Function Declaration", () => {
10
11
  describe("Function bound to Typespec Types", () => {
11
12
  describe("Bound to Operation", () => {
@@ -1,71 +1,57 @@
1
- import { render } from "@alloy-js/core";
2
- import { d } from "@alloy-js/core/testing";
1
+ import { Tester } from "#test/test-host.js";
3
2
  import { SourceFile } from "@alloy-js/typescript";
4
- import type { Operation } from "@typespec/compiler";
5
- import type { BasicTestRunner } from "@typespec/compiler/testing";
6
- import { beforeEach, describe, it } from "vitest";
3
+ import { t, type TesterInstance } from "@typespec/compiler/testing";
4
+ import { beforeEach, describe, expect, it } from "vitest";
7
5
  import { Output } from "../../../src/core/components/output.jsx";
8
6
  import { FunctionExpression } from "../../../src/typescript/components/function-expression.jsx";
9
- import { assertFileContents } from "../../utils.js";
10
- import { createEmitterFrameworkTestRunner } from "../test-host.js";
11
7
 
12
8
  describe("function expressions with a `type` prop", () => {
13
- let runner: BasicTestRunner;
9
+ let runner: TesterInstance;
14
10
 
15
11
  beforeEach(async () => {
16
- runner = await createEmitterFrameworkTestRunner();
12
+ runner = await Tester.createInstance();
17
13
  });
18
14
 
19
15
  it("creates a function", async () => {
20
- const { getName } = (await runner.compile(`
21
- @test op getName(id: string): string;
22
- `)) as { getName: Operation };
16
+ const { getName } = await runner.compile(t.code`
17
+ @test op ${t.op("getName")}(id: string): string;
18
+ `);
23
19
 
24
- const res = render(
20
+ expect(
25
21
  <Output program={runner.program}>
26
22
  <SourceFile path="test.ts">
27
23
  <FunctionExpression type={getName}>console.log("Hello!");</FunctionExpression>
28
24
  </SourceFile>
29
25
  </Output>,
30
- );
31
-
32
- assertFileContents(
33
- res,
34
- d`
26
+ ).toRenderTo(`
35
27
  function (id: string): string {
36
28
  console.log("Hello!");
37
29
  }
38
- `,
39
- );
30
+ `);
40
31
  });
41
32
 
42
33
  it("creates an async function", async () => {
43
- const { getName } = (await runner.compile(`
44
- @test op getName(id: string): string;
45
- `)) as { getName: Operation };
34
+ const { getName } = await runner.compile(t.code`
35
+ @test op ${t.op("getName")}(id: string): string;
36
+ `);
46
37
 
47
- const res = render(
38
+ expect(
48
39
  <Output program={runner.program}>
49
40
  <SourceFile path="test.ts">
50
41
  <FunctionExpression async type={getName} />
51
42
  </SourceFile>
52
43
  </Output>,
53
- );
54
-
55
- assertFileContents(
56
- res,
57
- d`
44
+ ).toRenderTo(`
58
45
  async function (id: string): Promise<string> {}
59
- `,
60
- );
46
+ `);
61
47
  });
62
48
 
63
49
  it("can append extra parameters with raw params provided", async () => {
64
- const { getName } = (await runner.compile(`
65
- @test op getName(id: string): string;
66
- `)) as { getName: Operation };
50
+ const { getName } = await runner.compile(t.code`
51
+ @test op ${t.op("getName")}(id: string): string;
52
+ `);
67
53
 
68
- const res = render(
54
+ expect(
69
55
  <Output program={runner.program}>
70
56
  <SourceFile path="test.ts">
71
57
  <FunctionExpression
@@ -74,13 +60,8 @@ describe("function expressions with a `type` prop", () => {
74
60
  />
75
61
  </SourceFile>
76
62
  </Output>,
77
- );
78
-
79
- assertFileContents(
80
- res,
81
- d`
63
+ ).toRenderTo(`
82
64
  function (additionalParam: number, id: string): string {}
83
- `,
84
- );
65
+ `);
85
66
  });
86
67
  });
@@ -1,81 +1,63 @@
1
- import { render } from "@alloy-js/core";
2
- import { d } from "@alloy-js/core/testing";
1
+ import { Tester } from "#test/test-host.js";
3
2
  import { SourceFile } from "@alloy-js/typescript";
4
3
  import type { Operation } from "@typespec/compiler";
5
- import type { BasicTestRunner } from "@typespec/compiler/testing";
6
- import { beforeEach, describe, it } from "vitest";
4
+ import { t, type TesterInstance } from "@typespec/compiler/testing";
5
+ import { beforeEach, describe, expect, it } from "vitest";
7
6
  import { Output } from "../../../src/core/components/output.jsx";
8
7
  import { FunctionType } from "../../../src/typescript/index.js";
9
- import { assertFileContents } from "../../utils.js";
10
- import { createEmitterFrameworkTestRunner } from "../test-host.js";
11
8
 
12
9
  describe("function types with a `type` prop", () => {
13
- let runner: BasicTestRunner;
10
+ let runner: TesterInstance;
14
11
 
15
12
  beforeEach(async () => {
16
- runner = await createEmitterFrameworkTestRunner();
13
+ runner = await Tester.createInstance();
17
14
  });
18
15
 
19
16
  it("creates a function type", async () => {
20
- const { getName } = (await runner.compile(`
21
- @test op getName(id: string): string;
22
- `)) as { getName: Operation };
17
+ const { getName } = await runner.compile(t.code`
18
+ @test op ${t.op("getName")}(id: string): string;
19
+ `);
23
20
 
24
- const res = render(
21
+ expect(
25
22
  <Output program={runner.program}>
26
23
  <SourceFile path="test.ts">
27
24
  <FunctionType type={getName} />
28
25
  </SourceFile>
29
26
  </Output>,
30
- );
31
-
32
- assertFileContents(
33
- res,
34
- d`
27
+ ).toRenderTo(`
35
28
  (id: string) => string
36
- `,
37
- );
29
+ `);
38
30
  });
39
31
 
40
32
  it("creates an async function type", async () => {
41
- const { getName } = (await runner.compile(`
42
- @test op getName(id: string): string;
43
- `)) as { getName: Operation };
33
+ const { getName } = await runner.compile(t.code`
34
+ @test op ${t.op("getName")}(id: string): string;
35
+ `);
44
36
 
45
- const res = render(
37
+ expect(
46
38
  <Output program={runner.program}>
47
39
  <SourceFile path="test.ts">
48
40
  <FunctionType async type={getName} />
49
41
  </SourceFile>
50
42
  </Output>,
51
- );
52
-
53
- assertFileContents(
54
- res,
55
- d`
43
+ ).toRenderTo(`
56
44
  (id: string) => Promise<string>
57
- `,
58
- );
45
+ `);
59
46
  });
60
47
 
61
48
  it("can append extra parameters with raw params provided", async () => {
62
- const { getName } = (await runner.compile(`
63
- @test op getName(id: string): string;
49
+ const { getName } = (await runner.compile(t.code`
50
+ @test op ${t.op("getName")}(id: string): string;
64
51
  `)) as { getName: Operation };
65
52
 
66
- const res = render(
53
+ expect(
67
54
  <Output program={runner.program}>
68
55
  <SourceFile path="test.ts">
69
56
  <FunctionType type={getName} parameters={[{ name: "additionalParam", type: "number" }]} />
70
57
  </SourceFile>
71
58
  </Output>,
72
- );
73
-
74
- assertFileContents(
75
- res,
76
- d`
59
+ ).toRenderTo(`
77
60
  (additionalParam: number, id: string) => string
78
- `,
79
- );
61
+ `);
80
62
  });
81
63
  });
@@ -1,10 +1,10 @@
1
+ import { getProgram } from "#test/utils.js";
1
2
  import { For, List } from "@alloy-js/core";
2
3
  import { SourceFile } from "@alloy-js/typescript";
3
4
  import type { Namespace } from "@typespec/compiler";
4
5
  import { describe, expect, it } from "vitest";
5
6
  import { Output } from "../../../src/core/components/output.jsx";
6
7
  import { InterfaceDeclaration } from "../../../src/typescript/components/interface-declaration.js";
7
- import { getProgram } from "../test-host.js";
8
8
 
9
9
  describe("Typescript Interface", () => {
10
10
  describe("Interface bound to Typespec Types", () => {