Skip to content

Commit c4c8ea8

Browse files
authored
chore: Fix snapshot tests (#74)
1 parent 8cfe47b commit c4c8ea8

File tree

3 files changed

+15
-22
lines changed

3 files changed

+15
-22
lines changed

scripts/docs.js

Lines changed: 14 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,28 +21,24 @@ function validatePublicFiles(definitionFiles) {
2121
}
2222

2323
function componentDocs() {
24-
const definitions = documentComponents(path.resolve("scripts/tsconfig.docs.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
}
41+
4642
function testUtilDocs() {
4743
const tsconfig = path.resolve("src/test-utils/tsconfig.json");
4844
["dom", "selectors"].forEach((testUtilType) => {

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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
exports[`definition for 'code-view' matches the snapshot 1`] = `
44
{
5+
"dashCaseName": "code-view",
56
"events": [],
67
"functions": [],
78
"name": "CodeView",

0 commit comments

Comments
 (0)