Skip to content

Commit ff1b802

Browse files
committed
Update ElectronFixture
1 parent c98ad58 commit ff1b802

File tree

1 file changed

+40
-13
lines changed

1 file changed

+40
-13
lines changed

src/ElectronNET.IntegrationTests/ElectronFixture.cs

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,65 @@
11
namespace ElectronNET.IntegrationTests
22
{
3+
using System.Diagnostics.CodeAnalysis;
34
using System.Reflection;
45
using ElectronNET.API;
56
using ElectronNET.API.Entities;
67

78
// Shared fixture that starts Electron runtime once
9+
[SuppressMessage("ReSharper", "MethodHasAsyncOverload")]
810
public class ElectronFixture : IAsyncLifetime
911
{
1012
public BrowserWindow MainWindow { get; private set; } = null!;
1113

1214
public async Task InitializeAsync()
1315
{
14-
AppDomain.CurrentDomain.SetData("ElectronTestAssembly", Assembly.GetExecutingAssembly());
15-
var runtimeController = ElectronNetRuntime.RuntimeController;
16-
await runtimeController.Start();
17-
await runtimeController.WaitReadyTask;
18-
19-
// create hidden window for tests (avoid showing UI)
20-
this.MainWindow = await Electron.WindowManager.CreateWindowAsync(new BrowserWindowOptions
16+
try
2117
{
22-
Show = false,
23-
Width = 800,
24-
Height = 600,
25-
}, "about:blank");
18+
Console.Error.WriteLine("[ElectronFixture] InitializeAsync: start");
19+
AppDomain.CurrentDomain.SetData("ElectronTestAssembly", Assembly.GetExecutingAssembly());
20+
21+
Console.WriteLine("[ElectronFixture] Acquire RuntimeController");
22+
var runtimeController = ElectronNetRuntime.RuntimeController;
23+
ElectronNetRuntime.ElectronExtraArguments = "--no-sandbox";
24+
25+
Console.Error.WriteLine("[ElectronFixture] Starting Electron runtime...");
26+
await runtimeController.Start();
27+
28+
Console.Error.WriteLine("[ElectronFixture] Waiting for Ready...");
29+
await Task.WhenAny(runtimeController.WaitReadyTask, Task.Delay(TimeSpan.FromSeconds(10)));
2630

27-
// Clear potential cache side-effects
28-
await this.MainWindow.WebContents.Session.ClearCacheAsync();
31+
if (!runtimeController.WaitReadyTask.IsCompleted)
32+
{
33+
throw new TimeoutException("The Electron process did not start within 10 seconds");
34+
}
35+
36+
Console.Error.WriteLine("[ElectronFixture] Runtime Ready");
37+
38+
// create hidden window for tests (avoid showing UI)
39+
this.MainWindow = await Electron.WindowManager.CreateWindowAsync(new BrowserWindowOptions
40+
{
41+
Show = false,
42+
Width = 800,
43+
Height = 600,
44+
}, "about:blank");
45+
46+
await this.MainWindow.WebContents.Session.ClearCacheAsync();
47+
}
48+
catch (Exception ex)
49+
{
50+
Console.Error.WriteLine("[ElectronFixture] InitializeAsync: exception");
51+
Console.Error.WriteLine(ex.ToString());
52+
throw;
53+
}
2954
}
3055

3156
public async Task DisposeAsync()
3257
{
3358
var runtimeController = ElectronNetRuntime.RuntimeController;
59+
Console.Error.WriteLine("[ElectronFixture] Stopping Electron runtime...");
3460
await runtimeController.Stop();
3561
await runtimeController.WaitStoppedTask;
62+
Console.Error.WriteLine("[ElectronFixture] Runtime stopped");
3663
}
3764
}
3865

0 commit comments

Comments
 (0)