Skip to content

Commit

Permalink
feat: rm gathered to use plugin with lhci and lightouse
Browse files Browse the repository at this point in the history
  • Loading branch information
hrenaud committed Nov 17, 2023
1 parent 81597eb commit 3b7509c
Show file tree
Hide file tree
Showing 6 changed files with 965 additions and 28 deletions.
11 changes: 10 additions & 1 deletion lighthouse-plugin-ecoindex/.release-it.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,14 @@
},
"hooks": {
"after:bump": "npx auto-changelog -p"
},
"plugins": {
"@j-ulrich/release-it-regex-bumper": {
"out": {
"file": "../examples/*/package.json",
"search": "\"lighthouse-plugin-ecoindex\":\\s*\"([0-9.]+)\"",
"replace": "\"lighthouse-plugin-ecoindex\": \"{{version}}\""
}
}
}
}
}
18 changes: 8 additions & 10 deletions lighthouse-plugin-ecoindex/audits/bp/print-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class BPPrintCSS extends Audit {
description: `A print css must be implemented to hide useless elements when printing. [See CNUMR BP_027](${refCnumr.bp_027.en})`,

// The name of the custom gatherer class that provides input to this audit.
requiredArtifacts: ['PrintCssGatherer', 'DOMStats', 'devtoolsLogs'],
requiredArtifacts: ['LinkElements', 'DOMStats', 'devtoolsLogs'],
}
}

Expand Down Expand Up @@ -50,16 +50,14 @@ class BPPrintCSS extends Audit {
}

static audit(artifacts) {
const value = artifacts.PrintCssGatherer.value
// const success = isNaN(value) && value >= 0
// console.log(
// 'artifacts.PrintCssGatherer.value',
// artifacts.PrintCssGatherer.value,
// )
const stylesheets = artifacts.LinkElements.filter(
link =>
link.rel === 'stylesheet' && link?.node?.snippet.match(/media="print"/),
)
return {
score: value > 0 ? 1 : 0,
displayValue: `Print CSS count: ${value}`,
numericValue: value,
score: stylesheets.length > 0 ? 1 : 0,
displayValue: `Print CSS count: ${stylesheets.length}`,
numericValue: stylesheets.length,
}
}
}
Expand Down
15 changes: 9 additions & 6 deletions lighthouse-plugin-ecoindex/audits/warn-nodes-count.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import { Audit } from 'lighthouse'
import { JSDOM } from 'jsdom'

class WarnNodesCount extends Audit {
static get meta() {
Expand All @@ -17,7 +18,7 @@ class WarnNodesCount extends Audit {
'Explication: In Ecoindex, we count all HTML nodes, withouts SVGs content.',

// The name of the custom gatherer class that provides input to this audit.
requiredArtifacts: ['NodesMinusSvgsGatherer', 'DOMStats', 'devtoolsLogs'],
requiredArtifacts: ['MainDocumentContent', 'DOMStats', 'devtoolsLogs'],
}
}

Expand Down Expand Up @@ -51,17 +52,19 @@ class WarnNodesCount extends Audit {
}

static audit(artifacts) {
const value = artifacts.NodesMinusSvgsGatherer.value
const MainDocumentContent = artifacts.MainDocumentContent
const dom = new JSDOM(MainDocumentContent)
const allNodes = dom.window.document.querySelectorAll('*').length
// const svgNodes = dom.window.document.querySelectorAll('svg').length
const svgContentNodes = dom.window.document.querySelectorAll('svg *').length
const value = allNodes - svgContentNodes
const DOMStats = artifacts.DOMStats.totalBodyElements
// const success = isNaN(value) && value >= 0

return {
numericValue: value,
// Cast true/false to 1/0
score: 0.8,
displayValue: `Ecoindex: ${value} - Lighthouse: ${DOMStats}`,
numericValue: value,
numericUnit: 'DOM elements',
// displayValue: value,
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions lighthouse-plugin-ecoindex/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import * as constants from 'lighthouse/core/config/constants.js'

import fs, { writeFileSync } from 'fs'

import CustomArtifacts from './gatherers/index.js'
import { hideBin } from 'yargs/helpers'
import path from 'path'
import puppeteer from 'puppeteer'
Expand Down Expand Up @@ -99,7 +98,6 @@ function getConfig(
disableStorageReset: isWarm,
},
plugins: ['lighthouse-plugin-ecoindex'],
artifacts: CustomArtifacts,
},
}
}
Expand Down
Loading

0 comments on commit 3b7509c

Please sign in to comment.