Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecoomber committed Oct 8, 2024
1 parent 9178c7e commit 9cfdbd8
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 24 deletions.
2 changes: 1 addition & 1 deletion scripts/code-connect/generate-connect-file-contents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const getTemplate = (iconName: string) =>
ts.factory.createIdentifier("props"),
ts.factory.createIdentifier("rounded"),
),
ts.factory.createTemplateTail(`>${iconName.toLowerCase().replace(" ", "-")}</zeta-icon>`),
ts.factory.createTemplateTail(`>${iconName.toLowerCase().replaceAll(" ", "-")}</zeta-icon>`),
),
]),
),
Expand Down
4 changes: 2 additions & 2 deletions scripts/fetch-icons/generators/generateDefinitionFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const generateDefinitionFiles = (outputDir: string, fontData: GenerateFon
* @returns {string} Content of `icons.g.dart`.
*/
const generateDartFile = (fontData: GenerateFontResult): string => {
let dartTemplate = readFileSync("./scripts/templates/icons.dart.template").toString();
let dartTemplate = readFileSync("./scripts/fetch-icons/templates/icons.dart.template").toString();
const newLine = "\n";

const icons = fontData.dartDefinitions.join(newLine);
Expand All @@ -60,7 +60,7 @@ const generateDartFile = (fontData: GenerateFontResult): string => {
* @returns {string} Content of `icon-types.ts`.
*/
const generateTSFile = (fontData: GenerateFontResult): string => {
let tsTemplate = readFileSync("./scripts/templates/icon-types.ts.template").toString();
let tsTemplate = readFileSync("./scripts/fetch-icons/templates/icon-types.ts.template").toString();

const nameList = fontData.iconNames.map((icon) => `"${icon}"`);
const iconNames = nameList.join(",\n ");
Expand Down
2 changes: 1 addition & 1 deletion test/data/generatedFontResponse.json

Large diffs are not rendered by default.

22 changes: 13 additions & 9 deletions test/fetch-icons/integration/fetchIcons.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { assert } from "chai";
import assert from "assert";
import { ZDS_ASSETS_FILE_ID, ZDS_ASSETS_ICON_PAGE_NAME } from "../../../figmaConfig.js";
import fetchIcons, { definitionsDir, fontDir } from "../../../scripts/fetch-icons/fetchIcons.js";
import { checkFigmaTokenIsSet } from "../../../scripts/utils/figmaUtils.js";
import { zdsIntegrationOutputDir } from "../../data/constants.js";
import { existsSync, readFileSync, rmSync } from "fs";
import { rmSync, existsSync, readFileSync } from "fs";
import fetchIcons from "../../../scripts/fetch-icons/fetchIcons.js";
import { IconManifest } from "../../../scripts/fetch-icons/types/customTypes.js";
import { checkFigmaTokenIsSet } from "../../../scripts/utils/figmaUtils.js";
import { zdsIntegrationOutputDir, testDartOutputDir, testTSOutputDir } from "../../data/constants.js";
import { checkFontsExist, checkIconsExist } from "../utils.js";
import { createRequire } from "module";
const require = createRequire(import.meta.url);
Expand All @@ -25,7 +25,7 @@ describe("fetchIcons", () => {
ZDS_ASSETS_ICON_PAGE_NAME,
"",
zdsIntegrationOutputDir,
true
true,
);
});

Expand All @@ -41,11 +41,15 @@ describe("fetchIcons", () => {
});

it("should create fonts", () => {
checkFontsExist("zeta-icons", `${zdsIntegrationOutputDir}/${fontDir}`);
checkFontsExist(
"zeta-icons",
`${zdsIntegrationOutputDir}/${testDartOutputDir}`,
`${zdsIntegrationOutputDir}/${testTSOutputDir}`,
);
});

it("should write definition files", () => {
assert.equal(existsSync(`${zdsIntegrationOutputDir}/${definitionsDir}/icons.dart`), true);
assert.equal(existsSync(`${zdsIntegrationOutputDir}/${definitionsDir}/icon-types.ts`), true);
assert.equal(existsSync(`${zdsIntegrationOutputDir}/${testDartOutputDir}/icons.g.dart`), true);
assert.equal(existsSync(`${zdsIntegrationOutputDir}/${testTSOutputDir}/icon-types.ts`), true);
});
});
8 changes: 4 additions & 4 deletions test/fetch-icons/integration/generateDefinitionFiles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import { assert } from "chai";
import { existsSync } from "fs";
import { generateDefinitionFiles } from "../../../scripts/fetch-icons/generators/generateDefinitionFiles.js";
import { generatedFontDefinitions, manifest } from "../../data/index.js";
import { testDefinitionsOutputDir, testOutputDir } from "../../data/constants.js";
import { testDartOutputDir, testOutputDir, testTSOutputDir } from "../../data/constants.js";

describe("generateDefinitionFiles", () => {
before(async () => {
generateDefinitionFiles(testOutputDir, testDefinitionsOutputDir, generatedFontDefinitions, manifest);
generateDefinitionFiles(testOutputDir, generatedFontDefinitions, manifest);
});

it("should write definition files", () => {
assert.equal(existsSync(`${testDefinitionsOutputDir}/icons.dart`), true);
assert.equal(existsSync(`${testDefinitionsOutputDir}/icon-types.ts`), true);
assert.equal(existsSync(`${testDartOutputDir}/icons.g.dart`), true);
assert.equal(existsSync(`${testTSOutputDir}/icon-types.ts`), true);
});

it("should write the icon manifest", () => {
Expand Down
20 changes: 13 additions & 7 deletions test/fetch-icons/integration/generateFontFiles.test.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
import "./saveSvgs.test.js"; // Ensures saveSVGs is called before running these tests.

import { optimizeSVGs } from "../../../scripts/utils/optimizeSvgs.js";
import { testFontName, testFontsOutputDir, testIconsOutputDir, testTempOutputDir } from "../../data/constants.js";
import { categoryNames, generatedFontDefinitions } from "../../data/index.js";
import { GenerateFontResult } from "../../../scripts/fetch-icons/types/customTypes.js";
import { generateFonts } from "../../../scripts/fetch-icons/generators/generateFonts.js";
import { assert } from "chai";
import { checkFontsExist } from "../utils.js";
import { generateFonts } from "../../../scripts/fetch-icons/generators/generateFonts.js";
import { GenerateFontResult } from "../../../scripts/fetch-icons/types/customTypes.js";
import { optimizeSVGs } from "../../../scripts/utils/optimizeSvgs.js";
import {
testIconsOutputDir,
testTempOutputDir,
testFontName,
testDartOutputDir,
testTSOutputDir,
} from "../../data/constants.js";
import { categoryNames, generatedFontDefinitions } from "../../data/index.js";

describe("generateFontFiles", () => {
let result: GenerateFontResult;

before(async () => {
await optimizeSVGs(testIconsOutputDir, testTempOutputDir, categoryNames);
result = await generateFonts(testTempOutputDir, testFontsOutputDir, testFontName);
result = await generateFonts(testTempOutputDir, testFontName, testDartOutputDir, testTSOutputDir);
});

it("should return a correct font generation result", () => {
assert.deepEqual(result, generatedFontDefinitions);
});

it("should have created sharp and rounded ttf and woff2 files", () => {
checkFontsExist(testFontName, testFontsOutputDir);
checkFontsExist(testFontName, testDartOutputDir, testTSOutputDir);
});
});

0 comments on commit 9cfdbd8

Please sign in to comment.