Skip to content

fescobar/LighthouseDotnet

Repository files navigation

LighthouseDotnet

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.

Compatible with newest version from dotnet5 and working from Docker containers.

PRE-REQUISITES

npm i lighthouse@10.0.2 -g
  • Install lighthouse.net into your project via NuGet
PM> Install-Package LighthouseDotnet

USAGE

LighthouseDotnetTests.cs

        [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);
        }
        [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);
        }
        [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()));
        }
        [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()));
        }

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages