-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[browser] Support WasmFilesToIncludeInFileSystem in WasmSdk #120970
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
7b9e236
Support WasmFilesToIncludeInFileSystem in WasmSdk
maraf 89a33e5
WBT
maraf 747d9ae
Fix merge
maraf 261e367
Register the test class
maraf 09d3586
Fix typo in class name
maraf d935c34
Apply VFS trait only when we have any WasmFilesToIncludeInFileSystem
maraf a04cf3f
WasmAppBuilder copies VFS to _framework
maraf 2cca4eb
Configure rollup for JavascriptBundlers WBT to treat .txt as static f…
maraf 2145d20
Simplify
maraf 6d8cd3e
Fix VFS imports in JavascriptBunlderFriendly mode
maraf 239fc96
Don't LoadFilesToVfs on JavascriptBunlderFriendly scenario for build
maraf 6e4432b
Remove inline data
maraf 3eb27f1
Feedback: Leading slash for computed target path; fail build when mis…
maraf b479153
Merge branch 'main' into WasmSdkVfs
maraf 04bbea0
Merge branch 'main' into WasmSdkVfs
maraf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
56 changes: 56 additions & 0 deletions
56
src/mono/wasm/Wasm.Build.Tests/FilesToIncludeInFileSystemTests.cs
This file contains hidden or 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; | ||
| using System.Collections.Generic; | ||
| using System.Collections.Specialized; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using System.Threading.Tasks; | ||
| using Xunit; | ||
| using Xunit.Abstractions; | ||
|
|
||
| #nullable enable | ||
|
|
||
| namespace Wasm.Build.Tests; | ||
|
|
||
| public class FilesToIncludeInFileSystemTests : WasmTemplateTestsBase | ||
| { | ||
| public FilesToIncludeInFileSystemTests(ITestOutputHelper output, SharedBuildPerTestClassFixture buildContext) | ||
| : base(output, buildContext) | ||
| { | ||
| } | ||
|
|
||
| public static IEnumerable<object?[]> LoadFilesToVfsData() | ||
| { | ||
| if (!EnvironmentVariables.UseJavascriptBundler) | ||
| yield return new object?[] { false }; | ||
|
|
||
| yield return new object?[] { true }; | ||
| } | ||
|
|
||
| [Theory, TestCategory("bundler-friendly")] | ||
| [MemberData(nameof(LoadFilesToVfsData))] | ||
| public async Task LoadFilesToVfs(bool publish) | ||
| { | ||
| Configuration config = Configuration.Debug; | ||
| ProjectInfo info = CopyTestAsset(config, aot: false, TestAsset.WasmBasicTestApp, "FilesToIncludeInFileSystemTest"); | ||
|
|
||
| if (publish) | ||
| PublishProject(info, config, new PublishOptions()); | ||
| else | ||
| BuildProject(info, config, new BuildOptions()); | ||
|
|
||
| BrowserRunOptions runOptions = new( | ||
| config, | ||
| TestScenario: "FilesToIncludeInFileSystemTest" | ||
| ); | ||
| RunResult result = publish | ||
| ? await RunForPublishWithWebServer(runOptions) | ||
| : await RunForBuildWithDotnetRun(runOptions); | ||
|
|
||
| Assert.Contains(result.TestOutput, m => m.Contains("'/myfiles/Vfs1.txt' exists 'True' with content 'Vfs1.txt'")); | ||
| Assert.Contains(result.TestOutput, m => m.Contains("'/myfiles/Vfs2.txt' exists 'True' with content 'Vfs2.txt'")); | ||
| Assert.Contains(result.TestOutput, m => m.Contains("'/subdir/subsubdir/Vfs3.txt' exists 'True' with content 'Vfs3.txt'")); | ||
| } | ||
| } |
This file contains hidden or 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
22 changes: 22 additions & 0 deletions
22
src/mono/wasm/testassets/WasmBasicTestApp/App/FilesToIncludeInFileSystemTest.cs
This file contains hidden or 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,22 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.IO; | ||
| using System.Text.Json; | ||
| using System.Runtime.InteropServices.JavaScript; | ||
|
|
||
| public partial class FilesToIncludeInFileSystemTest | ||
| { | ||
| [JSExport] | ||
| public static void Run() | ||
| { | ||
| // Check file presence in VFS based on application environment | ||
| PrintFileExistence("/myfiles/Vfs1.txt"); | ||
| PrintFileExistence("/myfiles/Vfs2.txt"); | ||
| PrintFileExistence("/subdir/subsubdir/Vfs3.txt"); | ||
| } | ||
|
|
||
| // Synchronize with FilesToIncludeInFileSystemTests | ||
| private static void PrintFileExistence(string path) => TestOutput.WriteLine($"'{path}' exists '{File.Exists(path)}' with content '{File.ReadAllText(path)}'"); | ||
| } |
This file contains hidden or 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 hidden or 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 @@ | ||
| Vfs1.txt |
This file contains hidden or 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
1 change: 1 addition & 0 deletions
1
src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/subdir/Vfs2.txt
This file contains hidden or 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 @@ | ||
| Vfs2.txt |
1 change: 1 addition & 0 deletions
1
src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/subdir/subsubdir/Vfs3.txt
This file contains hidden or 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 @@ | ||
| Vfs3.txt |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.