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.
Add Unit test to run WasmApp outside of AppBundle directory
V8: Could not determine scriptDirectory (always empty string). You must explicitly specify the base path within locateFile. Chrome: Failed to load dotnet.wasm
- Loading branch information
Showing
3 changed files
with
81 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
63 changes: 63 additions & 0 deletions
63
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,63 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Collections.Generic; | ||
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) | ||
{} | ||
|
||
public static IEnumerable<object?[]> MainMethodTestData(bool aot, RunHost host) | ||
=> ConfigWithAOTData(aot) | ||
.WithRunHosts(host) | ||
.UnwrapItemsAsArrays(); | ||
|
||
[Theory] | ||
// NOTE: V8 and Chrome now fail | ||
// Ref: https://github.com/dotnet/runtime/issues/69259 | ||
[MemberData(nameof(MainMethodTestData), parameters: new object[] { /*aot*/ true, RunHost.NodeJS })] | ||
[MemberData(nameof(MainMethodTestData), parameters: new object[] { /*aot*/ false, RunHost.NodeJS })] | ||
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 baseBundleDir = Path.Combine(binDir, "AppBundle"); | ||
string tmpBundleDir = Path.Combine(binDir, "AppBundleTmp"); | ||
string deepBundleDir = Path.Combine(baseBundleDir, "AppBundle"); | ||
|
||
Directory.Move(baseBundleDir, tmpBundleDir); | ||
Directory.CreateDirectory(baseBundleDir); | ||
|
||
// Create $binDir/AppBundle/AppBundle | ||
Directory.Move(tmpBundleDir, deepBundleDir); | ||
|
||
if (host == RunHost.Chrome) | ||
{ | ||
string indexHtmlPath = Path.Combine(baseBundleDir, "index.html"); | ||
if (!File.Exists(indexHtmlPath)) | ||
{ | ||
var html = @"<html><body><script type=""text/javascript"" src=""AppBundle/test-main.js""></script></body></html>"; | ||
File.WriteAllText(indexHtmlPath, html); | ||
} | ||
} | ||
|
||
RunAndTestWasmApp(buildArgs, expectedExitCode: 42, host: host, id: id, extraXHarnessMonoArgs: "--run-deep-work-dir=true"); | ||
} | ||
} | ||
} |