forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[browser] Fix debugger support in WasmAppBuilder (dotnet#100675)
- Loading branch information
Showing
10 changed files
with
250 additions
and
146 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
109 changes: 0 additions & 109 deletions
109
src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DebugLevelTests.cs
This file was deleted.
Oops, something went wrong.
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); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
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,70 @@ | ||
// 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"); | ||
string projectDir = Path.GetDirectoryName(projectfile)!; | ||
string mainJs = Path.Combine(projectDir, "main.mjs"); | ||
string mainJsContent = File.ReadAllText(mainJs); | ||
mainJsContent = mainJsContent | ||
.Replace("import { dotnet }", "import { dotnet, exit }") | ||
.Replace("await runMainAndExit()", "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)); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/WasmSdkDebugLevelTests.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,46 @@ | ||
// 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 WasmSdkDebugLevelTests : DebugLevelTestsBase | ||
{ | ||
public WasmSdkDebugLevelTests(ITestOutputHelper output, SharedBuildPerTestClassFixture buildContext) | ||
: base(output, buildContext) | ||
{ | ||
} | ||
|
||
protected override void SetupProject(string projectId) => CopyTestAsset("WasmBasicTestApp", projectId, "App"); | ||
|
||
protected override Task<RunResult> RunForBuild(string configuration) => RunSdkStyleAppForBuild(new( | ||
Configuration: configuration, | ||
TestScenario: "DebugLevelTest" | ||
)); | ||
|
||
protected override Task<RunResult> RunForPublish(string configuration) => RunSdkStyleAppForPublish(new( | ||
Configuration: configuration, | ||
TestScenario: "DebugLevelTest" | ||
)); | ||
|
||
[Theory] | ||
[InlineData("Debug")] | ||
[InlineData("Release")] | ||
public async Task PublishWithDefaultLevelAndPdbs(string configuration) | ||
{ | ||
SetupProject($"DebugLevelTests_PublishWithDefaultLevelAndPdbs_{configuration}"); | ||
PublishProject(configuration, assertAppBundle: false, extraArgs: $"-p:CopyOutputSymbolsToPublishDirectory=true"); | ||
|
||
var result = await RunForPublish(configuration); | ||
AssertDebugLevel(result, -1); | ||
} | ||
} |
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
Oops, something went wrong.