Skip to content

Commit 26f0b79

Browse files
Add E2E tests
1 parent 684dfd0 commit 26f0b79

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

src/Components/WebAssembly/testassets/HostedInAspNet.Client/wwwroot/index.html

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@
77
<body>
88
<app>Loading...</app>
99
<script src="customJsFileForTests.js"></script>
10-
<script src="_framework/blazor.webassembly.js"></script>
10+
<script src="_framework/blazor.webassembly.js" autostart="false"></script>
11+
12+
<!--
13+
To show we can customize the boot resource loading process, the server looks for these
14+
flags when collecting logs, and E2E tests check the right entries were seen.
15+
-->
16+
<script>
17+
Blazor.start({
18+
loadBootResource: function (type, name, defaultUri, integrity) {
19+
return type === 'dotnetjs'
20+
? `${defaultUri}?customizedbootresource=true`
21+
: fetch(defaultUri, { integrity: integrity, cache: 'no-cache', headers: { 'customizedbootresource': 'true' } });
22+
}
23+
});
24+
</script>
1125
</body>
1226
</html>

src/Components/WebAssembly/testassets/HostedInAspNet.Server/RequestLog.cs renamed to src/Components/WebAssembly/testassets/HostedInAspNet.Server/BootResourceRequestLog.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace HostedInAspNet.Server
88
{
9-
public class RequestLog
9+
public class BootResourceRequestLog
1010
{
1111
private List<string> _requestPaths = new List<string>();
1212

src/Components/WebAssembly/testassets/HostedInAspNet.Server/Startup.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,21 @@ public class Startup
1414
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
1515
public void ConfigureServices(IServiceCollection services)
1616
{
17-
services.AddSingleton<RequestLog>();
17+
services.AddSingleton<BootResourceRequestLog>();
1818
}
1919

2020
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
21-
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, RequestLog requestLog)
21+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, BootResourceRequestLog bootResourceRequestLog)
2222
{
2323
app.Use((context, next) =>
2424
{
25-
// This is used by E2E tests to verify that the correct resources were fetched
26-
requestLog.AddRequest(context.Request);
25+
// This is used by E2E tests to verify that the correct resources were fetched,
26+
// and that it was possible to override the loading mechanism
27+
if (context.Request.Query.ContainsKey("customizedbootresource")
28+
|| context.Request.Headers.ContainsKey("customizedbootresource"))
29+
{
30+
bootResourceRequestLog.AddRequest(context.Request);
31+
}
2732
return next();
2833
});
2934

src/Components/test/E2ETest/Tests/BootResourceCachingTest.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public void CachesResourcesAfterFirstLoad()
4646
var initialResourcesRequested = GetAndClearRequestedPaths();
4747
Assert.NotEmpty(initialResourcesRequested.Where(path => path.EndsWith("/blazor.boot.json")));
4848
Assert.NotEmpty(initialResourcesRequested.Where(path => path.EndsWith("/dotnet.wasm")));
49-
Assert.NotEmpty(initialResourcesRequested.Where(path => path.EndsWith(".js")));
49+
Assert.NotEmpty(initialResourcesRequested.Where(path => path.EndsWith("/dotnet.timezones.dat")));
50+
Assert.NotEmpty(initialResourcesRequested.Where(path => path.EndsWith(".js?customizedbootresource=true")));
5051
Assert.NotEmpty(initialResourcesRequested.Where(path => path.EndsWith(".dll")));
5152

5253
// On subsequent loads, we skip the items referenced from blazor.boot.json
@@ -57,11 +58,12 @@ public void CachesResourcesAfterFirstLoad()
5758
var subsequentResourcesRequested = GetAndClearRequestedPaths();
5859
Assert.NotEmpty(initialResourcesRequested.Where(path => path.EndsWith("/blazor.boot.json")));
5960
Assert.Empty(subsequentResourcesRequested.Where(path => path.EndsWith("/dotnet.wasm")));
60-
Assert.NotEmpty(subsequentResourcesRequested.Where(path => path.EndsWith(".js")));
61+
Assert.Empty(initialResourcesRequested.Where(path => path.EndsWith("/dotnet.timezones.dat")));
62+
Assert.NotEmpty(subsequentResourcesRequested.Where(path => path.EndsWith(".js?customizedbootresource=true")));
6163
Assert.Empty(subsequentResourcesRequested.Where(path => path.EndsWith(".dll")));
6264
}
6365

64-
[Fact(Skip = "https://github.com/dotnet/aspnetcore/issues/20154")]
66+
[Fact]
6567
public void IncrementallyUpdatesCache()
6668
{
6769
// Perform a first load to populate the cache
@@ -137,7 +139,7 @@ private void AddCacheEntry(string url, string content)
137139

138140
private IReadOnlyCollection<string> GetAndClearRequestedPaths()
139141
{
140-
var requestLog = _serverFixture.Host.Services.GetRequiredService<RequestLog>();
142+
var requestLog = _serverFixture.Host.Services.GetRequiredService<BootResourceRequestLog>();
141143
var result = requestLog.RequestPaths.ToList();
142144
requestLog.Clear();
143145
return result;

0 commit comments

Comments
 (0)