@typespec/emitter-framework 0.11.0-dev.8 → 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/class/declaration.js +1 -1
- package/dist/src/csharp/components/class/declaration.js.map +1 -1
- package/dist/src/csharp/components/class/declaration.test.js +3 -0
- package/dist/src/csharp/components/class/declaration.test.js.map +1 -1
- package/dist/src/csharp/components/type-expression.test.js +13 -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/class/declaration.test.tsx +3 -0
- package/src/csharp/components/class/declaration.tsx +1 -1
- package/src/csharp/components/type-expression.test.tsx +18 -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,17 +1,17 @@
|
|
|
1
|
+
import { Tester } from "#test/test-host.js";
|
|
1
2
|
import { type Children } from "@alloy-js/core";
|
|
2
3
|
import { SourceFile } from "@alloy-js/csharp";
|
|
3
|
-
import type {
|
|
4
|
-
import type
|
|
4
|
+
import type { ModelProperty } from "@typespec/compiler";
|
|
5
|
+
import { t, type TesterInstance } from "@typespec/compiler/testing";
|
|
5
6
|
import { beforeEach, describe, expect, it } from "vitest";
|
|
6
|
-
import { createEmitterFrameworkTestRunner } from "../../../test/typescript/test-host.js";
|
|
7
7
|
import { Output } from "../../core/index.js";
|
|
8
8
|
import { ClassDeclaration } from "./class/declaration.js";
|
|
9
9
|
import { TypeExpression } from "./type-expression.jsx";
|
|
10
10
|
|
|
11
|
-
let runner:
|
|
11
|
+
let runner: TesterInstance;
|
|
12
12
|
|
|
13
13
|
beforeEach(async () => {
|
|
14
|
-
runner = await
|
|
14
|
+
runner = await Tester.createInstance();
|
|
15
15
|
});
|
|
16
16
|
|
|
17
17
|
function Wrapper(props: { children: Children }) {
|
|
@@ -73,12 +73,12 @@ describe("Record map to IDictionary", () => {
|
|
|
73
73
|
});
|
|
74
74
|
|
|
75
75
|
it("for models", async () => {
|
|
76
|
-
const { test, Pet } =
|
|
76
|
+
const { test, Pet } = await runner.compile(t.code`
|
|
77
77
|
model Test {
|
|
78
|
-
|
|
78
|
+
${t.modelProperty("test")}: Record<Pet>;
|
|
79
79
|
}
|
|
80
|
-
@test model Pet {}
|
|
81
|
-
`)
|
|
80
|
+
@test model ${t.model("Pet")} {}
|
|
81
|
+
`);
|
|
82
82
|
|
|
83
83
|
expect(
|
|
84
84
|
<Wrapper>
|
|
@@ -98,11 +98,11 @@ describe("Record map to IDictionary", () => {
|
|
|
98
98
|
|
|
99
99
|
describe("Nullable union", () => {
|
|
100
100
|
it("nullable boolean", async () => {
|
|
101
|
-
const { Pet } =
|
|
102
|
-
@test model Pet {
|
|
101
|
+
const { Pet } = await runner.compile(t.code`
|
|
102
|
+
@test model ${t.model("Pet")} {
|
|
103
103
|
@test name: boolean | null;
|
|
104
104
|
}
|
|
105
|
-
`)
|
|
105
|
+
`);
|
|
106
106
|
|
|
107
107
|
expect(
|
|
108
108
|
<Wrapper>
|
|
@@ -119,14 +119,14 @@ describe("Nullable union", () => {
|
|
|
119
119
|
|
|
120
120
|
describe("Literal types", () => {
|
|
121
121
|
it("literal types (string, int, double, bool)", async () => {
|
|
122
|
-
const { Pet } =
|
|
123
|
-
@test model Pet {
|
|
122
|
+
const { Pet } = await runner.compile(t.code`
|
|
123
|
+
@test model ${t.model("Pet")} {
|
|
124
124
|
@test boolName: true;
|
|
125
125
|
@test intName: 42;
|
|
126
126
|
@test doubleName: 3.14;
|
|
127
127
|
@test stringName: "Hello";
|
|
128
128
|
}
|
|
129
|
-
`)
|
|
129
|
+
`);
|
|
130
130
|
|
|
131
131
|
expect(
|
|
132
132
|
<Wrapper>
|
|
@@ -136,8 +136,11 @@ describe("Literal types", () => {
|
|
|
136
136
|
class Pet
|
|
137
137
|
{
|
|
138
138
|
public required bool boolName { get; set; }
|
|
139
|
+
|
|
139
140
|
public required int intName { get; set; }
|
|
141
|
+
|
|
140
142
|
public required double doubleName { get; set; }
|
|
143
|
+
|
|
141
144
|
public required string stringName { get; set; }
|
|
142
145
|
}
|
|
143
146
|
`);
|
|
@@ -1,22 +1,21 @@
|
|
|
1
|
+
import { Tester } from "#test/test-host.js";
|
|
1
2
|
import { SourceFile } from "@alloy-js/typescript";
|
|
2
|
-
import type
|
|
3
|
-
import type { BasicTestRunner } from "@typespec/compiler/testing";
|
|
3
|
+
import { type TesterInstance, t } from "@typespec/compiler/testing";
|
|
4
4
|
import { beforeEach, describe, expect, it } from "vitest";
|
|
5
5
|
import { Output } from "../../../src/core/components/output.jsx";
|
|
6
6
|
import { ArrowFunction } from "../../../src/typescript/components/arrow-function.jsx";
|
|
7
|
-
import { createEmitterFrameworkTestRunner } from "../test-host.js";
|
|
8
7
|
|
|
9
8
|
describe("arrow functions with a `type` prop", () => {
|
|
10
|
-
let runner:
|
|
9
|
+
let runner: TesterInstance;
|
|
11
10
|
|
|
12
11
|
beforeEach(async () => {
|
|
13
|
-
runner = await
|
|
12
|
+
runner = await Tester.createInstance();
|
|
14
13
|
});
|
|
15
14
|
|
|
16
15
|
it("creates a function", async () => {
|
|
17
|
-
const { getName } =
|
|
18
|
-
@test op getName(id: string): string;
|
|
19
|
-
`)
|
|
16
|
+
const { getName } = await runner.compile(t.code`
|
|
17
|
+
@test op ${t.op("getName")}(id: string): string;
|
|
18
|
+
`);
|
|
20
19
|
|
|
21
20
|
expect(
|
|
22
21
|
<Output program={runner.program}>
|
|
@@ -32,9 +31,9 @@ describe("arrow functions with a `type` prop", () => {
|
|
|
32
31
|
});
|
|
33
32
|
|
|
34
33
|
it("creates an async function", async () => {
|
|
35
|
-
const { getName } =
|
|
36
|
-
@test op getName(id: string): string;
|
|
37
|
-
`)
|
|
34
|
+
const { getName } = await runner.compile(t.code`
|
|
35
|
+
@test op ${t.op("getName")}(id: string): string;
|
|
36
|
+
`);
|
|
38
37
|
|
|
39
38
|
expect(
|
|
40
39
|
<Output program={runner.program}>
|
|
@@ -48,9 +47,9 @@ describe("arrow functions with a `type` prop", () => {
|
|
|
48
47
|
});
|
|
49
48
|
|
|
50
49
|
it("can append extra parameters with raw params provided", async () => {
|
|
51
|
-
const { getName } =
|
|
52
|
-
@test op getName(id: string): string;
|
|
53
|
-
`)
|
|
50
|
+
const { getName } = await runner.compile(t.code`
|
|
51
|
+
@test op ${t.op("getName")}(id: string): string;
|
|
52
|
+
`);
|
|
54
53
|
|
|
55
54
|
expect(
|
|
56
55
|
<Output program={runner.program}>
|
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
Experimental_ComponentOverrides,
|
|
3
3
|
Experimental_ComponentOverridesConfig,
|
|
4
4
|
} from "#core/index.js";
|
|
5
|
+
import { Tester } from "#test/test-host.js";
|
|
5
6
|
import { FunctionDeclaration } from "#typescript/index.js";
|
|
6
7
|
import { For, List, type Children } from "@alloy-js/core";
|
|
7
8
|
import { d } from "@alloy-js/core/testing";
|
|
@@ -10,7 +11,6 @@ import type { Namespace } from "@typespec/compiler";
|
|
|
10
11
|
import { expect, it } from "vitest";
|
|
11
12
|
import { Output } from "../../../src/core/components/output.jsx";
|
|
12
13
|
import { InterfaceDeclaration } from "../../../src/typescript/components/interface-declaration.jsx";
|
|
13
|
-
import { Tester } from "../../test-host.js";
|
|
14
14
|
|
|
15
15
|
it("uses overridden component", async () => {
|
|
16
16
|
const { program } = await Tester.compile(`
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getProgram } from "#test/utils.js";
|
|
1
2
|
import { code } from "@alloy-js/core";
|
|
2
3
|
import { d } from "@alloy-js/core/testing";
|
|
3
4
|
import { SourceFile } from "@alloy-js/typescript";
|
|
@@ -5,7 +6,7 @@ import type { Namespace } from "@typespec/compiler";
|
|
|
5
6
|
import { describe, expect, it } from "vitest";
|
|
6
7
|
import { Output } from "../../../src/core/components/output.jsx";
|
|
7
8
|
import { FunctionDeclaration } from "../../../src/typescript/components/function-declaration.js";
|
|
8
|
-
|
|
9
|
+
|
|
9
10
|
describe("Typescript Function Declaration", () => {
|
|
10
11
|
describe("Function bound to Typespec Types", () => {
|
|
11
12
|
describe("Bound to Operation", () => {
|
|
@@ -1,22 +1,21 @@
|
|
|
1
|
+
import { Tester } from "#test/test-host.js";
|
|
1
2
|
import { SourceFile } from "@alloy-js/typescript";
|
|
2
|
-
import type
|
|
3
|
-
import type { BasicTestRunner } from "@typespec/compiler/testing";
|
|
3
|
+
import { t, type TesterInstance } from "@typespec/compiler/testing";
|
|
4
4
|
import { beforeEach, describe, expect, it } from "vitest";
|
|
5
5
|
import { Output } from "../../../src/core/components/output.jsx";
|
|
6
6
|
import { FunctionExpression } from "../../../src/typescript/components/function-expression.jsx";
|
|
7
|
-
import { createEmitterFrameworkTestRunner } from "../test-host.js";
|
|
8
7
|
|
|
9
8
|
describe("function expressions with a `type` prop", () => {
|
|
10
|
-
let runner:
|
|
9
|
+
let runner: TesterInstance;
|
|
11
10
|
|
|
12
11
|
beforeEach(async () => {
|
|
13
|
-
runner = await
|
|
12
|
+
runner = await Tester.createInstance();
|
|
14
13
|
});
|
|
15
14
|
|
|
16
15
|
it("creates a function", async () => {
|
|
17
|
-
const { getName } =
|
|
18
|
-
@test op getName(id: string): string;
|
|
19
|
-
`)
|
|
16
|
+
const { getName } = await runner.compile(t.code`
|
|
17
|
+
@test op ${t.op("getName")}(id: string): string;
|
|
18
|
+
`);
|
|
20
19
|
|
|
21
20
|
expect(
|
|
22
21
|
<Output program={runner.program}>
|
|
@@ -32,9 +31,9 @@ describe("function expressions with a `type` prop", () => {
|
|
|
32
31
|
});
|
|
33
32
|
|
|
34
33
|
it("creates an async function", async () => {
|
|
35
|
-
const { getName } =
|
|
36
|
-
@test op getName(id: string): string;
|
|
37
|
-
`)
|
|
34
|
+
const { getName } = await runner.compile(t.code`
|
|
35
|
+
@test op ${t.op("getName")}(id: string): string;
|
|
36
|
+
`);
|
|
38
37
|
|
|
39
38
|
expect(
|
|
40
39
|
<Output program={runner.program}>
|
|
@@ -48,9 +47,9 @@ describe("function expressions with a `type` prop", () => {
|
|
|
48
47
|
});
|
|
49
48
|
|
|
50
49
|
it("can append extra parameters with raw params provided", async () => {
|
|
51
|
-
const { getName } =
|
|
52
|
-
@test op getName(id: string): string;
|
|
53
|
-
`)
|
|
50
|
+
const { getName } = await runner.compile(t.code`
|
|
51
|
+
@test op ${t.op("getName")}(id: string): string;
|
|
52
|
+
`);
|
|
54
53
|
|
|
55
54
|
expect(
|
|
56
55
|
<Output program={runner.program}>
|
|
@@ -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 () => {
|