diff --git a/cypress-demo/config.js b/cypress-demo/config.js index 02e1b02..b10a714 100644 --- a/cypress-demo/config.js +++ b/cypress-demo/config.js @@ -8,7 +8,7 @@ module.exports = { reports: [ "html", (_options, result) => { - console.log(result) + console.log(result); }, ], verbose: true, diff --git a/cypress-demo/cypress.config.js b/cypress-demo/cypress.config.js index 134a0e0..5fee410 100644 --- a/cypress-demo/cypress.config.js +++ b/cypress-demo/cypress.config.js @@ -21,6 +21,7 @@ if(fs.existsSync(ecoIndexOutputPathDir)){ fs.mkdirSync(ecoIndexOutputPathDir, {recursive: true}); fs.mkdirSync(lighthouseOutputPathDir, {recursive: true}); + module.exports = defineConfig({ e2e: { setupNodeEvents(on) { @@ -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, diff --git a/cypress-demo/cypress/e2e/demo.cy.js b/cypress-demo/cypress/e2e/demo.cy.js index e066e99..678beb3 100644 --- a/cypress-demo/cypress/e2e/demo.cy.js +++ b/cypress-demo/cypress/e2e/demo.cy.js @@ -10,6 +10,6 @@ describe("template spec", () => { it("lighthouse", () => { cy.visit(url); - cy.lighthouse(); + cy.lighthouse(undefined, { output: "html"}); }); }); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 0401fbe..2f13054 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2044,6 +2044,16 @@ "integrity": "sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ==", "dev": true }, + "fs-extra": { + "version": "11.1.1", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.1.1.tgz", + "integrity": "sha512-MGIE4HOvQCeUCzmlHs0vXpih4ysz4wg9qiSAu6cd42lVwPbTM1TjV7RusoyQqMmk/95gdQZX72u+YW+c3eEpFQ==", + "requires": { + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" + } + }, "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -2122,8 +2132,7 @@ "graceful-fs": { "version": "4.2.11", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", - "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==", - "dev": true + "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==" }, "grapheme-splitter": { "version": "1.0.4", @@ -3641,6 +3650,15 @@ "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", "dev": true }, + "jsonfile": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", + "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", + "requires": { + "graceful-fs": "^4.1.6", + "universalify": "^2.0.0" + } + }, "kleur": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/kleur/-/kleur-3.0.3.tgz", @@ -4352,6 +4370,11 @@ "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.17.4.tgz", "integrity": "sha512-T9q82TJI9e/C1TAxYvfb16xO120tMVFZrGA3f9/P4424DNu6ypK103y0GPFVa17yotwSyZW5iYXgjYHkGrJW/g==" }, + "universalify": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", + "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==" + }, "update-browserslist-db": { "version": "1.0.10", "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.0.10.tgz", diff --git a/package.json b/package.json index 78d9f85..dc699fe 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/reporters/generatorReports.js b/src/reporters/generatorReports.js index 91fc6af..4ac6cfb 100644 --- a/src/reporters/generatorReports.js +++ b/src/reporters/generatorReports.js @@ -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, @@ -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"); @@ -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,