https://github.com/fescobar/lighthousedotnet
https://github.com/fescobar/lighthousedotnet
Last synced: over 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/fescobar/lighthousedotnet
- Owner: fescobar
- Created: 2023-02-28T17:03:23.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-03-04T09:08:53.000Z (over 3 years ago)
- Last Synced: 2025-02-12T10:57:15.396Z (over 1 year ago)
- Language: C#
- Size: 13.7 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# LighthouseDotnet
[](https://www.nuget.org/packages/LighthouseDotnet)
This is a .net (c#) library for [Google Lighthouse](https://github.com/GoogleChrome/lighthouse) tool.
Lighthouse.NET analyzes web apps and web pages, collecting modern performance metrics and insights on developer best practices from your code.
*Auditing, performance metrics, and best practices for Progressive Web Apps in .NET tests.*
Compatible with newest version from dotnet5 and working from `Docker` containers.
- Note: Project based on https://github.com/dima-horror/lighthouse.net
## PRE-REQUISITES
- Install Google Chrome https://www.google.com/chrome/
- Install node from 18x version https://nodejs.org/en/download/
- Install lighthouse `10.0.2` globally
```sh
npm i lighthouse@10.0.2 -g
```
- Install lighthouse.net into your project via NuGet
```
PM> Install-Package LighthouseDotnet
```
- https://www.nuget.org/packages/LighthouseDotnet
## USAGE
[LighthouseDotnetTests.cs](https://github.com/fescobar/LighthouseDotnet/blob/main/LighthouseDotnetTests/Tests/LighthouseDotnetTests.cs)
```c#
[Test]
public async Task NpmExistTest()
{
var lh = new Lighthouse();
var res = await lh.Run("http://example.com");
Assert.IsNotNull(res);
Assert.IsNotNull(res.Performance);
Assert.IsTrue(res.Performance > 0.5m);
Assert.IsNotNull(res.Accessibility);
Assert.IsTrue(res.Accessibility > 0.5m);
Assert.IsNotNull(res.BestPractices);
Assert.IsTrue(res.BestPractices > 0.5m);
Assert.IsNotNull(res.Pwa);
Assert.IsTrue(res.Pwa > 0.2m);
Assert.IsNotNull(res.Seo);
Assert.IsTrue(res.Seo > 0.2m);
}
```
```c#
[Test]
public async Task GetHtmlReport()
{
var lh = new Lighthouse();
var res = await lh.Run("http://example.com");
var reportsDir = "./lighthouse-reports";
var filename = $"{Guid.NewGuid()}--{DateTime.Now:dd-MM-yyyy--HH-mm-ss}";
var reportPath = lh.SaveReportHtml(reportsDir, filename, res);
Console.WriteLine(reportPath);
var report = File.ReadAllText(reportPath);
Console.WriteLine(report);
Assert.NotNull(report);
}
```
```c#
[Test]
public async Task GetCsvReport()
{
var lh = new Lighthouse();
var res = await lh.Run("http://example.com");
var reportsDir = "./lighthouse-reports";
var filename = $"{Guid.NewGuid()}--{DateTime.Now:dd-MM-yyyy--HH-mm-ss}";
var reportPath = lh.SaveReportCsv(reportsDir, filename, res);
Console.WriteLine(reportPath);
var reportContent = File.ReadAllText(reportPath);
Assert.False(String.IsNullOrEmpty(reportContent.Trim()));
}
```
```c#
[Test]
public async Task GetJsonReport()
{
var lh = new Lighthouse();
var res = await lh.Run("http://example.com");
var reportsDir = "./lighthouse-reports";
var filename = $"{Guid.NewGuid()}--{DateTime.Now:dd-MM-yyyy--HH-mm-ss}";
var reportPath = lh.SaveReportJson(reportsDir, filename, res);
Console.WriteLine(reportPath);
var reportContent = File.ReadAllText(reportPath);
Assert.False(String.IsNullOrEmpty(reportContent.Trim()));
}
```