Skip to content

Commit fc96ccc

Browse files
Copilotkobenguyent
andcommitted
Fix test hang issue when restart: false by properly mapping to context restart
Co-authored-by: kobenguyent <7845001+kobenguyent@users.noreply.github.com>
1 parent c8913f8 commit fc96ccc

File tree

3 files changed

+58
-6
lines changed

3 files changed

+58
-6
lines changed

lib/helper/extras/PlaywrightRestartOpts.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ export function setRestartStrategy(options) {
1414
return (restarts = restart)
1515
}
1616

17-
// When restart is false, don't restart anything
17+
// When restart is false, map to 'context' restart (as per documentation)
1818
if (restart === false) {
19-
restarts = null
19+
restarts = 'context'
2020
return
2121
}
2222

lib/listener/helpers.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ export default function () {
7474

7575
event.dispatcher.on(event.all.result, () => {
7676
// Skip _finishTest for all helpers if any browser helper restarts to avoid double cleanup
77+
// Note: restart: false is equivalent to restart: 'context' per documentation
7778
const hasBrowserRestart = Object.values(helpers).some(helper =>
78-
(helper.config && (helper.config.restart === 'browser' || helper.config.restart === 'context' || helper.config.restart === true)) ||
79-
(helper.options && (helper.options.restart === 'browser' || helper.options.restart === 'context' || helper.options.restart === true))
79+
(helper.config && (helper.config.restart === 'browser' || helper.config.restart === 'context' || helper.config.restart === false || helper.config.restart === true)) ||
80+
(helper.options && (helper.options.restart === 'browser' || helper.options.restart === 'context' || helper.options.restart === false || helper.options.restart === true))
8081
)
8182

8283
Object.keys(helpers).forEach(key => {
@@ -89,9 +90,10 @@ export default function () {
8990

9091
event.dispatcher.on(event.all.after, () => {
9192
// Skip _cleanup for all helpers if any browser helper restarts to avoid double cleanup
93+
// Note: restart: false is equivalent to restart: 'context' per documentation
9294
const hasBrowserRestart = Object.values(helpers).some(helper =>
93-
(helper.config && (helper.config.restart === 'browser' || helper.config.restart === 'context' || helper.config.restart === true)) ||
94-
(helper.options && (helper.options.restart === 'browser' || helper.options.restart === 'context' || helper.options.restart === true))
95+
(helper.config && (helper.config.restart === 'browser' || helper.config.restart === 'context' || helper.config.restart === false || helper.config.restart === true)) ||
96+
(helper.options && (helper.options.restart === 'browser' || helper.options.restart === 'context' || helper.options.restart === false || helper.options.restart === true))
9597
)
9698

9799
Object.keys(helpers).forEach(key => {
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import * as chai from 'chai'
2+
3+
const assert = chai.assert
4+
const expect = chai.expect
5+
6+
import {
7+
setRestartStrategy,
8+
restartsSession,
9+
restartsContext,
10+
restartsBrowser
11+
} from '../../lib/helper/extras/PlaywrightRestartOpts.js'
12+
13+
describe('PlaywrightRestartOpts', function () {
14+
describe('setRestartStrategy', function () {
15+
it('should set context restart when restart is false', function () {
16+
setRestartStrategy({ restart: false })
17+
assert.isFalse(restartsSession())
18+
assert.isTrue(restartsContext())
19+
assert.isFalse(restartsBrowser())
20+
})
21+
22+
it('should set browser restart when restart is true', function () {
23+
setRestartStrategy({ restart: true })
24+
assert.isFalse(restartsSession())
25+
assert.isFalse(restartsContext())
26+
assert.isTrue(restartsBrowser())
27+
})
28+
29+
it('should set context restart when restart is "context"', function () {
30+
setRestartStrategy({ restart: 'context' })
31+
assert.isFalse(restartsSession())
32+
assert.isTrue(restartsContext())
33+
assert.isFalse(restartsBrowser())
34+
})
35+
36+
it('should set session restart when restart is "session"', function () {
37+
setRestartStrategy({ restart: 'session' })
38+
assert.isTrue(restartsSession())
39+
assert.isFalse(restartsContext())
40+
assert.isFalse(restartsBrowser())
41+
})
42+
43+
it('should set browser restart when restart is "browser"', function () {
44+
setRestartStrategy({ restart: 'browser' })
45+
assert.isFalse(restartsSession())
46+
assert.isFalse(restartsContext())
47+
assert.isTrue(restartsBrowser())
48+
})
49+
})
50+
})

0 commit comments

Comments
 (0)