Skip to content

Commit c9f0914

Browse files
authored
fix(xunit): support netstandard2.0 (#3063)
1 parent 8cd88de commit c9f0914

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

src/Playwright.Xunit/BrowserTest.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ public override async Task InitializeAsync()
4848

4949
public override async Task DisposeAsync()
5050
{
51-
await base.DisposeAsync().ConfigureAwait(false);
5251
if (TestOk)
5352
{
5453
foreach (var context in _contexts)
@@ -58,5 +57,6 @@ public override async Task DisposeAsync()
5857
}
5958
_contexts.Clear();
6059
Browser = null!;
60+
await base.DisposeAsync().ConfigureAwait(false);
6161
}
6262
}

src/Playwright.Xunit/Playwright.Xunit.csproj

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
and fixtures to enable using it within xUnit.
1010
</Description>
1111
<PackageIcon>icon.png</PackageIcon>
12-
<TargetFramework>net8.0</TargetFramework>
12+
<TargetFramework>netstandard2.0</TargetFramework>
1313
<PublishRepositoryUrl>true</PublishRepositoryUrl>
1414
<RunWithWarnings>true</RunWithWarnings>
1515
<RootNamespace>Microsoft.Playwright.Xunit</RootNamespace>
@@ -35,9 +35,7 @@
3535
<PrivateAssets>all</PrivateAssets>
3636
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
3737
</PackageReference>
38-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
3938
<PackageReference Include="xunit" Version="2.8.0" />
40-
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.0" />
4139
</ItemGroup>
4240
<ItemGroup>
4341
<None Include="..\Common\icon.png" Pack="true" Visible="false" PackagePath="icon.png" />

src/Playwright.Xunit/WorkerAwareTest.cs

+20-10
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
using System;
2626
using System.Collections.Concurrent;
2727
using System.Collections.Generic;
28-
using System.Runtime.CompilerServices;
2928
using System.Threading;
3029
using System.Threading.Tasks;
3130
using Microsoft.Playwright.Core;
@@ -34,10 +33,10 @@
3433

3534
namespace Microsoft.Playwright.Xunit;
3635

37-
public class WorkerAwareTest : ExceptionCapturer, IAsyncLifetime
36+
public class WorkerAwareTest : ExceptionCapturer
3837
{
3938
private static readonly ConcurrentStack<Worker> _allWorkers = new();
40-
private Worker? _currentWorker = null!;
39+
private Worker _currentWorker = null!;
4140

4241
internal class Worker
4342
{
@@ -58,8 +57,9 @@ public async Task<T> RegisterService<T>(string name, Func<Task<T>> factory) wher
5857
return (_currentWorker.Services[name] as T)!;
5958
}
6059

61-
public virtual Task InitializeAsync()
60+
async public override Task InitializeAsync()
6261
{
62+
await base.InitializeAsync().ConfigureAwait(false);
6363
if (!_allWorkers.TryPop(out _currentWorker!))
6464
{
6565
_currentWorker = new();
@@ -69,10 +69,9 @@ public virtual Task InitializeAsync()
6969
{
7070
AssertionsBase.SetDefaultTimeout(PlaywrightSettingsProvider.ExpectTimeout.Value);
7171
}
72-
return Task.CompletedTask;
7372
}
7473

75-
public virtual async Task DisposeAsync()
74+
public async override Task DisposeAsync()
7675
{
7776
if (TestOk)
7877
{
@@ -90,6 +89,7 @@ public virtual async Task DisposeAsync()
9089
}
9190
_currentWorker.Services.Clear();
9291
}
92+
await base.DisposeAsync().ConfigureAwait(false);
9393
}
9494
}
9595

@@ -107,16 +107,26 @@ public interface IWorkerService
107107
/// Note: There is no way of getting the test status in xUnit in the dispose method.
108108
/// For more information, see: https://stackoverflow.com/questions/28895448/current-test-status-in-xunit-net
109109
/// </summary>
110-
public class ExceptionCapturer
110+
public class ExceptionCapturer : IAsyncLifetime
111111
{
112-
protected static bool TestOk { get; private set; } = true;
112+
protected bool TestOk { get; private set; } = true;
113113

114-
[ModuleInitializer]
115-
public static void Setup()
114+
public ExceptionCapturer()
116115
{
117116
AppDomain.CurrentDomain.FirstChanceException += (_, e) =>
118117
{
119118
TestOk = false;
120119
};
121120
}
121+
122+
public virtual Task InitializeAsync()
123+
{
124+
TestOk = true;
125+
return Task.CompletedTask;
126+
}
127+
128+
public virtual Task DisposeAsync()
129+
{
130+
return Task.CompletedTask;
131+
}
122132
}

0 commit comments

Comments
 (0)