- 
                Notifications
    
You must be signed in to change notification settings  - Fork 5.2k
 
[browser] Migrate more Blazor features, prepare JavaScript API for Blazor cleanup #87959
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            64 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      b0f2999
              
                Import functions from blazor
              
              
                maraf ba25c1f
              
                Merge remote-tracking branch 'upstream/main' into WasmSatelliteLazyLoad
              
              
                maraf 7dd3d71
              
                Satellite assembly callback
              
              
                maraf 1c4081c
              
                Lazy loading callback
              
              
                maraf e3f8887
              
                Fix imports. Use locateFile
              
              
                maraf e8aa02c
              
                Interop for lazy loading and satellite
              
              
                maraf 54b2c90
              
                Dissolve startupOptions
              
              
                maraf 968829d
              
                Merge remote-tracking branch 'upstream/main' into WasmSatelliteLazyLoad
              
              
                maraf 12ecc3d
              
                WBT test for lazy loading
              
              
                maraf b44c755
              
                WBT for satellite loading.
              
              
                maraf b792851
              
                Refactor tests
              
              
                maraf 3a48997
              
                Merge remote-tracking branch 'upstream/main' into WasmSatelliteLazyLoad
              
              
                maraf e860e40
              
                Fix checking is lazy assembly was already loaded
              
              
                maraf 3ceaf94
              
                Introduce WasmDebugLevel to Wasm SDK.
              
              
                maraf 3fe3fc4
              
                bootConfig.aspnetCoreBrowserTools -> env:__ASPNETCORE_BROWSER_TOOLS
              
              
                maraf 1347c2d
              
                Alternatives for withStartupOptions
              
              
                maraf 919f238
              
                Import JS intializers
              
              
                maraf 1e8ef5d
              
                Pass runtime API to onRuntimeReady library initializer
              
              
                maraf 2c73ca2
              
                Library initializer test
              
              
                maraf 3d17711
              
                Merge remote-tracking branch 'upstream/main' into WasmSatelliteLazyLoad
              
              
                maraf 8fbb58f
              
                Ensure loadedAssemblies has value
              
              
                maraf 3e8575d
              
                Register new WBT for CI run
              
              
                maraf be9831f
              
                Fix resolving URL when baseURI contains a query string
              
              
                maraf 5c329b5
              
                Resources in mono config
              
              
                maraf cc65ac9
              
                Unify GlobalizationMode and ICUDataMode
              
              
                maraf 6789edd
              
                Include extensions in monoConfig
              
              
                maraf 37b50fa
              
                Generate dotnet.d.ts
              
              
                maraf 9b2a5d4
              
                Load libraryInitializers early and add onRuntimeConfigLoaded
              
              
                maraf d8c1b93
              
                Fix test
              
              
                maraf 1a90ef1
              
                Fix application environment. Add tests
              
              
                maraf 89fa18d
              
                Merge remote-tracking branch 'upstream/main' into WasmSatelliteLazyLoad
              
              
                maraf 4e0b921
              
                Drop .NET 8.0 condition on default value for WasmDebugLevel
              
              
                maraf b1aa977
              
                Use funcs from loaderHelpers
              
              
                maraf fa9dbbe
              
                Check document and document.baseURI
              
              
                maraf 3a3ab7a
              
                Licence headers
              
              
                maraf b0fe374
              
                Comments in tests
              
              
                maraf eab8e45
              
                File scoped namespace
              
              
                maraf 81a7474
              
                Drop export for BootJsonData and ICUDataMode
              
              
                maraf 5f8b211
              
                Update comment
              
              
                maraf 6a40be5
              
                Remove extra text from test
              
              
                maraf 101af8e
              
                Fix no-prototype-builtins
              
              
                maraf bbfea47
              
                Comment with marshaled signature
              
              
                maraf d6939a9
              
                Failed lazy load test. Fix double set result on error
              
              
                maraf a33e227
              
                Catch and log errors from library intializers
              
              
                maraf 975ae2f
              
                Merge remote-tracking branch 'upstream/main' into WasmSatelliteLazyLoad
              
              
                maraf e67550f
              
                Split library initializers by required download place
              
              
                maraf ce9b2cc
              
                Fix build
              
              
                maraf 2680a37
              
                Missing end lines
              
              
                maraf 0c3db1c
              
                Fix boot json generator for new library initializers schema
              
              
                maraf 77ea58e
              
                Make way to override content check for library initializer load place
              
              
                maraf 9af8dfc
              
                Drop duplicate initialization of loaderHelpers.loadedAssemblies
              
              
                maraf 42d982d
              
                Feedback
              
              
                maraf 872bc57
              
                Move libraryInitializers and loadBootResource to loaderHelpers
              
              
                maraf cd52d28
              
                Abort startup on library initializer error. Replace getLibraryInitial…
              
              
                maraf 39732dc
              
                Replace toAbsoluteBaseUri with locateFile
              
              
                maraf 88ceb2a
              
                Update WBT
              
              
                maraf 72661c2
              
                Export invokeLibraryInitializers early so onConfigLoaded callbacks ca…
              
              
                maraf 8d4656b
              
                Use config fileName when checking file name
              
              
                maraf 5d895db
              
                Export GlobalizationMode
              
              
                maraf 0d62773
              
                Feedback
              
              
                maraf 9722b6b
              
                Fix URL polyfill usage in locateFile
              
              
                maraf e8b282d
              
                Pass TargetFrameworkVersion to the GenerateWasmBootJson instead of bo…
              
              
                maraf b2b5308
              
                Merge remote-tracking branch 'upstream/main' into WasmSatelliteLazyLoad
              
              
                maraf 934e7e4
              
                Backward compatibility (1)
              
              
                maraf File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
  
    
      
          
            47 changes: 47 additions & 0 deletions
          
          47 
        
  src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/AppSettingsTests.cs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| 
     | 
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using System.Threading.Tasks; | ||
| using Xunit; | ||
| using Xunit.Abstractions; | ||
| 
     | 
