/
LighthouseDotnetTests.cs
135 lines (108 loc) · 4.06 KB
/
LighthouseDotnetTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
using LighthouseDotnet;
using LighthouseDotnet.Objects;
using NUnit.Framework;
using System;
using System.Threading.Tasks;
using System.IO;
using static LighthouseDotnet.Objects.AuditRequest;
namespace LighthouseDotnetTests.Tests
{
public class LighthouseDonetTests
{
[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 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()));
}
[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 reportContent = File.ReadAllText(reportPath);
Assert.False(String.IsNullOrEmpty(reportContent.Trim()));
}
[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 ScreenShots()
{
var lh = new Lighthouse();
var res = await lh.Run("http://example.com");
Assert.IsNotNull(res);
Assert.IsNotNull(res.FinalScreenshot);
Assert.IsFalse(String.IsNullOrWhiteSpace(res.FinalScreenshot.Base64Data));
Assert.IsNotNull(res.Thumbnails);
Assert.IsFalse(res.Thumbnails.Count == 0);
Assert.IsFalse(String.IsNullOrWhiteSpace(res.Thumbnails[0].Base64Data));
}
[Test]
public async Task FormFactorTest()
{
var lh = new Lighthouse();
var ar = new AuditRequest("http://example.com")
{
EmulatedFormFactor = FormFactor.Desktop
};
var res = await lh.Run(ar);
Assert.IsNotNull(res);
}
[Test]
[Ignore("TODO")]
public async Task OnlyCategoriesTest()
{
var lh = new Lighthouse();
var ar = new AuditRequest("http://example.com")
{
OnlyCategories = new[]
{
Category.Performance,
},
EnableLogging = true
};
var res = await lh.Run(ar);
Assert.IsNotNull(res);
Assert.IsNotNull(res.Performance);
Assert.IsTrue(res.Performance > 0.5m);
Assert.IsNull(res.Accessibility);
}
}
}