Skip to content
Prev Previous commit
apply patch that allow configuring bundleDir
  • Loading branch information
yamachu committed Jul 27, 2022
commit eb07469f47f3fac81443a390e55b0f50859ce2ec
3 changes: 2 additions & 1 deletion src/tests/BuildWasmApps/Wasm.Build.Tests/BuildTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ protected string RunAndTestWasmApp(BuildArgs buildArgs,
string id,
Action<string>? test=null,
string? buildDir = null,
string? bundleDir = null,
int expectedExitCode = 0,
string? args = null,
Dictionary<string, string>? envVars = null,
Expand All @@ -152,7 +153,7 @@ protected string RunAndTestWasmApp(BuildArgs buildArgs,
envVars[kvp.Key] = kvp.Value;
}

string bundleDir = Path.Combine(GetBinDir(baseDir: buildDir, config: buildArgs.Config, targetFramework: targetFramework), "AppBundle");
bundleDir ??= Path.Combine(GetBinDir(baseDir: buildDir, config: buildArgs.Config, targetFramework: targetFramework), "AppBundle");

// Use wasm-console.log to get the xharness output for non-browser cases
(string testCommand, string extraXHarnessArgs, bool useWasmConsoleOutput) = host switch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,38 +29,28 @@ public void RunOutOfAppBundle(BuildArgs buildArgs, RunHost host, string id)

string binDir = GetBinDir(baseDir: _projectDir!, config: buildArgs.Config);
string appBundleDir = Path.Combine(binDir, "AppBundle");
string tmpBundleDirName = "AppBundleTmp";
string tmpBundleDir = Path.Combine(binDir, tmpBundleDirName);
string outerDir = Path.GetFullPath(Path.Combine(appBundleDir, ".."));

string tmpDir = Path.Combine(Path.GetTempPath(), $"{id}-{buildArgs.ProjectName}");

if (host == RunHost.Chrome)
if (host is 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");
// 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);
}
} else {
Utils.DirectoryCopy(appBundleDir, tmpDir);
}

RunAndTestWasmApp(buildArgs, expectedExitCode: 42, host: host, id: id, jsRelativePath: Path.Combine(tmpDir, "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(tmpDir, true);
}
RunAndTestWasmApp(buildArgs,
expectedExitCode: 42,
host: host,
id: id,
bundleDir: outerDir,
jsRelativePath: "./AppBundle/test-main.js");
}
}