@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.
Files changed (28) hide show
  1. package/dist/src/core/write-output.js +10 -6
  2. package/dist/src/csharp/components/class/declaration.d.ts.map +1 -1
  3. package/dist/src/csharp/components/class/declaration.js +2 -1
  4. package/dist/src/typescript/components/interface-declaration.d.ts.map +1 -1
  5. package/dist/src/typescript/components/interface-declaration.js +2 -2
  6. package/dist/src/typescript/components/union/expression.test.js +3 -3
  7. package/dist/test/typescript/components/function-declaration.test.js +31 -112
  8. package/dist/test/typescript/components/interface-declaration.test.js +146 -308
  9. package/dist/test/typescript/components/type-alias-declaration.test.js +17 -75
  10. package/dist/test/typescript/components/type-transform.test.js +32 -83
  11. package/dist/test/typescript/components/value-expression.test.js +3 -6
  12. package/dist/test/typescript/utils.d.ts +7 -0
  13. package/dist/test/typescript/utils.d.ts.map +1 -0
  14. package/dist/test/typescript/utils.js +18 -0
  15. package/dist/test/utils.d.ts.map +1 -1
  16. package/dist/test/utils.js +2 -0
  17. package/package.json +7 -7
  18. package/src/core/write-output.ts +10 -6
  19. package/src/csharp/components/class/declaration.tsx +2 -1
  20. package/src/typescript/components/interface-declaration.tsx +3 -3
  21. package/src/typescript/components/union/expression.test.tsx +5 -5
  22. package/test/typescript/components/function-declaration.test.tsx +31 -121
  23. package/test/typescript/components/interface-declaration.test.tsx +123 -342
  24. package/test/typescript/components/type-alias-declaration.test.tsx +17 -76
  25. package/test/typescript/components/type-transform.test.tsx +32 -93
  26. package/test/typescript/components/value-expression.test.tsx +4 -12
  27. package/test/typescript/utils.tsx +12 -0
  28. package/test/utils.ts +2 -1
@@ -1,8 +1,7 @@
1
- import { memo as _$memo, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
- import { For, List, render } from "@alloy-js/core";
1
+ import { memo as _$memo, createComponent as _$createComponent, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
2
+ import { For, List } from "@alloy-js/core";
3
3
  import { SourceFile } from "@alloy-js/typescript";
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.js";
7
6
  import { InterfaceDeclaration } from "../../../src/typescript/components/interface-declaration.js";
8
7
  import { getProgram } from "../test-host.js";
@@ -22,7 +21,7 @@ describe("Typescript Interface", () => {
22
21
  `);
23
22
  const [namespace] = program.resolveTypeReference("DemoService");
24
23
  const models = Array.from(namespace.models.values());
25
- const res = render(_$createComponent(Output, {
24
+ expect(_$createComponent(Output, {
26
25
  program: program,
27
26
  get children() {
28
27
  return _$createComponent(SourceFile, {
@@ -41,13 +40,7 @@ describe("Typescript Interface", () => {
41
40
  }
42
41
  });
43
42
  }
44
- }));
45
- const testFile = res.contents.find(file => file.path === "test.ts");
46
- assert(testFile, "test.ts file not rendered");
47
- const actualContent = await format(testFile.contents, {
48
- parser: "typescript"
49
- });
50
- const expectedContent = await format(`
43
+ })).toRenderTo(`
51
44
  /**
52
45
  * This is an overridden doc comment
53
46
  * with multiple lines
@@ -55,10 +48,7 @@ describe("Typescript Interface", () => {
55
48
  export interface Foo {
56
49
  knownProp: string;
57
50
  }
58
- `, {
59
- parser: "typescript"
60
- });
61
- expect(actualContent).toBe(expectedContent);
51
+ `);
62
52
  });
63
53
  it("declares an interface with multi line docs", async () => {
64
54
  const program = await getProgram(`
@@ -74,7 +64,7 @@ describe("Typescript Interface", () => {
74
64
  `);
75
65
  const [namespace] = program.resolveTypeReference("DemoService");
76
66
  const models = Array.from(namespace.models.values());
77
- const res = render(_$createComponent(Output, {
67
+ expect(_$createComponent(Output, {
78
68
  program: program,
79
69
  get children() {
80
70
  return _$createComponent(SourceFile, {
@@ -92,13 +82,7 @@ describe("Typescript Interface", () => {
92
82
  }
93
83
  });
94
84
  }
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, {
99
- parser: "typescript"
100
- });
101
- const expectedContent = await format(`
85
+ })).toRenderTo(`
102
86
  /**
103
87
  * This is a test
104
88
  * with multiple lines
@@ -106,10 +90,7 @@ describe("Typescript Interface", () => {
106
90
  export interface Foo {
107
91
  knownProp: string;
108
92
  }
109
- `, {
110
- parser: "typescript"
111
- });
112
- expect(actualContent).toBe(expectedContent);
93
+ `);
113
94
  });
114
95
  it("declares an interface with @doc", async () => {
115
96
  const program = await getProgram(`
