@typespec/emitter-framework 0.11.0-dev.6 → 0.11.0-dev.8

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 (173) 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.js +2 -1
  22. package/dist/src/core/write-output.js.map +1 -0
  23. package/dist/src/csharp/components/class/declaration.d.ts.map +1 -1
  24. package/dist/src/csharp/components/class/declaration.js +9 -1
  25. package/dist/src/csharp/components/class/declaration.js.map +1 -0
  26. package/dist/src/csharp/components/class/declaration.test.js +62 -105
  27. package/dist/src/csharp/components/class/declaration.test.js.map +1 -0
  28. package/dist/src/csharp/components/enum/declaration.js +2 -1
  29. package/dist/src/csharp/components/enum/declaration.js.map +1 -0
  30. package/dist/src/csharp/components/enum/declaration.test.js +52 -88
  31. package/dist/src/csharp/components/enum/declaration.test.js.map +1 -0
  32. package/dist/src/csharp/components/index.js +2 -1
  33. package/dist/src/csharp/components/index.js.map +1 -0
  34. package/dist/src/csharp/components/property/property.d.ts.map +1 -1
  35. package/dist/src/csharp/components/property/property.js +31 -2
  36. package/dist/src/csharp/components/property/property.js.map +1 -0
  37. package/dist/src/csharp/components/property/property.test.js +91 -39
  38. package/dist/src/csharp/components/property/property.test.js.map +1 -0
  39. package/dist/src/csharp/components/type-expression.js +2 -1
  40. package/dist/src/csharp/components/type-expression.js.map +1 -0
  41. package/dist/src/csharp/components/type-expression.test.js +43 -74
  42. package/dist/src/csharp/components/type-expression.test.js.map +1 -0
  43. package/dist/src/csharp/components/utils/doc-comments.js +2 -1
  44. package/dist/src/csharp/components/utils/doc-comments.js.map +1 -0
  45. package/dist/src/csharp/components/utils/nullable-util.js +2 -1
  46. package/dist/src/csharp/components/utils/nullable-util.js.map +1 -0
  47. package/dist/src/csharp/components/utils/refkey.js +2 -1
  48. package/dist/src/csharp/components/utils/refkey.js.map +1 -0
  49. package/dist/src/csharp/index.js +2 -1
  50. package/dist/src/csharp/index.js.map +1 -0
  51. package/dist/src/lib.js +2 -1
  52. package/dist/src/lib.js.map +1 -0
  53. package/dist/src/testing/index.js +2 -1
  54. package/dist/src/testing/index.js.map +1 -0
  55. package/dist/src/testing/scenario-test/code-block-expectation.js +2 -1
  56. package/dist/src/testing/scenario-test/code-block-expectation.js.map +1 -0
  57. package/dist/src/testing/scenario-test/code-block-expectation.test.js +2 -1
  58. package/dist/src/testing/scenario-test/code-block-expectation.test.js.map +1 -0
  59. package/dist/src/testing/scenario-test/harness.js +2 -1
  60. package/dist/src/testing/scenario-test/harness.js.map +1 -0
  61. package/dist/src/testing/scenario-test/index.js +2 -1
  62. package/dist/src/testing/scenario-test/index.js.map +1 -0
  63. package/dist/src/testing/scenario-test/snippet-extractor.js +2 -1
  64. package/dist/src/testing/scenario-test/snippet-extractor.js.map +1 -0
  65. package/dist/src/typescript/components/array-expression.js +2 -1
  66. package/dist/src/typescript/components/array-expression.js.map +1 -0
  67. package/dist/src/typescript/components/arrow-function.js +2 -1
  68. package/dist/src/typescript/components/arrow-function.js.map +1 -0
  69. package/dist/src/typescript/components/class-method.js +2 -1
  70. package/dist/src/typescript/components/class-method.js.map +1 -0
  71. package/dist/src/typescript/components/enum-declaration.js +2 -1
  72. package/dist/src/typescript/components/enum-declaration.js.map +1 -0
  73. package/dist/src/typescript/components/function-declaration.js +2 -1
  74. package/dist/src/typescript/components/function-declaration.js.map +1 -0
  75. package/dist/src/typescript/components/function-expression.js +2 -1
  76. package/dist/src/typescript/components/function-expression.js.map +1 -0
  77. package/dist/src/typescript/components/function-type.js +2 -1
  78. package/dist/src/typescript/components/function-type.js.map +1 -0
  79. package/dist/src/typescript/components/index.js +2 -1
  80. package/dist/src/typescript/components/index.js.map +1 -0
  81. package/dist/src/typescript/components/interface-declaration.js +2 -1
  82. package/dist/src/typescript/components/interface-declaration.js.map +1 -0
  83. package/dist/src/typescript/components/interface-member.js +2 -1
  84. package/dist/src/typescript/components/interface-member.js.map +1 -0
  85. package/dist/src/typescript/components/interface-method.js +2 -1
  86. package/dist/src/typescript/components/interface-method.js.map +1 -0
  87. package/dist/src/typescript/components/record-expression.js +2 -1
  88. package/dist/src/typescript/components/record-expression.js.map +1 -0
  89. package/dist/src/typescript/components/static-serializers.js +2 -1
  90. package/dist/src/typescript/components/static-serializers.js.map +1 -0
  91. package/dist/src/typescript/components/type-alias-declaration.js +2 -1
  92. package/dist/src/typescript/components/type-alias-declaration.js.map +1 -0
  93. package/dist/src/typescript/components/type-declaration.js +2 -1
  94. package/dist/src/typescript/components/type-declaration.js.map +1 -0
  95. package/dist/src/typescript/components/type-expression.js +2 -1
  96. package/dist/src/typescript/components/type-expression.js.map +1 -0
  97. package/dist/src/typescript/components/type-transform.js +2 -1
  98. package/dist/src/typescript/components/type-transform.js.map +1 -0
  99. package/dist/src/typescript/components/union/declaration.js +2 -1
  100. package/dist/src/typescript/components/union/declaration.js.map +1 -0
  101. package/dist/src/typescript/components/union/declaration.test.js +2 -1
  102. package/dist/src/typescript/components/union/declaration.test.js.map +1 -0
  103. package/dist/src/typescript/components/union/expression.js +2 -1
  104. package/dist/src/typescript/components/union/expression.js.map +1 -0
  105. package/dist/src/typescript/components/union/expression.test.js +2 -1
  106. package/dist/src/typescript/components/union/expression.test.js.map +1 -0
  107. package/dist/src/typescript/components/value-expression.js +2 -1
  108. package/dist/src/typescript/components/value-expression.js.map +1 -0
  109. package/dist/src/typescript/index.js +2 -1
  110. package/dist/src/typescript/index.js.map +1 -0
  111. package/dist/src/typescript/lib.js +2 -1
  112. package/dist/src/typescript/lib.js.map +1 -0
  113. package/dist/src/typescript/utils/index.js +2 -1
  114. package/dist/src/typescript/utils/index.js.map +1 -0
  115. package/dist/src/typescript/utils/operation.js +2 -1
  116. package/dist/src/typescript/utils/operation.js.map +1 -0
  117. package/dist/src/typescript/utils/refkey.js +2 -1
  118. package/dist/src/typescript/utils/refkey.js.map +1 -0
  119. package/dist/test/test-host.js +2 -1
  120. package/dist/test/test-host.js.map +1 -0
  121. package/dist/test/testing/snippet-extractor-csharp.test.js +2 -1
  122. package/dist/test/testing/snippet-extractor-csharp.test.js.map +1 -0
  123. package/dist/test/testing/snippet-extractor-java.test.js +2 -1
  124. package/dist/test/testing/snippet-extractor-java.test.js.map +1 -0
  125. package/dist/test/testing/snippet-extractor-python.test.js +2 -1
  126. package/dist/test/testing/snippet-extractor-python.test.js.map +1 -0
  127. package/dist/test/testing/snippet-extractor-typescript.test.js +2 -1
  128. package/dist/test/testing/snippet-extractor-typescript.test.js.map +1 -0
  129. package/dist/test/typescript/components/arrow-function.test.js +9 -14
  130. package/dist/test/typescript/components/arrow-function.test.js.map +1 -0
  131. package/dist/test/typescript/components/component-override.test.js +2 -1
  132. package/dist/test/typescript/components/component-override.test.js.map +1 -0
  133. package/dist/test/typescript/components/enum-declaration.test.js +2 -1
  134. package/dist/test/typescript/components/enum-declaration.test.js.map +1 -0
  135. package/dist/test/typescript/components/function-declaration.test.js +2 -1
  136. package/dist/test/typescript/components/function-declaration.test.js.map +1 -0
  137. package/dist/test/typescript/components/function-expression.test.js +9 -14
  138. package/dist/test/typescript/components/function-expression.test.js.map +1 -0
  139. package/dist/test/typescript/components/function-type.test.js +9 -14
  140. package/dist/test/typescript/components/function-type.test.js.map +1 -0
  141. package/dist/test/typescript/components/interface-declaration.test.js +2 -1
  142. package/dist/test/typescript/components/interface-declaration.test.js.map +1 -0
  143. package/dist/test/typescript/components/interface-method.test.js +19 -29
  144. package/dist/test/typescript/components/interface-method.test.js.map +1 -0
  145. package/dist/test/typescript/components/member-expression.test.js +2 -1
  146. package/dist/test/typescript/components/member-expression.test.js.map +1 -0
  147. package/dist/test/typescript/components/type-alias-declaration.test.js +2 -1
  148. package/dist/test/typescript/components/type-alias-declaration.test.js.map +1 -0
  149. package/dist/test/typescript/components/type-transform.test.js +2 -1
  150. package/dist/test/typescript/components/type-transform.test.js.map +1 -0
  151. package/dist/test/typescript/components/value-expression.test.js +2 -1
  152. package/dist/test/typescript/components/value-expression.test.js.map +1 -0
  153. package/dist/test/typescript/test-host.js +2 -1
  154. package/dist/test/typescript/test-host.js.map +1 -0
  155. package/dist/test/typescript/utils.js +2 -1
  156. package/dist/test/typescript/utils.js.map +1 -0
  157. package/dist/test/utils.d.ts.map +1 -1
  158. package/dist/test/utils.js +5 -2
  159. package/dist/test/utils.js.map +1 -0
  160. package/dist/test/vitest.setup.js +2 -1
  161. package/dist/test/vitest.setup.js.map +1 -0
  162. package/package.json +7 -7
  163. package/src/csharp/components/class/declaration.test.tsx +61 -102
  164. package/src/csharp/components/class/declaration.tsx +6 -0
  165. package/src/csharp/components/enum/declaration.test.tsx +47 -78
  166. package/src/csharp/components/property/property.test.tsx +74 -35
  167. package/src/csharp/components/property/property.tsx +34 -1
  168. package/src/csharp/components/type-expression.test.tsx +41 -93
  169. package/test/typescript/components/arrow-function.test.tsx +10 -28
  170. package/test/typescript/components/function-expression.test.tsx +10 -28
  171. package/test/typescript/components/function-type.test.tsx +10 -28
  172. package/test/typescript/components/interface-method.test.tsx +25 -68
  173. package/test/utils.ts +3 -1
