Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vn7n24fzkq committed Aug 27, 2020
1 parent 71e7c20 commit 23cd7ae
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 3 deletions.
141 changes: 141 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
"number-abbreviate": "^2.0.0"
},
"devDependencies": {
"jest": "^26.4.2"
}
"jest": "^26.4.2",
"pre-commit": "^1.2.2"
},
"pre-commit": [
"test"
]
}
2 changes: 1 addition & 1 deletion src/utils/svg-writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const writeSVG = function (folder,filename, svgString) {
err,
result
) {
if (err) console.log("error", err);
if (err) throw (err);
});
});
};
Expand Down
16 changes: 16 additions & 0 deletions tests/const/theme.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const Themes = require("../../src/const/theme");

describe("Validate all theme", () => {
it("theme colors are match the color regex", () => {
const colorRegex = /^#[0-9A-Fa-f]{6}$/;
for (let themeName in Themes) {
let theme = Themes[themeName];
expect(theme.title_color).toMatch(colorRegex);
expect(theme.text_color).toMatch(colorRegex);
expect(theme.bg_color).toMatch(colorRegex);
expect(theme.stroke_color).toMatch(colorRegex);
expect(theme.icon_color).toMatch(colorRegex);
expect(theme.line_chart_color).toMatch(colorRegex);
}
});
});
13 changes: 13 additions & 0 deletions tests/utils/svg-writer.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const { writeSVG, outputPath } = require("../../src/utils/svg-writer");
const fs = require("fs");

describe("Test output function", () => {
it("test write svg can work", () => {
writeSVG("test", "write-svg", "work");
let content = fs.readFileSync(`${outputPath}test/write-svg.svg`, {
encoding: "utf8",
flag: "r",
});
expect(content).toEqual("work");
});
});

0 comments on commit 23cd7ae

Please sign in to comment.