From 000af9197ef3e96072793b2e4b043795c2f4b3d6 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 21 Jan 2022 04:35:56 +0000 Subject: [PATCH] chore: code formatting --- source/app/metrics/utils.mjs | 72 +++++++++++++++++++----------------- tests/ci.test.js | 3 +- tests/mocks/index.mjs | 2 +- 3 files changed, 41 insertions(+), 36 deletions(-) diff --git a/source/app/metrics/utils.mjs b/source/app/metrics/utils.mjs index a845b26e..7c32d2dd 100644 --- a/source/app/metrics/utils.mjs +++ b/source/app/metrics/utils.mjs @@ -435,41 +435,45 @@ export const svg = { console.debug("metrics/svg/resize > resizing svg") let height, resized, width try { - ({resized, width, height} = await page.evaluate(async (padding, js) => { - //Execute user JavaScript if provided - if (js) { - try { - console.debug(`metrics/svg/resize > executing ${js}`) - await new Function("document", `return (async () => {${js}})()`)(document) //eslint-disable-line no-new-func - console.debug("metrics/svg/resize > successfully executed user javascript") + ({resized, width, height} = await page.evaluate( + async (padding, js) => { + //Execute user JavaScript if provided + if (js) { + try { + console.debug(`metrics/svg/resize > executing ${js}`) + await new Function("document", `return (async () => {${js}})()`)(document) //eslint-disable-line no-new-func + console.debug("metrics/svg/resize > successfully executed user javascript") + } + catch (error) { + console.debug(`an error occured while evaluating user js: ${error}`) + } } - catch (error) { - console.debug(`an error occured while evaluating user js: ${error}`) - } - } - //Disable animations - const animated = !document.querySelector("svg").classList.contains("no-animations") - if (animated) - document.querySelector("svg").classList.add("no-animations") - console.debug(`animations are ${animated ? "enabled" : "disabled"}`) - await new Promise(solve => setTimeout(solve, 2400)) - //Get bounds and resize - let {y:height, width} = document.querySelector("svg #metrics-end").getBoundingClientRect() - console.debug(`bounds width=${width}, height=${height}`) - height = Math.ceil(height * padding.height + padding.absolute.height) - width = Math.ceil(width * padding.width + padding.absolute.width) - console.debug(`bounds after applying padding width=${width} (*${padding.width}+${padding.absolute.width}), height=${height} (*${padding.height}+${padding.absolute.height})`) - //Resize svg - if (document.querySelector("svg").getAttribute("height") === "auto") - console.debug('skipped height resizing because it was set to "auto"') - else - document.querySelector("svg").setAttribute("height", height) - //Enable animations - if (animated) - document.querySelector("svg").classList.remove("no-animations") - //Result - return {resized:new XMLSerializer().serializeToString(document.querySelector("svg")), height, width} - }, padding, js)) + //Disable animations + const animated = !document.querySelector("svg").classList.contains("no-animations") + if (animated) + document.querySelector("svg").classList.add("no-animations") + console.debug(`animations are ${animated ? "enabled" : "disabled"}`) + await new Promise(solve => setTimeout(solve, 2400)) + //Get bounds and resize + let {y:height, width} = document.querySelector("svg #metrics-end").getBoundingClientRect() + console.debug(`bounds width=${width}, height=${height}`) + height = Math.ceil(height * padding.height + padding.absolute.height) + width = Math.ceil(width * padding.width + padding.absolute.width) + console.debug(`bounds after applying padding width=${width} (*${padding.width}+${padding.absolute.width}), height=${height} (*${padding.height}+${padding.absolute.height})`) + //Resize svg + if (document.querySelector("svg").getAttribute("height") === "auto") + console.debug('skipped height resizing because it was set to "auto"') + else + document.querySelector("svg").setAttribute("height", height) + //Enable animations + if (animated) + document.querySelector("svg").classList.remove("no-animations") + //Result + return {resized:new XMLSerializer().serializeToString(document.querySelector("svg")), height, width} + }, + padding, + js, + )) } catch (error) { console.error(error) diff --git a/tests/ci.test.js b/tests/ci.test.js index 821890ed..e3112d15 100644 --- a/tests/ci.test.js +++ b/tests/ci.test.js @@ -19,7 +19,7 @@ describe("Check files editions (checkout your files if needed)", () => { ".github/workflows/examples.yml", ".github/readme/partials/documentation/compatibility.md", ])("%s", async file => expect((await diff()).includes(file)).toBe(false))) - if (!["lowlighter"].includes(process.env.PR_AUTHOR)) + if (!["lowlighter"].includes(process.env.PR_AUTHOR)) { describe("Repository level files were not modified", () => void test.each([ ".github/config/*", @@ -39,6 +39,7 @@ describe("Check files editions (checkout your files if needed)", () => { "source/app/mocks/.eslintrc.yml", "vercel.json", ])("%s", async file => expect((await diff()).filter(edited => new RegExp(`^${file.replace(/[.]/g, "[.]").replace(/[*]/g, "[\\s\\S]*")}$`).test(edited)).length).toBe(0))) + } }) //Templates editions diff --git a/tests/mocks/index.mjs b/tests/mocks/index.mjs index 5d650fe5..a5edde4d 100644 --- a/tests/mocks/index.mjs +++ b/tests/mocks/index.mjs @@ -1,7 +1,7 @@ //Imports +import faker from "@faker-js/faker" import fs from "fs/promises" import axios from "axios" -import faker from "@faker-js/faker" import paths from "path" import rss from "rss-parser" import urls from "url"