@@ -1,7 +1,7 @@
1
1
  import { type Children } from "@alloy-js/core";
2
2
  import * as cs from "@alloy-js/csharp";
3
3
  import { Attribute } from "@alloy-js/csharp";
4
- import { type ModelProperty, resolveEncodedName, type Type } from "@typespec/compiler";
4
+ import { getProperty, type ModelProperty, resolveEncodedName, type Type } from "@typespec/compiler";
5
5
  import { useTsp } from "../../../core/index.js";
6
6
  import { TypeExpression } from "../type-expression.jsx";
7
7
  import { getDocComments } from "../utils/doc-comments.jsx";
@@ -20,11 +20,44 @@ export function Property(props: PropertyProps): Children {
20
20
  const result = preprocessPropertyType(props.type);
21
21
  const { $ } = useTsp();
22
22
 
23
+ let overrideType: "" | "override" | "new" = "";
24
+ let isVirtual = false;
25
+ if (props.type.model) {
26
+ if (props.type.model.baseModel) {
27
+ const base = props.type.model.baseModel;
28
+ const baseProperty = getProperty(base, props.type.name);
29
+ if (baseProperty) {
30
+ const baseResult = preprocessPropertyType(baseProperty);
31
+ if (baseResult.nullable === result.nullable && baseResult.type === result.type) {
32
+ overrideType = "override";
33
+ } else {
34
+ overrideType = "new";
35
+ }
36
+ }
37
+ }
38
+ if (
39
+ overrideType === "" &&
40
+ props.type.model.derivedModels &&
41
+ props.type.model.derivedModels.length > 0
42
+ ) {
43
+ isVirtual = props.type.model.derivedModels.some((derived) => {
44
+ const derivedProperty = derived.properties.get(props.type.name);
45
+ if (derivedProperty) {
46
+ const derivedResult = preprocessPropertyType(derivedProperty);
47
+ return derivedResult.nullable === result.nullable && derivedResult.type === result.type;
48
+ }
49
+ });
50
+ }
51
+ }
52
+
23
53
  return (
24
54
  <cs.Property
25
55
  name={props.type.name}
26
56
  type={<TypeExpression type={result.type} />}
57
+ override={overrideType === "override"}
58
+ new={overrideType === "new"}
27
59
  public
60
+ virtual={isVirtual}
28
61
  required={!props.type.optional}
29
62
  nullable={result.nullable}
30
63
  doc={getDocComments($, props.type)}
@@ -1,11 +1,9 @@
1
- import { type Children, render } from "@alloy-js/core";
2
- import { d } from "@alloy-js/core/testing";
3
- import { Namespace, SourceFile } from "@alloy-js/csharp";
1
+ import { type Children } from "@alloy-js/core";
2
+ import { SourceFile } from "@alloy-js/csharp";
4
3
  import type { Model, ModelProperty } from "@typespec/compiler";
5
4
  import type { BasicTestRunner } from "@typespec/compiler/testing";
6
- import { beforeEach, describe, it } from "vitest";
5
+ import { beforeEach, describe, expect, it } from "vitest";
7
6
  import { createEmitterFrameworkTestRunner } from "../../../test/typescript/test-host.js";
8
- import { assertFileContents } from "../../../test/utils.js";
9
7
  import { Output } from "../../core/index.js";
10
8
  import { ClassDeclaration } from "./class/declaration.js";
11
9
  import { TypeExpression } from "./type-expression.jsx";
@@ -19,9 +17,7 @@ beforeEach(async () => {
19
17
  function Wrapper(props: { children: Children }) {
20
18
  return (
21
19
  <Output program={runner.program}>
22
- <Namespace name="TestNamespace">
23
- <SourceFile path="test.ts">{props.children}</SourceFile>
24
- </Namespace>
20
+ <SourceFile path="test.ts">{props.children}</SourceFile>
25
21
  </Output>
26
22
  );
27
23
  }
@@ -43,61 +39,37 @@ describe("map scalar to c# built-in types", () => {
43
39
  ["int64", "long"],
44
40
  ])("%s => %s", async (tspType, csType) => {
45
41
  const type = await compileType(tspType);
46
- const res = render(
42
+ expect(
47
43
  <Wrapper>
48
44
  <TypeExpression type={type} />
49
45
  </Wrapper>,
50
- );
51
-
52
- assertFileContents(
53
- res,
54
- d`
55
- namespace TestNamespace
56
- {
57
- ${csType}
58
- }
59
- `,
60
- );
46
+ ).toRenderTo(`
47
+ ${csType}
48
+ `);
61
49
  });
62
50
  });
63
51
 
64
52
  it("maps array to c# array", async () => {
65
53
  const type = await compileType("int32[]");
66
- const res = render(
54
+ expect(
67
55
  <Wrapper>
68
56
  <TypeExpression type={type} />
69
57
  </Wrapper>,
70
- );
71
-
72
- assertFileContents(
73
- res,
74
- d`
75
- namespace TestNamespace
76
- {
77
- int[]
78
- }
79
- `,
80
- );
58
+ ).toRenderTo(`
59
+ int[]
60
+ `);
81
61
  });
82
62
 
83
63
  describe("Record map to IDictionary", () => {
84
64
  it("for primitive types", async () => {
85
65
  const type = await compileType("Record<int32>");
86
- const res = render(
66
+ expect(
87
67
  <Wrapper>
88
68
  <TypeExpression type={type} />
89
69
  </Wrapper>,
90
- );
91
-
92
- assertFileContents(
93
- res,
94
- d`
95
- namespace TestNamespace
96
- {
97
- IDictionary<string, int>
98
- }
99
- `,
100
- );
70
+ ).toRenderTo(`
71
+ IDictionary<string, int>
72
+ `);
101
73
  });
102
74
 
103
75
  it("for models", async () => {
@@ -108,27 +80,19 @@ describe("Record map to IDictionary", () => {
108
80
  @test model Pet {}
109
81
  `)) as { test: ModelProperty; Pet: Model };
110
82
 
111
- const res = render(
83
+ expect(
112
84
  <Wrapper>
113
85
  <ClassDeclaration type={Pet} />
114
86
  <hbr />
115
87
  <TypeExpression type={test.type} />
116
88
  </Wrapper>,
117
- );
118
-
119
- assertFileContents(
120
- res,
121
- d`
122
- namespace TestNamespace
123
- {
124
- class Pet
125
- {
126
-
127
- }
128
- IDictionary<string, Pet>
129
- }
130
- `,
131
- );
89
+ ).toRenderTo(`
90
+ class Pet
91
+ {
92
+
93
+ }
94
+ IDictionary<string, Pet>
95
+ `);
132
96
  });
133
97
  });
134
98
 
@@ -140,24 +104,16 @@ describe("Nullable union", () => {
140
104
  }
141
105
  `)) as { Pet: Model };
142
106
 
143
- const res = render(
107
+ expect(
144
108
  <Wrapper>
145
109
  <ClassDeclaration type={Pet} />
146
110
  </Wrapper>,
147
- );
148
-
149
- assertFileContents(
150
- res,
151
- d`
152
- namespace TestNamespace
153
- {
154
- class Pet
155
- {
156
- public required bool? name { get; set; }
157
- }
158
- }
159
- `,
160
- );
111
+ ).toRenderTo(`
112
+ class Pet
113
+ {
114
+ public required bool? name { get; set; }
115
+ }
116
+ `);
161
117
  });
162
118
  });
163
119
 
@@ -172,26 +128,18 @@ describe("Literal types", () => {
172
128
  }
173
129
  `)) as { Pet: Model };
174
130
 
175
- const res = render(
131
+ expect(
176
132
  <Wrapper>
177
133
  <ClassDeclaration type={Pet} />
178
134
  </Wrapper>,
179
- );
180
-
181
- assertFileContents(
182
- res,
183
- d`
184
- namespace TestNamespace
185
- {
186
- class Pet
187
- {
188
- public required bool boolName { get; set; }
189
- public required int intName { get; set; }
190
- public required double doubleName { get; set; }
191
- public required string stringName { get; set; }
192
- }
193
- }
194
- `,
195
- );
135
+ ).toRenderTo(`
136
+ class Pet
137
+ {
138
+ public required bool boolName { get; set; }
139
+ public required int intName { get; set; }
140
+ public required double doubleName { get; set; }
141
+ public required string stringName { get; set; }
142
+ }
143
+ `);
196
144
  });
197
145
  });
@@ -1,12 +1,9 @@
1
- import { render } from "@alloy-js/core";
2
- import { d } from "@alloy-js/core/testing";
3
1
  import { SourceFile } from "@alloy-js/typescript";
4
2
  import type { Operation } from "@typespec/compiler";
5
3
  import type { BasicTestRunner } from "@typespec/compiler/testing";
6
- import { beforeEach, describe, it } from "vitest";
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
7
  import { createEmitterFrameworkTestRunner } from "../test-host.js";
11
8
 
12
9
  describe("arrow functions with a `type` prop", () => {
@@ -21,22 +18,17 @@ describe("arrow functions with a `type` prop", () => {
21
18
  @test op getName(id: string): string;
22
19
  `)) as { getName: Operation };
23
20
 
24
- const res = render(
21
+ expect(
25
22
  <Output program={runner.program}>
26
23
  <SourceFile path="test.ts">
27
24
  <ArrowFunction type={getName}>console.log("Hello!");</ArrowFunction>
28
25
  </SourceFile>
29
26
  </Output>,
30
- );
31
-
32
- assertFileContents(
33
- res,
34
- d`
27
+ ).toRenderTo(`
35
28
  (id: string): string => {
36
29
  console.log("Hello!");
37
30
  }
38
- `,
39
- );
31
+ `);
40
32
  });
