forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WasmRunOutOfAppBundleTests.cs
56 lines (46 loc) · 2.15 KB
/
WasmRunOutOfAppBundleTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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");
}
}