honkit
Version:
HonKit is building beautiful books using Markdown.
43 lines (42 loc) • 1.85 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const html_1 = require("@honkit/html");
const path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
const tmpdir_1 = require("../../../fs/tmpdir");
const inlineSvg_1 = __importDefault(require("../inlineSvg"));
describe("inlineSvg", () => {
let dir;
let svgPath;
beforeEach(() => {
dir = (0, tmpdir_1.createTmpDirWithRealPath)("honkit-inline-svg-test-");
svgPath = path_1.default.join(dir, "test.svg");
});
test("should inline svg icons", () => {
const svg = '<svg xmlns="http://www.w3.org/2000/svg" width="200" height="100" version="1.1"><rect width="200" height="100" stroke-width="6"/></svg>';
const $ = (0, html_1.loadHtml)('<img src="test.svg"/>');
return fs_1.default.promises
.writeFile(svgPath, svg)
.then(() => {
return (0, inlineSvg_1.default)(dir, "index.html", $);
})
.then(() => {
expect($("svg").attr("fill")).toBe("currentColor");
});
});
test("should not inline svgs with style tags", () => {
const svg = '<svg xmlns="http://www.w3.org/2000/svg" width="200" height="100" version="1.1" style="background-color:red"><rect width="200" height="100" stroke="black" stroke-width="6" fill="green"/></svg>';
const $ = (0, html_1.loadHtml)('<img src="test.svg"/>');
return fs_1.default.promises
.writeFile(svgPath, svg)
.then(() => {
return (0, inlineSvg_1.default)(dir, "index.html", $);
})
.then(() => {
expect($("svg").length).toBe(0);
});
});
});