UNPKG

@realfavicongenerator/generate-favicon

Version:
49 lines (48 loc) 3.33 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const promises_1 = __importDefault(require("fs/promises")); const path_1 = __importDefault(require("path")); const desktop_1 = require("./desktop"); const helper_1 = require("../icon/helper"); const svg_1 = require("../svg"); const image_adapter_node_1 = require("@realfavicongenerator/image-adapter-node"); // See https://github.com/RealFaviconGenerator/core/issues/3 test("createFilteredSvgIcon - Issue #3", () => __awaiter(void 0, void 0, void 0, function* () { const inputPath = path_1.default.join(__dirname, '../../fixtures/issue-3-input.svg'); const outputPath = path_1.default.join(__dirname, '../../fixtures/issue-3-output.svg'); const inputSvg = yield promises_1.default.readFile(inputPath, 'utf-8'); const expectedOutput = yield promises_1.default.readFile(outputPath, 'utf-8'); const imageAdapter = yield (0, image_adapter_node_1.getNodeImageAdapter)(); const svg = (0, svg_1.stringToSvg)(inputSvg, imageAdapter); const lightTransformation = (0, helper_1.initTransformation)(helper_1.IconTransformationType.Brightness, {}); const darkTransformation = (0, helper_1.initTransformation)(helper_1.IconTransformationType.Brightness, {}); const result = (0, desktop_1.createFilteredSvgIcon)(svg, imageAdapter, lightTransformation, darkTransformation); const resultSvg = result.svg(); expect(resultSvg).toEqual(expectedOutput.trim()); })); test("cloneSvg creates a deep copy of the SVG", () => __awaiter(void 0, void 0, void 0, function* () { const inputPath = path_1.default.join(__dirname, '../../fixtures/simple.svg'); const inputSvg = yield promises_1.default.readFile(inputPath, 'utf-8'); const imageAdapter = yield (0, image_adapter_node_1.getNodeImageAdapter)(); const originalSvg = (0, svg_1.stringToSvg)(inputSvg, imageAdapter); const clone = (0, desktop_1.cloneSvg)(originalSvg, imageAdapter); const extraPrefix = '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" width="300" height="130">'; const extraSuffix = '</svg>'; // The original SVG is wrapped two times: // - The first time when it is loaded by this very test case // - The second time when it is cloned by the cloneSvg function // This is okay: we just want to make sure the content is duplicated correctly. expect(clone.svg()).toEqual(`${extraPrefix}${extraPrefix}${inputSvg.trim()}${extraSuffix}${extraSuffix}`); }));