41
33
 
42
34
  it("creates an async function", async () => {
@@ -44,20 +36,15 @@ describe("arrow functions with a `type` prop", () => {
44
36
  @test op getName(id: string): string;
45
37
  `)) as { getName: Operation };
46
38
 
47
- const res = render(
39
+ expect(
48
40
  <Output program={runner.program}>
49
41
  <SourceFile path="test.ts">
50
42
  <ArrowFunction async type={getName} />
51
43
  </SourceFile>
52
44
  </Output>,
53
- );
54
-
55
- assertFileContents(
56
- res,
57
- d`
45
+ ).toRenderTo(`
58
46
  async (id: string): Promise<string> => {}
59
- `,
60
- );
47
+ `);
61
48
  });
62
49
 
63
50
  it("can append extra parameters with raw params provided", async () => {
@@ -65,7 +52,7 @@ describe("arrow functions with a `type` prop", () => {
65
52
  @test op getName(id: string): string;
66
53
  `)) as { getName: Operation };
67
54
 
68
- const res = render(
55
+ expect(
69
56
  <Output program={runner.program}>
70
57
  <SourceFile path="test.ts">
71
58
  <ArrowFunction
@@ -74,13 +61,8 @@ describe("arrow functions with a `type` prop", () => {
74
61
  />
75
62
  </SourceFile>
76
63
  </Output>,
77
- );
78
-
79
- assertFileContents(
80
- res,
81
- d`
64
+ ).toRenderTo(`
82
65
  (additionalParam: number, id: string): string => {}
83
- `,
84
- );
66
+ `);
85
67
  });
86
68
  });
