-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[release/8.0-staging] [browser] Fix debugger support (#98494)
- Loading branch information
Showing
29 changed files
with
337 additions
and
99 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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
86 changes: 86 additions & 0 deletions
86
src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DebugLevelTestsBase.cs
This file contains 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,86 @@ | ||
// 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 abstract class DebugLevelTestsBase : AppTestBase | ||
{ | ||
public DebugLevelTestsBase(ITestOutputHelper output, SharedBuildPerTestClassFixture buildContext) | ||
: base(output, buildContext) | ||
{ | ||
} | ||
|
||
protected void AssertDebugLevel(RunResult result, int value) | ||
{ | ||
Assert.Collection( | ||
result.TestOutput, | ||
m => Assert.Equal($"WasmDebugLevel: {value}", m) | ||
); | ||
} | ||
|
||
protected abstract void SetupProject(string projectId); | ||
protected abstract Task<RunResult> RunForBuild(string configuration); | ||
protected abstract Task<RunResult> RunForPublish(string configuration); | ||
|
||
[Theory] | ||
[InlineData("Debug")] | ||
[InlineData("Release")] | ||
public async Task BuildWithDefaultLevel(string configuration) | ||
{ | ||
SetupProject($"DebugLevelTests_BuildWithDefaultLevel_{configuration}"); | ||
BuildProject(configuration, assertAppBundle: false); | ||
|
||
var result = await RunForBuild(configuration); | ||
AssertDebugLevel(result, -1); | ||
} | ||
|
||
[Theory] | ||
[InlineData("Debug", 1)] | ||
[InlineData("Release", 1)] | ||
[InlineData("Debug", 0)] | ||
[InlineData("Release", 0)] | ||
public async Task BuildWithExplicitValue(string configuration, int debugLevel) | ||
{ | ||
SetupProject($"DebugLevelTests_BuildWithExplicitValue_{configuration}"); | ||
BuildProject(configuration, assertAppBundle: false, extraArgs: $"-p:WasmDebugLevel={debugLevel}"); | ||
|
||
var result = await RunForBuild(configuration); | ||
AssertDebugLevel(result, debugLevel); | ||
} | ||
|
||
[Theory] | ||
[InlineData("Debug")] | ||
[InlineData("Release")] | ||
public async Task PublishWithDefaultLevel(string configuration) | ||
{ | ||
SetupProject($"DebugLevelTests_PublishWithDefaultLevel_{configuration}"); | ||
PublishProject(configuration, assertAppBundle: false); | ||
|
||
var result = await RunForPublish(configuration); | ||
AssertDebugLevel(result, 0); | ||
} | ||
|
||
[Theory] | ||
[InlineData("Debug", 1)] | ||
[InlineData("Release", 1)] | ||
[InlineData("Debug", -1)] | ||
[InlineData("Release", -1)] | ||
public async Task PublishWithExplicitValue(string configuration, int debugLevel) | ||
{ | ||
SetupProject($"DebugLevelTests_PublishWithExplicitValue_{configuration}"); | ||
PublishProject(configuration, assertAppBundle: false, extraArgs: $"-p:WasmDebugLevel={debugLevel}"); | ||
|
||
var result = await RunForPublish(configuration); | ||
AssertDebugLevel(result, debugLevel); | ||
} | ||
} |
This file contains 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 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 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 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
69 changes: 69 additions & 0 deletions
69
src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/WasmAppBuilderDebugLevelTests.cs
This file contains 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,69 @@ | ||
// 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 WasmAppBuilderDebugLevelTests : DebugLevelTestsBase | ||
{ | ||
public WasmAppBuilderDebugLevelTests(ITestOutputHelper output, SharedBuildPerTestClassFixture buildContext) | ||
: base(output, buildContext) | ||
{ | ||
} | ||
|
||
protected override void SetupProject(string projectId) | ||
{ | ||
Id = $"{projectId}_{GetRandomId()}"; | ||
string projectfile = CreateWasmTemplateProject(Id, "wasmconsole", extraArgs: "-f net8.0"); | ||
string projectDir = Path.GetDirectoryName(projectfile)!; | ||
string mainJs = Path.Combine(projectDir, "main.mjs"); | ||
string mainJsContent = File.ReadAllText(mainJs); | ||
mainJsContent = mainJsContent | ||
.Replace("await dotnet.run()", "console.log('TestOutput -> WasmDebugLevel: ' + config.debugLevel); exit(0)"); | ||
File.WriteAllText(mainJs, mainJsContent); | ||
} | ||
|
||
protected override Task<RunResult> RunForBuild(string configuration) | ||
{ | ||
CommandResult res = new RunCommand(s_buildEnv, _testOutput) | ||
.WithWorkingDirectory(_projectDir!) | ||
.ExecuteWithCapturedOutput($"run --no-silent --no-build -c {configuration}"); | ||
|
||
return Task.FromResult(ProcessRunOutput(res)); | ||
} | ||
|
||
private RunResult ProcessRunOutput(CommandResult res) | ||
{ | ||
var output = res.Output.Split(Environment.NewLine); | ||
_testOutput.WriteLine($"DEBUG: parsed lines '{String.Join(", ", output)}'"); | ||
|
||
var prefix = "[] TestOutput -> "; | ||
var testOutput = output | ||
.Where(l => l.StartsWith(prefix)) | ||
.Select(l => l.Substring(prefix.Length)) | ||
.ToArray(); | ||
|
||
_testOutput.WriteLine($"DEBUG: testOutput '{String.Join(", ", testOutput)}'"); | ||
return new RunResult(res.ExitCode, testOutput, output); | ||
} | ||
|
||
protected override Task<RunResult> RunForPublish(string configuration) | ||
{ | ||
// WasmAppBuilder does publish to the same folder as build (it overrides the output), | ||
// and thus using dotnet run work correctly for publish as well. | ||
CommandResult res = new RunCommand(s_buildEnv, _testOutput) | ||
.WithWorkingDirectory(_projectDir!) | ||
.ExecuteWithCapturedOutput($"run --no-silent --no-build -c {configuration}"); | ||
|
||
return Task.FromResult(ProcessRunOutput(res)); | ||
} | ||
} |
Oops, something went wrong.