Skip to content

Commit 23f34aa

Browse files
authored
test: apply api.d.ts validations in all packages (#112)
1 parent fb7c396 commit 23f34aa

File tree

6 files changed

+90
-14
lines changed

6 files changed

+90
-14
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import * as publicApi from "../api";
2+
import * as implementation from "../src/api";
3+
4+
// https://www.typescriptlang.org/docs/handbook/generics.html#generic-constraints
5+
type AssertIsSubSet<SUBSET extends SUPERSET, SUPERSET> = [SUBSET, SUPERSET];
6+
7+
// TODO: export these helper types from test-utils
8+
// Because TypeScript uses a Structural Typing system
9+
// We can perform logical assertions on the API vs Impel
10+
// using discrete math semantics (subsets/supersets)
11+
// See: https://www.typescriptlang.org/docs/handbook/type-compatibility.html
12+
type EnsureAllDeclaredAreExposedAtRuntime = AssertIsSubSet<
13+
typeof implementation,
14+
typeof publicApi
15+
>;
16+
17+
type EnsureNoRedundantAreExposedAtRuntime = AssertIsSubSet<
18+
typeof publicApi,
19+
typeof implementation
20+
>;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import * as publicApi from "../api";
2+
import * as implementation from "../src/api";
3+
4+
// https://www.typescriptlang.org/docs/handbook/generics.html#generic-constraints
5+
type AssertIsSubSet<SUBSET extends SUPERSET, SUPERSET> = [SUBSET, SUPERSET];
6+
7+
// TODO: export these helper types from test-utils
8+
// Because TypeScript uses a Structural Typing system
9+
// We can perform logical assertions on the API vs Impel
10+
// using discrete math semantics (subsets/supersets)
11+
// See: https://www.typescriptlang.org/docs/handbook/type-compatibility.html
12+
type EnsureAllDeclaredAreExposedAtRuntime = AssertIsSubSet<
13+
typeof implementation,
14+
typeof publicApi
15+
>;
16+
17+
type EnsureNoRedundantAreExposedAtRuntime = AssertIsSubSet<
18+
typeof publicApi,
19+
typeof implementation
20+
>;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import * as publicApi from "../api";
2+
import * as implementation from "../src/api";
3+
4+
// https://www.typescriptlang.org/docs/handbook/generics.html#generic-constraints
5+
type AssertIsSubSet<SUBSET extends SUPERSET, SUPERSET> = [SUBSET, SUPERSET];
6+
7+
// TODO: export these helper types from test-utils
8+
// Because TypeScript uses a Structural Typing system
9+
// We can perform logical assertions on the API vs Impel
10+
// using discrete math semantics (subsets/supersets)
11+
// See: https://www.typescriptlang.org/docs/handbook/type-compatibility.html
12+
type EnsureAllDeclaredAreExposedAtRuntime = AssertIsSubSet<
13+
typeof implementation,
14+
typeof publicApi
15+
>;
16+
17+
type EnsureNoRedundantAreExposedAtRuntime = AssertIsSubSet<
18+
typeof publicApi,
19+
typeof implementation
20+
>;

test-packages/test-utils/api.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,10 @@ export function expectXMLAttribute(
109109

110110
export function isObject(value: unknown): value is Record<string, unknown>;
111111

112-
export function getFQN(model: UI5SemanticModel, target: unknown): string;
112+
export function getFQN(
113+
model: UI5SemanticModel,
114+
target: unknown
115+
): string | undefined;
113116

114117
export function expectExists(value: unknown, message: string): asserts value;
115118

test-packages/test-utils/src/utils/semantic-model-builder.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ import {
1515
UI5Field,
1616
UI5EnumValue,
1717
UI5DeprecatedInfo,
18+
UI5Association,
1819
} from "@ui5-language-assistant/semantic-model-types";
1920

2021
import { PartialWithName } from "../../api";
21-
import { Ui5Association } from "@ui5-language-assistant/semantic-model/src/api-json";
2222

2323
const baseUI5NodeDefaults: BaseUI5Node = {
2424
name: "",
@@ -89,20 +89,13 @@ export function buildUI5Constructor(
8989
}
9090

9191
export function buildUI5Association(
92-
opts: PartialWithName<Ui5Association>
93-
): Ui5Association {
92+
opts: PartialWithName<UI5Association>
93+
): UI5Association {
9494
return {
9595
...baseUI5NodeDefaults,
96-
cardinality: undefined,
97-
deprecated: undefined,
98-
description: "",
99-
experimental: undefined,
100-
methods: [],
101-
name: undefined,
102-
since: undefined,
103-
singularName: undefined,
104-
type: "",
105-
visibility: undefined,
96+
kind: "UI5Association",
97+
cardinality: "0..n",
98+
type: undefined,
10699
...opts,
107100
};
108101
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import * as publicApi from "../api";
2+
import * as implementation from "../src/api";
3+
4+
// https://www.typescriptlang.org/docs/handbook/generics.html#generic-constraints
5+
type AssertIsSubSet<SUBSET extends SUPERSET, SUPERSET> = [SUBSET, SUPERSET];
6+
7+
// TODO: export these helper types from test-utils
8+
// Because TypeScript uses a Structural Typing system
9+
// We can perform logical assertions on the API vs Impel
10+
// using discrete math semantics (subsets/supersets)
11+
// See: https://www.typescriptlang.org/docs/handbook/type-compatibility.html
12+
type EnsureAllDeclaredAreExposedAtRuntime = AssertIsSubSet<
13+
typeof implementation,
14+
typeof publicApi
15+
>;
16+
17+
type EnsureNoRedundantAreExposedAtRuntime = AssertIsSubSet<
18+
typeof publicApi,
19+
typeof implementation
20+
>;

0 commit comments

Comments
 (0)