@@ -122,7 +103,7 @@ describe("Typescript Interface", () => {
122
103
  `);
123
104
  const [namespace] = program.resolveTypeReference("DemoService");
124
105
  const models = Array.from(namespace.models.values());
125
- const res = render(_$createComponent(Output, {
106
+ expect(_$createComponent(Output, {
126
107
  program: program,
127
108
  get children() {
128
109
  return _$createComponent(SourceFile, {
@@ -140,23 +121,14 @@ describe("Typescript Interface", () => {
140
121
  }
141
122
  });
142
123
  }
143
- }));
144
- const testFile = res.contents.find(file => file.path === "test.ts");
145
- assert(testFile, "test.ts file not rendered");
146
- const actualContent = await format(testFile.contents, {
147
- parser: "typescript"
148
- });
149
- const expectedContent = await format(`
124
+ })).toRenderTo(`
150
125
  /**
151
126
  * This is a test
152
127
  */
153
128
  export interface Foo {
154
129
  knownProp: string;
155
130
  }
156
- `, {
157
- parser: "typescript"
158
- });
159
- expect(actualContent).toBe(expectedContent);
131
+ `);
160
132
  });
161
133
  it("declares an interface with doc", async () => {
162
134
  const program = await getProgram(`
@@ -172,7 +144,7 @@ describe("Typescript Interface", () => {
172
144
  `);
173
145
  const [namespace] = program.resolveTypeReference("DemoService");
174
146
  const models = Array.from(namespace.models.values());
175
- const res = render(_$createComponent(Output, {
147
+ expect(_$createComponent(Output, {
176
148
  program: program,
177
149
  get children() {
178
150
  return _$createComponent(SourceFile, {
@@ -190,13 +162,7 @@ describe("Typescript Interface", () => {
190
162
  }
191
163
  });
192
164
  }
193
- }));
194
- const testFile = res.contents.find(file => file.path === "test.ts");
195
- assert(testFile, "test.ts file not rendered");
196
- const actualContent = await format(testFile.contents, {
197
- parser: "typescript"
198
- });
199
- const expectedContent = await format(`
165
+ })).toRenderTo(`
200
166
  /**
201
167
  * This is a test
202
168
  */
@@ -206,10 +172,7 @@ describe("Typescript Interface", () => {
206
172
  */
207
173
  knownProp: string;
208
174
  }
209
- `, {
210
- parser: "typescript"
211
- });
212
- expect(actualContent).toBe(expectedContent);
175
+ `);
213
176
  });
214
177
  describe("Bound to Model", () => {
215
178
  it("creates an interface that extends a model for Record spread", async () => {
@@ -223,7 +186,7 @@ describe("Typescript Interface", () => {
223
186
  `);
224
187
  const [namespace] = program.resolveTypeReference("DemoService");
225
188
  const models = Array.from(namespace.models.values());
