Skip to content

Commit

Permalink
fix: change file type
Browse files Browse the repository at this point in the history
  • Loading branch information
tommm2 committed Jul 5, 2024
1 parent 352f24b commit 320a8c4
Showing 1 changed file with 8 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,34 +1,17 @@
type Core = {
setOutput: (name: string, value: string) => void;
};

type Result = {
url: string;
isRepresentativeRun: string;
htmlPath: string;
jsonPath: string;
summary: {
performance: number;
accessibility: number;
'best-practices': number;
seo: number;
}
}

const stoplight = (res: number) => (res >= 90 ? '🟢' : res >= 75 ? '🟠' : '🔴');
const normalizeScore = (res: number) => Math.round(res * 100);
const formatScore = (res: number) => {
const stoplight = (res) => (res >= 90 ? '🟢' : res >= 75 ? '🟠' : '🔴');
const normalizeScore = (res) => Math.round(res * 100);
const formatScore = (res) => {
const normalizedScore = normalizeScore(res);

return `${stoplight(normalizedScore)} ${normalizedScore}`;
};

export const formatLighthouseResults = ({ core }: { core: Core }) => {
export const formatLighthouseResults = ({ core }) => {
// this will be the shape of https://github.com/treosh/lighthouse-ci-action#manifest
const results = JSON.parse(process.env.LIGHTHOUSE_RESULT as string);
const results = JSON.parse(process.env.LIGHTHOUSE_RESULT);

// this will be the shape of https://github.com/treosh/lighthouse-ci-action#links
const links = JSON.parse(process.env.LIGHTHOUSE_LINKS as string);
const links = JSON.parse(process.env.LIGHTHOUSE_LINKS);

// start creating our markdown table
const header = [
Expand All @@ -38,10 +21,10 @@ export const formatLighthouseResults = ({ core }: { core: Core }) => {
];

// map over each url result, formatting and linking to the output
const urlResults = results.map(({ url, summary }: Result) => {
const urlResults = results.map(({ url, summary }) => {
// make the tested link as a markdown link, without the long-generated host
const shortPreviewLink = `[${url.replace(
process.env.VERCEL_PREVIEW_URL as string,
process.env.VERCEL_PREVIEW_URL,
'',
)}](${url})`;

Expand Down

0 comments on commit 320a8c4

Please sign in to comment.