Skip to content

Commit

Permalink
Merge pull request #2740 from hardkoded/v19
Browse files Browse the repository at this point in the history
V19 to Master
  • Loading branch information
kblok authored Aug 15, 2024
2 parents 78e2cf3 + 838ed8d commit a3cca3a
Show file tree
Hide file tree
Showing 280 changed files with 1,576 additions and 1,409 deletions.
15 changes: 12 additions & 3 deletions .github/workflows/demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ on:
- master
- release-*
pull_request:
branches: [master]
paths:
- "**.cs"
- "**.csproj"
Expand Down Expand Up @@ -35,7 +34,17 @@ jobs:
working-directory: ./demos/PuppeteerSharpPdfDemo
run: |
dotnet restore PuppeteerSharpPdfDemo-Local.csproj
- name: Run Project
- name: Run on .NET
working-directory: ./demos/PuppeteerSharpPdfDemo
run: |
dotnet run --project PuppeteerSharpPdfDemo-Local.csproj auto-exit
dotnet run --project PuppeteerSharpPdfDemo-Local.csproj auto-exit -f net8.0
- name: Run with AOT
if: matrix.os == 'macos-latest'
working-directory: ./demos/PuppeteerSharpPdfDemo
run: |
dotnet run --project PuppeteerSharpPdfDemo-Local.csproj -r osx-arm64 -c Release -f net8.0 auto-exit
- name: Run on .NET Framework
if: matrix.os == 'windows-2022'
working-directory: ./demos/PuppeteerSharpPdfDemo
run: |
dotnet run --project PuppeteerSharpPdfDemo-Local.csproj auto-exit -f net471
3 changes: 1 addition & 2 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ on:
- release-*
merge_group:
pull_request:
branches: [ master ]
paths:
- '**.yml'
- '**.cs'
Expand Down Expand Up @@ -84,7 +83,7 @@ jobs:
Get-ChildItem -Path cert:\CurrentUSer\my | where { $_.friendlyname -eq "Puppeteer" } | Export-Certificate -FilePath $env:GITHUB_WORKSPACE\lib\PuppeteerSharp.TestServer\testCert.cer
- name: Check formatting
if: ${{ matrix.os == 'ubuntu-latest' && matrix.browser == 'CHROME' && matrix.mode == 'headless' }}
run: dotnet format ./lib/PuppeteerSharp.sln --verify-no-changes
run: dotnet format ./lib/PuppeteerSharp.sln --verify-no-changes --exclude-diagnostics CA1865
- name: Build
working-directory: lib
run: dotnet build PuppeteerSharp.sln
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ var result = await page.GetContentAsync();
```cs
await using var page = await browser.NewPageAsync();
var seven = await page.EvaluateExpressionAsync<int>("4 + 3");
var someObject = await page.EvaluateFunctionAsync<dynamic>("(value) => ({a: value})", 5);
Console.WriteLine(someObject.a);
var someObject = await page.EvaluateFunctionAsync<JsonElement>("(value) => ({a: value})", 5);
Console.WriteLine(someObject.GetProperty("a").GetString());
```
<sup><a href='https://github.com/hardkoded/puppeteer-sharp/blob/master/lib/PuppeteerSharp.Tests/QuerySelectorTests/ElementHandleQuerySelectorEvalTests.cs#L16-L21' title='Snippet source file'>snippet source</a> | <a href='#snippet-Evaluate' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/hardkoded/puppeteer-sharp/blob/master/lib/PuppeteerSharp.Tests/QuerySelectorTests/ElementHandleQuerySelectorEvalTests.cs#L17-L22' title='Snippet source file'>snippet source</a> | <a href='#snippet-Evaluate' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

### Wait For Selector
Expand Down
22 changes: 22 additions & 0 deletions demos/PuppeteerSharpPdfDemo/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Linq;
using System.IO;
using System.Text.Json.Serialization;
using System.Text.Json.Serialization.Metadata;
using System.Threading.Tasks;
using PuppeteerSharp;

Expand All @@ -10,6 +12,10 @@ class MainClass
{
public static async Task Main(string[] args)
{
#if NET8_0_OR_GREATER
Puppeteer.ExtraJsonSerializerContext = DemoJsonSerializationContext.Default;
#endif

var options = new LaunchOptions { Headless = true };

Console.WriteLine("Downloading chromium");
Expand All @@ -28,10 +34,26 @@ public static async Task Main(string[] args)

Console.WriteLine("Export completed");

#if NET8_0_OR_GREATER
// AOT Test
var result = await page.EvaluateFunctionAsync<TestClass>("test => test", new TestClass { Name = "Dario"});
Console.WriteLine($"Name evaluated to {result.Name}");
#endif
if (!args.Any(arg => arg == "auto-exit"))
{
Console.ReadLine();
}
}
}