@@ -1,12 +1,9 @@
1
- import { render } from "@alloy-js/core";
2
- import { d } from "@alloy-js/core/testing";
3
1
  import { SourceFile } from "@alloy-js/typescript";
4
2
  import type { Operation } from "@typespec/compiler";
5
3
  import type { BasicTestRunner } from "@typespec/compiler/testing";
6
- import { beforeEach, describe, it } from "vitest";
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
7
  import { createEmitterFrameworkTestRunner } from "../test-host.js";
11
8
 
12
9
  describe("function expressions with a `type` prop", () => {
@@ -21,22 +18,17 @@ describe("function expressions with a `type` prop", () => {
21
18
  @test op getName(id: string): string;
22
19
  `)) as { getName: Operation };
23
20
 
24
- const res = render(
21
+ expect(
25
22
  <Output program={runner.program}>
26
23
  <SourceFile path="test.ts">
27
24
  <FunctionExpression type={getName}>console.log("Hello!");</FunctionExpression>
28
25
  </SourceFile>
29
26
  </Output>,
30
- );
31
-
32
- assertFileContents(
33
- res,
34
- d`
27
+ ).toRenderTo(`
35
28
  function (id: string): string {
36
29
  console.log("Hello!");
37
30
  }
38
- `,
39
- );
31
+ `);
40
32
  });
41
33
 
42
34
  it("creates an async function", async () => {
@@ -44,20 +36,15 @@ describe("function expressions with a `type` prop", () => {
44
36
  @test op getName(id: string): string;
45
37
  `)) as { getName: Operation };
46
38
 
47
- const res = render(
39
+ expect(
48
40
  <Output program={runner.program}>
49
41
  <SourceFile path="test.ts">
50
42
  <FunctionExpression async type={getName} />
51
43
  </SourceFile>
52
44
  </Output>,
53
- );
54
-
55
- assertFileContents(
56
- res,
57
- d`
45
+ ).toRenderTo(`
58
46
  async function (id: string): Promise<string> {}
59
- `,
60
- );
47
+ `);
61
48
  });
