-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[wasm][wbt] Test that
dotnet.js
could be run from any current direc…
…tory (#69441) In #72275 we fixed locateFile to deal with relative file path or URL. We could also handle absolute path/URL. This PR is adding tests to prove it works.
- Loading branch information
Showing
5 changed files
with
106 additions
and
5 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
37 changes: 37 additions & 0 deletions
37
src/tests/BuildWasmApps/Wasm.Build.Tests/ConfigSrcTests.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,37 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.IO; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
#nullable enable | ||
|
||
namespace Wasm.Build.Tests; | ||
|
||
public class ConfigSrcTests : BuildTestBase | ||
{ | ||
public ConfigSrcTests(ITestOutputHelper output, SharedBuildPerTestClassFixture buildContext) : base(output, buildContext) | ||
{} | ||
|
||
// NOTE: port number determinizes dynamically, so could not generate absolute URI | ||
[Theory] | ||
[BuildAndRun(host: RunHost.V8 | RunHost.NodeJS)] | ||
public void ConfigSrcAbsolutePath(BuildArgs buildArgs, RunHost host, string id) | ||
{ | ||
buildArgs = buildArgs with { ProjectName = $"configsrcabsolute_{buildArgs.Config}_{buildArgs.AOT}" }; | ||
buildArgs = ExpandBuildArgs(buildArgs); | ||
|
||
BuildProject(buildArgs, | ||
id: id, | ||
new BuildProjectOptions( | ||
InitProject: () => File.WriteAllText(Path.Combine(_projectDir!, "Program.cs"), s_mainReturns42), | ||
DotnetWasmFromRuntimePack: !(buildArgs.AOT || buildArgs.Config == "Release"))); | ||
|
||
string binDir = GetBinDir(baseDir: _projectDir!, config: buildArgs.Config); | ||
string bundleDir = Path.Combine(binDir, "AppBundle"); | ||
string configSrc = Path.GetFullPath(Path.Combine(bundleDir, "mono-config.json")); | ||
|
||
RunAndTestWasmApp(buildArgs, expectedExitCode: 42, host: host, id: id, extraXHarnessMonoArgs: $"--config-src={configSrc}"); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/tests/BuildWasmApps/Wasm.Build.Tests/WasmRunOutOfAppBundleTests.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,56 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.IO; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
#nullable enable | ||
|
||
namespace Wasm.Build.Tests; | ||
|
||
public class WasmRunOutOfAppBundleTests : BuildTestBase | ||
{ | ||
public WasmRunOutOfAppBundleTests(ITestOutputHelper output, SharedBuildPerTestClassFixture buildContext) : base(output, buildContext) | ||
{} | ||
|
||
[Theory] | ||
[BuildAndRun] | ||
public void RunOutOfAppBundle(BuildArgs buildArgs, RunHost host, string id) | ||
{ | ||
buildArgs = buildArgs with { ProjectName = $"outofappbundle_{buildArgs.Config}_{buildArgs.AOT}" }; | ||
buildArgs = ExpandBuildArgs(buildArgs); | ||
|
||
BuildProject(buildArgs, | ||
id: id, | ||
new BuildProjectOptions( | ||
InitProject: () => File.WriteAllText(Path.Combine(_projectDir!, "Program.cs"), s_mainReturns42), | ||
DotnetWasmFromRuntimePack: !(buildArgs.AOT || buildArgs.Config == "Release"))); | ||
|
||
string binDir = GetBinDir(baseDir: _projectDir!, config: buildArgs.Config); | ||
string appBundleDir = Path.Combine(binDir, "AppBundle"); | ||
string outerDir = Path.GetFullPath(Path.Combine(appBundleDir, "..")); | ||
|
||
if (host is RunHost.Chrome) | ||
{ | ||
string indexHtmlPath = Path.Combine(appBundleDir, "index.html"); | ||
// Delete the original one, so we don't use that by accident | ||
if (File.Exists(indexHtmlPath)) | ||
File.Delete(indexHtmlPath); | ||
|
||
indexHtmlPath = Path.Combine(outerDir, "index.html"); | ||
if (!File.Exists(indexHtmlPath)) | ||
{ | ||
var html = @"<html><body><script type=""module"" src=""./AppBundle/test-main.js""></script></body></html>"; | ||
File.WriteAllText(indexHtmlPath, html); | ||
} | ||
} | ||
|
||
RunAndTestWasmApp(buildArgs, | ||
expectedExitCode: 42, | ||
host: host, | ||
id: id, | ||
bundleDir: outerDir, | ||
jsRelativePath: "./AppBundle/test-main.js"); | ||
} | ||
} |