UNPKG

honkit

Version:

HonKit is building beautiful books using Markdown.

82 lines (81 loc) 4.67 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const location_1 = __importDefault(require("../location")); describe("LocationUtils", () => { test("should correctly test external location", () => { expect(location_1.default.isExternal("http://google.fr")).toBe(true); expect(location_1.default.isExternal("https://google.fr")).toBe(true); expect(location_1.default.isExternal("test.md")).toBe(false); expect(location_1.default.isExternal("folder/test.md")).toBe(false); expect(location_1.default.isExternal("/folder/test.md")).toBe(false); expect(location_1.default.isExternal("data:image/png")).toBe(false); }); test("should correctly test data:uri location", () => { expect(location_1.default.isDataURI("data:image/png")).toBe(true); expect(location_1.default.isDataURI("http://google.fr")).toBe(false); expect(location_1.default.isDataURI("https://google.fr")).toBe(false); expect(location_1.default.isDataURI("test.md")).toBe(false); expect(location_1.default.isDataURI("data.md")).toBe(false); }); test("should correctly detect anchor location", () => { expect(location_1.default.isAnchor("#test")).toBe(true); expect(location_1.default.isAnchor(" #test")).toBe(true); expect(location_1.default.isAnchor("https://google.fr#test")).toBe(false); expect(location_1.default.isAnchor("test.md#test")).toBe(false); }); describe(".relative", () => { test("should resolve to a relative path (same folder)", () => { expect(location_1.default.relative("links/", "links/test.md")).toBe("test.md"); }); test("should resolve to a relative path (parent folder)", () => { expect(location_1.default.relative("links/", "test.md")).toBe("../test.md"); }); test("should resolve to a relative path (child folder)", () => { expect(location_1.default.relative("links/", "links/hello/test.md")).toBe("hello/test.md"); }); }); describe(".flatten", () => { test("should remove leading slash", () => { expect(location_1.default.flatten("/test.md")).toBe("test.md"); expect(location_1.default.flatten("/hello/cool.md")).toBe("hello/cool.md"); }); test("should remove leading slashes", () => { expect(location_1.default.flatten("///test.md")).toBe("test.md"); }); test("should not break paths", () => { expect(location_1.default.flatten("hello/cool.md")).toBe("hello/cool.md"); }); }); describe(".toAbsolute", () => { test("should correctly transform as absolute", () => { // @ts-expect-error expect(location_1.default.toAbsolute("http://google.fr")).toBe("http://google.fr"); expect(location_1.default.toAbsolute("test.md", "./", "./")).toBe("test.md"); expect(location_1.default.toAbsolute("folder/test.md", "./", "./")).toBe("folder/test.md"); }); test("should correctly handle windows path", () => { expect(location_1.default.toAbsolute("folder\\test.md", "./", "./")).toBe("folder/test.md"); }); test("should correctly handle absolute path", () => { expect(location_1.default.toAbsolute("/test.md", "./", "./")).toBe("test.md"); expect(location_1.default.toAbsolute("/test.md", "test", "test")).toBe("../test.md"); expect(location_1.default.toAbsolute("/sub/test.md", "test", "test")).toBe("../sub/test.md"); expect(location_1.default.toAbsolute("/test.png", "folder", "")).toBe("test.png"); }); test("should correctly handle absolute path (windows)", () => { expect(location_1.default.toAbsolute("\\test.png", "folder", "")).toBe("test.png"); }); test("should resolve path starting by \"/\" in root directory", () => { expect(location_1.default.toAbsolute("/test/hello.md", "./", "./")).toBe("test/hello.md"); }); test("should resolve path starting by \"/\" in child directory", () => { expect(location_1.default.toAbsolute("/test/hello.md", "./hello", "./")).toBe("test/hello.md"); }); test("should resolve path starting by \"/\" in child directory, with same output directory", () => { expect(location_1.default.toAbsolute("/test/hello.md", "./hello", "./hello")).toBe("../test/hello.md"); }); }); });