{"id":47929963,"url":"https://github.com/cnumr/ecoindex-audit","last_synced_at":"2026-04-04T07:15:02.373Z","repository":{"id":172812119,"uuid":"641408697","full_name":"cnumr/ecoindex-audit","owner":"cnumr","description":null,"archived":false,"fork":false,"pushed_at":"2024-02-19T21:27:28.000Z","size":1819,"stargazers_count":7,"open_issues_count":7,"forks_count":3,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-10-20T04:49:44.028Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cnumr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-05-16T12:08:51.000Z","updated_at":"2025-09-01T12:04:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"3c4dcd2f-e808-488b-b4c0-75147c212758","html_url":"https://github.com/cnumr/ecoindex-audit","commit_stats":{"total_commits":148,"total_committers":5,"mean_commits":29.6,"dds":"0.10810810810810811","last_synced_commit":"8dffd7050bec21d4cb6c198823aa365678713710"},"previous_names":["cnumr/ecoindex-audit"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/cnumr/ecoindex-audit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cnumr%2Fecoindex-audit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cnumr%2Fecoindex-audit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cnumr%2Fecoindex-audit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cnumr%2Fecoindex-audit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cnumr","download_url":"https://codeload.github.com/cnumr/ecoindex-audit/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cnumr%2Fecoindex-audit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31391079,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-04T04:26:24.776Z","status":"ssl_error","status_checked_at":"2026-04-04T04:23:34.147Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-04-04T07:15:01.629Z","updated_at":"2026-04-04T07:15:02.362Z","avatar_url":"https://github.com/cnumr.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Eco Index Audit\n\n[![Actions Status](https://github.com/cnumr/ecoindex-audit/workflows/Build/badge.svg)](https://github.com/cnumr/ecoindex-audit/actions)\n[![npm version](https://badge.fury.io/js/@cnumr%2Feco-index-audit.svg)](https://badge.fury.io/js/@cnumr%2Feco-index-audit)\n\nThis tool is the CLI version of [this website](https://www.ecoindex.fr/)\n\n## Installation\n\nIf you just need to run an audit, you can use NPX\n\n```bash\nnpx @cnumr/eco-index-audit --url=https://www.google.com/ --ecoIndex=50 --visits=2000 --output=table\n\nnpx @cnumr/eco-index-audit --url=https://www.google.com/ --ecoIndex=50 --visits=2000 --output=csv\n\nnpx @cnumr/eco-index-audit --url=https://www.google.com/ --ecoIndex=50 --visits=2000 --output=json\n\nnpx @cnumr/eco-index-audit --url=https://www.google.com/ --ecoIndex=50 --visits=2000 --output=sonar --sonarFilePath=index.html --outputPathDir=./reports\n```\n\nBut you can also clone, install and run the project locally.\n\n```bash\ngit clone https://github.com/cnumr/eco-index-audit\ncd eco-index-audit\nnpm i\n```\n\n## Usage/Examples\n\n```shell\nnode ./src/cli.js --url=https://www.google.com/ --ecoIndex=50 --visits=2000 --output=table\nnode ./src/cli.js --url=https://www.google.com/ --ecoIndex=50 --visits=2000 --output=csv\nnode ./src/cli.js --url=https://www.google.com/ --ecoIndex=50 --visits=2000 --output=json\n```\n\n## CI Integration\n\nYou can execute this module directly from your CI. Here is an example for Github Actions :\n\n```yaml\nname: Running Eco Index via a Github Action\n\non:\n  workflow_dispatch:\n\njobs:\n  build:\n    runs-on: ubuntu-latest\n\n    steps:\n      - uses: actions/checkout@v3\n      - name: Use Node.js\n        uses: actions/setup-node@v3\n        with:\n          node-version: 16\n      - run: npx @cnumr/eco-index-audit --url=https://www.google.com/ --ecoIndex=90 --output=table\n```\n\n## Integration with Sonar\n\nSince the version _3.3.0_ the CLI can generate a external sonar report you can add to the Sonar configuration (via the `sonar.externalIssuesReportPaths` option).\n\nYou need to define the path to one of your file managed by Sonar, in order to make the rule visible in Sonar Cloud.\n\n```shell\nnpx @cnumr/eco-index-audit --url=https://www.google.com/ --ecoIndex=50 --visits=2000 --output=sonar --sonarFilePath=index.html --outputPathDir=./reports\n```\n\n## Integration with Cypress\n\nFor the moment, you can only use `eco-index-audit` inside a Cypress test suites running on a Chromium-based browser.\n\n```shell\nnpx cypress run -b chrome\n```\n\nYou are able to run this module during your Cypress test. The first step is to define a new task in the `cypress.config.js` file.\n\n```js\nconst { defineConfig } = require(\"cypress\");\nconst {\n  prepareAudit,\n  checkEcoIndex,\n} = require(\"eco-@cnumr/eco-index-audit/src/cypress\");\n\nmodule.exports = defineConfig({\n  e2e: {\n    setupNodeEvents(on) {\n      on(\"before:browser:launch\", (_browser, launchOptions) =\u003e {\n        prepareAudit(launchOptions);\n      });\n\n      on(\"task\", {\n        checkEcoIndex: ({ url, options }) =\u003e\n          checkEcoIndex({\n            url,\n            options: {\n              headless: false,\n              globals: { data: \"data\" },\n              beforeScript: (globals) =\u003e console.log(globals),\n              afterScript: (globals) =\u003e console.log(globals),\n              cookies: [{name:\"mycookie\", value:\"mycookieValue\", domain:\"mydomain.com\", httpOnly:false}]\n            },\n          }),\n      });\n    },\n  },\n});\n```\n\nIf the `headless` parameter is set to false, the UI will opened with the Devtools enabled and will automatically stopped running everything after loading the page (using a debugger statement),\n\nThe `globals` object can be used if you need to share some data during the execution of the `beforeScript` and `afterScript` hooks. This object will be available as a parameter to these two hooks.\n\nInside a Cypress test, `eco-index-audit` will reuse the same Chromium-based browser used by Cypress.\n\nAnd then use this task inside your test. Inside your test, you can check if the ecoIndex is below a threshold.\n\n```js\ndescribe(\"Cypress test\", () =\u003e {\n  const url = \"https://google.com\";\n  beforeEach(() =\u003e {\n    cy.visit(url);\n  });\n\n  it(\"should have a good ecoindex\", () =\u003e {\n    const threshold = 50;\n    cy.task(\"checkEcoIndex\", { url })\n      .its(\"ecoIndex\", { timeout: 0 })\n      .should(\"be.greaterThan\", threshold);\n  });\n});\n```\n\nIf you have interceptors inside your Cypress test, your eco-index will be better than expected. In order to be as closed as the reality, you can update the initial values of the metrics we used to. For example, if you intercept 4 HTTP requests of 1024 bytes\n\n```js\ndescribe(\"Cypress test\", () =\u003e {\n  const url = \"https://google.com\";\n  beforeEach(() =\u003e {\n    cy.visit(url);\n  });\n\n  it(\"should have a good ecoindex\", () =\u003e {\n    const threshold = 50;\n    cy.task(\"checkEcoIndex\", {\n      url,\n      initialValues: {\n        numberOfRequests: 4,\n        sizeOfRequests: 4 * 1024,\n      },\n    })\n      .its(\"ecoIndex\", { timeout: 0 })\n      .should(\"be.greaterThan\", threshold);\n  });\n});\n```\n\nYou can also define the `outputPathDir` option in order to save the result in a file. These properties are only use for the `json` and `csv` formats.\n\n```js\nconst path = require(\"path\");\n\ndescribe(\"Cypress test\", () =\u003e {\n  const url = \"https://google.com\";\n  beforeEach(() =\u003e {\n    cy.visit(url);\n  });\n\n  const outputPathDir = path.join(__dirname, \"reports\");\n\n  it(\"should have a good ecoindex\", () =\u003e {\n    const threshold = 50;\n    cy.task(\"checkEcoIndex\", {\n      url,\n      options: {\n        output: \"json\",\n        outputPathDir,\n      },\n    })\n      .its(\"ecoIndex\", { timeout: 0 })\n      .should(\"be.greaterThan\", threshold);\n  });\n});\n```\n\nYou can also add a `timeout` before closing the Puppeteer page in order to debug the page thank to the `beforeClosingPageTimeout` options. The value is in `ms`\n\n```js\ndescribe(\"Cypress test\", () =\u003e {\n  const url = \"https://google.com\";\n  beforeEach(() =\u003e {\n    cy.visit(url);\n  });\n\n  it(\"should have a good ecoindex\", () =\u003e {\n    const threshold = 50;\n    cy.task(\"checkEcoIndex\", {\n      url,\n      options: {\n        beforeClosingPageTimeout: 10000,\n      },\n    })\n      .its(\"ecoIndex\", { timeout: 0 })\n      .should(\"be.greaterThan\", threshold);\n  });\n});\n```\n\n## Integration with Playwright\n\nWe can also run the `eco-index-audit` module inside a Playwright test. In this repository, we have a working demo. you just need to run the following command after cloning the source code.\n\n```shell\nnpx playwright test\n```\n\nIn order to be able to run this module inside a Playwright test suites, you need to add this configuration in your `playwright.config.ts`\n\n```typescript\n{\n  name: 'chromium',\n  use: {\n    ...devices['Desktop Chrome'],\n    launchOptions: {\n      args: ['--remote-debugging-port=9222'],\n    }\n  },\n\n}\n```\n\nAn then, in the configuration of `eco-index-audit`, you need to reuse the same `9222` HTTP port.\n\n```typescript\nimport { test, expect } from \"@playwright/test\";\nconst check = require(\"../src/main\");\n\ntest(\"get started link\", async ({ page, launchOptions }) =\u003e {\n  const url = \"https://playwright.dev/\";\n\n  await page.goto(url);\n\n  // Click the get started link.\n  await page.getByRole(\"link\", { name: \"Get started\" }).click();\n\n  // Expects the URL to contain intro.\n  await expect(page).toHaveURL(/.*intro/);\n\n  const result = await check(\n    {\n      url,\n      remote_debugging_port: 9222,\n    },\n    true\n  );\n\n  expect(result.ecoIndex).toBe(100);\n});\n```\n\n## Configure via the eco-index-audit.js file\n\nYou can also configure this module via a `eco-index-audit.js` configuration file. This file should be located in the root folder of your project.\n\n```js\nmodule.exports = {\n  url: [\"https://www.google.com/\"],\n  output: [\"table\"],\n};\n```\n\nThanks to this file, you can enable dynamic output in order to archive results into any external service. In the following snippet, we will sotre the result into Elasticsearch.\n\n```js\nmodule.exports = {\n  url: [\"https://www.google.com/\"],\n  output: [\n    \"table\",\n    (results) =\u003e {\n      const { Client } = require(\"@elastic/elasticsearch\");\n      const client = new Client({\n        cloud: {\n          id: \"...\",\n        },\n        auth: {\n          username: \"...\",\n          password: \"...\",\n        },\n      });\n      client.index({\n        index: \"eco-index\",\n        document: results,\n      });\n    },\n  ],\n};\n```\n\n## Environment Variables\n\nYou can add environment variables in order to configure `eco-index-audit`:\n\n- `ECOINDEX_VERBOSE`: if set to true, will log more information in the terminal.\n- `ECOINDEX_DISPLAY_HTML`: if set to true, will log the HTML of the audited page.\n\n```\nECOINDEX_VERBOSE=true npx eco-index-audit --url=https://www.google.com/ --ecoIndex=50 --visits=2000 --output=table\n```\n\n## Tests\n\nUpdate snapshots with `npm test -- -u`\n\n## Tech Stack\n\nTypescript, Puppeteer, Cypress\n\n## Resources\n\n- [Eco Index Audit Cypress Plugin by Gleb Bahmutov](https://www.youtube.com/watch?v=pmuPVl7mdKI)\n\n## Authors\n\n- [@EmmanuelDemey](https://www.github.com/EmmanuelDemey)\n\n## Disclaimer\n\nThe LCA values used by [ecoindex_api](https://github.com/cnumr/ecoindex_api) to evaluate environmental impacts are not under free license - ©Frédéric Bordage\nPlease also refer to the mentions provided in the code files for specifics on the IP regime.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcnumr%2Fecoindex-audit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcnumr%2Fecoindex-audit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcnumr%2Fecoindex-audit/lists"}