@typespec/emitter-framework 0.10.0-dev.2 → 0.10.0

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 (29) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/src/core/write-output.js +10 -6
  3. package/dist/src/csharp/components/class/declaration.d.ts.map +1 -1
  4. package/dist/src/csharp/components/class/declaration.js +2 -1
  5. package/dist/src/typescript/components/interface-declaration.d.ts.map +1 -1
  6. package/dist/src/typescript/components/interface-declaration.js +2 -2
  7. package/dist/src/typescript/components/union/expression.test.js +3 -3
  8. package/dist/test/typescript/components/function-declaration.test.js +31 -112
  9. package/dist/test/typescript/components/interface-declaration.test.js +146 -308
  10. package/dist/test/typescript/components/type-alias-declaration.test.js +17 -75
  11. package/dist/test/typescript/components/type-transform.test.js +32 -83
  12. package/dist/test/typescript/components/value-expression.test.js +3 -6
  13. package/dist/test/typescript/utils.d.ts +7 -0
  14. package/dist/test/typescript/utils.d.ts.map +1 -0
  15. package/dist/test/typescript/utils.js +18 -0
  16. package/dist/test/utils.d.ts.map +1 -1
  17. package/dist/test/utils.js +2 -0
  18. package/package.json +14 -15
  19. package/src/core/write-output.ts +10 -6
  20. package/src/csharp/components/class/declaration.tsx +2 -1
  21. package/src/typescript/components/interface-declaration.tsx +3 -3
  22. package/src/typescript/components/union/expression.test.tsx +5 -5
  23. package/test/typescript/components/function-declaration.test.tsx +31 -121
  24. package/test/typescript/components/interface-declaration.test.tsx +123 -342
  25. package/test/typescript/components/type-alias-declaration.test.tsx +17 -76
  26. package/test/typescript/components/type-transform.test.tsx +32 -93
  27. package/test/typescript/components/value-expression.test.tsx +4 -12
  28. package/test/typescript/utils.tsx +12 -0
  29. package/test/utils.ts +2 -1
@@ -1,8 +1,7 @@
1
- import { For, List, render } from "@alloy-js/core";
1
+ import { For, List } from "@alloy-js/core";
2
2
  import { SourceFile } from "@alloy-js/typescript";
3
3
  import type { Namespace } from "@typespec/compiler";
4
- import { format } from "prettier";
5
- import { assert, describe, expect, it } from "vitest";
4
+ import { describe, expect, it } from "vitest";
6
5
  import { Output } from "../../../src/core/components/output.jsx";
7
6
  import { InterfaceDeclaration } from "../../../src/typescript/components/interface-declaration.js";
8
7
  import { getProgram } from "../test-host.js";