226
- const res = render(_$createComponent(Output, {
189
+ expect(_$createComponent(Output, {
227
190
  program: program,
228
191
  get children() {
229
192
  return _$createComponent(SourceFile, {
@@ -241,21 +204,12 @@ describe("Typescript Interface", () => {
241
204
  }
242
205
  });
243
206
  }
244
- }));
245
- const testFile = res.contents.find(file => file.path === "test.ts");
246
- assert(testFile, "test.ts file not rendered");
247
- const actualContent = await format(testFile.contents, {
248
- parser: "typescript"
249
- });
250
- const expectedContent = await format(`
207
+ })).toRenderTo(`
251
208
  export interface DifferentSpreadModelRecord {
252
209
  knownProp: string;
253
210
  additionalProperties?: Record<string, unknown>;
254
211
  }
255
- `, {
256
- parser: "typescript"
257
- });
258
- expect(actualContent).toBe(expectedContent);
212
+ `);
259
213
  });
260
214
  it("creates an interface for a model that 'is' an array ", async () => {
261
215
  const program = await getProgram(`
@@ -265,7 +219,7 @@ describe("Typescript Interface", () => {
265
219
  `);
266
220
  const [namespace] = program.resolveTypeReference("DemoService");
267
221
  const models = namespace.models;
268
- const res = render(_$createComponent(Output, {
222
+ expect(_$createComponent(Output, {
269
223
  program: program,
270
224
  get children() {
271
225
  return _$createComponent(SourceFile, {
@@ -284,17 +238,10 @@ describe("Typescript Interface", () => {
284
238
  }
285
239
  });
286
240
  }
287
- }));
288
- const testFile = res.contents.find(file => file.path === "test.ts");
289
- assert(testFile, "test.ts file not rendered");
290
- const actualContent = await format(testFile.contents, {
291
- parser: "typescript"
292
- });
293
- const expectedContent = await format(`export interface Foo extends Array<string> { }
294
- `, {
295
- parser: "typescript"
296
- });
297
- expect(actualContent).toBe(expectedContent);
241
+ })).toRenderTo(`
242
+ export interface Foo extends Array<string> {
243
+
244
+ }`);
298
245
  });
299
246
  it("creates an interface for a model that 'is' a record ", async () => {
300
247
  const program = await getProgram(`
@@ -304,7 +251,7 @@ describe("Typescript Interface", () => {
304
251
  `);
305
252
  const [namespace] = program.resolveTypeReference("DemoService");
306
253
  const models = namespace.models;
307
- const res = render(_$createComponent(Output, {
254
+ expect(_$createComponent(Output, {
308
255
  program: program,
309
256
  get children() {
310
257
  return _$createComponent(SourceFile, {
@@ -323,19 +270,10 @@ describe("Typescript Interface", () => {
323
270
  }
324
271
  });
325
272
  }
326
- }));
327
- const testFile = res.contents.find(file => file.path === "test.ts");
328
- assert(testFile, "test.ts file not rendered");
329
- const actualContent = await format(testFile.contents, {
330
- parser: "typescript"
331
- });
332
- const expectedContent = await format(`export interface Foo {
333
- additionalProperties?: Record<string, string>;
334
- }
335
- `, {
336
- parser: "typescript"
337
- });
338
- expect(actualContent).toBe(expectedContent);
273
+ })).toRenderTo(`
274
+ export interface Foo {
275
+ additionalProperties?: Record<string, string>;
276
+ }`);
339
277
  });
340
278
  it("creates an interface of a model that spreads a Record", async () => {
341
279
  const program = await getProgram(`
@@ -347,7 +285,7 @@ describe("Typescript Interface", () => {
347
285
  `);
348
286
  const [namespace] = program.resolveTypeReference("DemoService");
349
287
  const models = namespace.models;
350
- const res = render(_$createComponent(Output, {
288
+ expect(_$createComponent(Output, {
351
289
  program: program,
352
290
  get children() {
353
291
  return _$createComponent(SourceFile, {
@@ -366,20 +304,11 @@ describe("Typescript Interface", () => {
366
304
  }
367
305
  });
368
306
  }
369
- }));
370
- const testFile = res.contents.find(file => file.path === "test.ts");
371
- assert(testFile, "test.ts file not rendered");
372
- const actualContent = await format(testFile.contents, {
373
- parser: "typescript"
374
- });
375
- const expectedContent = await format(`
307
+ })).toRenderTo(`
376
308
  export interface Foo {
377
309
  additionalProperties?: Record<string, string>;
378
310
  }
379
- `, {
380
- parser: "typescript"
381
- });
382
- expect(actualContent).toBe(expectedContent);
311
+ `);
383
312
  });
384
313
  it("creates an interface that extends an spread model", async () => {
385
314
  const program = await getProgram(`
@@ -400,7 +329,7 @@ describe("Typescript Interface", () => {
400
329
  `);
401
330
  const [namespace] = program.resolveTypeReference("DemoService");
402
331
  const models = namespace.models;
403
- const res = render(_$createComponent(Output, {
332
+ expect(_$createComponent(Output, {
404
333
  program: program,
405
334
  get children() {
406
335
  return _$createComponent(SourceFile, {
@@ -419,27 +348,18 @@ describe("Typescript Interface", () => {
419
348
  }
420
349
  });
421
350
  }
422
- }));
423
- const testFile = res.contents.find(file => file.path === "test.ts");
424
- assert(testFile, "test.ts file not rendered");
425
- const actualContent = await format(testFile.contents, {
426
- parser: "typescript"
427
- });
428
- const expectedContent = await format(`export interface ModelForRecord {
429
- state: string;
430
- }
431
- export interface DifferentSpreadModelRecord {
432
- knownProp: string;
433
- additionalProperties?: Record<string, ModelForRecord>;
434
- }
435
- export interface DifferentSpreadModelDerived extends DifferentSpreadModelRecord {
436
- derivedProp: ModelForRecord;
437
- additionalProperties?: Record<string, ModelForRecord>;
438
- }
439
- `, {
440
- parser: "typescript"
441
- });
442
- expect(actualContent).toBe(expectedContent);
351
+ })).toRenderTo(`
352
+ export interface ModelForRecord {
353
+ state: string;
354
+ }
355
+ export interface DifferentSpreadModelRecord {
356
+ knownProp: string;
357
+ additionalProperties?: Record<string, ModelForRecord>;
358
+ }
359
+ export interface DifferentSpreadModelDerived extends DifferentSpreadModelRecord {
360
+ derivedProp: ModelForRecord;
361
+ additionalProperties?: Record<string, ModelForRecord>;
362
+ }`);
443
363
  });
444
364
  it("creates an interface that has additional properties", async () => {
445
365
  const program = await getProgram(`
@@ -452,7 +372,7 @@ describe("Typescript Interface", () => {
452
372
  `);
453
373
  const [namespace] = program.resolveTypeReference("DemoService");
454
374
  const models = Array.from(namespace.models.values());
455
- const res = render(_$createComponent(Output, {
375
+ expect(_$createComponent(Output, {
456
376
  program: program,
457
377
  get children() {
458
378
  return _$createComponent(SourceFile, {
@@ -465,21 +385,13 @@ describe("Typescript Interface", () => {
465
385
  }
466
386
  });
467
387
  }
468
- }));
469
- const testFile = res.contents.find(file => file.path === "test.ts");
470
- assert(testFile, "test.ts file not rendered");
471
- const actualContent = await format(testFile.contents, {
472
- parser: "typescript"
473
- });
474
- const expectedContent = await format(`export interface Widget {
388
+ })).toRenderTo(`
389
+ export interface Widget {
475
390
  id: string;
476
391
  weight: number;
477
392
  color: "blue" | "red";
478
393
  additionalProperties?: Record<string, unknown>;
479
- }`, {
480
- parser: "typescript"
481
- });
482
- expect(actualContent).toBe(expectedContent);
394
+ }`);
483
395
  });
484
396
  it("handles a type reference to a union variant", async () => {
485
397
  const program = await getProgram(`
@@ -498,7 +410,7 @@ describe("Typescript Interface", () => {
498
410
  `);
499
411
  const [namespace] = program.resolveTypeReference("DemoService");
500
412
  const models = Array.from(namespace.models.values());
501
- const res = render(_$createComponent(Output, {
413
+ expect(_$createComponent(Output, {
502
414
  program: program,
503
415
  get children() {
504
416
  return _$createComponent(SourceFile, {
@@ -512,20 +424,12 @@ describe("Typescript Interface", () => {
512
424
  }
513
425
  });
514
426
  }
515
- }));
516
- const testFile = res.contents.find(file => file.path === "test.ts");
517
- assert(testFile, "test.ts file not rendered");
518
- const actualContent = await format(testFile.contents, {
519
- parser: "typescript"
520
- });
521
- const expectedContent = await format(`interface Widget {
522
- id: string;
523
- weight: number;
524
- color: "BLUE";
525
- }`, {
526
- parser: "typescript"
527
- });
528
- expect(actualContent).toBe(expectedContent);
427
+ })).toRenderTo(`
428
+ interface Widget {
429
+ id: string;
430
+ weight: number;
431
+ color: "BLUE";
432
+ }`);
529
433
  });
530
434
  it("creates an interface", async () => {
531
435
  const program = await getProgram(`
@@ -539,7 +443,7 @@ describe("Typescript Interface", () => {
539
443
  `);
540
444
  const [namespace] = program.resolveTypeReference("DemoService");
541
445
  const models = Array.from(namespace.models.values());
542
- const res = render(_$createComponent(Output, {
446
+ expect(_$createComponent(Output, {
543
447
  program: program,
544
448
  get children() {
545
449
  return _$createComponent(SourceFile, {
@@ -553,20 +457,12 @@ describe("Typescript Interface", () => {
553
457
  }
554
458
  });
555
459
  }
556
- }));
557
- const testFile = res.contents.find(file => file.path === "test.ts");
558
- assert(testFile, "test.ts file not rendered");
559
- const actualContent = await format(testFile.contents, {
560
- parser: "typescript"
561
- });
562
- const expectedContent = await format(`interface Widget {
460
+ })).toRenderTo(`
461
+ interface Widget {
563
462
  id: string;
564
463
  weight: number;
565
464
  color: "blue" | "red";
566
- }`, {
567
- parser: "typescript"
568
- });
569
- expect(actualContent).toBe(expectedContent);
465
+ }`);
570
466
  });
571
467
  it("renders an empty interface with a never-typed member", async () => {
572
468
  const program = await getProgram(`
@@ -578,7 +474,7 @@ describe("Typescript Interface", () => {
578
474
  `);
579
475
  const [namespace] = program.resolveTypeReference("DemoService");
580
476
  const models = Array.from(namespace.models.values());
581
- const res = render(_$createComponent(Output, {
477
+ expect(_$createComponent(Output, {
582
478
  program: program,
583
479
  get children() {
584
480
  return _$createComponent(SourceFile, {
@@ -593,17 +489,10 @@ describe("Typescript Interface", () => {
593
489
  }
594
490
  });
595
491
  }
596
- }));
597
- const testFile = res.contents.find(file => file.path === "test.ts");
598
- assert(testFile, "test.ts file not rendered");
599
- const actualContent = await format(testFile.contents, {
600
- parser: "typescript"
601
- });
602
- const expectedContent = await format(`export interface Widget {
603
- }`, {
604
- parser: "typescript"
605
- });
606
- expect(actualContent).toBe(expectedContent);
492
+ })).toRenderTo(`
493
+ export interface Widget {
494
+
495
+ }`);
607
496
  });
608
497
  it("can override interface name", async () => {
609
498
  const program = await getProgram(`
@@ -617,7 +506,7 @@ describe("Typescript Interface", () => {
617
506
  `);
618
507
  const [namespace] = program.resolveTypeReference("DemoService");
619
508
  const models = Array.from(namespace.models.values());
620
- const res = render(_$createComponent(Output, {
509
+ expect(_$createComponent(Output, {
621
510
  program: program,
622
511
  get children() {
623
512
  return _$createComponent(SourceFile, {
@@ -633,20 +522,12 @@ describe("Typescript Interface", () => {
633
522
  }
634
523
  });
635
524
  }
636
- }));
637
- const testFile = res.contents.find(file => file.path === "test.ts");
638
- assert(testFile, "test.ts file not rendered");
639
- const actualContent = await format(testFile.contents, {
640
- parser: "typescript"
641
- });
642
- const expectedContent = await format(`export interface MyOperations {
643
- id: string;
644
- weight: number;
645
- color: "blue" | "red";
646
- }`, {
647
- parser: "typescript"
648
- });
649
- expect(actualContent).toBe(expectedContent);
525
+ })).toRenderTo(`
526
+ export interface MyOperations {
527
+ id: string;
528
+ weight: number;
529
+ color: "blue" | "red";
530
+ }`);
650
531
  });
651
532
  it("can add a members to the interface", async () => {
652
533
  const program = await getProgram(`
@@ -660,7 +541,7 @@ describe("Typescript Interface", () => {
660
541
  `);
661
542
  const [namespace] = program.resolveTypeReference("DemoService");
662
543
  const models = Array.from(namespace.models.values());
663
- const res = render(_$createComponent(Output, {
544
+ expect(_$createComponent(Output, {
664
545
  program: program,
665
546
  get children() {
666
547
  return _$createComponent(SourceFile, {
@@ -672,27 +553,25 @@ describe("Typescript Interface", () => {
672
553
  get type() {
673
554
  return models[0];
674
555
  },
675
- children: "customProperty: string; customMethod(): void;"
556
+ get children() {
557
+ return [_$createIntrinsic("hbr", {}), _$createComponent(List, {
558
+ get children() {
559
+ return [["customProperty: string;"], ["customMethod(): void;"]];
560
+ }
561
+ })];
562
+ }
676
563
  });
677
564
  }
678
565
  });
679
566
  }
680
- }));
681
- const testFile = res.contents.find(file => file.path === "test.ts");
682
- assert(testFile, "test.ts file not rendered");
683
- const actualContent = await format(testFile.contents, {
684
- parser: "typescript"
685
- });
686
- const expectedContent = await format(`export interface MyOperations {
687
- id: string;
688
- weight: number;
689
- color: "blue" | "red";
690
- customProperty: string;
691
- customMethod(): void;
692
- }`, {
693
- parser: "typescript"
694
- });
695
- expect(actualContent).toBe(expectedContent);
567
+ })).toRenderTo(`
568
+ export interface MyOperations {
569
+ id: string;
570
+ weight: number;
571
+ color: "blue" | "red";
572
+ customProperty: string;
573
+ customMethod(): void;
574
+ }`);
696
575
  });
697
576
  it("interface name can be customized", async () => {
698
577
  const program = await getProgram(`
@@ -706,7 +585,7 @@ describe("Typescript Interface", () => {
706
585
  `);
707
586
  const [namespace] = program.resolveTypeReference("DemoService");
708
587
  const models = Array.from(namespace.models.values());
709
- const res = render(_$createComponent(Output, {
588
+ expect(_$createComponent(Output, {
710
589
  program: program,
711
590
  get children() {
712
591
  return _$createComponent(SourceFile, {
@@ -722,20 +601,12 @@ describe("Typescript Interface", () => {
722
601
  }
723
602
  });
724
603
  }
725
- }));
726
- const testFile = res.contents.find(file => file.path === "test.ts");
727
- assert(testFile, "test.ts file not rendered");
728
- const actualContent = await format(testFile.contents, {
729
- parser: "typescript"
730
- });
731
- const expectedContent = await format(`export interface MyModel {
604
+ })).toRenderTo(`
605
+ export interface MyModel {
732
606
  id: string;
733
607
  weight: number;
734
608
  color: "blue" | "red";
735
- }`, {
736
- parser: "typescript"
737
- });
738
- expect(actualContent).toBe(expectedContent);
609
+ }`);
739
610
  });
740
611
  it("interface with extends", async () => {
741
612
  const program = await getProgram(`
@@ -754,26 +625,24 @@ describe("Typescript Interface", () => {
754
625
  `);
755
626
  const [namespace] = program.resolveTypeReference("DemoService");
756
627
  const models = Array.from(namespace.models.values());
757
- const res = render(_$createComponent(Output, {
628
+ expect(_$createComponent(Output, {
758
629
  program: program,
759
630
  get children() {
760
631
  return _$createComponent(SourceFile, {
761
632
  path: "test.ts",
762
633
  get children() {
763
- return models.map(model => _$createComponent(InterfaceDeclaration, {
764
- "export": true,
765
- type: model
766
- }));
634
+ return _$createComponent(For, {
635
+ each: models,
636
+ children: model => _$createComponent(InterfaceDeclaration, {
637
+ "export": true,
638
+ type: model
639
+ })
640
+ });
767
641
  }
768
642
  });
769
643
  }
770
- }));
771
- const testFile = res.contents.find(file => file.path === "test.ts");
772
- assert(testFile, "test.ts file not rendered");
773
- const actualContent = await format(testFile.contents, {
774
- parser: "typescript"
775
- });
776
- const expectedContent = await format(`export interface Widget {
644
+ })).toRenderTo(`
645
+ export interface Widget {
777
646
  id: string;
778
647
  weight: number;
779
648
  color: "blue" | "red";
@@ -781,10 +650,7 @@ describe("Typescript Interface", () => {
781
650
  export interface ErrorWidget extends Widget {
782
651
  code: number;
783
652
  message: string;
784
- }`, {
785
- parser: "typescript"
786
- });
787
- expect(actualContent).toBe(expectedContent);
653
+ }`);
788
654
  });
789
655
  });
790
656
  describe("Bound to Interface", () => {
@@ -798,7 +664,7 @@ describe("Typescript Interface", () => {
798
664
  `);
799
665
  const [namespace] = program.resolveTypeReference("DemoService");
800
666
  const interfaces = Array.from(namespace.interfaces.values());
801
- const res = render(_$createComponent(Output, {
667
+ expect(_$createComponent(Output, {
802
668
  program: program,
803
669
  get children() {
804
670
  return _$createComponent(SourceFile, {
@@ -813,18 +679,10 @@ describe("Typescript Interface", () => {
813
679
  }
814
680
  });
815
681
  }
816
- }));
817
- const testFile = res.contents.find(file => file.path === "test.ts");
818
- assert(testFile, "test.ts file not rendered");
819
- const actualContent = await format(testFile.contents, {
820
- parser: "typescript"
821
- });
822
- const expectedContent = await format(`export interface WidgetOperations {
823
- getName(id: string): string;
824
- }`, {
825
- parser: "typescript"
826
- });
827
- expect(actualContent).toBe(expectedContent);
682
+ })).toRenderTo(`
683
+ export interface WidgetOperations {
684
+ getName(id: string): string;
685
+ }`);
828
686
  });
829
687
  it("should handle spread and non spread model parameters", async () => {
830
688
  const program = await getProgram(`
@@ -842,7 +700,7 @@ describe("Typescript Interface", () => {
842
700
  const [namespace] = program.resolveTypeReference("DemoService");
843
701
  const interfaces = Array.from(namespace.interfaces.values());
844
702
  const models = Array.from(namespace.models.values());
845
- const res = render(_$createComponent(Output, {
703
+ expect(_$createComponent(Output, {
846
704
  program: program,
847
705
  get children() {
848
706
  return _$createComponent(SourceFile, {
@@ -853,7 +711,7 @@ describe("Typescript Interface", () => {
853
711
  get type() {
854
712
  return interfaces[0];
855
713
  }
856
- }), _$createComponent(InterfaceDeclaration, {
714
+ }), _$createIntrinsic("hbr", {}), _$createComponent(InterfaceDeclaration, {
857
715
  "export": true,
858
716
  get type() {
859
717
  return models[0];
@@ -862,23 +720,14 @@ describe("Typescript Interface", () => {
862
720
  }
863
721
  });
864
722
  }
865
- }));
866
- const testFile = res.contents.find(file => file.path === "test.ts");
867
- assert(testFile, "test.ts file not rendered");
868
- const actualContent = await format(testFile.contents, {
869
- parser: "typescript"
870
- });
871
- const expectedContent = await format(`export interface WidgetOperations {
872
- getName(foo: Foo): string;
873
- getOtherName(name: string): string
874
- }
875
- export interface Foo {
876
- name: string;
877
- }
878
- `, {
879
- parser: "typescript"
880
- });
881
- expect(actualContent).toBe(expectedContent);
723
+ })).toRenderTo(`
724
+ export interface WidgetOperations {
725
+ getName(foo: Foo): string;
726
+ getOtherName(name: string): string;
727
+ }
728
+ export interface Foo {
729
+ name: string;
730
+ }`);
882
731
  });
883
732
  it("creates an interface with Model references", async () => {
884
733
  const program = await getProgram(`
@@ -908,7 +757,7 @@ describe("Typescript Interface", () => {
908
757
  const [namespace] = program.resolveTypeReference("DemoService");
909
758
  const interfaces = Array.from(namespace.interfaces.values());
910
759
  const models = Array.from(namespace.models.values());
911
- const res = render(_$createComponent(Output, {
760
+ expect(_$createComponent(Output, {
912
761
  program: program,
913
762
  get children() {
914
763
  return _$createComponent(SourceFile, {
@@ -919,27 +768,24 @@ describe("Typescript Interface", () => {
919
768
  get type() {
920
769
  return interfaces[0];
921
770
  }
922
- }), _$memo(() => models.map(model => _$createComponent(InterfaceDeclaration, {
923
- "export": true,
924
- type: model
925
- })))];
771
+ }), _$createIntrinsic("hbr", {}), _$createComponent(For, {
772
+ each: models,
773
+ children: model => _$createComponent(InterfaceDeclaration, {
774
+ "export": true,
775
+ type: model
776
+ })
777
+ })];
926
778
  }
927
779
  });
928
780
  }
929
- }));
930
- const testFile = res.contents.find(file => file.path === "test.ts");
931
- assert(testFile, "test.ts file not rendered");
932
- const actualContent = await format(testFile.contents, {
933
- parser: "typescript"
934
- });
935
- const expectedContent = await format(`
781
+ })).toRenderTo(`
936
782
  /**
937
783
  * Operations for Widget
938
784
  */
939
785
  export interface WidgetOperations {
940
786
  /**
941
787
  * Get the name of the widget
942
- *
788
+ *
943
789
  * @param {string} id - The id of the widget
944
790
  */
945
791
  getName(id: string): Widget;
@@ -948,10 +794,7 @@ describe("Typescript Interface", () => {
948
794
  id: string;
949
795
  weight: number;
950
796
  color: "blue" | "red";
951
- }`, {
952
- parser: "typescript"
953
- });
954
- expect(actualContent).toBe(expectedContent);
797
+ }`);
955
798
  });
956
799
  it("creates an interface that extends another", async () => {
957
800
  const program = await getProgram(`
@@ -974,7 +817,7 @@ describe("Typescript Interface", () => {
974
817
  const [namespace] = program.resolveTypeReference("DemoService");
975
818
  const interfaces = Array.from(namespace.interfaces.values());
976
819
  const models = Array.from(namespace.models.values());
977
- const res = render(_$createComponent(Output, {
820
+ expect(_$createComponent(Output, {
978
821
  program: program,
979
822
  get children() {
980
823
  return _$createComponent(SourceFile, {
@@ -985,31 +828,26 @@ describe("Typescript Interface", () => {
985
828
  get type() {
986
829
  return interfaces[1];
987
830
  }
988
- }), _$memo(() => models.map(model => _$createComponent(InterfaceDeclaration, {
989
- "export": true,
990
- type: model
991
- })))];
831
+ }), _$createIntrinsic("hbr", {}), _$createComponent(For, {
832
+ each: models,
833
+ children: model => _$createComponent(InterfaceDeclaration, {
834
+ "export": true,
835
+ type: model
836
+ })
837
+ })];
992
838
  }
993
839
  });
994
840
  }
995
- }));
996
- const testFile = res.contents.find(file => file.path === "test.ts");
997
- assert(testFile, "test.ts file not rendered");
998
- const actualContent = await format(testFile.contents, {
999
- parser: "typescript"
1000
- });
1001
- const expectedContent = await format(`export interface WidgetOperationsExtended {
1002
- getName(id: string): Widget;
1003
- delete(id: string): void;
1004
- }
1005
- export interface Widget {
1006
- id: string;
1007
- weight: number;
1008
- color: "blue" | "red";
1009
- }`, {
1010
- parser: "typescript"
1011
- });
1012
- expect(actualContent).toBe(expectedContent);
841
+ })).toRenderTo(`
842
+ export interface WidgetOperationsExtended {
843
+ getName(id: string): Widget;
844
+ delete(id: string): void;
845
+ }
846
+ export interface Widget {
847
+ id: string;
848
+ weight: number;
849
+ color: "blue" | "red";
850
+ }`);
1013
851
  });
1014
852
  });
1015
853
  });