Skip to content

Commit 9c7f0c3

Browse files
committed
chore: Add documenter tests
1 parent 8abde3a commit 9c7f0c3

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

src/__tests__/__snapshots__/documenter.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`definition for 'code-view' matches the snapshot 1`] = `
3+
exports[`definition for code-view matches the snapshot > code-view 1`] = `
44
{
55
"dashCaseName": "code-view",
66
"events": [],

src/__tests__/documenter.test.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@
22
// SPDX-License-Identifier: Apache-2.0
33
import { expect, test } from "vitest";
44

5-
import apiDocs from "../../lib/components/internal/api-docs/components";
5+
import componentDefinitions from "../../lib/components/internal/api-docs/components";
6+
import { getAllComponents } from "./utils";
67

7-
test.each(Object.entries(apiDocs))("definition for $0 matches the snapshot", (_name, definition) => {
8-
expect(definition).toMatchSnapshot();
8+
test.each<string>(getAllComponents())(`definition for %s matches the snapshot`, (componentName: string) => {
9+
const definition = componentDefinitions[componentName];
10+
// overriding with a fake value so that when there are icon changes in components this test doesn't block it
11+
const iconNameDefinition = definition.properties.find(({ name }: { name: string }) => name === "iconName");
12+
if (iconNameDefinition && iconNameDefinition.inlineType?.type === "union") {
13+
iconNameDefinition.inlineType.values = ["comes from @cloudscape-design/components"];
14+
}
15+
expect(definition).toMatchSnapshot(componentName);
916
});

src/__tests__/utils.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* eslint-env node */
2+
/* eslint-disable header/header */
3+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
// SPDX-License-Identifier: Apache-2.0
5+
import * as fs from "node:fs";
6+
import * as path from "node:path";
7+
8+
const componentsDir = path.resolve(__dirname, "../../lib/components");
9+
10+
export function getAllComponents(): string[] {
11+
return fs
12+
.readdirSync(componentsDir)
13+
.filter(
14+
(name) =>
15+
name !== "internal" &&
16+
name !== "test-utils" &&
17+
!name.includes(".") &&
18+
!name.includes("LICENSE") &&
19+
!name.includes("NOTICE"),
20+
);
21+
}
22+
23+
export async function requireComponent(componentName: string) {
24+
// eslint-disable-next-line no-unsanitized/method
25+
const { default: Component } = await import(path.join(componentsDir, componentName));
26+
return Component;
27+
}

0 commit comments

Comments
 (0)