Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
61889f89
Unverified
Commit
61889f89
authored
Dec 12, 2023
by
OJ Kwon
Committed by
GitHub
Dec 12, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(playwright): teardown when global quit force terminates browser (#59548)
parent
ed12b552
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
10 deletions
+18
-10
run-tests.js
run-tests.js
+2
-1
playwright.ts
test/lib/browsers/playwright.ts
+16
-9
No files found.
run-tests.js
View file @
61889f89
...
@@ -555,7 +555,8 @@ ${ENDGROUP}`)
...
@@ -555,7 +555,8 @@ ${ENDGROUP}`)
// If environment is CI and if this test execution is failed after retry, preserve test traces
// If environment is CI and if this test execution is failed after retry, preserve test traces
// to upload into github actions artifacts for debugging purpose
// to upload into github actions artifacts for debugging purpose
const
shouldPreserveTracesOutput
=
const
shouldPreserveTracesOutput
=
process
.
env
.
CI
&&
isRetry
&&
isChildExitWithNonZero
(
process
.
env
.
CI
&&
isRetry
&&
isChildExitWithNonZero
)
||
process
.
env
.
PRESERVE_TRACES_OUTPUT
if
(
!
shouldPreserveTracesOutput
)
{
if
(
!
shouldPreserveTracesOutput
)
{
await
fsp
await
fsp
.
rm
(
.
rm
(
...
...
test/lib/browsers/playwright.ts
View file @
61889f89
...
@@ -21,13 +21,25 @@ let websocketFrames: Array<{ payload: string | Buffer }> = []
...
@@ -21,13 +21,25 @@ let websocketFrames: Array<{ payload: string | Buffer }> = []
const
tracePlaywright
=
process
.
env
.
TRACE_PLAYWRIGHT
const
tracePlaywright
=
process
.
env
.
TRACE_PLAYWRIGHT
// loose global to register teardown functions before quitting the browser instance.
// This is due to `quit` can be called anytime outside of BrowserInterface's lifecycle,
// which can create corrupted state by terminating the context.
// [TODO] global `quit` might need to be removed, instead should introduce per-instance teardown
const
pendingTeardown
=
[]
export
async
function
quit
()
{
export
async
function
quit
()
{
await
Promise
.
all
(
pendingTeardown
.
map
((
fn
)
=>
fn
()))
await
context
?.
close
()
await
context
?.
close
()
await
browser
?.
close
()
await
browser
?.
close
()
context
=
undefined
context
=
undefined
browser
=
undefined
browser
=
undefined
}
}
async
function
teardown
(
tearDownFn
:
()
=>
Promise
<
void
>
)
{
pendingTeardown
.
push
(
tearDownFn
)
await
tearDownFn
()
pendingTeardown
.
splice
(
pendingTeardown
.
indexOf
(
tearDownFn
),
1
)
}
interface
ElementHandleExt
extends
ElementHandle
{
interface
ElementHandleExt
extends
ElementHandle
{
getComputedCss
(
prop
:
string
):
Promise
<
string
>
getComputedCss
(
prop
:
string
):
Promise
<
string
>
text
():
Promise
<
string
>
text
():
Promise
<
string
>
...
@@ -38,7 +50,6 @@ export class Playwright extends BrowserInterface {
...
@@ -38,7 +50,6 @@ export class Playwright extends BrowserInterface {
private
eventCallbacks
:
Record
<
Event
,
Set
<
(...
args
:
any
[])
=>
void
>>
=
{
private
eventCallbacks
:
Record
<
Event
,
Set
<
(...
args
:
any
[])
=>
void
>>
=
{
request
:
new
Set
(),
request
:
new
Set
(),
}
}
private
async
initContextTracing
(
private
async
initContextTracing
(
url
:
string
,
url
:
string
,
page
:
Page
,
page
:
Page
,
...
@@ -50,7 +61,7 @@ export class Playwright extends BrowserInterface {
...
@@ -50,7 +61,7 @@ export class Playwright extends BrowserInterface {
try
{
try
{
// Clean up if any previous traces are still active
// Clean up if any previous traces are still active
await
t
his
.
teardownTracing
(
)
await
t
eardown
(
this
.
teardownTracing
.
bind
(
this
)
)
await
context
.
tracing
.
start
({
await
context
.
tracing
.
start
({
screenshots
:
true
,
screenshots
:
true
,
...
@@ -60,7 +71,7 @@ export class Playwright extends BrowserInterface {
...
@@ -60,7 +71,7 @@ export class Playwright extends BrowserInterface {
this
.
activeTrace
=
encodeURIComponent
(
url
)
this
.
activeTrace
=
encodeURIComponent
(
url
)
page
.
on
(
'close'
,
async
()
=>
{
page
.
on
(
'close'
,
async
()
=>
{
await
t
his
.
teardownTracing
(
)
await
t
eardown
(
this
.
teardownTracing
.
bind
(
this
)
)
})
})
}
catch
(
e
)
{
}
catch
(
e
)
{
this
.
activeTrace
=
undefined
this
.
activeTrace
=
undefined
...
@@ -87,6 +98,7 @@ export class Playwright extends BrowserInterface {
...
@@ -87,6 +98,7 @@ export class Playwright extends BrowserInterface {
path
:
traceOutputPath
,
path
:
traceOutputPath
,
})
})
}
catch
(
e
)
{
}
catch
(
e
)
{
require
(
'console'
).
warn
(
'Failed to teardown playwright tracing'
,
e
)
}
finally
{
}
finally
{
this
.
activeTrace
=
undefined
this
.
activeTrace
=
undefined
}
}
...
@@ -128,6 +140,7 @@ export class Playwright extends BrowserInterface {
...
@@ -128,6 +140,7 @@ export class Playwright extends BrowserInterface {
if
(
browser
)
{
if
(
browser
)
{
if
(
contextHasJSEnabled
!==
javaScriptEnabled
)
{
if
(
contextHasJSEnabled
!==
javaScriptEnabled
)
{
// If we have switched from having JS enable/disabled we need to recreate the context.
// If we have switched from having JS enable/disabled we need to recreate the context.
await
teardown
(
this
.
teardownTracing
.
bind
(
this
))
await
context
?.
close
()
await
context
?.
close
()
context
=
await
browser
.
newContext
({
context
=
await
browser
.
newContext
({
locale
,
locale
,
...
@@ -135,9 +148,6 @@ export class Playwright extends BrowserInterface {
...
@@ -135,9 +148,6 @@ export class Playwright extends BrowserInterface {
ignoreHTTPSErrors
,
ignoreHTTPSErrors
,
...
device
,
...
device
,
})
})
context
.
once
(
'close'
,
async
()
=>
{
await
this
.
teardownTracing
()
})
contextHasJSEnabled
=
javaScriptEnabled
contextHasJSEnabled
=
javaScriptEnabled
}
}
return
return
...
@@ -150,9 +160,6 @@ export class Playwright extends BrowserInterface {
...
@@ -150,9 +160,6 @@ export class Playwright extends BrowserInterface {
ignoreHTTPSErrors
,
ignoreHTTPSErrors
,
...
device
,
...
device
,
})
})
context
.
once
(
'close'
,
async
()
=>
{
await
this
.
teardownTracing
()
})
contextHasJSEnabled
=
javaScriptEnabled
contextHasJSEnabled
=
javaScriptEnabled
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment