|
1 | 1 | namespace ElectronNET.IntegrationTests |
2 | 2 | { |
| 3 | + using System.Diagnostics.CodeAnalysis; |
3 | 4 | using System.Reflection; |
4 | 5 | using ElectronNET.API; |
5 | 6 | using ElectronNET.API.Entities; |
6 | 7 |
|
7 | 8 | // Shared fixture that starts Electron runtime once |
| 9 | + [SuppressMessage("ReSharper", "MethodHasAsyncOverload")] |
8 | 10 | public class ElectronFixture : IAsyncLifetime |
9 | 11 | { |
10 | 12 | public BrowserWindow MainWindow { get; private set; } = null!; |
11 | 13 |
|
12 | 14 | public async Task InitializeAsync() |
13 | 15 | { |
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 |
21 | 17 | { |
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))); |
26 | 30 |
|
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 | + } |
29 | 54 | } |
30 | 55 |
|
31 | 56 | public async Task DisposeAsync() |
32 | 57 | { |
33 | 58 | var runtimeController = ElectronNetRuntime.RuntimeController; |
| 59 | + Console.Error.WriteLine("[ElectronFixture] Stopping Electron runtime..."); |
34 | 60 | await runtimeController.Stop(); |
35 | 61 | await runtimeController.WaitStoppedTask; |
| 62 | + Console.Error.WriteLine("[ElectronFixture] Runtime stopped"); |
36 | 63 | } |
37 | 64 | } |
38 | 65 |
|
|
0 commit comments