@@ -21,7 +21,7 @@ public WasmTemplateTests(ITestOutputHelper output, SharedBuildPerTestClassFixtur
21
21
{
22
22
}
23
23
24
- private void updateProgramCS ( )
24
+ private void UpdateProgramCS ( )
25
25
{
26
26
string programText = """
27
27
Console.WriteLine("Hello, Console!");
@@ -188,7 +188,7 @@ public void ConsoleBuildAndRun(string config, bool relinking)
188
188
string projectFile = CreateWasmTemplateProject ( id , "wasmconsole" ) ;
189
189
string projectName = Path . GetFileNameWithoutExtension ( projectFile ) ;
190
190
191
- updateProgramCS ( ) ;
191
+ UpdateProgramCS ( ) ;
192
192
UpdateConsoleMainJs ( ) ;
193
193
if ( relinking )
194
194
AddItemsPropertiesToProject ( projectFile , "<WasmBuildNative>true</WasmBuildNative>" ) ;
@@ -216,6 +216,112 @@ public void ConsoleBuildAndRun(string config, bool relinking)
216
216
Assert . Contains ( "args[2] = z" , output ) ;
217
217
}
218
218
219
+ public static TheoryData < bool , bool , string > TestDataForAppBundleDir ( )
220
+ {
221
+ var data = new TheoryData < bool , bool , string > ( ) ;
222
+ AddTestData ( forConsole : true , runOutsideProjectDirectory : false ) ;
223
+ AddTestData ( forConsole : true , runOutsideProjectDirectory : true ) ;
224
+
225
+ AddTestData ( forConsole : false , runOutsideProjectDirectory : false ) ;
226
+ AddTestData ( forConsole : false , runOutsideProjectDirectory : true ) ;
227
+
228
+ void AddTestData ( bool forConsole , bool runOutsideProjectDirectory )
229
+ {
230
+ data . Add ( runOutsideProjectDirectory , forConsole , string . Empty ) ;
231
+
232
+ data . Add ( runOutsideProjectDirectory , forConsole ,
233
+ $ "<OutputPath>{ Path . Combine ( Path . GetTempPath ( ) , Path . GetRandomFileName ( ) ) } </OutputPath>") ;
234
+ data . Add ( runOutsideProjectDirectory , forConsole ,
235
+ $ "<WasmAppDir>{ Path . Combine ( Path . GetTempPath ( ) , Path . GetRandomFileName ( ) ) } </WasmAppDir>") ;
236
+ }
237
+
238
+ return data ;
239
+ }
240
+
241
+ [ ConditionalTheory ( typeof ( BuildTestBase ) , nameof ( IsUsingWorkloads ) ) ]
242
+ [ MemberData ( nameof ( TestDataForAppBundleDir ) ) ]
243
+ public async Task RunWithDifferentAppBundleLocations ( bool forConsole , bool runOutsideProjectDirectory , string extraProperties )
244
+ => await ( forConsole
245
+ ? ConsoleRunWithAndThenWithoutBuildAsync ( "Release" , extraProperties , runOutsideProjectDirectory )
246
+ : BrowserRunTwiceWithAndThenWithoutBuildAsync ( "Release" , extraProperties , runOutsideProjectDirectory ) ) ;
247
+
248
+ private async Task BrowserRunTwiceWithAndThenWithoutBuildAsync ( string config , string extraProperties = "" , bool runOutsideProjectDirectory = false )
249
+ {
250
+ string id = $ "browser_{ config } _{ Path . GetRandomFileName ( ) } ";
251
+ string projectFile = CreateWasmTemplateProject ( id , "wasmbrowser" ) ;
252
+
253
+ UpdateBrowserMainJs ( ) ;
254
+
255
+ if ( ! string . IsNullOrEmpty ( extraProperties ) )
256
+ AddItemsPropertiesToProject ( projectFile , extraProperties : extraProperties ) ;
257
+
258
+ string workingDir = runOutsideProjectDirectory ? Path . GetTempPath ( ) : _projectDir ! ;
259
+
260
+ {
261
+ using var runCommand = new RunCommand ( s_buildEnv , _testOutput )
262
+ . WithWorkingDirectory ( workingDir ) ;
263
+
264
+ await using var runner = new BrowserRunner ( ) ;
265
+ var page = await runner . RunAsync ( runCommand , $ "run -c { config } --project { projectFile } --forward-console") ;
266
+ await runner . WaitForExitMessageAsync ( TimeSpan . FromMinutes ( 2 ) ) ;
267
+ Assert . Contains ( "Hello, Browser!" , string . Join ( Environment . NewLine , runner . OutputLines ) ) ;
268
+ }
269
+
270
+ {
271
+ using var runCommand = new RunCommand ( s_buildEnv , _testOutput )
272
+ . WithWorkingDirectory ( workingDir ) ;
273
+
274
+ await using var runner = new BrowserRunner ( ) ;
275
+ var page = await runner . RunAsync ( runCommand , $ "run -c { config } --no-build --project { projectFile } --forward-console") ;
276
+ await runner . WaitForExitMessageAsync ( TimeSpan . FromMinutes ( 2 ) ) ;
277
+ Assert . Contains ( "Hello, Browser!" , string . Join ( Environment . NewLine , runner . OutputLines ) ) ;
278
+ }
279
+ }
280
+
281
+ private Task ConsoleRunWithAndThenWithoutBuildAsync ( string config , string extraProperties = "" , bool runOutsideProjectDirectory = false )
282
+ {
283
+ string id = $ "console_{ config } _{ Path . GetRandomFileName ( ) } ";
284
+ string projectFile = CreateWasmTemplateProject ( id , "wasmconsole" ) ;
285
+
286
+ UpdateProgramCS ( ) ;
287
+ UpdateConsoleMainJs ( ) ;
288
+
289
+ if ( ! string . IsNullOrEmpty ( extraProperties ) )
290
+ AddItemsPropertiesToProject ( projectFile , extraProperties : extraProperties ) ;
291
+
292
+ string workingDir = runOutsideProjectDirectory ? Path . GetTempPath ( ) : _projectDir ! ;
293
+
294
+ {
295
+ string runArgs = $ "run -c { config } --project { projectFile } ";
296
+ runArgs += " x y z" ;
297
+ using var cmd = new RunCommand ( s_buildEnv , _testOutput , label : id )
298
+ . WithWorkingDirectory ( workingDir )
299
+ . WithEnvironmentVariables ( s_buildEnv . EnvVars ) ;
300
+ var res = cmd . ExecuteWithCapturedOutput ( runArgs ) . EnsureExitCode ( 42 ) ;
301
+
302
+ Assert . Contains ( "args[0] = x" , res . Output ) ;
303
+ Assert . Contains ( "args[1] = y" , res . Output ) ;
304
+ Assert . Contains ( "args[2] = z" , res . Output ) ;
305
+ }
306
+
307
+ _testOutput . WriteLine ( $ "{ Environment . NewLine } [{ id } ] Running again with --no-build{ Environment . NewLine } ") ;
308
+
309
+ {
310
+ // Run with --no-build
311
+ string runArgs = $ "run -c { config } --project { projectFile } --no-build";
312
+ runArgs += " x y z" ;
313
+ using var cmd = new RunCommand ( s_buildEnv , _testOutput , label : id )
314
+ . WithWorkingDirectory ( workingDir ) ;
315
+ var res = cmd . ExecuteWithCapturedOutput ( runArgs ) . EnsureExitCode ( 42 ) ;
316
+
317
+ Assert . Contains ( "args[0] = x" , res . Output ) ;
318
+ Assert . Contains ( "args[1] = y" , res . Output ) ;
319
+ Assert . Contains ( "args[2] = z" , res . Output ) ;
320
+ }
321
+
322
+ return Task . CompletedTask ;
323
+ }
324
+
219
325
public static TheoryData < string , bool , bool > TestDataForConsolePublishAndRun ( )
220
326
{
221
327
var data = new TheoryData < string , bool , bool > ( ) ;
@@ -242,7 +348,7 @@ public void ConsolePublishAndRun(string config, bool aot, bool relinking)
242
348
string projectFile = CreateWasmTemplateProject ( id , "wasmconsole" ) ;
243
349
string projectName = Path . GetFileNameWithoutExtension ( projectFile ) ;
244
350
245
- updateProgramCS ( ) ;
351
+ UpdateProgramCS ( ) ;
246
352
UpdateConsoleMainJs ( ) ;
247
353
248
354
if ( aot )
0 commit comments