{"id":15433929,"url":"https://github.com/abhinaba-ghosh/testcafe-lighthouse","last_synced_at":"2025-04-19T18:09:14.732Z","repository":{"id":38212746,"uuid":"270426134","full_name":"abhinaba-ghosh/testcafe-lighthouse","owner":"abhinaba-ghosh","description":":mag: Run Lighthouse performance audit with TestCafe","archived":false,"fork":false,"pushed_at":"2023-11-09T23:28:03.000Z","size":5215,"stargazers_count":10,"open_issues_count":13,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-18T08:34:23.516Z","etag":null,"topics":["audit","lighthouse","lighthouse-audits","testcafe"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/testcafe-lighthouse","language":"JavaScript","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/abhinaba-ghosh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"patreon":"user?u=32109749","custom":["paypal.me/abhinabaghosh"]}},"created_at":"2020-06-07T20:36:44.000Z","updated_at":"2023-08-30T20:09:36.000Z","dependencies_parsed_at":"2024-10-20T20:32:27.227Z","dependency_job_id":null,"html_url":"https://github.com/abhinaba-ghosh/testcafe-lighthouse","commit_stats":{"total_commits":53,"total_committers":5,"mean_commits":10.6,"dds":"0.41509433962264153","last_synced_commit":"1c667498216afc2c9af90b891d7b7ef1f4204fc6"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhinaba-ghosh%2Ftestcafe-lighthouse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhinaba-ghosh%2Ftestcafe-lighthouse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhinaba-ghosh%2Ftestcafe-lighthouse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhinaba-ghosh%2Ftestcafe-lighthouse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/abhinaba-ghosh","download_url":"https://codeload.github.com/abhinaba-ghosh/testcafe-lighthouse/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249758729,"owners_count":21321585,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["audit","lighthouse","lighthouse-audits","testcafe"],"created_at":"2024-10-01T18:36:09.613Z","updated_at":"2025-04-19T18:09:14.702Z","avatar_url":"https://github.com/abhinaba-ghosh.png","language":"JavaScript","funding_links":["https://patreon.com/user?u=32109749","paypal.me/abhinabaghosh"],"categories":[],"sub_categories":[],"readme":"![screen](./docs/lh.jpg)\n\n## Lighthouse Testcafe - NPM Package\n\n[![NPM release](https://img.shields.io/npm/v/testcafe-lighthouse.svg 'NPM release')](https://www.npmjs.com/package/testcafe-lighthouse)\n\n[Lighthouse](https://developers.google.com/web/tools/lighthouse) is a tool developed by Google that analyzes web apps and web pages, collecting modern performance metrics and insights on developer best practices.\n\nThe purpose of this package is to produce performance report for several pages in connected mode and in an automated (programmatic) way.\n\n## Usage\n\n### Installation\n\nYou can have to add the `testcafe-lighthouse` library as a dependency (or dev-dependency) in your project\n\n```sh\n$ yarn add -D testcafe-lighthouse\n# or\n$ npm install --save-dev testcafe-lighthouse\n```\n\n### In your code\n\nAfter completion of the Installation, you can use `testcafe-lighthouse` in your code to audit the current page.\n\n**_Step 1:_**\nIn your test code you need to import `testcafe-lighthouse` and assign a `cdpPort` for the lighthouse scan. You can choose any non-allocated port.\n\n```js\nimport { testcafeAudit } from 'testcafe-lighthouse';\n\nfixture(`Audit Test`).page('http://localhost:3000/login');\n\ntest('user performs lighthouse audit', async (t) =\u003e {\n  const currentURL = await t.eval(() =\u003e document.documentURI);\n  await testcafeAudit({\n    url: currentURL,\n    cdpPort: 9222,\n  });\n});\n```\n\n**_Step 2:_**\nKick start test execution with the same `cdpPort`.\n\n```ssh\n// headless mode, preferable for CI\nnpx testcafe chrome:headless:cdpPort=9222 test.js\n\n// non headless mode\nnpx testcafe 'chrome:emulation:cdpPort=9222'  test.js\n```\n\n## Thresholds per tests\n\nIf you don't provide any threshold argument to the `testcafeAudit` command, the test will fail if at least one of your metrics is under `100`.\n\nYou can make assumptions on the different metrics by passing an object as argument to the `testcafeAudit` command:\n\n```javascript\nimport { testcafeAudit } from 'testcafe-lighthouse';\n\nfixture(`Audit Test`).page('https://angular.io/');\n\ntest('user page performance with specific thresholds', async (t) =\u003e {\n  const currentURL = await t.eval(() =\u003e document.documentURI);\n  await testcafeAudit({\n    url: currentURL,\n    thresholds: {\n      performance: 50,\n      accessibility: 50,\n      'best-practices': 50,\n      seo: 50,\n      pwa: 50,\n    },\n    cdpPort: 9222,\n  });\n});\n```\n\nIf the Lighthouse analysis returns scores that are under the one set in arguments, the test will fail.\n\nYou can also make assumptions only on certain metrics. For example, the following test will **only** verify the \"correctness\" of the `performance` metric:\n\n```javascript\ntest('user page performance with specific thresholds', async (t) =\u003e {\n  const currentURL = await t.eval(() =\u003e document.documentURI);\n  await testcafeAudit({\n    url: currentURL,\n    thresholds: {\n      performance: 85,\n    },\n    cdpPort: 9222,\n  });\n});\n```\n\nThis test will fail only when the `performance` metric provided by Lighthouse will be under `85`.\n\n## Passing different Lighthouse config to testcafe-lighthouse directly\n\nYou can also pass any argument directly to the Lighthouse module using the second and third options of the command:\n\n```js\nconst thresholdsConfig = {\n  /* ... */\n};\n\nconst lighthouseOptions = {\n  /* ... your lighthouse options */\n};\n\nconst lighthouseConfig = {\n  /* ... your lighthouse configs */\n};\n\nawait testcafeAudit({\n  thresholds: thresholdsConfig,\n  opts: lighthouseOptions,\n  config: lighthouseConfig,\n\n  /* ... other configurations */\n});\n```\n\n## Generating audit reports\n\n`testcafe-lighthouse` library can produce Lighthouse CSV, HTML and JSON audit reports, that you can host in your CI server. These reports can be useful for ongoing audits and monitoring from build to build.\n\n```js\nawait testcafeAudit({\n  /* ... other configurations */\n\n  reports: {\n    formats: {\n      /* you can any of them or combination of them */\n      json: true, //defaults to false\n      html: true, //defaults to false\n      csv: true, //defaults to false\n    },\n    name: `name-of-the-report`, //defaults to `lighthouse-${new Date().getTime()}`\n    directory: `path/to/directory`, //defaults to `${process.cwd()}/lighthouse`\n  },\n});\n```\n\nThis will result in below HTML report\n\n![screen](./docs/lighthouse_report.png)\n\n## Sample Tests\n\nYou can find sample tests [here](./test)\n\n## Demo\n\n![demo](./docs/demo.gif)\n\n## Tell me your issues\n\nyou can raise any issue [here](https://github.com/abhinaba-ghosh/testcafe-lighthouse/issues)\n\n## Before you go\n\nIf it works for you , give a [Star](https://github.com/abhinaba-ghosh/testcafe-lighthouse)! :star:\n\n_- Copyright \u0026copy; 2020- [Abhinaba Ghosh](https://www.linkedin.com/in/abhinaba-ghosh-9a2ab8a0/)_\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabhinaba-ghosh%2Ftestcafe-lighthouse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabhinaba-ghosh%2Ftestcafe-lighthouse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabhinaba-ghosh%2Ftestcafe-lighthouse/lists"}