Skip to content

Commit 3bdf751

Browse files
committed
StackTrace support
1 parent b0e0ee4 commit 3bdf751

File tree

2 files changed

+104
-15
lines changed

2 files changed

+104
-15
lines changed

lib/PuppeteerSharp.Nunit/TestExpectations/TestExpectations.local.json

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,21 +1087,6 @@
10871087
"FAIL"
10881088
]
10891089
},
1090-
{
1091-
"comment": "This is part of organizing the webdriver bidi implementation, We will remove it one by one",
1092-
"testIdPattern": "[stacktrace.spec] *",
1093-
"platforms": [
1094-
"darwin",
1095-
"linux",
1096-
"win32"
1097-
],
1098-
"parameters": [
1099-
"webDriverBiDi"
1100-
],
1101-
"expectations": [
1102-
"FAIL"
1103-
]
1104-
},
11051090
{
11061091
"comment": "This is part of organizing the webdriver bidi implementation, We will remove it one by one",
11071092
"testIdPattern": "[target.spec] *",
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
using System.Threading.Tasks;
2+
using NUnit.Framework;
3+
using PuppeteerSharp.Nunit;
4+
5+
namespace PuppeteerSharp.Tests.StackTraceTests
6+
{
7+
public class StackTraceTests : PuppeteerPageBaseTest
8+
{
9+
[Test, PuppeteerTest("stacktrace.spec", "Stack trace", "should work")]
10+
public void ShouldWork()
11+
{
12+
var exception = Assert.ThrowsAsync<EvaluationFailedException>(async () =>
13+
{
14+
await Page.EvaluateFunctionAsync(@"() => {
15+
throw new Error('Test');
16+
}");
17+
});
18+
19+
Assert.That(exception.Message, Does.Contain("Test"));
20+
}
21+
22+
[Test, PuppeteerTest("stacktrace.spec", "Stack trace", "should work with handles")]
23+
public void ShouldWorkWithHandles()
24+
{
25+
var exception = Assert.ThrowsAsync<EvaluationFailedException>(async () =>
26+
{
27+
await Page.EvaluateFunctionHandleAsync(@"() => {
28+
throw new Error('Test');
29+
}");
30+
});
31+
32+
Assert.That(exception.Message, Does.Contain("Test"));
33+
}
34+
35+
[Test, PuppeteerTest("stacktrace.spec", "Stack trace", "should work with contiguous evaluation")]
36+
public async Task ShouldWorkWithContiguousEvaluation()
37+
{
38+
await using var thrower = await Page.EvaluateFunctionHandleAsync(@"() => {
39+
return () => {
40+
throw new Error('Test');
41+
};
42+
}");
43+
44+
var exception = Assert.ThrowsAsync<EvaluationFailedException>(async () =>
45+
{
46+
await thrower.EvaluateFunctionAsync(@"thrower => {
47+
thrower();
48+
}");
49+
});
50+
51+
Assert.That(exception.Message, Does.Contain("Test"));
52+
}
53+
54+
[Test, PuppeteerTest("stacktrace.spec", "Stack trace", "should work with nested function calls")]
55+
public void ShouldWorkWithNestedFunctionCalls()
56+
{
57+
var exception = Assert.ThrowsAsync<EvaluationFailedException>(async () =>
58+
{
59+
await Page.EvaluateFunctionAsync(@"() => {
60+
function a() {
61+
throw new Error('Test');
62+
}
63+
function b() {
64+
a();
65+
}
66+
function c() {
67+
b();
68+
}
69+
function d() {
70+
c();
71+
}
72+
d();
73+
}");
74+
});
75+
76+
Assert.That(exception.Message, Does.Contain("Test"));
77+
}
78+
79+
[Test, PuppeteerTest("stacktrace.spec", "Stack trace", "should work for none error objects")]
80+
public async Task ShouldWorkForNonErrorObjects()
81+
{
82+
var errorTask = new TaskCompletionSource<PageErrorEventArgs>();
83+
84+
void ErrorHandler(object sender, PageErrorEventArgs e)
85+
{
86+
errorTask.TrySetResult(e);
87+
Page.PageError -= ErrorHandler;
88+
}
89+
90+
Page.PageError += ErrorHandler;
91+
92+
await Task.WhenAll(
93+
errorTask.Task,
94+
Page.EvaluateFunctionAsync(@"() => {
95+
// This can happen when a 404 with HTML is returned
96+
void Promise.reject(new Response());
97+
}")
98+
);
99+
100+
var error = await errorTask.Task;
101+
Assert.That(error, Is.Not.Null);
102+
}
103+
}
104+
}

0 commit comments

Comments
 (0)