@typespec/emitter-framework 0.10.0-dev.2 → 0.10.0-dev.3
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/write-output.js +10 -6
- package/dist/src/csharp/components/class/declaration.d.ts.map +1 -1
- package/dist/src/csharp/components/class/declaration.js +2 -1
- package/dist/src/typescript/components/interface-declaration.d.ts.map +1 -1
- package/dist/src/typescript/components/interface-declaration.js +2 -2
- package/dist/src/typescript/components/union/expression.test.js +3 -3
- package/dist/test/typescript/components/function-declaration.test.js +31 -112
- package/dist/test/typescript/components/interface-declaration.test.js +146 -308
- package/dist/test/typescript/components/type-alias-declaration.test.js +17 -75
- package/dist/test/typescript/components/type-transform.test.js +32 -83
- package/dist/test/typescript/components/value-expression.test.js +3 -6
- package/dist/test/typescript/utils.d.ts +7 -0
- package/dist/test/typescript/utils.d.ts.map +1 -0
- package/dist/test/typescript/utils.js +18 -0
- package/dist/test/utils.d.ts.map +1 -1
- package/dist/test/utils.js +2 -0
- package/package.json +7 -7
- package/src/core/write-output.ts +10 -6
- package/src/csharp/components/class/declaration.tsx +2 -1
- package/src/typescript/components/interface-declaration.tsx +3 -3
- package/src/typescript/components/union/expression.test.tsx +5 -5
- package/test/typescript/components/function-declaration.test.tsx +31 -121
- package/test/typescript/components/interface-declaration.test.tsx +123 -342
- package/test/typescript/components/type-alias-declaration.test.tsx +17 -76
- package/test/typescript/components/type-transform.test.tsx +32 -93
- package/test/typescript/components/value-expression.test.tsx +4 -12
- package/test/typescript/utils.tsx +12 -0
- package/test/utils.ts +2 -1
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import { render } from "@alloy-js/core";
|
|
2
1
|
import { SourceFile } from "@alloy-js/typescript";
|
|
3
2
|
import type { Namespace, Operation } from "@typespec/compiler";
|
|
4
|
-
import {
|
|
5
|
-
import { assert, describe, expect, it } from "vitest";
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
6
4
|
import { Output } from "../../../src/core/components/output.jsx";
|
|
7
5
|
import { TypeAliasDeclaration } from "../../../src/typescript/components/type-alias-declaration.jsx";
|
|
8
|
-
import { assertFileContents } from "../../utils.js";
|
|
9
6
|
import { createEmitterFrameworkTestRunner, getProgram } from "../test-host.js";
|
|
10
7
|
|
|
11
8
|
describe("Typescript Type Alias Declaration", () => {
|
|
@@ -20,21 +17,13 @@ describe("Typescript Type Alias Declaration", () => {
|
|
|
20
17
|
const [namespace] = program.resolveTypeReference("DemoService");
|
|
21
18
|
const scalar = Array.from((namespace as Namespace).scalars.values())[0];
|
|
22
19
|
|
|
23
|
-
|
|
20
|
+
expect(
|
|
24
21
|
<Output program={program}>
|
|
25
22
|
<SourceFile path="test.ts">
|
|
26
23
|
<TypeAliasDeclaration type={scalar} />
|
|
27
24
|
</SourceFile>
|
|
28
25
|
</Output>,
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
const testFile = res.contents.find((file) => file.path === "test.ts");
|
|
32
|
-
assert(testFile, "test.ts file not rendered");
|
|
33
|
-
const actualContent = await format(testFile.contents as string, { parser: "typescript" });
|
|
34
|
-
const expectedContent = await format(`type MyDate = Date;`, {
|
|
35
|
-
parser: "typescript",
|
|
36
|
-
});
|
|
37
|
-
expect(actualContent).toBe(expectedContent);
|
|
26
|
+
).toRenderTo(`type MyDate = Date;`);
|
|
38
27
|
});
|
|
39
28
|
|
|
40
29
|
it("creates a type alias declaration with JSDoc", async () => {
|
|
@@ -49,28 +38,17 @@ describe("Typescript Type Alias Declaration", () => {
|
|
|
49
38
|
const [namespace] = program.resolveTypeReference("DemoService");
|
|
50
39
|
const scalar = Array.from((namespace as Namespace).scalars.values())[0];
|
|
51
40
|
|
|
52
|
-
|
|
41
|
+
expect(
|
|
53
42
|
<Output program={program}>
|
|
54
43
|
<SourceFile path="test.ts">
|
|
55
44
|
<TypeAliasDeclaration type={scalar} />
|
|
56
45
|
</SourceFile>
|
|
57
46
|
</Output>,
|
|
58
|
-
)
|
|
59
|
-
|
|
60
|
-
const testFile = res.contents.find((file) => file.path === "test.ts");
|
|
61
|
-
assert(testFile, "test.ts file not rendered");
|
|
62
|
-
const actualContent = await format(testFile.contents as string, { parser: "typescript" });
|
|
63
|
-
const expectedContent = await format(
|
|
64
|
-
`
|
|
47
|
+
).toRenderTo(`
|
|
65
48
|
/**
|
|
66
49
|
* Type to represent a date
|
|
67
50
|
*/
|
|
68
|
-
type MyDate = Date
|
|
69
|
-
{
|
|
70
|
-
parser: "typescript",
|
|
71
|
-
},
|
|
72
|
-
);
|
|
73
|
-
expect(actualContent).toBe(expectedContent);
|
|
51
|
+
type MyDate = Date;`);
|
|
74
52
|
});
|
|
75
53
|
|
|
76
54
|
it("can override JSDoc", async () => {
|
|
@@ -85,28 +63,17 @@ describe("Typescript Type Alias Declaration", () => {
|
|
|
85
63
|
const [namespace] = program.resolveTypeReference("DemoService");
|
|
86
64
|
const scalar = Array.from((namespace as Namespace).scalars.values())[0];
|
|
87
65
|
|
|
88
|
-
|
|
66
|
+
expect(
|
|
89
67
|
<Output program={program}>
|
|
90
68
|
<SourceFile path="test.ts">
|
|
91
69
|
<TypeAliasDeclaration doc={"Overridden Doc"} type={scalar} />
|
|
92
70
|
</SourceFile>
|
|
93
71
|
</Output>,
|
|
94
|
-
)
|
|
95
|
-
|
|
96
|
-
const testFile = res.contents.find((file) => file.path === "test.ts");
|
|
97
|
-
assert(testFile, "test.ts file not rendered");
|
|
98
|
-
const actualContent = await format(testFile.contents as string, { parser: "typescript" });
|
|
99
|
-
const expectedContent = await format(
|
|
100
|
-
`
|
|
72
|
+
).toRenderTo(`
|
|
101
73
|
/**
|
|
102
74
|
* Overridden Doc
|
|
103
75
|
*/
|
|
104
|
-
type MyDate = Date
|
|
105
|
-
{
|
|
106
|
-
parser: "typescript",
|
|
107
|
-
},
|
|
108
|
-
);
|
|
109
|
-
expect(actualContent).toBe(expectedContent);
|
|
76
|
+
type MyDate = Date;`);
|
|
110
77
|
});
|
|
111
78
|
|
|
112
79
|
it("creates a type alias declaration for a utcDateTime with unixTimeStamp encoding", async () => {
|
|
@@ -119,21 +86,13 @@ describe("Typescript Type Alias Declaration", () => {
|
|
|
119
86
|
const [namespace] = program.resolveTypeReference("DemoService");
|
|
120
87
|
const scalar = Array.from((namespace as Namespace).scalars.values())[0];
|
|
121
88
|
|
|
122
|
-
|
|
89
|
+
expect(
|
|
123
90
|
<Output program={program}>
|
|
124
91
|
<SourceFile path="test.ts">
|
|
125
92
|
<TypeAliasDeclaration type={scalar} />
|
|
126
93
|
</SourceFile>
|
|
127
94
|
</Output>,
|
|
128
|
-
);
|
|
129
|
-
|
|
130
|
-
const testFile = res.contents.find((file) => file.path === "test.ts");
|
|
131
|
-
assert(testFile, "test.ts file not rendered");
|
|
132
|
-
const actualContent = await format(testFile.contents as string, { parser: "typescript" });
|
|
133
|
-
const expectedContent = await format(`type MyDate = Date;`, {
|
|
134
|
-
parser: "typescript",
|
|
135
|
-
});
|
|
136
|
-
expect(actualContent).toBe(expectedContent);
|
|
95
|
+
).toRenderTo(`type MyDate = Date;`);
|
|
137
96
|
});
|
|
138
97
|
|
|
139
98
|
it("creates a type alias declaration for a utcDateTime with rfc7231 encoding", async () => {
|
|
@@ -146,21 +105,13 @@ describe("Typescript Type Alias Declaration", () => {
|
|
|
146
105
|
const [namespace] = program.resolveTypeReference("DemoService");
|
|
147
106
|
const scalar = Array.from((namespace as Namespace).scalars.values())[0];
|
|
148
107
|
|
|
149
|
-
|
|
108
|
+
expect(
|
|
150
109
|
<Output program={program}>
|
|
151
110
|
<SourceFile path="test.ts">
|
|
152
111
|
<TypeAliasDeclaration type={scalar} />
|
|
153
112
|
</SourceFile>
|
|
154
113
|
</Output>,
|
|
155
|
-
);
|
|
156
|
-
|
|
157
|
-
const testFile = res.contents.find((file) => file.path === "test.ts");
|
|
158
|
-
assert(testFile, "test.ts file not rendered");
|
|
159
|
-
const actualContent = await format(testFile.contents as string, { parser: "typescript" });
|
|
160
|
-
const expectedContent = await format(`type MyDate = Date;`, {
|
|
161
|
-
parser: "typescript",
|
|
162
|
-
});
|
|
163
|
-
expect(actualContent).toBe(expectedContent);
|
|
114
|
+
).toRenderTo(`type MyDate = Date;`);
|
|
164
115
|
});
|
|
165
116
|
|
|
166
117
|
it("creates a type alias declaration for a utcDateTime with rfc3339 encoding", async () => {
|
|
@@ -173,21 +124,13 @@ describe("Typescript Type Alias Declaration", () => {
|
|
|
173
124
|
const [namespace] = program.resolveTypeReference("DemoService");
|
|
174
125
|
const scalar = Array.from((namespace as Namespace).scalars.values())[0];
|
|
175
126
|
|
|
176
|
-
|
|
127
|
+
expect(
|
|
177
128
|
<Output program={program}>
|
|
178
129
|
<SourceFile path="test.ts">
|
|
179
130
|
<TypeAliasDeclaration export type={scalar} />
|
|
180
131
|
</SourceFile>
|
|
181
132
|
</Output>,
|
|
182
|
-
);
|
|
183
|
-
|
|
184
|
-
const testFile = res.contents.find((file) => file.path === "test.ts");
|
|
185
|
-
assert(testFile, "test.ts file not rendered");
|
|
186
|
-
const actualContent = await format(testFile.contents as string, { parser: "typescript" });
|
|
187
|
-
const expectedContent = await format(`export type MyDate = Date;`, {
|
|
188
|
-
parser: "typescript",
|
|
189
|
-
});
|
|
190
|
-
expect(actualContent).toBe(expectedContent);
|
|
133
|
+
).toRenderTo(`export type MyDate = Date;`);
|
|
191
134
|
});
|
|
192
135
|
});
|
|
193
136
|
});
|
|
@@ -198,14 +141,12 @@ describe("Typescript Type Alias Declaration", () => {
|
|
|
198
141
|
@test op getName(id: string): string;
|
|
199
142
|
`)) as { getName: Operation };
|
|
200
143
|
|
|
201
|
-
|
|
144
|
+
expect(
|
|
202
145
|
<Output program={runner.program}>
|
|
203
146
|
<SourceFile path="test.ts">
|
|
204
147
|
<TypeAliasDeclaration type={getName} />
|
|
205
148
|
</SourceFile>
|
|
206
149
|
</Output>,
|
|
207
|
-
);
|
|
208
|
-
|
|
209
|
-
assertFileContents(res, "type getName = (id: string) => string;");
|
|
150
|
+
).toRenderTo("type getName = (id: string) => string;");
|
|
210
151
|
});
|
|
211
152
|
});
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { code, Output
|
|
2
|
-
import { d } from "@alloy-js/core/testing";
|
|
1
|
+
import { code, Output } from "@alloy-js/core";
|
|
3
2
|
import * as ts from "@alloy-js/typescript";
|
|
4
3
|
import { SourceFile } from "@alloy-js/typescript";
|
|
5
4
|
import type { Model } from "@typespec/compiler";
|
|
6
5
|
import type { BasicTestRunner } from "@typespec/compiler/testing";
|
|
7
|
-
import {
|
|
6
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
8
7
|
import {
|
|
9
8
|
ArraySerializer,
|
|
10
9
|
DateDeserializer,
|
|
@@ -39,7 +38,7 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
39
38
|
|
|
40
39
|
const { Widget } = (await testRunner.compile(spec)) as { Widget: Model };
|
|
41
40
|
|
|
42
|
-
|
|
41
|
+
expect(
|
|
43
42
|
<Output namePolicy={namePolicy}>
|
|
44
43
|
<SourceFile path="test.ts">
|
|
45
44
|
{code`
|
|
@@ -53,19 +52,13 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
53
52
|
/>
|
|
54
53
|
</SourceFile>
|
|
55
54
|
</Output>,
|
|
56
|
-
)
|
|
57
|
-
|
|
58
|
-
const testFile = res.contents.find((file) => file.path === "test.ts");
|
|
59
|
-
assert(testFile, "test.ts file not rendered");
|
|
60
|
-
const actualContent = testFile.contents;
|
|
61
|
-
const expectedContent = d`
|
|
55
|
+
).toRenderTo(`
|
|
62
56
|
const wireWidget = {id: "1", birth_year: 1988, color: "blue"};
|
|
63
57
|
const clientWidget = {
|
|
64
58
|
"id": wireWidget.id,
|
|
65
59
|
"birthYear": wireWidget.birth_year,
|
|
66
60
|
"color": wireWidget.color
|
|
67
|
-
}
|
|
68
|
-
expect(actualContent).toBe(expectedContent);
|
|
61
|
+
}`);
|
|
69
62
|
});
|
|
70
63
|
|
|
71
64
|
it("should render a transform expression to wire", async () => {
|
|
@@ -80,7 +73,7 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
80
73
|
|
|
81
74
|
const { Widget } = (await testRunner.compile(spec)) as { Widget: Model };
|
|
82
75
|
|
|
83
|
-
|
|
76
|
+
expect(
|
|
84
77
|
<Output namePolicy={namePolicy}>
|
|
85
78
|
<SourceFile path="test.ts">
|
|
86
79
|
{code`
|
|
@@ -94,19 +87,13 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
94
87
|
/>
|
|
95
88
|
</SourceFile>
|
|
96
89
|
</Output>,
|
|
97
|
-
)
|
|
98
|
-
|
|
99
|
-
const testFile = res.contents.find((file) => file.path === "test.ts");
|
|
100
|
-
assert(testFile, "test.ts file not rendered");
|
|
101
|
-
const actualContent = testFile.contents;
|
|
102
|
-
const expectedContent = d`
|
|
90
|
+
).toRenderTo(`
|
|
103
91
|
const clientWidget = {id: "1", birthYear: 1988, color: "blue"};
|
|
104
92
|
const wireWidget = {
|
|
105
93
|
"id": clientWidget.id,
|
|
106
94
|
"birth_year": clientWidget.birthYear,
|
|
107
95
|
"color": clientWidget.color
|
|
108
|
-
}
|
|
109
|
-
expect(actualContent).toBe(expectedContent);
|
|
96
|
+
}`);
|
|
110
97
|
});
|
|
111
98
|
|
|
112
99
|
it("should render a transform expression that contains a utcDateTime to client", async () => {
|
|
@@ -121,7 +108,7 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
121
108
|
|
|
122
109
|
const { Widget } = (await testRunner.compile(spec)) as { Widget: Model };
|
|
123
110
|
|
|
124
|
-
|
|
111
|
+
expect(
|
|
125
112
|
<Output namePolicy={namePolicy}>
|
|
126
113
|
<SourceFile path="static-serializers.ts">
|
|
127
114
|
<DateDeserializer />
|
|
@@ -138,12 +125,7 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
138
125
|
/>
|
|
139
126
|
</SourceFile>
|
|
140
127
|
</Output>,
|
|
141
|
-
)
|
|
142
|
-
|
|
143
|
-
const testFile = res.contents.find((file) => file.path === "test.ts");
|
|
144
|
-
assert(testFile, "test.ts file not rendered");
|
|
145
|
-
const actualContent = testFile.contents;
|
|
146
|
-
const expectedContent = d`
|
|
128
|
+
).toRenderTo(`
|
|
147
129
|
import { dateDeserializer } from "./static-serializers.js";
|
|
148
130
|
|
|
149
131
|
const wireWidget = {id: "1", birth_date: "1988-04-29T19:30:00Z", color: "blue"};
|
|
@@ -151,8 +133,7 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
151
133
|
"id": wireWidget.id,
|
|
152
134
|
"birthDate": dateDeserializer(wireWidget.birth_date),
|
|
153
135
|
"color": wireWidget.color
|
|
154
|
-
}
|
|
155
|
-
expect(actualContent).toBe(expectedContent);
|
|
136
|
+
}`);
|
|
156
137
|
});
|
|
157
138
|
});
|
|
158
139
|
|
|
@@ -172,7 +153,7 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
172
153
|
|
|
173
154
|
const { Widget } = (await testRunner.compile(spec)) as { Widget: Model };
|
|
174
155
|
|
|
175
|
-
|
|
156
|
+
expect(
|
|
176
157
|
<Output namePolicy={namePolicy}>
|
|
177
158
|
<SourceFile path="serializers.ts">
|
|
178
159
|
<ArraySerializer />
|
|
@@ -183,12 +164,7 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
183
164
|
<TypeTransformDeclaration type={Widget} target="transport" />
|
|
184
165
|
</SourceFile>
|
|
185
166
|
</Output>,
|
|
186
|
-
)
|
|
187
|
-
|
|
188
|
-
const testFile = res.contents.find((file) => file.path === "test.ts");
|
|
189
|
-
assert(testFile, "test.ts file not rendered");
|
|
190
|
-
const actualContent = testFile.contents;
|
|
191
|
-
const expectedContent = d`
|
|
167
|
+
).toRenderTo(`
|
|
192
168
|
import { arraySerializer } from "./serializers.js";
|
|
193
169
|
|
|
194
170
|
export interface Widget {
|
|
@@ -219,8 +195,7 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
219
195
|
"optionalString": item.optionalString
|
|
220
196
|
};
|
|
221
197
|
}
|
|
222
|
-
|
|
223
|
-
expect(actualContent).toBe(expectedContent);
|
|
198
|
+
`);
|
|
224
199
|
});
|
|
225
200
|
it("should render a transform functions for a model containing record", async () => {
|
|
226
201
|
const spec = `
|
|
@@ -236,7 +211,7 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
236
211
|
|
|
237
212
|
const { Widget } = (await testRunner.compile(spec)) as { Widget: Model };
|
|
238
213
|
|
|
239
|
-
|
|
214
|
+
expect(
|
|
240
215
|
<Output namePolicy={namePolicy}>
|
|
241
216
|
<SourceFile path="serializers.ts">
|
|
242
217
|
<RecordSerializer />
|
|
@@ -247,12 +222,7 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
247
222
|
<TypeTransformDeclaration type={Widget} target="transport" />
|
|
248
223
|
</SourceFile>
|
|
249
224
|
</Output>,
|
|
250
|
-
)
|
|
251
|
-
|
|
252
|
-
const testFile = res.contents.find((file) => file.path === "test.ts");
|
|
253
|
-
assert(testFile, "test.ts file not rendered");
|
|
254
|
-
const actualContent = testFile.contents;
|
|
255
|
-
const expectedContent = d`
|
|
225
|
+
).toRenderTo(`
|
|
256
226
|
import { recordSerializer } from "./serializers.js";
|
|
257
227
|
|
|
258
228
|
export interface Widget {
|
|
@@ -280,8 +250,7 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
280
250
|
"nested": recordSerializer(item.nested, (i: any) => recordSerializer(i, widgetToTransport))
|
|
281
251
|
};
|
|
282
252
|
}
|
|
283
|
-
|
|
284
|
-
expect(actualContent).toBe(expectedContent);
|
|
253
|
+
`);
|
|
285
254
|
});
|
|
286
255
|
it("should render a transform functions for a model", async () => {
|
|
287
256
|
const spec = `
|
|
@@ -294,7 +263,7 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
294
263
|
|
|
295
264
|
const { Widget } = (await testRunner.compile(spec)) as { Widget: Model };
|
|
296
265
|
|
|
297
|
-
|
|
266
|
+
expect(
|
|
298
267
|
<Output namePolicy={namePolicy}>
|
|
299
268
|
<SourceFile path="test.ts">
|
|
300
269
|
<TypeDeclaration export type={Widget} />
|
|
@@ -302,12 +271,7 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
302
271
|
<TypeTransformDeclaration type={Widget} target="transport" />
|
|
303
272
|
</SourceFile>
|
|
304
273
|
</Output>,
|
|
305
|
-
)
|
|
306
|
-
|
|
307
|
-
const testFile = res.contents.find((file) => file.path === "test.ts");
|
|
308
|
-
assert(testFile, "test.ts file not rendered");
|
|
309
|
-
const actualContent = testFile.contents;
|
|
310
|
-
const expectedContent = d`
|
|
274
|
+
).toRenderTo(`
|
|
311
275
|
export interface Widget {
|
|
312
276
|
"id": string;
|
|
313
277
|
"myColor": "blue" | "red";
|
|
@@ -324,8 +288,7 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
324
288
|
"my_color": item.myColor
|
|
325
289
|
};
|
|
326
290
|
}
|
|
327
|
-
|
|
328
|
-
expect(actualContent).toBe(expectedContent);
|
|
291
|
+
`);
|
|
329
292
|
});
|
|
330
293
|
});
|
|
331
294
|
describe("Calling a model transform functions", () => {
|
|
@@ -339,7 +302,7 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
339
302
|
|
|
340
303
|
const { Widget } = (await testRunner.compile(spec)) as { Widget: Model };
|
|
341
304
|
|
|
342
|
-
|
|
305
|
+
expect(
|
|
343
306
|
<Output namePolicy={namePolicy}>
|
|
344
307
|
<SourceFile path="test.ts">
|
|
345
308
|
{code`
|
|
@@ -348,16 +311,10 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
348
311
|
`}
|
|
349
312
|
</SourceFile>
|
|
350
313
|
</Output>,
|
|
351
|
-
)
|
|
352
|
-
|
|
353
|
-
const testFile = res.contents.find((file) => file.path === "test.ts");
|
|
354
|
-
assert(testFile, "test.ts file not rendered");
|
|
355
|
-
const actualContent = testFile.contents;
|
|
356
|
-
const expectedContent = d`
|
|
314
|
+
).toRenderTo(`
|
|
357
315
|
const clientWidget = {id: "1", my_color: "blue"};
|
|
358
316
|
const wireWidget = clientWidget.id
|
|
359
|
-
|
|
360
|
-
expect(actualContent).toBe(expectedContent);
|
|
317
|
+
`);
|
|
361
318
|
});
|
|
362
319
|
|
|
363
320
|
it("should call transform functions for a model", async () => {
|
|
@@ -371,7 +328,7 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
371
328
|
|
|
372
329
|
const { Widget } = (await testRunner.compile(spec)) as { Widget: Model };
|
|
373
330
|
|
|
374
|
-
|
|
331
|
+
expect(
|
|
375
332
|
<Output namePolicy={namePolicy}>
|
|
376
333
|
<SourceFile path="types.ts">
|
|
377
334
|
<TypeDeclaration export type={Widget} />
|
|
@@ -386,19 +343,13 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
386
343
|
`}
|
|
387
344
|
</SourceFile>
|
|
388
345
|
</Output>,
|
|
389
|
-
)
|
|
390
|
-
|
|
391
|
-
const testFile = res.contents.find((file) => file.path === "test.ts");
|
|
392
|
-
assert(testFile, "test.ts file not rendered");
|
|
393
|
-
const actualContent = testFile.contents;
|
|
394
|
-
const expectedContent = d`
|
|
346
|
+
).toRenderTo(`
|
|
395
347
|
import { widgetToApplication, widgetToTransport } from "./types.js";
|
|
396
348
|
|
|
397
349
|
const wireWidget = {id: "1", my_color: "blue"};
|
|
398
350
|
const clientWidget = widgetToApplication(wireWidget);
|
|
399
351
|
const wireWidget2 = widgetToTransport(clientWidget);
|
|
400
|
-
|
|
401
|
-
expect(actualContent).toBe(expectedContent);
|
|
352
|
+
`);
|
|
402
353
|
});
|
|
403
354
|
});
|
|
404
355
|
});
|
|
@@ -420,7 +371,7 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
420
371
|
}
|
|
421
372
|
`)) as { Pet: Model; Cat: Model; Dog: Model };
|
|
422
373
|
|
|
423
|
-
|
|
374
|
+
expect(
|
|
424
375
|
<Output namePolicy={namePolicy}>
|
|
425
376
|
<SourceFile path="test.ts">
|
|
426
377
|
<TypeDeclaration export type={Pet} />
|
|
@@ -434,12 +385,7 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
434
385
|
<TypeTransformDeclaration type={Pet} target="transport" />
|
|
435
386
|
</SourceFile>
|
|
436
387
|
</Output>,
|
|
437
|
-
)
|
|
438
|
-
|
|
439
|
-
const testFile = res.contents.find((file) => file.path === "test.ts");
|
|
440
|
-
assert(testFile, "test.ts file not rendered");
|
|
441
|
-
const actualContent = testFile.contents;
|
|
442
|
-
const expectedContent = d`
|
|
388
|
+
).toRenderTo(`
|
|
443
389
|
export interface Pet {
|
|
444
390
|
"kind": string;
|
|
445
391
|
}
|
|
@@ -485,8 +431,7 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
485
431
|
return dogToTransport(item)
|
|
486
432
|
}
|
|
487
433
|
}
|
|
488
|
-
|
|
489
|
-
expect(actualContent).toBe(expectedContent);
|
|
434
|
+
`);
|
|
490
435
|
});
|
|
491
436
|
});
|
|
492
437
|
describe("Discriminated Union Transforms", () => {
|
|
@@ -507,7 +452,7 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
507
452
|
}
|
|
508
453
|
`)) as { Pet: Model; Cat: Model; Dog: Model };
|
|
509
454
|
|
|
510
|
-
|
|
455
|
+
expect(
|
|
511
456
|
<Output namePolicy={namePolicy}>
|
|
512
457
|
<SourceFile path="test.ts">
|
|
513
458
|
<TypeDeclaration export type={Pet} />
|
|
@@ -521,12 +466,7 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
521
466
|
<TypeTransformDeclaration type={Pet} target="transport" />
|
|
522
467
|
</SourceFile>
|
|
523
468
|
</Output>,
|
|
524
|
-
)
|
|
525
|
-
|
|
526
|
-
const testFile = res.contents.find((file) => file.path === "test.ts");
|
|
527
|
-
assert(testFile, "test.ts file not rendered");
|
|
528
|
-
const actualContent = testFile.contents;
|
|
529
|
-
const expectedContent = d`
|
|
469
|
+
).toRenderTo(`
|
|
530
470
|
export type Pet = Cat | Dog;
|
|
531
471
|
export interface Dog {
|
|
532
472
|
"kind": "dog";
|
|
@@ -570,8 +510,7 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
570
510
|
return dogToTransport(item)
|
|
571
511
|
}
|
|
572
512
|
}
|
|
573
|
-
|
|
574
|
-
expect(actualContent).toBe(expectedContent);
|
|
513
|
+
`);
|
|
575
514
|
});
|
|
576
515
|
});
|
|
577
516
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Output
|
|
1
|
+
import { Output } from "@alloy-js/core";
|
|
2
2
|
import { dedent } from "@alloy-js/core/testing";
|
|
3
3
|
import { SourceFile } from "@alloy-js/typescript";
|
|
4
4
|
import {
|
|
@@ -221,23 +221,15 @@ it("renders enums", async () => {
|
|
|
221
221
|
*/
|
|
222
222
|
async function testValueExpression(value: Value, expected: string) {
|
|
223
223
|
const prefix = "const val = ";
|
|
224
|
-
|
|
224
|
+
|
|
225
|
+
expect(
|
|
225
226
|
<Output>
|
|
226
227
|
<SourceFile path="test.ts">
|
|
227
228
|
{prefix}
|
|
228
229
|
<ValueExpression value={value} />
|
|
229
230
|
</SourceFile>
|
|
230
231
|
</Output>,
|
|
231
|
-
);
|
|
232
|
-
const testFile = res.contents.find((file) => file.path === "test.ts");
|
|
233
|
-
|
|
234
|
-
assert.exists(testFile, "test.ts file not rendered");
|
|
235
|
-
|
|
236
|
-
assert.equal(
|
|
237
|
-
testFile.contents,
|
|
238
|
-
`${prefix}${expected}`,
|
|
239
|
-
"test.ts file contents do not match expected",
|
|
240
|
-
);
|
|
232
|
+
).toRenderTo(`${prefix}${expected}`);
|
|
241
233
|
}
|
|
242
234
|
|
|
243
235
|
/**
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Children } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { SourceFile } from "@alloy-js/typescript";
|
|
3
|
+
import type { Program } from "@typespec/compiler";
|
|
4
|
+
import { Output } from "../../src/core/components/output.jsx";
|
|
5
|
+
|
|
6
|
+
export function TestFile(props: { program: Program; children: Children }) {
|
|
7
|
+
return (
|
|
8
|
+
<Output program={props.program}>
|
|
9
|
+
<SourceFile path="test.ts">{props.children}</SourceFile>
|
|
10
|
+
</Output>
|
|
11
|
+
);
|
|
12
|
+
}
|
package/test/utils.ts
CHANGED
|
@@ -10,12 +10,13 @@ export async function getEmitOutput(tspCode: string, cb: (program: Program) => C
|
|
|
10
10
|
|
|
11
11
|
const res = render(Output().children(SourceFile({ path: "test.ts" }).children(cb(program))));
|
|
12
12
|
const testFile = res.contents.find((file) => file.path === "test.ts")!;
|
|
13
|
-
|
|
13
|
+
assert("contents" in testFile, "test.ts file does not have contents");
|
|
14
14
|
return testFile.contents;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export function assertFileContents(res: OutputDirectory, contents: string) {
|
|
18
18
|
const testFile = res.contents.find((file) => file.path === "test.ts")!;
|
|
19
19
|
assert(testFile, "test.ts file not rendered");
|
|
20
|
+
assert("contents" in testFile, "test.ts file does not have contents");
|
|
20
21
|
assert.equal(testFile.contents, contents);
|
|
21
22
|
}
|