Skip to content

Commit

Permalink
Merge pull request #23 from AxaFrance/feat/review
Browse files Browse the repository at this point in the history
Feat/review
  • Loading branch information
sandydelhoute authored Mar 30, 2023
2 parents 7dc82c3 + f19bddd commit a02b1de
Show file tree
Hide file tree
Showing 12 changed files with 1,267 additions and 7,864 deletions.
18 changes: 18 additions & 0 deletions cypress-demo/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const path = require("path");
const fs = require("fs");

const lighthouseOutputPathDir = path.join(__dirname, "reports/lighthouse");
const ecoIndexOutputPathDir = path.join(__dirname, "reports/ecoindex");

module.exports = {
reports: [
"html",
(_options, result) => {
console.log(result);
},
],
verbose: true,
srcLighthouse: lighthouseOutputPathDir,
srcEcoIndex: ecoIndexOutputPathDir,
outputPath: "report_final",
};
69 changes: 31 additions & 38 deletions cypress-demo/cypress.config.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,58 @@
const {defineConfig} = require("cypress");
const {lighthouse, prepareAudit} = require("@cypress-audit/lighthouse")
const {lighthouse, prepareAudit} = require("@cypress-audit/lighthouse");
const fs = require("fs");
const path = require("path");
const aggregate = require("lighthouse-eco-index-aggregator/src/main");
const aggregate = require("../src/main");

const { prepareAudit: prepareEcoIndexAudit, checkEcoIndex } = require("eco-index-audit/src/cypress");
const { cwd } = require("process");


const lighthouseOutputPathDir = path.join(__dirname, "reports/lighthouse");
const ecoIndexOutputPathDir = path.join(__dirname, "reports/ecoindex");
const globalOutputPathDir = path.join(__dirname, "reports");
fs.rmdirSync(globalOutputPathDir, { recursive: true, force: true });

if(fs.existsSync(lighthouseOutputPathDir)){
fs.rmdirSync(lighthouseOutputPathDir, { recursive: true, force: true });
}
if(fs.existsSync(ecoIndexOutputPathDir)){
fs.rmdirSync(ecoIndexOutputPathDir, { recursive: true, force: true });
}

fs.mkdirSync(ecoIndexOutputPathDir, {recursive: true});
fs.mkdirSync(lighthouseOutputPathDir, {recursive: true});


module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
setupNodeEvents(on) {
on("after:run", async () => {
await aggregate({
reports: "html",
verbose: true,
srcLighthouse: lighthouseOutputPathDir,
srcEcoIndex: ecoIndexOutputPathDir,
outputPath: path.resolve(globalOutputPathDir, "report.html")
config: path.resolve(cwd(), "./config.js")
});
});

on("before:browser:launch", (_browser = {}, launchOptions) => {
prepareAudit(launchOptions);

const remoteDebuggingPort = launchOptions.args.find((config) => config.startsWith("--remote-debugging-port"));
const remoteDebuggingAddress = launchOptions.args.find((config) =>
config.startsWith("--remote-debugging-address")
);
if (remoteDebuggingPort) {
global.remote_debugging_port = remoteDebuggingPort.split("=")[1];
}
if (remoteDebuggingAddress) {
global.remote_debugging_address = remoteDebuggingAddress.split("=")[1];
}
prepareEcoIndexAudit(launchOptions);
});
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, overrideOptions} = {}) {
const check = require("eco-index-audit/src/main");
return check(
{
...overrideOptions,
url: url,
output: "json",
outputPathDir: ecoIndexOutputPathDir,
outputPath: path.join(ecoIndexOutputPathDir, `${url.replace("://", "_").replace("/", "_")}.json`),
remote_debugging_port: global.remote_debugging_port,
remote_debugging_address: global.remote_debugging_address,
},
true
);
},
checkEcoIndex: ({ url }) => checkEcoIndex({
url,
options: {
output: ["json"],
outputPathDir: ecoIndexOutputPathDir,
outputFileName: url.replace("://", "_").replace("/", "_"),
}
})
});
},
},
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"});
});
});
Loading

0 comments on commit a02b1de

Please sign in to comment.