Skip to content

Commit a7547c9

Browse files
authored
feat: add support for xUnit.v3 (#3097)
1 parent 1ea0e5e commit a7547c9

File tree

14 files changed

+1083
-8
lines changed

14 files changed

+1083
-8
lines changed

src/Playwright.TestAdapter/PlaywrightSettingsProvider.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424

2525
using System;
26+
using System.Text.Json;
2627
using System.Xml;
2728
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
2829
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
@@ -35,6 +36,22 @@ public class PlaywrightSettingsProvider : ISettingsProvider
3536
{
3637
private static PlaywrightSettingsXml? _settings = null!;
3738

39+
public static void LoadViaEnvIfNeeded()
40+
{
41+
if (_settings == null)
42+
{
43+
var settings = Environment.GetEnvironmentVariable("PW_INTERNAL_ADAPTER_SETTINGS");
44+
if (!string.IsNullOrEmpty(settings))
45+
{
46+
_settings = JsonSerializer.Deserialize<PlaywrightSettingsXml>(settings);
47+
}
48+
else
49+
{
50+
_settings = new PlaywrightSettingsXml();
51+
}
52+
}
53+
}
54+
3855
public static string BrowserName
3956
{
4057
get
@@ -102,5 +119,10 @@ private static void ValidateBrowserName(string browserName, string fromText, str
102119
}
103120

104121
public void Load(XmlReader reader)
105-
=> _settings = new PlaywrightSettingsXml(reader);
122+
{
123+
// NOTE: ISettingsProvider::Load is not called when there are no runsettings (either file or passed via command line).
124+
_settings = new PlaywrightSettingsXml(reader);
125+
Environment.SetEnvironmentVariable("PW_INTERNAL_ADAPTER_SETTINGS", JsonSerializer.Serialize(_settings));
126+
}
106127
}
128+

src/Playwright.TestAdapter/PlaywrightSettingsXml.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ namespace Microsoft.Playwright.TestAdapter;
3535

3636
public class PlaywrightSettingsXml
3737
{
38+
public PlaywrightSettingsXml()
39+
{
40+
}
41+
3842
public PlaywrightSettingsXml(XmlReader reader)
3943
{
4044
// Skip Playwright root Element
@@ -159,10 +163,10 @@ private static object ParseAsJson(string value, Type type)
159163
return JsonSerializer.Deserialize(value.Replace('\'', '"'), type)!;
160164
}
161165

162-
public BrowserTypeLaunchOptions? LaunchOptions { get; private set; }
163-
public string? BrowserName { get; private set; }
164-
public bool? Headless { get; private set; }
165-
public float? ExpectTimeout { get; private set; }
166-
public int? Retries { get; private set; }
166+
public BrowserTypeLaunchOptions? LaunchOptions { get; set; }
167+
public string? BrowserName { get; set; }
168+
public bool? Headless { get; set; }
169+
public float? ExpectTimeout { get; set; }
170+
public int? Retries { get; set; }
167171
}
168172

src/Playwright.TestingHarnessTest/Playwright.TestingHarnessTest.csproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<ItemGroup>
1212
<ProjectReference Include="..\Playwright\Playwright.csproj" />
1313

14-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
14+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
1515

1616
<!-- MSTest -->
1717
<ProjectReference Include="..\Playwright.MSTest\Playwright.MSTest.csproj" Condition="'$(TEST_MODE)' == 'mstest'" />
@@ -26,6 +26,11 @@
2626
<ProjectReference Include="..\Playwright.Xunit\Playwright.Xunit.csproj" Condition="'$(TEST_MODE)' == 'xunit'" />
2727
<PackageReference Include="xunit" Version="2.9.2" Condition="'$(TEST_MODE)' == 'xunit'" />
2828
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" Condition="'$(TEST_MODE)' == 'xunit'" />
29+
30+
<!-- xUnit.v3 -->
31+
<ProjectReference Include="..\Playwright.Xunit.v3\Playwright.Xunit.v3.csproj" Condition="'$(TEST_MODE)' == 'xunit.v3'" />
32+
<PackageReference Include="xunit.v3" Version="3.0.0" Condition="'$(TEST_MODE)' == 'xunit.v3'" />
33+
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2" Condition="'$(TEST_MODE)' == 'xunit.v3'" />
2934
</ItemGroup>
3035

3136
<ItemGroup>

src/Playwright.TestingHarnessTest/tests/baseTest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type RunResult = {
1919

2020
export const test = base.extend<{
2121
proxyServer: ProxyServer;
22-
testMode: 'nunit' | 'mstest' | 'xunit';
22+
testMode: 'nunit' | 'mstest' | 'xunit' | 'xunit.v3';
2323
runTest: (files: Record<string, string>, command: string, env?: NodeJS.ProcessEnv) => Promise<RunResult>;
2424
launchServer: (options: { port: number }) => Promise<void>;
2525
server: SimpleServer;

0 commit comments

Comments
 (0)