Skip to content

Commit

Permalink
feat: be able to send aggregated data to anywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmanuelDemey committed Mar 30, 2023
1 parent c4df77f commit 743ffab
Show file tree
Hide file tree
Showing 7 changed files with 299 additions and 78 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",
};
60 changes: 25 additions & 35 deletions cypress-demo/cypress.config.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,38 @@
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("../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 => {
Expand All @@ -45,21 +42,14 @@ module.exports = defineConfig({
finalPath,
JSON.stringify(result.lhr, undefined, 2));
}),
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
168 changes: 161 additions & 7 deletions cypress-demo/package-lock.json

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

2 changes: 1 addition & 1 deletion cypress-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"devDependencies": {
"cypress": "^12.3.0",
"@cypress-audit/lighthouse": "^1.4.2",
"eco-index-audit": "^3.2.0"
"eco-index-audit": "^4.2.0"
}
}
Loading

0 comments on commit 743ffab

Please sign in to comment.