||
| #nullable enable | ||
| 
     | 
||
| namespace Wasm.Build.Tests.TestAppScenarios; | ||
| 
     | 
||
| public class AppSettingsTests : AppTestBase | ||
| { | ||
| public AppSettingsTests(ITestOutputHelper output, SharedBuildPerTestClassFixture buildContext) | ||
| : base(output, buildContext) | ||
| { | ||
| } | ||
| 
     | 
||
| [Theory] | ||
| [InlineData("Development")] | ||
| [InlineData("Production")] | ||
| public async Task LoadAppSettingsBasedOnApplicationEnvironment(string applicationEnvironment) | ||
| { | ||
| CopyTestAsset("WasmBasicTestApp", "AppSettingsTests"); | ||
| PublishProject("Debug"); | ||
| 
     | 
||
| var result = await RunSdkStyleApp(new( | ||
| Configuration: "Debug", | ||
| ForPublish: true, | ||
| TestScenario: "AppSettingsTest", | ||
| BrowserQueryString: new Dictionary<string, string> { ["applicationEnvironment"] = applicationEnvironment } | ||
| )); | ||
| Assert.Collection( | ||
| result.TestOutput, | ||
| m => Assert.Equal(GetFileExistenceMessage("/appsettings.json", true), m), | ||
| m => Assert.Equal(GetFileExistenceMessage("/appsettings.Development.json", applicationEnvironment == "Development"), m), | ||
| m => Assert.Equal(GetFileExistenceMessage("/appsettings.Production.json", applicationEnvironment == "Production"), m) | ||
| ); | ||
| } | ||
| 
     | 
||
| // Synchronize with AppSettingsTest | ||
| private static string GetFileExistenceMessage(string path, bool expected) => $"'{path}' exists '{expected}'"; | ||
| } | 
        
          
  
    
      
          
            133 changes: 133 additions & 0 deletions
          
          133 
        
  src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/AppTestBase.cs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| 
     | 
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using System.Security.Authentication.ExtendedProtection; | ||
| using System.Text; | ||
| using System.Text.RegularExpressions; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.Playwright; | ||
| using Xunit.Abstractions; | ||
| 
     | 
||
| namespace Wasm.Build.Tests.TestAppScenarios; | ||
| 
     | 