@@ -25,7 +24,7 @@ describe("Typescript Interface", () => {
25
24
  const [namespace] = program.resolveTypeReference("DemoService");
26
25
  const models = Array.from((namespace as Namespace).models.values());
27
26
 
28
- const res = render(
27
+ expect(
29
28
  <Output program={program}>
30
29
  <SourceFile path="test.ts">
31
30
  <List hardline>
@@ -39,12 +38,7 @@ describe("Typescript Interface", () => {
39
38
  </List>
40
39
  </SourceFile>
41
40
  </Output>,
42
- );
43
-
44
- const testFile = res.contents.find((file) => file.path === "test.ts");
45
- assert(testFile, "test.ts file not rendered");
46
- const actualContent = await format(testFile.contents as string, { parser: "typescript" });
47
- const expectedContent = await format(
41
+ ).toRenderTo(
48
42
  `
49
43
  /**
50
44
  * This is an overridden doc comment
@@ -54,12 +48,7 @@ describe("Typescript Interface", () => {
54
48
  knownProp: string;
55
49
  }
56
50
  `,
57
- {
58
- parser: "typescript",
59
- },
60
51
  );
61
-
62
- expect(actualContent).toBe(expectedContent);
63
52
  });
64
53
  it("declares an interface with multi line docs", async () => {
65
54
  const program = await getProgram(`
@@ -77,7 +66,7 @@ describe("Typescript Interface", () => {
77
66
  const [namespace] = program.resolveTypeReference("DemoService");
78
67
  const models = Array.from((namespace as Namespace).models.values());
79
68
 
80
- const res = render(
69
+ expect(
81
70
  <Output program={program}>
82
71
  <SourceFile path="test.ts">
83
72
  <List hardline>
@@ -87,12 +76,7 @@ describe("Typescript Interface", () => {
87
76
  </List>
88
77
  </SourceFile>
89
78
  </Output>,
90
- );
91
-
92
- const testFile = res.contents.find((file) => file.path === "test.ts");
93
- assert(testFile, "test.ts file not rendered");
94
- const actualContent = await format(testFile.contents as string, { parser: "typescript" });
95
- const expectedContent = await format(
79
+ ).toRenderTo(
96
80
  `
97
81
  /**
98
82
  * This is a test
@@ -102,12 +86,7 @@ describe("Typescript Interface", () => {
102
86
  knownProp: string;
103
87
  }
104
88
  `,
105
- {
106
- parser: "typescript",
107
- },
108
89
  );
109
-
110
- expect(actualContent).toBe(expectedContent);
111
90
  });
112
91
  it("declares an interface with @doc", async () => {
113
92
  const program = await getProgram(`
@@ -122,7 +101,7 @@ describe("Typescript Interface", () => {
122
101
  const [namespace] = program.resolveTypeReference("DemoService");
123
102
  const models = Array.from((namespace as Namespace).models.values());
124
103
 
125
- const res = render(
104
+ expect(
126
105
  <Output program={program}>
127
106
  <SourceFile path="test.ts">
128
107
  <List hardline>
@@ -132,12 +111,7 @@ describe("Typescript Interface", () => {
132
111
  </List>
133
112
  </SourceFile>
134
113
  </Output>,
135
- );
136
-
137
- const testFile = res.contents.find((file) => file.path === "test.ts");
138
- assert(testFile, "test.ts file not rendered");
139
- const actualContent = await format(testFile.contents as string, { parser: "typescript" });
140
- const expectedContent = await format(
114
+ ).toRenderTo(
141
115
  `
142
116
  /**
143
117
  * This is a test
@@ -146,12 +120,7 @@ describe("Typescript Interface", () => {
146
120
  knownProp: string;
147
121
  }
148
122
  `,
149
- {
150
- parser: "typescript",
151
- },
152
123
  );
153
-
154
- expect(actualContent).toBe(expectedContent);
155
124
  });
156
125
  it("declares an interface with doc", async () => {
157
126
  const program = await getProgram(`
@@ -169,7 +138,7 @@ describe("Typescript Interface", () => {
169
138
  const [namespace] = program.resolveTypeReference("DemoService");
170
139
  const models = Array.from((namespace as Namespace).models.values());
171
140
 
172
- const res = render(
141
+ expect(
173
142
  <Output program={program}>
174
143
  <SourceFile path="test.ts">
175
144
  <List hardline>
@@ -179,12 +148,7 @@ describe("Typescript Interface", () => {
179
148
  </List>
180
149
  </SourceFile>
181
150
  </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(
151
+ ).toRenderTo(
188
152
  `
189
153
  /**
190
154
  * This is a test
@@ -196,12 +160,7 @@ describe("Typescript Interface", () => {
196
160
  knownProp: string;
197
161
  }
198
162
  `,
199
- {
200
- parser: "typescript",
201
- },
202
163
  );
203
-
204
- expect(actualContent).toBe(expectedContent);
205
164
  });
206
165
  describe("Bound to Model", () => {
207
166
  it("creates an interface that extends a model for Record spread", async () => {
@@ -217,7 +176,7 @@ describe("Typescript Interface", () => {
217
176
  const [namespace] = program.resolveTypeReference("DemoService");
218
177
  const models = Array.from((namespace as Namespace).models.values());
219
178
 
220
- const res = render(
179
+ expect(
221
180
  <Output program={program}>
222
181
  <SourceFile path="test.ts">
223
182
  <List hardline>
@@ -227,25 +186,14 @@ describe("Typescript Interface", () => {
227
186
  </List>
228
187
  </SourceFile>
229
188
  </Output>,
230
- );
231
-
232
- const testFile = res.contents.find((file) => file.path === "test.ts");
233
- assert(testFile, "test.ts file not rendered");
234
- const actualContent = await format(testFile.contents as string, { parser: "typescript" });
235
- const expectedContent = await format(
236
- `
189
+ ).toRenderTo(`
237
190
  export interface DifferentSpreadModelRecord {
238
191
  knownProp: string;
239
192
  additionalProperties?: Record<string, unknown>;
240
193
  }
241
- `,
242
- {
243
- parser: "typescript",
244
- },
245
- );
246
-
247
- expect(actualContent).toBe(expectedContent);
194
+ `);
248
195
  });
196
+
249
197
  it("creates an interface for a model that 'is' an array ", async () => {
250
198
  const program = await getProgram(`
251
199
  namespace DemoService;
@@ -256,7 +204,7 @@ describe("Typescript Interface", () => {
256
204
  const [namespace] = program.resolveTypeReference("DemoService");
257
205
  const models = (namespace as Namespace).models;
258
206
 
259
- const res = render(
207
+ expect(
260
208
  <Output program={program}>
261
209
  <SourceFile path="test.ts">
262
210
  <For each={Array.from(models.values())} hardline>
@@ -264,20 +212,10 @@ describe("Typescript Interface", () => {
264
212
  </For>
265
213
  </SourceFile>
266
214
  </Output>,
267
- );
215
+ ).toRenderTo(`
216
+ export interface Foo extends Array<string> {
268
217
 
269
- const testFile = res.contents.find((file) => file.path === "test.ts");
270
- assert(testFile, "test.ts file not rendered");
271
- const actualContent = await format(testFile.contents as string, { parser: "typescript" });
272
- const expectedContent = await format(
273
- `export interface Foo extends Array<string> { }
274
- `,
275
- {
276
- parser: "typescript",
277
- },
278
- );
279
-
280
- expect(actualContent).toBe(expectedContent);
218
+ }`);
281
219
  });
282
220
 
283
221
  it("creates an interface for a model that 'is' a record ", async () => {
@@ -290,7 +228,7 @@ describe("Typescript Interface", () => {
290
228
  const [namespace] = program.resolveTypeReference("DemoService");
291
229
  const models = (namespace as Namespace).models;
292
230
 
293
- const res = render(
231
+ expect(
294
232
  <Output program={program}>
295
233
  <SourceFile path="test.ts">
296
234
  <For each={Array.from(models.values())} hardline>
@@ -298,22 +236,10 @@ describe("Typescript Interface", () => {
298
236
  </For>
299
237
  </SourceFile>
300
238
  </Output>,
301
- );
302
-
303
- const testFile = res.contents.find((file) => file.path === "test.ts");
304
- assert(testFile, "test.ts file not rendered");
305
- const actualContent = await format(testFile.contents as string, { parser: "typescript" });
306
- const expectedContent = await format(
307
- `export interface Foo {
308
- additionalProperties?: Record<string, string>;
309
- }
310
- `,
311
- {
312
- parser: "typescript",
313
- },
314
- );
315
-
316
- expect(actualContent).toBe(expectedContent);
239
+ ).toRenderTo(`
240
+ export interface Foo {
241
+ additionalProperties?: Record<string, string>;
242
+ }`);
317
243
  });
318
244
 
319
245
  it("creates an interface of a model that spreads a Record", async () => {
@@ -328,7 +254,7 @@ describe("Typescript Interface", () => {
328
254
  const [namespace] = program.resolveTypeReference("DemoService");
329
255
  const models = (namespace as Namespace).models;
330
256
 
331
- const res = render(
257
+ expect(
332
258
  <Output program={program}>
333
259
  <SourceFile path="test.ts">
334
260
  <For each={Array.from(models.values())} hardline>
@@ -336,23 +262,11 @@ describe("Typescript Interface", () => {
336
262
  </For>
337
263
  </SourceFile>
338
264
  </Output>,
339
- );
340
-
341
- const testFile = res.contents.find((file) => file.path === "test.ts");
342
- assert(testFile, "test.ts file not rendered");
343
- const actualContent = await format(testFile.contents as string, { parser: "typescript" });
344
- const expectedContent = await format(
345
- `
265
+ ).toRenderTo(`
346
266
  export interface Foo {
347
267
  additionalProperties?: Record<string, string>;
348
268
  }
349
- `,
350
- {
351
- parser: "typescript",
352
- },
353
- );
354
-
355
- expect(actualContent).toBe(expectedContent);
269
+ `);
356
270
  });
357
271
 
358
272
  it("creates an interface that extends an spread model", async () => {
@@ -376,7 +290,7 @@ describe("Typescript Interface", () => {
376
290
  const [namespace] = program.resolveTypeReference("DemoService");
377
291
  const models = (namespace as Namespace).models;
378
292
 
379
- const res = render(
293
+ expect(
380
294
  <Output program={program}>
381
295
  <SourceFile path="test.ts">
382
296
  <For each={Array.from(models.values())} hardline>
@@ -384,30 +298,18 @@ describe("Typescript Interface", () => {
384
298
  </For>
385
299
  </SourceFile>
386
300
  </Output>,
387
- );
388
-
389
- const testFile = res.contents.find((file) => file.path === "test.ts");
390
- assert(testFile, "test.ts file not rendered");
391
- const actualContent = await format(testFile.contents as string, { parser: "typescript" });
392
- const expectedContent = await format(
393
- `export interface ModelForRecord {
394
- state: string;
395
- }
396
- export interface DifferentSpreadModelRecord {
397
- knownProp: string;
398
- additionalProperties?: Record<string, ModelForRecord>;
399
- }
400
- export interface DifferentSpreadModelDerived extends DifferentSpreadModelRecord {
401
- derivedProp: ModelForRecord;
402
- additionalProperties?: Record<string, ModelForRecord>;
403
- }
404
- `,
405
- {
406
- parser: "typescript",
407
- },
408
- );
409
-
410
- expect(actualContent).toBe(expectedContent);
301
+ ).toRenderTo(`
302
+ export interface ModelForRecord {
303
+ state: string;
304
+ }
305
+ export interface DifferentSpreadModelRecord {
306
+ knownProp: string;
307
+ additionalProperties?: Record<string, ModelForRecord>;
308
+ }
309
+ export interface DifferentSpreadModelDerived extends DifferentSpreadModelRecord {
310
+ derivedProp: ModelForRecord;
311
+ additionalProperties?: Record<string, ModelForRecord>;
312
+ }`);
411
313
  });
412
314
 
413
315
  it("creates an interface that has additional properties", async () => {
@@ -423,7 +325,7 @@ describe("Typescript Interface", () => {
423
325
  const [namespace] = program.resolveTypeReference("DemoService");
424
326
  const models = Array.from((namespace as Namespace).models.values());
425
327
 
426
- const res = render(
328
+ expect(
427
329
  <Output program={program}>
428
330
  <SourceFile path="test.ts">
429
331
  {models.map((model) => (
@@ -431,24 +333,13 @@ describe("Typescript Interface", () => {
431
333
  ))}
432
334
  </SourceFile>
433
335
  </Output>,
434
- );
435
-
436
- const testFile = res.contents.find((file) => file.path === "test.ts");
437
- assert(testFile, "test.ts file not rendered");
438
- const actualContent = await format(testFile.contents as string, { parser: "typescript" });
439
- const expectedContent = await format(
440
- `export interface Widget {
336
+ ).toRenderTo(`
337
+ export interface Widget {
441
338
  id: string;
442
339
  weight: number;
443
340
  color: "blue" | "red";
444
341
  additionalProperties?: Record<string, unknown>;
445
- }`,
446
- {
447
- parser: "typescript",
448
- },
449
- );
450
-
451
- expect(actualContent).toBe(expectedContent);
342
+ }`);
452
343
  });
453
344
 
454
345
  it("handles a type reference to a union variant", async () => {
@@ -470,28 +361,18 @@ describe("Typescript Interface", () => {
470
361
  const [namespace] = program.resolveTypeReference("DemoService");
471
362
  const models = Array.from((namespace as Namespace).models.values());
472
363
 
473
- const res = render(
364
+ expect(
474
365
  <Output program={program}>
475
366
  <SourceFile path="test.ts">
476
367
  <InterfaceDeclaration type={models[0]} />
477
368
  </SourceFile>
478
369
  </Output>,
479
- );
480
-
481
- const testFile = res.contents.find((file) => file.path === "test.ts");
482
- assert(testFile, "test.ts file not rendered");
483
- const actualContent = await format(testFile.contents as string, { parser: "typescript" });
484
- const expectedContent = await format(
485
- `interface Widget {
486
- id: string;
487
- weight: number;
488
- color: "BLUE";
489
- }`,
490
- {
491
- parser: "typescript",
492
- },
493
- );
494
- expect(actualContent).toBe(expectedContent);
370
+ ).toRenderTo(`
371
+ interface Widget {
372
+ id: string;
373
+ weight: number;
374
+ color: "BLUE";
375
+ }`);
495
376
  });
496
377
  it("creates an interface", async () => {
497
378
  const program = await getProgram(`
@@ -507,28 +388,18 @@ describe("Typescript Interface", () => {
507
388
  const [namespace] = program.resolveTypeReference("DemoService");
508
389
  const models = Array.from((namespace as Namespace).models.values());
509
390
 
510
- const res = render(
391
+ expect(
511
392
  <Output program={program}>
512
393
  <SourceFile path="test.ts">
513
394
  <InterfaceDeclaration type={models[0]} />
514
395
  </SourceFile>
515
396
  </Output>,
516
- );
517
-
518
- const testFile = res.contents.find((file) => file.path === "test.ts");
519
- assert(testFile, "test.ts file not rendered");
520
- const actualContent = await format(testFile.contents as string, { parser: "typescript" });
521
- const expectedContent = await format(
522
- `interface Widget {
397
+ ).toRenderTo(`
398
+ interface Widget {
523
399
  id: string;
524
400
  weight: number;
525
401
  color: "blue" | "red";
526
- }`,
527
- {
528
- parser: "typescript",
529
- },
530
- );
531
- expect(actualContent).toBe(expectedContent);
402
+ }`);
532
403
  });
533
404
 
534
405
  it("renders an empty interface with a never-typed member", async () => {
@@ -543,25 +414,16 @@ describe("Typescript Interface", () => {
543
414
  const [namespace] = program.resolveTypeReference("DemoService");
544
415
  const models = Array.from((namespace as Namespace).models.values());
545
416
 
546
- const res = render(
417
+ expect(
547
418
  <Output program={program}>
548
419
  <SourceFile path="test.ts">
549
420
  <InterfaceDeclaration export type={models[0]} />
550
421
  </SourceFile>
551
422
  </Output>,
552
- );
553
-
554
- const testFile = res.contents.find((file) => file.path === "test.ts");
555
- assert(testFile, "test.ts file not rendered");
556
- const actualContent = await format(testFile.contents as string, { parser: "typescript" });
557
- const expectedContent = await format(
558
- `export interface Widget {
559
- }`,
560
- {
561
- parser: "typescript",
562
- },
563
- );
564
- expect(actualContent).toBe(expectedContent);
423
+ ).toRenderTo(`
424
+ export interface Widget {
425
+
426
+ }`);
565
427
  });
566
428
 
567
429
  it("can override interface name", async () => {
@@ -578,28 +440,18 @@ describe("Typescript Interface", () => {
578
440
  const [namespace] = program.resolveTypeReference("DemoService");
579
441
  const models = Array.from((namespace as Namespace).models.values());
580
442
 
581
- const res = render(
443
+ expect(
582
444
  <Output program={program}>
583
445
  <SourceFile path="test.ts">
584
446
  <InterfaceDeclaration export name="MyOperations" type={models[0]} />
585
447
  </SourceFile>
586
448
  </Output>,
587
- );
588
-
589
- const testFile = res.contents.find((file) => file.path === "test.ts");
590
- assert(testFile, "test.ts file not rendered");
591
- const actualContent = await format(testFile.contents as string, { parser: "typescript" });
592
- const expectedContent = await format(
593
- `export interface MyOperations {
594
- id: string;
595
- weight: number;
596
- color: "blue" | "red";
597
- }`,
598
- {
599
- parser: "typescript",
600
- },
601
- );
602
- expect(actualContent).toBe(expectedContent);
449
+ ).toRenderTo(`
450
+ export interface MyOperations {
451
+ id: string;
452
+ weight: number;
453
+ color: "blue" | "red";
454
+ }`);
603
455
  });
604
456
 
605
457
  it("can add a members to the interface", async () => {
@@ -616,32 +468,26 @@ describe("Typescript Interface", () => {
616
468
  const [namespace] = program.resolveTypeReference("DemoService");
617
469
  const models = Array.from((namespace as Namespace).models.values());
618
470
 
619
- const res = render(
471
+ expect(
620
472
  <Output program={program}>
621
473
  <SourceFile path="test.ts">
622
474
  <InterfaceDeclaration export name="MyOperations" type={models[0]}>
623
- customProperty: string; customMethod(): void;
475
+ <hbr />
476
+ <List>
477
+ <>customProperty: string;</>
478
+ <>customMethod(): void;</>
479
+ </List>
624
480
  </InterfaceDeclaration>
625
481
  </SourceFile>
626
482
  </Output>,
627
- );
628
-
629
- const testFile = res.contents.find((file) => file.path === "test.ts");
630
- assert(testFile, "test.ts file not rendered");
631
- const actualContent = await format(testFile.contents as string, { parser: "typescript" });
632
- const expectedContent = await format(
633
- `export interface MyOperations {
634
- id: string;
635
- weight: number;
636
- color: "blue" | "red";
637
- customProperty: string;
638
- customMethod(): void;
639
- }`,
640
- {
641
- parser: "typescript",
642
- },
643
- );
644
- expect(actualContent).toBe(expectedContent);
483
+ ).toRenderTo(`
484
+ export interface MyOperations {
485
+ id: string;
486
+ weight: number;
487
+ color: "blue" | "red";
488
+ customProperty: string;
489
+ customMethod(): void;
490
+ }`);
645
491
  });
646
492
 
647
493
  it("interface name can be customized", async () => {
@@ -658,28 +504,18 @@ describe("Typescript Interface", () => {
658
504
  const [namespace] = program.resolveTypeReference("DemoService");
659
505
  const models = Array.from((namespace as Namespace).models.values());
660
506
 
661
- const res = render(
507
+ expect(
662
508
  <Output program={program}>
663
509
  <SourceFile path="test.ts">
664
510
  <InterfaceDeclaration export name="MyModel" type={models[0]} />
665
511
  </SourceFile>
666
512
  </Output>,
667
- );
668
-
669
- const testFile = res.contents.find((file) => file.path === "test.ts");
670
- assert(testFile, "test.ts file not rendered");
671
- const actualContent = await format(testFile.contents as string, { parser: "typescript" });
672
- const expectedContent = await format(
673
- `export interface MyModel {
513
+ ).toRenderTo(`
514
+ export interface MyModel {
674
515
  id: string;
675
516
  weight: number;
676
517
  color: "blue" | "red";
677
- }`,
678
- {
679
- parser: "typescript",
680
- },
681
- );
682
- expect(actualContent).toBe(expectedContent);
518
+ }`);
683
519
  });
684
520
 
685
521
  it("interface with extends", async () => {
@@ -701,21 +537,14 @@ describe("Typescript Interface", () => {
701
537
  const [namespace] = program.resolveTypeReference("DemoService");
702
538
  const models = Array.from((namespace as Namespace).models.values());
703
539
 
704
- const res = render(
540
+ expect(
705
541
  <Output program={program}>
706
542
  <SourceFile path="test.ts">
707
- {models.map((model) => (
708
- <InterfaceDeclaration export type={model} />
709
- ))}
543
+ <For each={models}>{(model) => <InterfaceDeclaration export type={model} />}</For>
710
544
  </SourceFile>
711
545
  </Output>,
712
- );
713
-
714
- const testFile = res.contents.find((file) => file.path === "test.ts");
715
- assert(testFile, "test.ts file not rendered");
716
- const actualContent = await format(testFile.contents as string, { parser: "typescript" });
717
- const expectedContent = await format(
718
- `export interface Widget {
546
+ ).toRenderTo(`
547
+ export interface Widget {
719
548
  id: string;
720
549
  weight: number;
721
550
  color: "blue" | "red";
@@ -723,12 +552,7 @@ describe("Typescript Interface", () => {
723
552
  export interface ErrorWidget extends Widget {
724
553
  code: number;
725
554
  message: string;
726
- }`,
727
- {
728
- parser: "typescript",
729
- },
730
- );
731
- expect(actualContent).toBe(expectedContent);
555
+ }`);
732
556
  });
733
557
  });
734
558
 
@@ -745,26 +569,16 @@ describe("Typescript Interface", () => {
745
569
  const [namespace] = program.resolveTypeReference("DemoService");
746
570
  const interfaces = Array.from((namespace as Namespace).interfaces.values());
747
571
 
748
- const res = render(
572
+ expect(
749
573
  <Output program={program}>
750
574
  <SourceFile path="test.ts">
751
575
  <InterfaceDeclaration export type={interfaces[0]} />
752
576
  </SourceFile>
753
577
  </Output>,
754
- );
755
-
756
- const testFile = res.contents.find((file) => file.path === "test.ts");
757
- assert(testFile, "test.ts file not rendered");
758
- const actualContent = await format(testFile.contents as string, { parser: "typescript" });
759
- const expectedContent = await format(
760
- `export interface WidgetOperations {
761
- getName(id: string): string;
762
- }`,
763
- {
764
- parser: "typescript",
765
- },
766
- );
767
- expect(actualContent).toBe(expectedContent);
578
+ ).toRenderTo(`
579
+ export interface WidgetOperations {
580
+ getName(id: string): string;
581
+ }`);
768
582
  });
769
583
 
770
584
  it("should handle spread and non spread model parameters", async () => {
@@ -785,32 +599,22 @@ describe("Typescript Interface", () => {
785
599
  const interfaces = Array.from((namespace as Namespace).interfaces.values());
786
600
  const models = Array.from((namespace as Namespace).models.values());
787
601
 
788
- const res = render(
602
+ expect(
789
603
  <Output program={program}>
790
604
  <SourceFile path="test.ts">
791
605
  <InterfaceDeclaration export type={interfaces[0]} />
606
+ <hbr />
792
607
  <InterfaceDeclaration export type={models[0]} />
793
608
  </SourceFile>
794
609
  </Output>,
795
- );
796
-
797
- const testFile = res.contents.find((file) => file.path === "test.ts");
798
- assert(testFile, "test.ts file not rendered");
799
- const actualContent = await format(testFile.contents as string, { parser: "typescript" });
800
- const expectedContent = await format(
801
- `export interface WidgetOperations {
802
- getName(foo: Foo): string;
803
- getOtherName(name: string): string
804
- }
805
- export interface Foo {
806
- name: string;
807
- }
808
- `,
809
- {
810
- parser: "typescript",
811
- },
812
- );
813
- expect(actualContent).toBe(expectedContent);
610
+ ).toRenderTo(`
611
+ export interface WidgetOperations {
612
+ getName(foo: Foo): string;
613
+ getOtherName(name: string): string;
614
+ }
615
+ export interface Foo {
616
+ name: string;
617
+ }`);
814
618
  });
815
619
 
816
620
  it("creates an interface with Model references", async () => {
@@ -843,29 +647,22 @@ describe("Typescript Interface", () => {
843
647
  const interfaces = Array.from((namespace as Namespace).interfaces.values());
844
648
  const models = Array.from((namespace as Namespace).models.values());
845
649
 
846
- const res = render(
650
+ expect(
847
651
  <Output program={program}>
848
652
  <SourceFile path="test.ts">
849
653
  <InterfaceDeclaration export type={interfaces[0]} />
850
- {models.map((model) => (
851
- <InterfaceDeclaration export type={model} />
852
- ))}
654
+ <hbr />
655
+ <For each={models}>{(model) => <InterfaceDeclaration export type={model} />}</For>
853
656
  </SourceFile>
854
657
  </Output>,
855
- );
856
-
857
- const testFile = res.contents.find((file) => file.path === "test.ts");
858
- assert(testFile, "test.ts file not rendered");
859
- const actualContent = await format(testFile.contents as string, { parser: "typescript" });
860
- const expectedContent = await format(
861
- `
658
+ ).toRenderTo(`
862
659
  /**
863
660
  * Operations for Widget
864
661
  */
865
662
  export interface WidgetOperations {
866
663
  /**
867
664
  * Get the name of the widget
868
- *
665
+ *
869
666
  * @param {string} id - The id of the widget
870
667
  */
871
668
  getName(id: string): Widget;
@@ -874,12 +671,7 @@ describe("Typescript Interface", () => {
874
671
  id: string;
875
672
  weight: number;
876
673
  color: "blue" | "red";
877
- }`,
878
- {
879
- parser: "typescript",
880
- },
881
- );
882
- expect(actualContent).toBe(expectedContent);
674
+ }`);
883
675
  });
884
676
 
885
677
  it("creates an interface that extends another", async () => {
@@ -905,35 +697,24 @@ describe("Typescript Interface", () => {
905
697
  const interfaces = Array.from((namespace as Namespace).interfaces.values());
906
698
  const models = Array.from((namespace as Namespace).models.values());
907
699
 
908
- const res = render(
700
+ expect(
909
701
  <Output program={program}>
910
702
  <SourceFile path="test.ts">
911
703
  <InterfaceDeclaration export type={interfaces[1]} />
912
- {models.map((model) => (
913
- <InterfaceDeclaration export type={model} />
914
- ))}
704
+ <hbr />
705
+ <For each={models}>{(model) => <InterfaceDeclaration export type={model} />}</For>
915
706
  </SourceFile>
916
707
  </Output>,
917
- );
918
-
919
- const testFile = res.contents.find((file) => file.path === "test.ts");
920
- assert(testFile, "test.ts file not rendered");
921
- const actualContent = await format(testFile.contents as string, { parser: "typescript" });
922
- const expectedContent = await format(
923
- `export interface WidgetOperationsExtended {
924
- getName(id: string): Widget;
925
- delete(id: string): void;
926
- }
927
- export interface Widget {
928
- id: string;
929
- weight: number;
930
- color: "blue" | "red";
931
- }`,
932
- {
933
- parser: "typescript",
934
- },
935
- );
936
- expect(actualContent).toBe(expectedContent);
708
+ ).toRenderTo(`
709
+ export interface WidgetOperationsExtended {
710
+ getName(id: string): Widget;
711
+ delete(id: string): void;
712
+ }
713
+ export interface Widget {
714
+ id: string;
715
+ weight: number;
716
+ color: "blue" | "red";
717
+ }`);
937
718
  });
938
719
  });
939
720
  });