DotnetLighthouse 1.0.5

dotnet add package DotnetLighthouse --version 1.0.5                
NuGet\Install-Package DotnetLighthouse -Version 1.0.5                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DotnetLighthouse" Version="1.0.5" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DotnetLighthouse --version 1.0.5                
#r "nuget: DotnetLighthouse, 1.0.5"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DotnetLighthouse as a Cake Addin
#addin nuget:?package=DotnetLighthouse&version=1.0.5

// Install DotnetLighthouse as a Cake Tool
#tool nuget:?package=DotnetLighthouse&version=1.0.5                

DotnetLighthouse

DotnetLighthouse is a .NET library to run Lighthouse audits and process the results.

Prerequisites

  • Make sure you have Google Chrome installed
  • Make sure you have latest version of Node install (recommend to use LTS version) https://nodejs.org/en/download/prebuilt-installer
  • Install Lighthouse cli globally, by running following command by opening up your terminal/command prompt
npm install -g lighthouse 
  • You already have your dotnet test project using .net8.0 or higher or use following to create a xunit project
dotnet new xunit -o DotnetLighthouse.Tests

Installation

Now navigate to your project directory (e.g. DotnetLighthouse.Tests) You can install the DotnetLighthouse package by running following command in terminal:

dotnet add package DotnetLighthouse

Sample Code

  • Create a new test file "LighthouseAudit.cs"
  • Add following code into the class
using System;
using Xunit;
using DotnetLighthouse;

public class LighthouseAudit
{
[Fact]
        public void ValidateJsonAudit()
        {
            // Define the URL to be audited
            var url = "https://www.google.com";
            
            // Create an instance of LighthouseHelper with the specified URL
            var lighthouseHelper = new LighthouseHelper(url);
            
            // Run the Lighthouse audit for the specified URL
            lighthouseHelper.RunLighthouseAudit();
            
            // Retrieve the performance score from the Lighthouse audit results
            var performanceScore = lighthouseHelper.PerformanceScore;
            
            // Retrieve the accessibility score from the Lighthouse audit results
            var accessibilityScore = lighthouseHelper.AccessibilityScore;
            
            // Retrieve the best practices score from the Lighthouse audit results
            var bestPracticesScore = lighthouseHelper.BestPracticesScore;
            
            // Retrieve the SEO score from the Lighthouse audit results
            var seoScore = lighthouseHelper.SeoScore;
            
            // Retrieve the PWA score from the Lighthouse audit results
            var pwaScore = lighthouseHelper.PwaScore;
            
            // Assert that the performance score is greater than 90
            Assert.True(performanceScore > 90);
        }
}

More Configurations

  • By Default DotnetLighthouse generate Lghthouse Audit report with name "lighthouse-report.json" in bin folder. In case you want a different name you can update by overriding property "OutputPath"
  • You also have option to provide the custom config JS file as well, use following line of code to do the same
        var lighthouseHelper = new LighthouseHelper(url);
        // Use this line to enable custom config
        lighthouseHelper.ConfigPath = "<YoucustomconfigconfigFile>.js";
        // Run the Lighthouse audit for the specified URL
        lighthouseHelper.RunLighthouseAudit();
        var url = "https://www.google.com";
        var lighthouseHelper = new LighthouseHelper(url);
        lighthouseHelper.Preset = string.Empty;
        lighthouseHelper.AdditionalArguments = "--form-factor=desktop --screenEmulation.disabled";
        // Run the Lighthouse audit for the specified URL
        lighthouseHelper.RunLighthouseAudit();

Dependencies

This project has the following dependencies:

  • HtmlAgilityPack
  • Newtonsoft.Json

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

Known Issue

Only JSON reporting is supporting for Score Assertions and WIP for Supporting Score Extraction from HTML file.

Authors

Raj Uppadhyay

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.5 112 10/15/2024
1.0.4 89 10/14/2024
1.0.3 95 10/13/2024
1.0.2 83 10/13/2024
1.0.1 86 10/13/2024
1.0.0 83 10/13/2024