-
Notifications
You must be signed in to change notification settings - Fork 5.3k
[wasm][wbt] Test that dotnet.js could be run from any current directory
#69441
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
Changes from 6 commits
d5f10f5
2db7974
2952c7b
3922e05
d651c70
2f1c9eb
b6804be
5a94685
930c701
eb07469
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // 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}"); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| // 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 | ||
radical marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| 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 tmpBundleDirName = "AppBundleTmp"; | ||
| string tmpBundleDir = Path.Combine(binDir, tmpBundleDirName); | ||
|
||
|
|
||
| if (host == RunHost.Chrome) | ||
| { | ||
| Directory.Move(appBundleDir, tmpBundleDir); | ||
| Directory.CreateDirectory(appBundleDir); | ||
| // Create $binDir/AppBundle/AppBundle | ||
| Directory.Move(tmpBundleDir, Path.Combine(appBundleDir, "AppBundle")); | ||
|
|
||
| string indexHtmlPath = Path.Combine(appBundleDir, "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); | ||
| } | ||
| } else { | ||
| CopyAllFiles(appBundleDir, tmpBundleDir); | ||
| } | ||
|
|
||
| RunAndTestWasmApp(buildArgs, expectedExitCode: 42, host: host, id: id, jsRelativePath: $"../{tmpBundleDirName}/test-main.js"); | ||
|
|
||
| // Restore AppBundle Dir | ||
| if (host == RunHost.Chrome) | ||
| { | ||
| Directory.Move(Path.Combine(appBundleDir, "AppBundle"), tmpBundleDir); | ||
| Directory.Delete(appBundleDir, true); | ||
| Directory.Move(tmpBundleDir, appBundleDir); | ||
| } else { | ||
| Directory.Delete(tmpBundleDir, true); | ||
| } | ||
| } | ||
|
|
||
| private void CopyAllFiles(string srcDir, string destDir) | ||
| { | ||
| if (!Directory.Exists(destDir)) | ||
| { | ||
| Directory.CreateDirectory(destDir); | ||
| } | ||
|
|
||
| foreach (var file in Directory.GetFiles(srcDir)) | ||
| { | ||
| File.Copy(file, Path.Combine(destDir, Path.GetFileName(file)), true); | ||
| } | ||
|
|
||
| foreach (var directory in Directory.GetDirectories(srcDir)) | ||
| { | ||
| CopyAllFiles(directory, Path.Combine(destDir, Path.GetFileName(directory))); | ||
| } | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.