||
| public abstract class AppTestBase : BuildTestBase | ||
| { | ||
| protected AppTestBase(ITestOutputHelper output, SharedBuildPerTestClassFixture buildContext) | ||
| : base(output, buildContext) | ||
| { | ||
| } | ||
| 
     | 
||
| protected string Id { get; set; } | ||
| protected string LogPath { get; set; } | ||
| 
     | 
||
| protected void CopyTestAsset(string assetName, string generatedProjectNamePrefix = null) | ||
| { | ||
| Id = $"{generatedProjectNamePrefix ?? assetName}_{Path.GetRandomFileName()}"; | ||
| InitBlazorWasmProjectDir(Id); | ||
| 
     | 
||
| LogPath = Path.Combine(s_buildEnv.LogRootPath, Id); | ||
| Utils.DirectoryCopy(Path.Combine(BuildEnvironment.TestAssetsPath, assetName), Path.Combine(_projectDir!)); | ||
| } | ||
| 
     | 
||
| protected void BuildProject(string configuration) | ||
| { | ||
| CommandResult result = CreateDotNetCommand().ExecuteWithCapturedOutput("build", $"-bl:{GetBinLogFilePath()}", $"-p:Configuration={configuration}"); | ||
| result.EnsureSuccessful(); | ||
| } | ||
| 
     | 
||
| protected void PublishProject(string configuration) | ||
| { | ||
| CommandResult result = CreateDotNetCommand().ExecuteWithCapturedOutput("publish", $"-bl:{GetBinLogFilePath()}", $"-p:Configuration={configuration}"); | ||
| result.EnsureSuccessful(); | ||
| } | ||
| 
     | 
||
| protected string GetBinLogFilePath(string suffix = null) | ||
| { | ||
| if (!string.IsNullOrEmpty(suffix)) | ||
| suffix = "_" + suffix; | ||
| 
     | 
||
| return Path.Combine(LogPath, $"{Id}{suffix}.binlog"); | ||
| } | ||
| 
     | 
||
| protected ToolCommand CreateDotNetCommand() => new DotNetCommand(s_buildEnv, _testOutput) | ||
| .WithWorkingDirectory(_projectDir!) | ||
| .WithEnvironmentVariable("NUGET_PACKAGES", _nugetPackagesDir); | ||
| 
     | 
||
| protected async Task<RunResult> RunSdkStyleApp(RunOptions options) | ||
| { | ||
| string runArgs = $"{s_xharnessRunnerCommand} wasm webserver --app=. --web-server-use-default-files"; | ||
| string workingDirectory = Path.GetFullPath(Path.Combine(FindBlazorBinFrameworkDir(options.Configuration, forPublish: options.ForPublish), "..")); | ||
| 
     | 
||
| using var runCommand = new RunCommand(s_buildEnv, _testOutput) | ||
| .WithWorkingDirectory(workingDirectory); | ||
| 
     | 
||
| var tcs = new TaskCompletionSource<int>(); | ||
| 
     | 
||
| List<string> testOutput = new(); | ||
| List<string> consoleOutput = new(); | ||
| Regex exitRegex = new Regex("WASM EXIT (?<exitCode>[0-9]+)$"); | ||
| 
     | 
||
| await using var runner = new BrowserRunner(_testOutput); | ||
| 
     | 
||
| IPage page = null; | ||
| 
     | 
||
| string queryString = "?test=" + options.TestScenario; | ||
| if (options.BrowserQueryString != null) | ||
| queryString += "&" + string.Join("&", options.BrowserQueryString.Select(kvp => $"{kvp.Key}={kvp.Value}")); | ||
| 
     | 
||
| page = await runner.RunAsync(runCommand, runArgs, onConsoleMessage: OnConsoleMessage, modifyBrowserUrl: url => url + queryString); | ||
| 
     | 
||
| void OnConsoleMessage(IConsoleMessage msg) | ||
| { | ||
| if (EnvironmentVariables.ShowBuildOutput) | ||
| Console.WriteLine($"[{msg.Type}] {msg.Text}"); | ||
| 
     | 
||
| _testOutput.WriteLine($"[{msg.Type}] {msg.Text}"); | ||
| consoleOutput.Add(msg.Text); | ||
| 
     | 
||
| const string testOutputPrefix = "TestOutput -> "; | ||
| if (msg.Text.StartsWith(testOutputPrefix)) | ||
| testOutput.Add(msg.Text.Substring(testOutputPrefix.Length)); | ||
| 
     | 
||
| var exitMatch = exitRegex.Match(msg.Text); | ||
| if (exitMatch.Success) | ||
| tcs.TrySetResult(int.Parse(exitMatch.Groups["exitCode"].Value)); | ||
| 
     | 
||
| if (msg.Text.StartsWith("Error: Missing test scenario")) | ||
| throw new Exception(msg.Text); | ||
| 
     | 
||
| if (options.OnConsoleMessage != null) | ||
| options.OnConsoleMessage(msg, page); | ||
| } | ||
| 
     | 
||
| TimeSpan timeout = TimeSpan.FromMinutes(2); | ||
| await Task.WhenAny(tcs.Task, Task.Delay(timeout)); | ||
| if (!tcs.Task.IsCompleted) | ||
| throw new Exception($"Timed out after {timeout.TotalSeconds}s waiting for process to exit"); | ||
| 
     | 
||
| int wasmExitCode = tcs.Task.Result; | ||
| if (options.ExpectedExitCode != null && wasmExitCode != options.ExpectedExitCode) | ||
| throw new Exception($"Expected exit code {options.ExpectedExitCode} but got {wasmExitCode}"); | ||
| 
     | 
||
| return new(wasmExitCode, testOutput, consoleOutput); | ||
| } | ||
| 
     | 
||
| protected record RunOptions( | ||
| string Configuration, | ||
| string TestScenario, | ||
| Dictionary<string, string> BrowserQueryString = null, | ||
| bool ForPublish = false, | ||
| Action<IConsoleMessage, IPage> OnConsoleMessage = null, | ||
| int? ExpectedExitCode = 0 | ||
| ); | ||
| 
     | 
||
| protected record RunResult( | ||
| int ExitCode, | ||
| IReadOnlyCollection<string> TestOutput, | ||
| IReadOnlyCollection<string> ConsoleOutput | ||
| ); | ||
| } | 
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.