diff --git a/src/mono/browser/runtime/loader/assets.ts b/src/mono/browser/runtime/loader/assets.ts index c8ef478a7628f..03cbbfdf7db6e 100644 --- a/src/mono/browser/runtime/loader/assets.ts +++ b/src/mono/browser/runtime/loader/assets.ts @@ -375,12 +375,12 @@ export function prepareAssets () { if (config.loadAllSatelliteResources && resources.satelliteResources) { for (const culture in resources.satelliteResources) { for (const name in resources.satelliteResources[culture]) { - assetsToLoad.push({ + addAsset({ name, hash: resources.satelliteResources[culture][name], behavior: "resource", culture - }); + }, !resources.coreAssembly); } } } diff --git a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/SatelliteLoadingTests.cs b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/SatelliteLoadingTests.cs index 3acee24e88536..4ef606b784e45 100644 --- a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/SatelliteLoadingTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/SatelliteLoadingTests.cs @@ -24,19 +24,35 @@ public SatelliteLoadingTests(ITestOutputHelper output, SharedBuildPerTestClassFi { } - [Fact, TestCategory("no-fingerprinting")] - public async Task LoadSatelliteAssembly() + [Theory, TestCategory("no-fingerprinting")] + [InlineData(false)] + [InlineData(true)] + public async Task LoadSatelliteAssembly(bool loadAllSatelliteResources) { CopyTestAsset("WasmBasicTestApp", "SatelliteLoadingTests", "App"); BuildProject("Debug"); - var result = await RunSdkStyleAppForBuild(new(Configuration: "Debug", TestScenario: "SatelliteAssembliesTest")); + var result = await RunSdkStyleAppForBuild(new( + Configuration: "Debug", + TestScenario: "SatelliteAssembliesTest", + BrowserQueryString: new Dictionary { ["loadAllSatelliteResources"] = loadAllSatelliteResources.ToString().ToLowerInvariant() } + )); + + var expectedOutput = new List>(); + if (!loadAllSatelliteResources) + { + // If we are loading all satellite, we don't have a way to test resources without satellite assemblies being loaded. + // So there messages are should be present only when we are lazily loading satellites. + expectedOutput.Add(m => Assert.Equal("default: hello", m)); + expectedOutput.Add(m => Assert.Equal("es-ES without satellite: hello", m)); + } + + expectedOutput.Add(m => Assert.Equal("default: hello", m)); + expectedOutput.Add(m => Assert.Equal("es-ES with satellite: hola", m)); + Assert.Collection( result.TestOutput, - m => Assert.Equal("default: hello", m), - m => Assert.Equal("es-ES without satellite: hello", m), - m => Assert.Equal("default: hello", m), - m => Assert.Equal("es-ES with satellite: hola", m) + expectedOutput.ToArray() ); } diff --git a/src/mono/wasm/testassets/WasmBasicTestApp/App/SatelliteAssembliesTest.cs b/src/mono/wasm/testassets/WasmBasicTestApp/App/SatelliteAssembliesTest.cs index 23f3df8098cc5..8d7631e0c8f6c 100644 --- a/src/mono/wasm/testassets/WasmBasicTestApp/App/SatelliteAssembliesTest.cs +++ b/src/mono/wasm/testassets/WasmBasicTestApp/App/SatelliteAssembliesTest.cs @@ -8,11 +8,13 @@ public partial class SatelliteAssembliesTest { [JSExport] - public static async Task Run() + public static async Task Run(bool loadSatelliteAssemblies) { - ResourceLibrary.ResourceAccessor.Read(TestOutput.WriteLine, false); - - await LoadSatelliteAssemblies(new[] { "es-ES" }); + if (loadSatelliteAssemblies) + { + ResourceLibrary.ResourceAccessor.Read(TestOutput.WriteLine, false); + await LoadSatelliteAssemblies(new[] { "es-ES" }); + } ResourceLibrary.ResourceAccessor.Read(TestOutput.WriteLine, true); } diff --git a/src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js b/src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js index f0515c8dfe5cb..f76edd8c9874f 100644 --- a/src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js +++ b/src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js @@ -27,6 +27,11 @@ dotnet // Modify runtime start based on test case switch (testCase) { + case "SatelliteAssembliesTest": + if (params.get("loadAllSatelliteResources") === "true") { + dotnet.withConfig({ loadAllSatelliteResources: true }); + } + break; case "AppSettingsTest": dotnet.withApplicationEnvironment(params.get("applicationEnvironment")); break; @@ -132,7 +137,7 @@ const assemblyExtension = Object.keys(config.resources.coreAssembly)[0].endsWith try { switch (testCase) { case "SatelliteAssembliesTest": - await exports.SatelliteAssembliesTest.Run(); + await exports.SatelliteAssembliesTest.Run(params.get("loadAllSatelliteResources") !== "true"); exit(0); break; case "LazyLoadingTest":