Coder Social home page Coder Social logo

dima-hx / lighthouse.net Goto Github PK

View Code? Open in Web Editor NEW
15.0 2.0 6.0 47 KB

Auditing, performance metrics, and best practices for Progressive Web Apps in .NET tests.

Home Page: https://www.nuget.org/packages/lighthouse.net

License: Apache License 2.0

C# 100.00%
audit pwa web performance-metrics developer-tools asp-net asp-net-core csharp unit-testing

lighthouse.net's Introduction

lighthouse.net Nuget

This is a .net (c#) library for Google 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.

How to install

You need to install lighthouse as Node module on machine (more info).

  1. Download Google Chrome for Desktop.

  2. Install the current Long-Term Support version of Node.

  3. Install Lighthouse. The -g flag installs it as a global module. npm install -g lighthouse

  4. Install lighthouse.net into your project via NuGet

PM> Install-Package lighthouse.net

Basic example

[TestClass]
public class LighthouseTest
{
    [TestMethod]
    public async Task ExampleComAudit()
    {
        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.5m);

        Assert.IsNotNull(res.Seo);
        Assert.IsTrue(res.Seo > 0.5m);
    }
}

Known Issues

  • If you installed lighthouse package with version 9.0.0 and higher it's required to use Node.js version 14 (because Optional Chaining Operator is used in lighthouse package). To install lighthouse package, that supports Node.js v12 please use npm i [email protected] -g

lighthouse.net's People

Contributors

dima-hx avatar alexandrelocas avatar rcorvus avatar

Stargazers

lucas vasconcelos avatar  avatar José Wenceslao Castillo avatar Onur Gumus avatar John Smith avatar Arturs Krapans avatar Moritz Müller avatar Moe Manshad avatar  avatar Cocoy avatar  avatar Oleksandr Pidhainyi avatar  avatar Stuart Greig avatar Luke Paireepinart avatar

Watchers

 avatar Oleksandr Pidhainyi avatar

lighthouse.net's Issues

Using Lighthouse v8.0.0 causes crash

Using a slightly adjusted version of the basic example from the readme causes a crash due to an unhandled exception when using Lighthouse v8.0.0. Downgrading Lighthouse to v7.5.0 resolves this issue.

An unhandled exception has occurred while executing the request.
System.Exception: (node:12080) [DEP0147] DeprecationWarning: In future versions of Node.js, fs.rmdir(path, { recursive: true }) will be removed. Use fs.rm(path, { recursive: true }) instead(Use 'node --trace-deprecation ...' to show where the warning was created)

I'm not using the LTS version of Node.

DisableDeviceEmulation and EmulatedFormFactor does not give results for Desktop and gives scores for mobile by default

Sample code is below . Please let me know what are the correct steps to be used for receiving desktop scores and my lighthouse version is 1.0.6
public async Task Audit()
{

        try
        {
            var lh = new Lighthouse();
            string upmcURL = ConfigurationManager.AppSettings.Get("upmc");
            var ar = new AuditRequest(upmcURL);
            ar.DisableDeviceEmulation = true;
            ar.EnableLogging = false;

       
            {
                ar.EmulatedFormFactor = AuditRequest.FormFactor.Desktop;
                ar.EnableLogging = false;
                
            };
             

            var res = await lh.Run(ar);

}

Add Detailed Performance info

I'd like to add the detailed performance info to the AuditResult class, such as First Contentful Paint, SpeedIndex etc. This is available in the report json file (this is my first feature/contribution request by the way).

Compatibility dotnet5,6,7

Hi
I'm planning to use this library in a dotnet project.
I see this project is using .NET Standard 2.0, do you have some plans to make it compatible with dotnet?
Thank you in advance.

Setting EmulatedFormFactor does not return any results

Calling the following method never completes the async Task. However, if I remove "EmulatedFormFactor=FormFactor.Mobile" property from the AuditRequest everything seems to work. Any ideas? I am wanting to look at Desktop vs. Mobile metrics.

          static async Task GetLightHouseValsAsync(string url, FormFactor form)
          {
              try
              {
                  var lh = new Lighthouse();
  
                  var ar = new AuditRequest(@url)
                  {
                      OnlyCategories = new[]
                      {
                          lighthouse.net.Objects.Category.SEO,
                          lighthouse.net.Objects.Category.Performance,
                          lighthouse.net.Objects.Category.Accessibility,
                          lighthouse.net.Objects.Category.BestPractices,
                          lighthouse.net.Objects.Category.PWA,
                      },
                      EmulatedFormFactor=FormFactor.Mobile,
                      EnableLogging = false,
                  };
                  var res = await lh.Run(ar);
  
                  if (res != null)
                  {
                      Console.WriteLine("Performance: " + (res.Performance * 100) + "%");
                      Console.WriteLine("Accessibility: " + (res.Accessibility * 100) + "%");
                      Console.WriteLine("BestPractices: " + (res.BestPractices * 100) + "%");
                      Console.WriteLine("PWA: " + (res.Pwa * 100) + "%");
                      Console.WriteLine("SEO: " + (res.Seo * 100) + "%");
                  }
                  else
                  {
                      Console.WriteLine("No LightHouse Data!");
                  }
              }
              catch(Exception ex)
              {
                  Console.WriteLine(ex.Message);
              }
          }

Feature request - add possibility to add custom headers to run

In order to gather metrics for some of the pages I need to pre-setup additional headers (authorization, cookies, e.t.c). It shouldn't be too hard to implement, so I can do it by my self and create PR, just want to make sure this repo is still supported and my commit can be merged.

Regardless, thank you for creating this lib. I am looking forward to use it a lot in future for .net test automation projects.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.