2022-12-01 12:03:37 +01:00
|
|
|
import * as fs from "fs";
|
|
|
|
|
import * as path from "path";
|
2022-12-30 12:12:04 +01:00
|
|
|
import { run } from "ThemeGenerator";
|
2022-12-30 17:45:35 +01:00
|
|
|
import { cleanup } from "tests/Utils";
|
2022-12-01 12:03:37 +01:00
|
|
|
import Config from "../Config";
|
|
|
|
|
|
|
|
|
|
jest.mock("../Paths", () => ({
|
|
|
|
|
workPath: () => __dirname,
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
/**
|
2022-12-30 17:45:35 +01:00
|
|
|
* Test written here are supposed to be general ones and not specific to any generator.
|
|
|
|
|
*
|
|
|
|
|
* But as we need at least one generator to execute the bin we need to choose one to use by default,
|
|
|
|
|
* that's why we use the css generator.
|
2022-12-01 12:03:37 +01:00
|
|
|
*/
|
|
|
|
|
describe("Cunningham Bin", () => {
|
|
|
|
|
beforeAll(() => {
|
|
|
|
|
jest.spyOn(console, "log").mockImplementation(() => {});
|
2022-12-30 17:45:35 +01:00
|
|
|
cleanup(__dirname);
|
2022-12-01 12:03:37 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
afterEach(() => {
|
2022-12-30 17:45:35 +01:00
|
|
|
cleanup(__dirname);
|
2022-12-01 12:03:37 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("Runs without existing config file with default values.", async () => {
|
2022-12-30 17:45:35 +01:00
|
|
|
const cssTokensFile = path.join(__dirname, Config.tokenFilenames.css);
|
2022-12-01 12:03:37 +01:00
|
|
|
expect(fs.existsSync(cssTokensFile)).toEqual(false);
|
2022-12-30 17:45:35 +01:00
|
|
|
await run(["", "", "-g", "css"]);
|
2022-12-01 12:03:37 +01:00
|
|
|
expect(fs.existsSync(cssTokensFile)).toEqual(true);
|
|
|
|
|
expect(fs.readFileSync(cssTokensFile).toString()).toEqual(`:root {
|
|
|
|
|
\t--c--colors--primary: #055FD2;
|
|
|
|
|
\t--c--colors--secondary: #DA0000;
|
|
|
|
|
}`);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("Runs with existing config file using local values.", async () => {
|
|
|
|
|
const localConfigurationFile = path.join(
|
|
|
|
|
__dirname,
|
|
|
|
|
Config.configurationFilenames[0]
|
|
|
|
|
);
|
|
|
|
|
expect(fs.existsSync(localConfigurationFile)).toEqual(false);
|
|
|
|
|
|
2022-12-30 17:45:35 +01:00
|
|
|
const cssTokensFile = path.join(__dirname, Config.tokenFilenames.css);
|
2022-12-01 12:03:37 +01:00
|
|
|
expect(fs.existsSync(cssTokensFile)).toEqual(false);
|
|
|
|
|
|
|
|
|
|
fs.copyFileSync(
|
|
|
|
|
path.join(__dirname, "assets", Config.configurationFilenames[0]),
|
|
|
|
|
localConfigurationFile
|
|
|
|
|
);
|
|
|
|
|
expect(fs.existsSync(localConfigurationFile)).toEqual(true);
|
|
|
|
|
|
2022-12-30 17:45:35 +01:00
|
|
|
await run(["", "", "-g", "css"]);
|
2022-12-01 12:03:37 +01:00
|
|
|
expect(fs.existsSync(cssTokensFile)).toEqual(true);
|
|
|
|
|
expect(fs.readFileSync(cssTokensFile).toString()).toEqual(`:root {
|
|
|
|
|
\t--c--colors--primary: AntiqueWhite;
|
|
|
|
|
\t--c--colors--secondary: #DA0000;
|
|
|
|
|
}`);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const testOutput = async (opt: string) => {
|
|
|
|
|
const outputDir = path.join(__dirname, "output");
|
2022-12-30 17:45:35 +01:00
|
|
|
const cssTokensFile = path.join(outputDir, Config.tokenFilenames.css);
|
2022-12-01 12:03:37 +01:00
|
|
|
expect(fs.existsSync(cssTokensFile)).toEqual(false);
|
2022-12-30 17:45:35 +01:00
|
|
|
await run(["", "", "-g", "css", opt, outputDir]);
|
2022-12-01 12:03:37 +01:00
|
|
|
expect(fs.existsSync(cssTokensFile)).toEqual(true);
|
|
|
|
|
expect(fs.readFileSync(cssTokensFile).toString()).toEqual(`:root {
|
|
|
|
|
\t--c--colors--primary: #055FD2;
|
|
|
|
|
\t--c--colors--secondary: #DA0000;
|
|
|
|
|
}`);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
it("Runs with -o options.", async () => {
|
|
|
|
|
await testOutput("-o");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("Runs with --output options.", async () => {
|
|
|
|
|
await testOutput("--output");
|
|
|
|
|
});
|
|
|
|
|
});
|