@typespec/emitter-framework 0.11.0-dev.9 → 0.11.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.
- package/CHANGELOG.md +24 -0
- package/dist/src/csharp/components/type-expression.test.js +10 -9
- package/dist/src/csharp/components/type-expression.test.js.map +1 -1
- package/dist/test/typescript/components/arrow-function.test.js +9 -8
- package/dist/test/typescript/components/arrow-function.test.js.map +1 -1
- package/dist/test/typescript/components/component-override.test.js +1 -1
- package/dist/test/typescript/components/component-override.test.js.map +1 -1
- package/dist/test/typescript/components/function-declaration.test.js +1 -1
- package/dist/test/typescript/components/function-declaration.test.js.map +1 -1
- package/dist/test/typescript/components/function-expression.test.js +9 -8
- package/dist/test/typescript/components/function-expression.test.js.map +1 -1
- package/dist/test/typescript/components/function-type.test.js +9 -8
- package/dist/test/typescript/components/function-type.test.js.map +1 -1
- package/dist/test/typescript/components/interface-declaration.test.js +1 -1
- package/dist/test/typescript/components/interface-declaration.test.js.map +1 -1
- package/dist/test/typescript/components/interface-method.test.js +18 -16
- package/dist/test/typescript/components/interface-method.test.js.map +1 -1
- package/dist/test/typescript/components/type-alias-declaration.test.js +6 -4
- package/dist/test/typescript/components/type-alias-declaration.test.js.map +1 -1
- package/dist/test/typescript/components/type-transform.test.js +27 -26
- package/dist/test/typescript/components/type-transform.test.js.map +1 -1
- package/dist/test/typescript/components/value-expression.test.js +1 -1
- package/dist/test/typescript/components/value-expression.test.js.map +1 -1
- package/dist/test/utils.d.ts +1 -0
- package/dist/test/utils.d.ts.map +1 -1
- package/dist/test/utils.js +8 -1
- package/dist/test/utils.js.map +1 -1
- package/package.json +4 -5
- package/src/csharp/components/type-expression.test.tsx +15 -15
- package/test/typescript/components/arrow-function.test.tsx +13 -14
- package/test/typescript/components/component-override.test.tsx +1 -1
- package/test/typescript/components/function-declaration.test.tsx +2 -1
- package/test/typescript/components/function-expression.test.tsx +13 -14
- package/test/typescript/components/function-type.test.tsx +12 -12
- package/test/typescript/components/interface-declaration.test.tsx +1 -1
- package/test/typescript/components/interface-method.test.tsx +25 -24
- package/test/typescript/components/type-alias-declaration.test.tsx +8 -6
- package/test/typescript/components/type-transform.test.tsx +37 -37
- package/test/typescript/components/value-expression.test.tsx +1 -1
- package/test/utils.ts +7 -2
- package/dist/test/typescript/test-host.d.ts +0 -12
- package/dist/test/typescript/test-host.d.ts.map +0 -1
- package/dist/test/typescript/test-host.js +0 -30
- package/dist/test/typescript/test-host.js.map +0 -1
- package/test/typescript/test-host.ts +0 -37
|
@@ -1,22 +1,22 @@
|
|
|
1
|
+
import { Tester } from "#test/test-host.js";
|
|
1
2
|
import { SourceFile } from "@alloy-js/typescript";
|
|
2
3
|
import type { Operation } from "@typespec/compiler";
|
|
3
|
-
import type
|
|
4
|
+
import { t, type TesterInstance } from "@typespec/compiler/testing";
|
|
4
5
|
import { beforeEach, describe, expect, it } from "vitest";
|
|
5
6
|
import { Output } from "../../../src/core/components/output.jsx";
|
|
6
7
|
import { FunctionType } from "../../../src/typescript/index.js";
|
|
7
|
-
import { createEmitterFrameworkTestRunner } from "../test-host.js";
|
|
8
8
|
|
|
9
9
|
describe("function types with a `type` prop", () => {
|
|
10
|
-
let runner:
|
|
10
|
+
let runner: TesterInstance;
|
|
11
11
|
|
|
12
12
|
beforeEach(async () => {
|
|
13
|
-
runner = await
|
|
13
|
+
runner = await Tester.createInstance();
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
it("creates a function type", async () => {
|
|
17
|
-
const { getName } =
|
|
18
|
-
@test op getName(id: string): string;
|
|
19
|
-
`)
|
|
17
|
+
const { getName } = await runner.compile(t.code`
|
|
18
|
+
@test op ${t.op("getName")}(id: string): string;
|
|
19
|
+
`);
|
|
20
20
|
|
|
21
21
|
expect(
|
|
22
22
|
<Output program={runner.program}>
|
|
@@ -30,9 +30,9 @@ describe("function types with a `type` prop", () => {
|
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
it("creates an async function type", async () => {
|
|
33
|
-
const { getName } =
|
|
34
|
-
@test op getName(id: string): string;
|
|
35
|
-
`)
|
|
33
|
+
const { getName } = await runner.compile(t.code`
|
|
34
|
+
@test op ${t.op("getName")}(id: string): string;
|
|
35
|
+
`);
|
|
36
36
|
|
|
37
37
|
expect(
|
|
38
38
|
<Output program={runner.program}>
|
|
@@ -46,8 +46,8 @@ describe("function types with a `type` prop", () => {
|
|
|
46
46
|
});
|
|
47
47
|
|
|
48
48
|
it("can append extra parameters with raw params provided", async () => {
|
|
49
|
-
const { getName } = (await runner.compile(`
|
|
50
|
-
@test op getName(id: string): string;
|
|
49
|
+
const { getName } = (await runner.compile(t.code`
|
|
50
|
+
@test op ${t.op("getName")}(id: string): string;
|
|
51
51
|
`)) as { getName: Operation };
|
|
52
52
|
|
|
53
53
|
expect(
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { getProgram } from "#test/utils.js";
|
|
1
2
|
import { For, List } from "@alloy-js/core";
|
|
2
3
|
import { SourceFile } from "@alloy-js/typescript";
|
|
3
4
|
import type { Namespace } from "@typespec/compiler";
|
|
4
5
|
import { describe, expect, it } from "vitest";
|
|
5
6
|
import { Output } from "../../../src/core/components/output.jsx";
|
|
6
7
|
import { InterfaceDeclaration } from "../../../src/typescript/components/interface-declaration.js";
|
|
7
|
-
import { getProgram } from "../test-host.js";
|
|
8
8
|
|
|
9
9
|
describe("Typescript Interface", () => {
|
|
10
10
|
describe("Interface bound to Typespec Types", () => {
|
|
@@ -1,21 +1,22 @@
|
|
|
1
|
+
import { Tester } from "#test/test-host.js";
|
|
2
|
+
import { getProgram } from "#test/utils.js";
|
|
1
3
|
import { InterfaceDeclaration, SourceFile } from "@alloy-js/typescript";
|
|
2
4
|
import type { Operation } from "@typespec/compiler";
|
|
3
|
-
import type
|
|
5
|
+
import { t, type TesterInstance } from "@typespec/compiler/testing";
|
|
4
6
|
import { beforeEach, describe, expect, it } from "vitest";
|
|
5
7
|
import { Output } from "../../../src/core/components/output.jsx";
|
|
6
8
|
import { InterfaceMethod } from "../../../src/typescript/components/interface-method.jsx";
|
|
7
|
-
import { createEmitterFrameworkTestRunner, getProgram } from "../test-host.js";
|
|
8
9
|
|
|
9
10
|
describe("interface methods with a `type` prop", () => {
|
|
10
|
-
let runner:
|
|
11
|
+
let runner: TesterInstance;
|
|
11
12
|
|
|
12
13
|
beforeEach(async () => {
|
|
13
|
-
runner = await
|
|
14
|
+
runner = await Tester.createInstance();
|
|
14
15
|
});
|
|
15
16
|
|
|
16
17
|
it("creates a interface method", async () => {
|
|
17
|
-
const { getName } = (await runner.compile(`
|
|
18
|
-
@test op getName(id: string): string;
|
|
18
|
+
const { getName } = (await runner.compile(t.code`
|
|
19
|
+
@test op ${t.op("getName")}(id: string): string;
|
|
19
20
|
`)) as { getName: Operation };
|
|
20
21
|
|
|
21
22
|
expect(
|
|
@@ -34,9 +35,9 @@ describe("interface methods with a `type` prop", () => {
|
|
|
34
35
|
});
|
|
35
36
|
|
|
36
37
|
it("creates an async interface function", async () => {
|
|
37
|
-
const { getName } =
|
|
38
|
-
@test op getName(id: string): string;
|
|
39
|
-
`)
|
|
38
|
+
const { getName } = await runner.compile(t.code`
|
|
39
|
+
@test op ${t.op("getName")}(id: string): string;
|
|
40
|
+
`);
|
|
40
41
|
|
|
41
42
|
expect(
|
|
42
43
|
<Output program={runner.program}>
|
|
@@ -54,9 +55,9 @@ describe("interface methods with a `type` prop", () => {
|
|
|
54
55
|
});
|
|
55
56
|
|
|
56
57
|
it("can append extra parameters with raw params provided", async () => {
|
|
57
|
-
const { getName } =
|
|
58
|
-
@test op getName(id: string): string;
|
|
59
|
-
`)
|
|
58
|
+
const { getName } = await runner.compile(t.code`
|
|
59
|
+
@test op ${t.op("getName")}(id: string): string;
|
|
60
|
+
`);
|
|
60
61
|
|
|
61
62
|
expect(
|
|
62
63
|
<Output program={runner.program}>
|
|
@@ -78,9 +79,9 @@ describe("interface methods with a `type` prop", () => {
|
|
|
78
79
|
});
|
|
79
80
|
|
|
80
81
|
it("can prepend extra parameters with raw params provided", async () => {
|
|
81
|
-
const { getName } =
|
|
82
|
-
@test op getName(id: string): string;
|
|
83
|
-
`)
|
|
82
|
+
const { getName } = await runner.compile(t.code`
|
|
83
|
+
@test op ${t.op("getName")}(id: string): string;
|
|
84
|
+
`);
|
|
84
85
|
|
|
85
86
|
expect(
|
|
86
87
|
<Output program={runner.program}>
|
|
@@ -102,9 +103,9 @@ describe("interface methods with a `type` prop", () => {
|
|
|
102
103
|
});
|
|
103
104
|
|
|
104
105
|
it("can replace parameters with raw params provided", async () => {
|
|
105
|
-
const { getName } =
|
|
106
|
-
@test op getName(id: string): string;
|
|
107
|
-
`)
|
|
106
|
+
const { getName } = await runner.compile(t.code`
|
|
107
|
+
@test op ${t.op("getName")}(id: string): string;
|
|
108
|
+
`);
|
|
108
109
|
|
|
109
110
|
expect(
|
|
110
111
|
<Output program={runner.program}>
|
|
@@ -129,9 +130,9 @@ describe("interface methods with a `type` prop", () => {
|
|
|
129
130
|
});
|
|
130
131
|
|
|
131
132
|
it("can override return type", async () => {
|
|
132
|
-
const { getName } =
|
|
133
|
-
@test op getName(id: string): string;
|
|
134
|
-
`)
|
|
133
|
+
const { getName } = await runner.compile(t.code`
|
|
134
|
+
@test op ${t.op("getName")}(id: string): string;
|
|
135
|
+
`);
|
|
135
136
|
|
|
136
137
|
expect(
|
|
137
138
|
<Output program={runner.program}>
|
|
@@ -149,9 +150,9 @@ describe("interface methods with a `type` prop", () => {
|
|
|
149
150
|
});
|
|
150
151
|
|
|
151
152
|
it("can override method name", async () => {
|
|
152
|
-
const { getName } =
|
|
153
|
-
@test op getName(id: string): string;
|
|
154
|
-
`)
|
|
153
|
+
const { getName } = await runner.compile(t.code`
|
|
154
|
+
@test op ${t.op("getName")}(id: string): string;
|
|
155
|
+
`);
|
|
155
156
|
|
|
156
157
|
expect(
|
|
157
158
|
<Output program={runner.program}>
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { Tester } from "#test/test-host.js";
|
|
2
|
+
import { getProgram } from "#test/utils.js";
|
|
1
3
|
import { SourceFile } from "@alloy-js/typescript";
|
|
2
|
-
import type { Namespace
|
|
4
|
+
import type { Namespace } from "@typespec/compiler";
|
|
5
|
+
import { t } from "@typespec/compiler/testing";
|
|
3
6
|
import { describe, expect, it } from "vitest";
|
|
4
7
|
import { Output } from "../../../src/core/components/output.jsx";
|
|
5
8
|
import { TypeAliasDeclaration } from "../../../src/typescript/components/type-alias-declaration.jsx";
|
|
6
|
-
import { createEmitterFrameworkTestRunner, getProgram } from "../test-host.js";
|
|
7
9
|
|
|
8
10
|
describe("Typescript Type Alias Declaration", () => {
|
|
9
11
|
describe("Type Alias bound to Typespec Scalar", () => {
|
|
@@ -136,10 +138,10 @@ describe("Typescript Type Alias Declaration", () => {
|
|
|
136
138
|
});
|
|
137
139
|
|
|
138
140
|
it("creates a type alias of a function", async () => {
|
|
139
|
-
const runner = await
|
|
140
|
-
const { getName } =
|
|
141
|
-
@test op
|
|
142
|
-
`)
|
|
141
|
+
const runner = await Tester.createInstance();
|
|
142
|
+
const { getName } = await runner.compile(t.code`
|
|
143
|
+
@test op ${t.op("getName")}(id: string): string;
|
|
144
|
+
`);
|
|
143
145
|
|
|
144
146
|
expect(
|
|
145
147
|
<Output program={runner.program}>
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { Tester } from "#test/test-host.js";
|
|
1
2
|
import { code, Output } from "@alloy-js/core";
|
|
2
3
|
import * as ts from "@alloy-js/typescript";
|
|
3
4
|
import { SourceFile } from "@alloy-js/typescript";
|
|
4
5
|
import type { Model } from "@typespec/compiler";
|
|
5
|
-
import type
|
|
6
|
+
import { t, type TesterInstance } from "@typespec/compiler/testing";
|
|
6
7
|
import { beforeEach, describe, expect, it } from "vitest";
|
|
7
8
|
import {
|
|
8
9
|
ArraySerializer,
|
|
@@ -16,27 +17,26 @@ import {
|
|
|
16
17
|
TypeTransformDeclaration,
|
|
17
18
|
} from "../../../src/typescript/components/type-transform.js";
|
|
18
19
|
import { TypeDeclaration } from "../../../src/typescript/index.js";
|
|
19
|
-
import { createEmitterFrameworkTestRunner } from "../test-host.js";
|
|
20
20
|
|
|
21
21
|
describe.skip("Typescript Type Transform", () => {
|
|
22
|
-
let testRunner:
|
|
22
|
+
let testRunner: TesterInstance;
|
|
23
23
|
const namePolicy = ts.createTSNamePolicy();
|
|
24
24
|
beforeEach(async () => {
|
|
25
|
-
testRunner = await
|
|
25
|
+
testRunner = await Tester.createInstance();
|
|
26
26
|
});
|
|
27
27
|
describe("Model Transforms", () => {
|
|
28
28
|
describe("ModelTransformExpression", () => {
|
|
29
29
|
it("should render a transform expression to client", async () => {
|
|
30
|
-
const spec = `
|
|
30
|
+
const spec = t.code`
|
|
31
31
|
namespace DemoService;
|
|
32
|
-
@test model Widget {
|
|
32
|
+
@test model ${t.model("Widget")} {
|
|
33
33
|
id: string;
|
|
34
34
|
birth_year: int32;
|
|
35
35
|
color: "blue" | "red";
|
|
36
36
|
}
|
|
37
37
|
`;
|
|
38
38
|
|
|
39
|
-
const { Widget } =
|
|
39
|
+
const { Widget } = await testRunner.compile(spec);
|
|
40
40
|
|
|
41
41
|
expect(
|
|
42
42
|
<Output namePolicy={namePolicy}>
|
|
@@ -62,16 +62,16 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
62
62
|
});
|
|
63
63
|
|
|
64
64
|
it("should render a transform expression to wire", async () => {
|
|
65
|
-
const spec = `
|
|
65
|
+
const spec = t.code`
|
|
66
66
|
namespace DemoService;
|
|
67
|
-
@test model Widget {
|
|
67
|
+
@test model ${t.model("Widget")} {
|
|
68
68
|
id: string;
|
|
69
69
|
birth_year: int32;
|
|
70
70
|
color: "blue" | "red";
|
|
71
71
|
}
|
|
72
72
|
`;
|
|
73
73
|
|
|
74
|
-
const { Widget } =
|
|
74
|
+
const { Widget } = await testRunner.compile(spec);
|
|
75
75
|
|
|
76
76
|
expect(
|
|
77
77
|
<Output namePolicy={namePolicy}>
|
|
@@ -97,9 +97,9 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
97
97
|
});
|
|
98
98
|
|
|
99
99
|
it("should render a transform expression that contains a utcDateTime to client", async () => {
|
|
100
|
-
const spec = `
|
|
100
|
+
const spec = t.code`
|
|
101
101
|
namespace DemoService;
|
|
102
|
-
@test model Widget {
|
|
102
|
+
@test model ${t.model("Widget")} {
|
|
103
103
|
id: string;
|
|
104
104
|
birth_date: utcDateTime;
|
|
105
105
|
color: "blue" | "red";
|
|
@@ -139,9 +139,9 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
139
139
|
|
|
140
140
|
describe("TypeTransformDeclaration", () => {
|
|
141
141
|
it("should render a transform functions for a model containing array", async () => {
|
|
142
|
-
const spec = `
|
|
142
|
+
const spec = t.code`
|
|
143
143
|
namespace DemoService;
|
|
144
|
-
@test model Widget {
|
|
144
|
+
@test model ${t.model("Widget")} {
|
|
145
145
|
id: string;
|
|
146
146
|
my_color: "blue" | "red";
|
|
147
147
|
simple?: string[];
|
|
@@ -151,7 +151,7 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
151
151
|
}
|
|
152
152
|
`;
|
|
153
153
|
|
|
154
|
-
const { Widget } =
|
|
154
|
+
const { Widget } = await testRunner.compile(spec);
|
|
155
155
|
|
|
156
156
|
expect(
|
|
157
157
|
<Output namePolicy={namePolicy}>
|
|
@@ -198,9 +198,9 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
198
198
|
`);
|
|
199
199
|
});
|
|
200
200
|
it("should render a transform functions for a model containing record", async () => {
|
|
201
|
-
const spec = `
|
|
201
|
+
const spec = t.code`
|
|
202
202
|
namespace DemoService;
|
|
203
|
-
@test model Widget {
|
|
203
|
+
@test model ${t.model("Widget")} {
|
|
204
204
|
id: string;
|
|
205
205
|
my_color: "blue" | "red";
|
|
206
206
|
simple: Record<string>;
|
|
@@ -209,7 +209,7 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
209
209
|
}
|
|
210
210
|
`;
|
|
211
211
|
|
|
212
|
-
const { Widget } =
|
|
212
|
+
const { Widget } = await testRunner.compile(spec);
|
|
213
213
|
|
|
214
214
|
expect(
|
|
215
215
|
<Output namePolicy={namePolicy}>
|
|
@@ -253,15 +253,15 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
253
253
|
`);
|
|
254
254
|
});
|
|
255
255
|
it("should render a transform functions for a model", async () => {
|
|
256
|
-
const spec = `
|
|
256
|
+
const spec = t.code`
|
|
257
257
|
namespace DemoService;
|
|
258
|
-
@test model Widget {
|
|
258
|
+
@test model ${t.model("Widget")} {
|
|
259
259
|
id: string;
|
|
260
260
|
my_color: "blue" | "red";
|
|
261
261
|
}
|
|
262
262
|
`;
|
|
263
263
|
|
|
264
|
-
const { Widget } =
|
|
264
|
+
const { Widget } = await testRunner.compile(spec);
|
|
265
265
|
|
|
266
266
|
expect(
|
|
267
267
|
<Output namePolicy={namePolicy}>
|
|
@@ -293,14 +293,14 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
293
293
|
});
|
|
294
294
|
describe("Calling a model transform functions", () => {
|
|
295
295
|
it("should collapse a model with single property", async () => {
|
|
296
|
-
const spec = `
|
|
296
|
+
const spec = t.code`
|
|
297
297
|
namespace DemoService;
|
|
298
|
-
@test model Widget {
|
|
298
|
+
@test model ${t.model("Widget")} {
|
|
299
299
|
id: string;
|
|
300
300
|
}
|
|
301
301
|
`;
|
|
302
302
|
|
|
303
|
-
const { Widget } =
|
|
303
|
+
const { Widget } = await testRunner.compile(spec);
|
|
304
304
|
|
|
305
305
|
expect(
|
|
306
306
|
<Output namePolicy={namePolicy}>
|
|
@@ -318,15 +318,15 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
318
318
|
});
|
|
319
319
|
|
|
320
320
|
it("should call transform functions for a model", async () => {
|
|
321
|
-
const spec = `
|
|
321
|
+
const spec = t.code`
|
|
322
322
|
namespace DemoService;
|
|
323
|
-
@test model Widget {
|
|
323
|
+
@test model ${t.model("Widget")} {
|
|
324
324
|
id: string;
|
|
325
325
|
my_color: "blue" | "red";
|
|
326
326
|
}
|
|
327
327
|
`;
|
|
328
328
|
|
|
329
|
-
const { Widget } =
|
|
329
|
+
const { Widget } = await testRunner.compile(spec);
|
|
330
330
|
|
|
331
331
|
expect(
|
|
332
332
|
<Output namePolicy={namePolicy}>
|
|
@@ -356,20 +356,20 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
356
356
|
|
|
357
357
|
describe("Discriminated Model Transforms", () => {
|
|
358
358
|
it("should handle a discriminated union", async () => {
|
|
359
|
-
const { Pet, Cat, Dog } =
|
|
359
|
+
const { Pet, Cat, Dog } = await testRunner.compile(t.code`
|
|
360
360
|
@discriminator("kind")
|
|
361
|
-
@test model Pet {
|
|
361
|
+
@test model ${t.model("Pet")} {
|
|
362
362
|
kind: string;
|
|
363
363
|
}
|
|
364
364
|
|
|
365
|
-
@test model Cat extends Pet {
|
|
365
|
+
@test model ${t.model("Cat")} extends Pet {
|
|
366
366
|
kind: "cat";
|
|
367
367
|
}
|
|
368
368
|
|
|
369
|
-
@test model Dog extends Pet {
|
|
369
|
+
@test model ${t.model("Dog")} extends Pet {
|
|
370
370
|
kind: "dog";
|
|
371
371
|
}
|
|
372
|
-
`)
|
|
372
|
+
`);
|
|
373
373
|
|
|
374
374
|
expect(
|
|
375
375
|
<Output namePolicy={namePolicy}>
|
|
@@ -436,21 +436,21 @@ describe.skip("Typescript Type Transform", () => {
|
|
|
436
436
|
});
|
|
437
437
|
describe("Discriminated Union Transforms", () => {
|
|
438
438
|
it("should handle a discriminated union", async () => {
|
|
439
|
-
const { Pet, Cat, Dog } =
|
|
439
|
+
const { Pet, Cat, Dog } = await testRunner.compile(t.code`
|
|
440
440
|
@discriminator("kind")
|
|
441
|
-
@test union Pet
|
|
441
|
+
@test union ${t.union("Pet")}{
|
|
442
442
|
cat: Cat;
|
|
443
443
|
dog: Dog;
|
|
444
444
|
}
|
|
445
445
|
|
|
446
|
-
@test model Cat
|
|
446
|
+
@test model ${t.model("Cat")} {
|
|
447
447
|
kind: "cat";
|
|
448
448
|
}
|
|
449
449
|
|
|
450
|
-
@test model Dog {
|
|
450
|
+
@test model ${t.model("Dog")} {
|
|
451
451
|
kind: "dog";
|
|
452
452
|
}
|
|
453
|
-
`)
|
|
453
|
+
`);
|
|
454
454
|
|
|
455
455
|
expect(
|
|
456
456
|
<Output namePolicy={namePolicy}>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getProgram } from "#test/utils.js";
|
|
1
2
|
import { Output } from "@alloy-js/core";
|
|
2
3
|
import { dedent } from "@alloy-js/core/testing";
|
|
3
4
|
import { SourceFile } from "@alloy-js/typescript";
|
|
@@ -13,7 +14,6 @@ import {
|
|
|
13
14
|
import { $ } from "@typespec/compiler/typekit";
|
|
14
15
|
import { assert, beforeAll, describe, expect, it } from "vitest";
|
|
15
16
|
import { ValueExpression } from "../../../src/typescript/components/value-expression.js";
|
|
16
|
-
import { getProgram } from "../test-host.js";
|
|
17
17
|
|
|
18
18
|
let program: Program;
|
|
19
19
|
beforeAll(async () => {
|
package/test/utils.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
+
import { Tester } from "#test/test-host.js";
|
|
1
2
|
import { type Children, type OutputDirectory, render } from "@alloy-js/core";
|
|
2
3
|
import { Output } from "@alloy-js/core/stc";
|
|
3
4
|
import { SourceFile } from "@alloy-js/typescript/stc";
|
|
4
5
|
import type { Program } from "@typespec/compiler";
|
|
5
6
|
import { assert } from "vitest";
|
|
6
|
-
import { getProgram } from "./typescript/test-host.js";
|
|
7
7
|
|
|
8
8
|
export async function getEmitOutput(tspCode: string, cb: (program: Program) => Children) {
|
|
9
9
|
const program = await getProgram(tspCode);
|
|
10
|
-
|
|
11
10
|
const res = render(Output().children(SourceFile({ path: "test.ts" }).children(cb(program))), {
|
|
12
11
|
insertFinalNewLine: false,
|
|
13
12
|
});
|
|
@@ -16,6 +15,12 @@ export async function getEmitOutput(tspCode: string, cb: (program: Program) => C
|
|
|
16
15
|
return testFile.contents;
|
|
17
16
|
}
|
|
18
17
|
|
|
18
|
+
export async function getProgram(tspCode: string) {
|
|
19
|
+
const runner = await Tester.createInstance();
|
|
20
|
+
const { program } = await runner.compile(tspCode);
|
|
21
|
+
return program;
|
|
22
|
+
}
|
|
23
|
+
|
|
19
24
|
export function assertFileContents(res: OutputDirectory, contents: string) {
|
|
20
25
|
const testFile = res.contents.find((file) => file.path === "test.ts")!;
|
|
21
26
|
assert(testFile, "test.ts file not rendered");
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { Program } from "@typespec/compiler";
|
|
2
|
-
export declare function createTypespecCliTestHost(): Promise<import("@typespec/compiler/testing").TestHost>;
|
|
3
|
-
export declare function createEmitterFrameworkTestRunner(options?: {
|
|
4
|
-
autoUsings?: string[];
|
|
5
|
-
}): Promise<import("@typespec/compiler/testing").BasicTestRunner>;
|
|
6
|
-
export declare function getProgram(code: string): Promise<Program>;
|
|
7
|
-
/**
|
|
8
|
-
* Initializes an empty program in the compiler.
|
|
9
|
-
* This is useful when you want to initialize the default TypeKits without any code.
|
|
10
|
-
*/
|
|
11
|
-
export declare function initEmptyProgram(): Promise<void>;
|
|
12
|
-
//# sourceMappingURL=test-host.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"test-host.d.ts","sourceRoot":"","sources":["../../../test/typescript/test-host.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAOlD,wBAAsB,yBAAyB,2DAE9C;AAED,wBAAsB,gCAAgC,CAAC,OAAO,GAAE;IAAE,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;CAAO,iEAK7F;AAED,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAU/D;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAEtD"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { createTestHost, createTestWrapper, expectDiagnosticEmpty } from "@typespec/compiler/testing";
|
|
2
|
-
export async function createTypespecCliTestHost() {
|
|
3
|
-
return createTestHost({});
|
|
4
|
-
}
|
|
5
|
-
export async function createEmitterFrameworkTestRunner(options = {}) {
|
|
6
|
-
const host = await createTypespecCliTestHost();
|
|
7
|
-
return createTestWrapper(host, {
|
|
8
|
-
autoUsings: options.autoUsings
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
export async function getProgram(code) {
|
|
12
|
-
const host = await createTypespecCliTestHost();
|
|
13
|
-
const wrapper = createTestWrapper(host, {
|
|
14
|
-
compilerOptions: {
|
|
15
|
-
noEmit: true
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
const [_, diagnostics] = await wrapper.compileAndDiagnose(code);
|
|
19
|
-
expectDiagnosticEmpty(diagnostics);
|
|
20
|
-
return wrapper.program;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Initializes an empty program in the compiler.
|
|
25
|
-
* This is useful when you want to initialize the default TypeKits without any code.
|
|
26
|
-
*/
|
|
27
|
-
export async function initEmptyProgram() {
|
|
28
|
-
await getProgram("");
|
|
29
|
-
}
|
|
30
|
-
//# sourceMappingURL=test-host.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["createTestHost","createTestWrapper","expectDiagnosticEmpty","createTypespecCliTestHost","createEmitterFrameworkTestRunner","options","host","autoUsings","getProgram","code","wrapper","compilerOptions","noEmit","_","diagnostics","compileAndDiagnose","program","initEmptyProgram"],"sources":["../../../test/typescript/test-host.ts"],"sourcesContent":[null],"mappings":"AACA,SACEA,cAAc,EACdC,iBAAiB,EACjBC,qBAAqB,QAChB,4BAA4B;AAEnC,OAAO,eAAeC,yBAAyBA,CAAA,EAAG;EAChD,OAAOH,cAAc,CAAC,CAAC,CAAC,CAAC;AAC3B;AAEA,OAAO,eAAeI,gCAAgCA,CAACC,OAAkC,GAAG,CAAC,CAAC,EAAE;EAC9F,MAAMC,IAAI,GAAG,MAAMH,yBAAyB,CAAC,CAAC;EAC9C,OAAOF,iBAAiB,CAACK,IAAI,EAAE;IAC7BC,UAAU,EAAEF,OAAO,CAACE;EACtB,CAAC,CAAC;AACJ;AAEA,OAAO,eAAeC,UAAUA,CAACC,IAAY,EAAoB;EAC/D,MAAMH,IAAI,GAAG,MAAMH,yBAAyB,CAAC,CAAC;EAC9C,MAAMO,OAAO,GAAGT,iBAAiB,CAACK,IAAI,EAAE;IACtCK,eAAe,EAAE;MACfC,MAAM,EAAE;IACV;EACF,CAAC,CAAC;EACF,MAAM,CAACC,CAAC,EAAEC,WAAW,CAAC,GAAG,MAAMJ,OAAO,CAACK,kBAAkB,CAACN,IAAI,CAAC;EAC/DP,qBAAqB,CAACY,WAAW,CAAC;EAClC,OAAOJ,OAAO,CAACM,OAAO;AACxB;;AAEA;AACA;AACA;AACA;AACA,OAAO,eAAeC,gBAAgBA,CAAA,EAAkB;EACtD,MAAMT,UAAU,CAAC,EAAE,CAAC;AACtB","ignoreList":[]}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { Program } from "@typespec/compiler";
|
|
2
|
-
import {
|
|
3
|
-
createTestHost,
|
|
4
|
-
createTestWrapper,
|
|
5
|
-
expectDiagnosticEmpty,
|
|
6
|
-
} from "@typespec/compiler/testing";
|
|
7
|
-
|
|
8
|
-
export async function createTypespecCliTestHost() {
|
|
9
|
-
return createTestHost({});
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export async function createEmitterFrameworkTestRunner(options: { autoUsings?: string[] } = {}) {
|
|
13
|
-
const host = await createTypespecCliTestHost();
|
|
14
|
-
return createTestWrapper(host, {
|
|
15
|
-
autoUsings: options.autoUsings,
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export async function getProgram(code: string): Promise<Program> {
|
|
20
|
-
const host = await createTypespecCliTestHost();
|
|
21
|
-
const wrapper = createTestWrapper(host, {
|
|
22
|
-
compilerOptions: {
|
|
23
|
-
noEmit: true,
|
|
24
|
-
},
|
|
25
|
-
});
|
|
26
|
-
const [_, diagnostics] = await wrapper.compileAndDiagnose(code);
|
|
27
|
-
expectDiagnosticEmpty(diagnostics);
|
|
28
|
-
return wrapper.program;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Initializes an empty program in the compiler.
|
|
33
|
-
* This is useful when you want to initialize the default TypeKits without any code.
|
|
34
|
-
*/
|
|
35
|
-
export async function initEmptyProgram(): Promise<void> {
|
|
36
|
-
await getProgram("");
|
|
37
|
-
}
|