#if NET8_0_OR_GREATER
public class TestClass
{
public string Name { get; set; }
}

[JsonSerializable(typeof(TestClass))]
public partial class DemoJsonSerializationContext : JsonSerializerContext
{}
#endif
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>8.0</LangVersion>
<TargetFrameworks>net8.0;net471</TargetFrameworks>
<LangVersion>12</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PublishAot>true</PublishAot>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\lib\PuppeteerSharp\PuppeteerSharp.csproj" />
Expand Down
16 changes: 15 additions & 1 deletion lib/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,18 @@ dotnet_diagnostic.CA1054.severity = none
dotnet_diagnostic.CA1056.severity = none
# Avoid empty interfaces
dotnet_diagnostic.CA1040.severity = none
# Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance
# This is not netstandard compatible
dotnet_diagnostic.CA1510.severity = none
# Use 'string.StartsWith(char)' instead of 'string.StartsWith(string)' when you have a string with a single char
# This is not .NET 8 compatible
dotnet_diagnostic.CA1865.severity = none
# Use 'ObjectDisposedException.ThrowIf' instead of explicitly throwing a new exception instance
# This is not netstandard compatible
dotnet_diagnostic.CA1513.severity = none
# Use Change the 'WriteAsync' method call to use the 'Stream.WriteAsync(ReadOnlyMemory<byte>, CancellationToken)' overload
# This is not netstandard compatible
dotnet_diagnostic.CA1835.severity = none
# Use ConfigureAwait
dotnet_diagnostic.CA2007.severity = error
# CA1711: Identifiers should not have incorrect suffix
Expand All @@ -264,6 +276,8 @@ dotnet_diagnostic.CA1815.severity = suggestion
# CA1848: Use the LoggerMessage delegates
# TODO: REMOVE
dotnet_diagnostic.CA1848.severity = none
# internal sealed
dotnet_diagnostic.CA1852.severity = error
# CA1859: Use concrete types when possible for improved performance
# It collides with https://www.jetbrains.com/help/rider/ReturnTypeCanBeEnumerable.Local.html
dotnet_diagnostic.CA1859.severity = none
Expand Down Expand Up @@ -303,7 +317,7 @@ dotnet_diagnostic.CA1001.severity = error
dotnet_diagnostic.CA1304.severity = error
# CA1305: String.Format with culture
dotnet_diagnostic.CA1305.severity = error
# CA1304: CA1308: Normalize strings to uppercase
# CA1308: Normalize strings to uppercase
dotnet_diagnostic.CA1308.severity = none
# CA1721: The property name 'DefaultArgs' is confusing given the existence of method 'GetDefaultArgs'. Rename or remove one of these members.
dotnet_diagnostic.CA1721.severity = error
Expand Down
2 changes: 1 addition & 1 deletion lib/Common/CommonProps.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
</None>
</ItemGroup>
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="dotnet format $(ProjectPath)" />
<Exec Command="dotnet format $(ProjectPath) --exclude-diagnostics CA1865" />
</Target>
</Project>
8 changes: 4 additions & 4 deletions lib/PuppeteerSharp.DevicesFetcher/Device.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace PuppeteerSharp.DevicesFetcher
{
public class Device
{
[JsonProperty("userAgent")]
[JsonPropertyName("userAgent")]
public string UserAgent { get; set; }
[JsonProperty("name")]
[JsonPropertyName("name")]
public string Name { get; set; }
[JsonProperty("viewport")]
[JsonPropertyName("viewport")]
public ViewPort Viewport { get; set; }
}
}
13 changes: 3 additions & 10 deletions lib/PuppeteerSharp.DevicesFetcher/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace PuppeteerSharp.DevicesFetcher
{
static class Program
Expand Down Expand Up @@ -34,7 +35,7 @@ static async Task Main(string[] args)
Device[] devices;
try
{
devices = JsonConvert.DeserializeObject<Device[]>(text);
devices = JsonSerializer.Deserialize<Device[]>(text);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -70,14 +71,6 @@ public static class DeviceDescriptors
new Lazy<IReadOnlyDictionary<DeviceDescriptorName, DeviceDescriptor>>(() => new ReadOnlyDictionary<DeviceDescriptorName, DeviceDescriptor>(Devices));
internal static IReadOnlyDictionary<DeviceDescriptorName, DeviceDescriptor> ToReadOnly() => _readOnlyDevices.Value;
/// <summary>
/// Get the specified device description.
/// </summary>
/// <returns>The device descriptor.</returns>
/// <param name=""name"">Device Name.</param>
[Obsolete(""Use Puppeteer.Devices instead"")]
public static DeviceDescriptor Get(DeviceDescriptorName name) => Devices[name];
}
}";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
<TargetFramework>net8.0</TargetFramework>
<LangVersion>12</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\PuppeteerSharp\PuppeteerSharp.csproj" />
</ItemGroup>
Expand Down
14 changes: 7 additions & 7 deletions lib/PuppeteerSharp.DevicesFetcher/ViewPort.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace PuppeteerSharp.DevicesFetcher
{
public class ViewPort
{
[JsonProperty("width")]
[JsonPropertyName("width")]
public int Width { get; set; }
[JsonProperty("height")]
[JsonPropertyName("height")]
public int Height { get; set; }

[JsonProperty("deviceScaleFactor")]
[JsonPropertyName("deviceScaleFactor")]
public double DeviceScaleFactor { get; set; }

[JsonProperty("isMobile")]
[JsonPropertyName("isMobile")]
public bool IsMobile { get; set; }
[JsonProperty("hasTouch")]
[JsonPropertyName("hasTouch")]
public bool HasTouch { get; set; }
[JsonProperty("isLandscape")]
[JsonPropertyName("isLandscape")]
public bool IsLandscape { get; set; }
}
}
1 change: 0 additions & 1 deletion lib/PuppeteerSharp.Nunit/PuppeteerSharp.Nunit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<LangVersion>12</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="NUnit" Version="4.1.0" />
</ItemGroup>
<ItemGroup>
Expand Down
15 changes: 13 additions & 2 deletions lib/PuppeteerSharp.Nunit/PuppeteerTestAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using Newtonsoft.Json;
using System.Text.Json;
using NUnit.Framework;
using NUnit.Framework.Interfaces;
using NUnit.Framework.Internal;
using PuppeteerSharp.Helpers.Json;
using PuppeteerSharp.Nunit.TestExpectations;

