✅(tokens) mock default tokens in tests
If we don't do that we will have to update all tests each time the default value of a token is changed.
This commit is contained in:
@@ -4,6 +4,15 @@ const jestConfig: JestConfigWithTsJest = {
|
||||
preset: "ts-jest",
|
||||
testEnvironment: "node",
|
||||
moduleDirectories: ["node_modules", "src/bin"],
|
||||
setupFiles: ["<rootDir>/src/bin/tests/Setup.ts"],
|
||||
transform: {
|
||||
"^.+\\.tsx?$": [
|
||||
"ts-jest",
|
||||
// required due to custom location of tsconfig.json configuration file
|
||||
// https://kulshekhar.github.io/ts-jest/docs/getting-started/options/tsconfig
|
||||
{ tsconfig: "./src/bin/tsconfig.json" },
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
export default jestConfig;
|
||||
|
||||
@@ -24,8 +24,8 @@ describe("CssGenerator", () => {
|
||||
await run(["", "", "-g", "css", opt, "html"]);
|
||||
expect(fs.existsSync(cssTokensFile)).toEqual(true);
|
||||
expect(fs.readFileSync(cssTokensFile).toString()).toEqual(`html {
|
||||
\t--c--colors--primary: #055FD2;
|
||||
\t--c--colors--secondary: #DA0000;
|
||||
\t--c--theme--colors--primary: #055FD2;
|
||||
\t--c--theme--colors--secondary: #DA0000;
|
||||
}`);
|
||||
};
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ describe("JsGenerator", () => {
|
||||
await run(["", "", "-g", "js"]);
|
||||
expect(fs.existsSync(tokensFile)).toEqual(true);
|
||||
expect(fs.readFileSync(tokensFile).toString()).toEqual(
|
||||
`export const tokens = {"colors":{"primary":"#055FD2","secondary":"#DA0000"}};`
|
||||
`export const tokens = {"theme":{"colors":{"primary":"#055FD2","secondary":"#DA0000"}}};`
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -24,7 +24,7 @@ describe("TsGenerator", () => {
|
||||
await run(["", "", "-g", "ts"]);
|
||||
expect(fs.existsSync(tokensFile)).toEqual(true);
|
||||
expect(fs.readFileSync(tokensFile).toString()).toEqual(
|
||||
`export const tokens = {"colors":{"primary":"#055FD2","secondary":"#DA0000"}};`
|
||||
`export const tokens = {"theme":{"colors":{"primary":"#055FD2","secondary":"#DA0000"}}};`
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
8
packages/tokens/src/bin/__mocks__/cunningham.dist.js
Normal file
8
packages/tokens/src/bin/__mocks__/cunningham.dist.js
Normal file
@@ -0,0 +1,8 @@
|
||||
module.exports = {
|
||||
theme: {
|
||||
colors: {
|
||||
primary: "#055FD2",
|
||||
secondary: "#DA0000",
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -11,6 +11,15 @@ jest.mock("../Paths", () => ({
|
||||
workPath: () => __dirname,
|
||||
}));
|
||||
|
||||
jest.mock("../cunningham.dist.js", () => ({
|
||||
theme: {
|
||||
colors: {
|
||||
primary: "#055FD2",
|
||||
secondary: "#DA0000",
|
||||
},
|
||||
},
|
||||
}));
|
||||
|
||||
const runBin = async (args: string) => {
|
||||
const exec = util.promisify(child_process.exec);
|
||||
const promise = exec(
|
||||
|
||||
1
packages/tokens/src/bin/tests/Setup.ts
Normal file
1
packages/tokens/src/bin/tests/Setup.ts
Normal file
@@ -0,0 +1 @@
|
||||
jest.mock("../cunningham.dist.js");
|
||||
Reference in New Issue
Block a user