Skip to content

Commit

Permalink
feat: copy lighthouse and ecoindex folders into the target folder
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmanuelDemey committed Mar 30, 2023
1 parent 743ffab commit b2705e2
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cypress-demo/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
reports: [
"html",
(_options, result) => {
console.log(result)
console.log(result);
},
],
verbose: true,
Expand Down
7 changes: 5 additions & 2 deletions cypress-demo/cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ if(fs.existsSync(ecoIndexOutputPathDir)){
fs.mkdirSync(ecoIndexOutputPathDir, {recursive: true});
fs.mkdirSync(lighthouseOutputPathDir, {recursive: true});


module.exports = defineConfig({
e2e: {
setupNodeEvents(on) {
Expand All @@ -37,10 +38,12 @@ module.exports = defineConfig({
on("task", {
lighthouse: lighthouse(result => {
const url = result.lhr.finalUrl;
const finalPath = path.resolve(__dirname, path.join(lighthouseOutputPathDir, `${url.replace("://", "_").replace("/", "_")}.json`));
fs.writeFileSync(
finalPath,
path.resolve(__dirname, path.join(lighthouseOutputPathDir, `${url.replace("://", "_").replace("/", "_")}.json`)),
JSON.stringify(result.lhr, undefined, 2));
fs.writeFileSync(
path.resolve(__dirname, path.join(lighthouseOutputPathDir, `${url.replace("://", "_").replace("/", "_")}.html`)),
result.report);
}),
checkEcoIndex: ({ url }) => checkEcoIndex({
url,
Expand Down
2 changes: 1 addition & 1 deletion cypress-demo/cypress/e2e/demo.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ describe("template spec", () => {

it("lighthouse", () => {
cy.visit(url);
cy.lighthouse();
cy.lighthouse(undefined, { output: "html"});
});
});
27 changes: 25 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"command-line-args": "^5.2.1",
"command-line-usage": "^5.0.0",
"ejs": "^3.1.8",
"fs-extra": "^11.1.1",
"html-minifier": "^4.0.0"
},
"devDependencies": {
Expand Down
22 changes: 22 additions & 0 deletions src/reporters/generatorReports.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const fs = require("fs");
const path = require("path");
const folderTranslate = "translate";
const minify = require("html-minifier").minify;
const fse = require("fs-extra");

const {
globalNoteTag,
Expand Down Expand Up @@ -37,6 +38,7 @@ const computeCssClassForMetrics = require("./utils/computeCssClassForMetrics");
const pageInErrorOrWarning = require("./utils/displayPageErrorIcon");
const { statusGreen } = require("./utils/statusGreen");
const { statusPerPage } = require("./utils/statusPerPage");
const { basename } = require("path");



Expand Down Expand Up @@ -100,10 +102,30 @@ const generateReports = async (options, results) => {
options.lang = "en-GB";
}
options.translations = populateTranslation(options);

if(options.srcLighthouse){
const finalSrcLighthouse = options.outputPath + "/" + basename(options.srcLighthouse);
fse.copySync(options.srcLighthouse, finalSrcLighthouse, { overwrite: true });
options.srcLighthouse = finalSrcLighthouse;
}
if(options.srcEcoIndex){
const finalSrcEcoIndex = options.outputPath + "/" + basename(options.srcEcoIndex);
fse.copySync(options.srcEcoIndex, finalSrcEcoIndex, { overwrite: true });
options.srcEcoIndex = finalSrcEcoIndex;
}
results.perPages = results.perPages.map(page => {
return {
...page,
lighthouseReport: page.lighthouseReport ? `${options.srcLighthouse}/${basename(page.lighthouseReport)}` : "",
};
});

const htmlPerPageResult = await populateTemplatePerPage(options, results);
let htmlResult = await populateTemplate(options, results, htmlPerPageResult);




const minifyOptions = {
includeAutoGeneratedTags: true,
removeAttributeQuotes: true,
Expand Down

0 comments on commit b2705e2

Please sign in to comment.