2022-12-30 17:45:35 +01:00
|
|
|
import path from "path";
|
|
|
|
|
import fs from "fs";
|
|
|
|
|
import Config from "Config";
|
|
|
|
|
import { run } from "ThemeGenerator";
|
|
|
|
|
import { cleanup } from "tests/Utils";
|
|
|
|
|
|
|
|
|
|
jest.mock("../Paths", () => ({
|
|
|
|
|
workPath: () => __dirname,
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
describe("CssGenerator", () => {
|
|
|
|
|
beforeAll(() => {
|
|
|
|
|
jest.spyOn(console, "log").mockImplementation(() => {});
|
|
|
|
|
cleanup(__dirname);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
|
cleanup(__dirname);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const testSelector = async (opt: string) => {
|
2023-01-02 12:06:00 +01:00
|
|
|
const cssTokensFile = path.join(__dirname, Config.tokenFilename + ".css");
|
2022-12-30 17:45:35 +01:00
|
|
|
expect(fs.existsSync(cssTokensFile)).toEqual(false);
|
|
|
|
|
await run(["", "", "-g", "css", opt, "html"]);
|
|
|
|
|
expect(fs.existsSync(cssTokensFile)).toEqual(true);
|
2023-01-19 15:30:23 +01:00
|
|
|
expect(fs.readFileSync(cssTokensFile).toString()).toEqual(
|
|
|
|
|
fs
|
|
|
|
|
.readFileSync(
|
|
|
|
|
path.join(
|
|
|
|
|
__dirname,
|
|
|
|
|
"..",
|
|
|
|
|
"tests",
|
|
|
|
|
"assets",
|
|
|
|
|
"expected-default-" + Config.tokenFilename + ".css"
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
.toString()
|
|
|
|
|
.replace(":root", "html")
|
|
|
|
|
);
|
2022-12-30 17:45:35 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
it("Runs with -s options.", async () => {
|
|
|
|
|
await testSelector("-s");
|
|
|
|
|
});
|
|
|
|
|
it("Runs with --selector options.", async () => {
|
|
|
|
|
await testSelector("--selector");
|
|
|
|
|
});
|
|
|
|
|
});
|