Skip to content

Commit 1b3abf2

Browse files
authored
chore: Fix snapshot tests (#347)
1 parent 9a7aa2f commit 1b3abf2

File tree

3 files changed

+18
-23
lines changed

3 files changed

+18
-23
lines changed

scripts/docs.js

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import path from "node:path";
44

55
import { documentComponents, documentTestUtils } from "@cloudscape-design/documenter";
6-
import { dashCase, listPublicDirs, writeSourceFile } from "./utils.js";
6+
7+
import { listPublicDirs, writeSourceFile } from "./utils.js";
78

89
const publicDirs = listPublicDirs("src");
910
const targetDir = "lib/components/internal/api-docs";
@@ -20,27 +21,22 @@ function validatePublicFiles(definitionFiles) {
2021
}
2122

2223
function componentDocs() {
23-
const definitions = documentComponents(path.resolve("tsconfig.json"), "src/*/index.tsx");
24+
const definitions = documentComponents({
25+
tsconfigPath: path.resolve("tsconfig.json"),
26+
publicFilesGlob: "src/*/index.tsx",
27+
});
2428
const outDir = path.join(targetDir, "components");
25-
const fileNames = definitions
26-
.filter((definition) => {
27-
const fileName = dashCase(definition.name);
28-
if (!publicDirs.includes(fileName)) {
29-
console.warn(`Excluded "${fileName}" from components definitions.`);
30-
return false;
31-
}
32-
return true;
33-
})
34-
.map((definition) => {
35-
const fileName = dashCase(definition.name);
36-
writeSourceFile(path.join(outDir, fileName + ".js"), `module.exports = ${JSON.stringify(definition, null, 2)};`);
37-
return fileName;
38-
});
39-
validatePublicFiles(fileNames);
29+
for (const definition of definitions) {
30+
writeSourceFile(
31+
path.join(outDir, definition.dashCaseName + ".js"),
32+
`module.exports = ${JSON.stringify(definition, null, 2)};`,
33+
);
34+
}
4035
const indexContent = `module.exports = {
41-
${fileNames.map((name) => `${JSON.stringify(name)}:require('./${name}')`).join(",\n")}
36+
${definitions.map((definition) => `${JSON.stringify(definition.dashCaseName)}:require('./${definition.dashCaseName}')`).join(",\n")}
4237
}`;
4338
writeSourceFile(path.join(outDir, "index.js"), indexContent);
39+
validatePublicFiles(definitions.map((def) => def.dashCaseName));
4440
}
4541

4642
function testUtilDocs() {

scripts/utils.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
3+
import lodash from "lodash";
34
import fs from "node:fs";
45
import path from "node:path";
5-
import lodash from "lodash";
66

77
export function pascalCase(text) {
88
return capitalize(lodash.camelCase(text));
99
}
1010

11-
export function dashCase(text) {
12-
return lodash.kebabCase(text);
13-
}
14-
1511
function capitalize(text) {
1612
return text[0].toUpperCase() + text.slice(1);
1713
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
exports[`definition for board matches the snapshot > board 1`] = `
44
{
5+
"dashCaseName": "board",
56
"events": [
67
{
78
"cancelable": false,
@@ -181,6 +182,7 @@ When items are loading the slot can be used to render the loading indicator.",
181182
182183
exports[`definition for board-item matches the snapshot > board-item 1`] = `
183184
{
185+
"dashCaseName": "board-item",
184186
"events": [],
185187
"functions": [],
186188
"name": "BoardItem",
@@ -259,6 +261,7 @@ ARIA labels:
259261
260262
exports[`definition for items-palette matches the snapshot > items-palette 1`] = `
261263
{
264+
"dashCaseName": "items-palette",
262265
"events": [],
263266
"functions": [],
264267
"name": "ItemsPalette",

0 commit comments

Comments
 (0)