Skip to content

Commit a7177ee

Browse files
Add test for PWA publish output
1 parent 8f0afb2 commit a7177ee

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/ProjectTemplates/test/BlazorWasmTemplateTest.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ public async Task BlazorWasmPwaTemplate_Works()
110110
var publishDir = Path.Combine(project.TemplatePublishDir, project.ProjectName, "dist");
111111
AspNetProcess.EnsureDevelopmentCertificates();
112112

113+
// When publishing the PWA template, we move service-worker.published.js to overwrite
114+
// service-worker.js, and append a GUID variable
115+
Assert.False(File.Exists(Path.Combine(publishDir, "service-worker.published.js")), "The 'published' service worker should be renamed on publish");
116+
Assert.True(File.Exists(Path.Combine(publishDir, "service-worker.js")), "There should be a service worker in the output");
117+
var serviceWorkerContents = File.ReadAllText(Path.Combine(publishDir, "service-worker.js"));
118+
Assert.True(serviceWorkerContents.Contains("const serviceWorkerVersion = '"), "The published service worker should contain a version variable");
119+
113120
Output.WriteLine("Running dotnet serve on published output...");
114121
using var serveProcess = ProcessEx.Run(Output, publishDir, DotNetMuxer.MuxerPathOrDefault(), "serve -S");
115122

0 commit comments

Comments
 (0)