Skip to content

Commit fd5fdfd

Browse files
authored
chore: Fix snapshot tests (#59)
1 parent 3a1d006 commit fd5fdfd

File tree

3 files changed

+17
-22
lines changed

3 files changed

+17
-22
lines changed

scripts/docs.js

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

55
import { documentComponents, documentTestUtils } from "@cloudscape-design/documenter";
66

7-
import { dashCase, listPublicDirs, writeSourceFile } from "./utils.js";
7+
import { listPublicDirs, writeSourceFile } from "./utils.js";
88

99
const publicDirs = listPublicDirs("src");
1010
const targetDir = "lib/components/internal/api-docs";
@@ -21,27 +21,22 @@ function validatePublicFiles(definitionFiles) {
2121
}
2222

2323
function componentDocs() {
24-
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+
});
2528
const outDir = path.join(targetDir, "components");
26-
const fileNames = definitions
27-
.filter((definition) => {
28-
const fileName = dashCase(definition.name);
29-
if (!publicDirs.includes(fileName)) {
30-
console.warn(`Excluded "${fileName}" from components definitions.`);
31-
return false;
32-
}
33-
return true;
34-
})
35-
.map((definition) => {
36-
const fileName = dashCase(definition.name);
37-
writeSourceFile(path.join(outDir, fileName + ".js"), `module.exports = ${JSON.stringify(definition, null, 2)};`);
38-
return fileName;
39-
});
40-
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+
}
4135
const indexContent = `module.exports = {
42-
${fileNames.map((name) => `${JSON.stringify(name)}:require('./${name}')`).join(",\n")}
36+
${definitions.map((definition) => `${JSON.stringify(definition.dashCaseName)}:require('./${definition.dashCaseName}')`).join(",\n")}
4337
}`;
4438
writeSourceFile(path.join(outDir, "index.js"), indexContent);
39+
validatePublicFiles(definitions.map((def) => def.dashCaseName));
4540
}
4641

4742
function testUtilDocs() {

scripts/utils.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ 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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
exports[`definition for avatar matches the snapshot > avatar 1`] = `
44
{
5+
"dashCaseName": "avatar",
56
"events": [],
67
"functions": [],
78
"name": "Avatar",
@@ -105,6 +106,7 @@ Use this property if the icon you want isn't available.",
105106
106107
exports[`definition for chat-bubble matches the snapshot > chat-bubble 1`] = `
107108
{
109+
"dashCaseName": "chat-bubble",
108110
"events": [],
109111
"functions": [],
110112
"name": "ChatBubble",
@@ -168,6 +170,7 @@ If avatar is being used, set its \`loading\` state to true.",
168170
169171
exports[`definition for loading-bar matches the snapshot > loading-bar 1`] = `
170172
{
173+
"dashCaseName": "loading-bar",
171174
"events": [],
172175
"functions": [],
173176
"name": "LoadingBar",
@@ -196,6 +199,7 @@ with rounded corners.",
196199
197200
exports[`definition for support-prompt-group matches the snapshot > support-prompt-group 1`] = `
198201
{
202+
"dashCaseName": "support-prompt-group",
199203
"events": [
200204
{
201205
"cancelable": false,

0 commit comments

Comments
 (0)