namespace PuppeteerSharp.Nunit
Expand Down Expand Up @@ -170,14 +171,24 @@ private static TestExpectation[] GetLocalExpectations() =>
private static TestExpectation[] GetUpstreamExpectations() =>
_upstreamExpectations ??= LoadExpectationsFromResource("PuppeteerSharp.Nunit.TestExpectations.TestExpectations.upstream.json");

private static readonly JsonSerializerOptions DefaultJsonSerializerOptions =
new JsonSerializerOptions()
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
Converters =
{
new JsonStringEnumMemberConverter(),
},
};

private static TestExpectation[] LoadExpectationsFromResource(string resourceName)
{
var assembly = Assembly.GetExecutingAssembly();

using var stream = assembly.GetManifestResourceStream(resourceName);
using var reader = new StreamReader(stream);
var fileContent = reader.ReadToEnd();
return JsonConvert.DeserializeObject<TestExpectation[]>(fileContent);
return JsonSerializer.Deserialize<TestExpectation[]>(fileContent, DefaultJsonSerializerOptions);
}
}
}
14 changes: 9 additions & 5 deletions lib/PuppeteerSharp.Nunit/TestExpectations/TestExpectation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace PuppeteerSharp.Nunit.TestExpectations;

Expand Down Expand Up @@ -56,7 +54,6 @@ public Regex TestIdRegex

public TestExpectationResult[] Expectations { get; set; }

[JsonConverter(typeof(StringEnumConverter))]
public enum TestExpectationResult
{
[EnumMember(Value = "FAIL")] Fail,
Expand All @@ -65,24 +62,31 @@ public enum TestExpectationResult
[EnumMember(Value = "TIMEOUT")] Timeout,
}

[JsonConverter(typeof(StringEnumConverter))]
public enum TestExpectationsParameter
{
[EnumMember(Value = "firefox")]
Firefox,
[EnumMember(Value = "chrome")]
Chrome,
[EnumMember(Value = "webDriverBiDi")]
WebDriverBiDi,
[EnumMember(Value = "cdp")]
Cdp,
[EnumMember(Value = "chrome-headless-shell")]
ChromeHeadlessShell,
[EnumMember(Value = "headless")]
Headless,
[EnumMember(Value = "headful")]
Headful,
}

[JsonConverter(typeof(StringEnumConverter))]
public enum TestExpectationPlatform
{
[EnumMember(Value = "darwin")]
Darwin,
[EnumMember(Value = "linux")]
Linux,
[EnumMember(Value = "win32")]
Win32,
}
}
Loading

0 comments on commit a3cca3a

Please sign in to comment.