62
49
 
63
50
  it("can append extra parameters with raw params provided", async () => {
@@ -65,7 +52,7 @@ describe("function expressions with a `type` prop", () => {
65
52
  @test op getName(id: string): string;
66
53
  `)) as { getName: Operation };
67
54
 
68
- const res = render(
55
+ expect(
69
56
  <Output program={runner.program}>
70
57
  <SourceFile path="test.ts">
71
58
  <FunctionExpression
@@ -74,13 +61,8 @@ describe("function expressions with a `type` prop", () => {
74
61
  />
75
62
  </SourceFile>
76
63
  </Output>,
77
- );
78
-
79
- assertFileContents(
80
- res,
81
- d`
64
+ ).toRenderTo(`
82
65
  function (additionalParam: number, id: string): string {}
83
- `,
84
- );
66
+ `);
85
67
  });
86
68
  });
@@ -1,12 +1,9 @@
1
- import { render } from "@alloy-js/core";
2
- import { d } from "@alloy-js/core/testing";
3
1
  import { SourceFile } from "@alloy-js/typescript";
4
2
  import type { Operation } from "@typespec/compiler";
5
3
  import type { BasicTestRunner } from "@typespec/compiler/testing";
6
- import { beforeEach, describe, it } from "vitest";
4
+ import { beforeEach, describe, expect, it } from "vitest";
7
5
  import { Output } from "../../../src/core/components/output.jsx";
8
6
  import { FunctionType } from "../../../src/typescript/index.js";
9
- import { assertFileContents } from "../../utils.js";
10
7
  import { createEmitterFrameworkTestRunner } from "../test-host.js";
11
8
 
12
9
  describe("function types with a `type` prop", () => {
@@ -21,20 +18,15 @@ describe("function types with a `type` prop", () => {
21
18
  @test op getName(id: string): string;
22
19
  `)) as { getName: Operation };
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 () => {
@@ -42,20 +34,15 @@ describe("function types with a `type` prop", () => {
42
34
  @test op getName(id: string): string;
43
35
  `)) as { getName: Operation };
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 () => {
@@ -63,19 +50,14 @@ describe("function types with a `type` prop", () => {
63
50
  @test 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
  });