UNPKG

honkit

Version:

HonKit is building beautiful books using Markdown.

70 lines (69 loc) 3.22 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; 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 tmpdir_1 = require("../../../fs/tmpdir"); const fetchRemoteImages_1 = __importDefault(require("../fetchRemoteImages")); const promises_1 = __importDefault(require("fs/promises")); const assert_1 = __importDefault(require("assert")); const constants = __importStar(require("constants")); const URL = "https://upload.wikimedia.org/wikipedia/commons/thumb/4/47/PNG_transparency_demonstration_1.png/280px-PNG_transparency_demonstration_1.png"; // download image from remote server is flaky jest.retryTimes(3); describe("fetchRemoteImages", () => { let dir; beforeEach(() => { dir = (0, tmpdir_1.createTmpDirWithRealPath)("honkit-fetch-remote-images-test-"); return promises_1.default.rm(dir, { recursive: true, force: true }); }); afterEach(() => { // remove temporary directory return promises_1.default.rm(dir, { recursive: true, force: true }); }); it("should download image file", async () => { const $ = (0, html_1.loadHtml)(`<img src="${URL}" />`); await (0, fetchRemoteImages_1.default)(dir, "index.html", $); const $img = $("img"); const src = $img.attr("src"); const expected = path_1.default.join(dir, src); await assert_1.default.doesNotReject(() => { return promises_1.default.access(expected, constants.F_OK); }); }, 15 * 1000); it("should download image file and replace with relative path", async () => { const $ = (0, html_1.loadHtml)(`<img src="${URL}" />`); await (0, fetchRemoteImages_1.default)(dir, "test/index.html", $); const $img = $("img"); const src = $img.attr("src"); const expected = path_1.default.join(dir, "test/" + src); await assert_1.default.doesNotReject(() => { return promises_1.default.access(expected, constants.F_OK); }); }, 15 * 1000); });