Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4270372

Browse files
authored
[WIP] CodeceptJS 3.7.x: "tryTo" and "session" do not work together (#5120)
1 parent 773ba14 commit 4270372

File tree

2 files changed

+73
-31
lines changed

2 files changed

+73
-31
lines changed

‎lib/recorder.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ let running = false
1111
let errFn
1212
let queueId = 0
1313
let sessionId = null
14+
let sessionStack = [] // Stack to support nested sessions
1415
let asyncErr = null
1516
let ignoredErrs = []
1617

@@ -89,6 +90,7 @@ module.exports = {
8990
if (promise && running) this.catch()
9091
queueId++
9192
sessionId = null
93+
sessionStack = [] // Clear the session stack
9294
asyncErr = null
9395
log(`${currentQueue()} Starting recording promises`)
9496
promise = Promise.resolve()
@@ -123,8 +125,13 @@ module.exports = {
123125
*/
124126
start(name) {
125127
if (sessionId) {
126-
debug(`${currentQueue()}Session already started as ${sessionId}`)
127-
this.restore(sessionId)
128+
debug(`${currentQueue()}Session already started as ${sessionId}, nesting session ${name}`)
129+
// Push current session to stack instead of restoring it
130+
sessionStack.push({
131+
id: sessionId,
132+
promise: promise,
133+
running: this.running,
134+
})
128135
}
129136
debug(`${currentQueue()}Starting <${name}> session`)
130137
tasks.push('--->')
@@ -142,9 +149,18 @@ module.exports = {
142149
tasks.push('<---')
143150
debug(`${currentQueue()}Finalize <${name}> session`)
144151
this.running = false
145-
sessionId = null
146152
this.catch(errFn)
147153
promise = promise.then(() => oldPromises.pop())
154+
155+
// Restore parent session from stack if available
156+
if (sessionStack.length > 0) {
157+
const parentSession = sessionStack.pop()
158+
sessionId = parentSession.id
159+
this.running = parentSession.running
160+
debug(`${currentQueue()}Restored parent session <${sessionId}>`)
161+
} else {
162+
sessionId = null
163+
}
148164
},
149165

150166
/**

‎test/data/sandbox/base_test_session.js

Lines changed: 54 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,66 @@
1-
Feature('Session');
1+
Feature('Session')
22

33
Scenario('basic session @1', ({ I }) => {
4-
I.do('writing');
4+
I.do('writing')
55
session('davert', () => {
6-
I.do('reading');
7-
});
8-
I.do('playing');
6+
I.do('reading')
7+
})
8+
I.do('playing')
99
session('john', () => {
10-
I.do('crying');
11-
});
10+
I.do('crying')
11+
})
1212
session('davert', () => {
13-
I.do('smiling');
14-
});
15-
I.do('laughing');
13+
I.do('smiling')
14+
})
15+
I.do('laughing')
1616
session('mike', () => {
17-
I.do('spying');
18-
});
17+
I.do('spying')
18+
})
1919
session('john', () => {
20-
I.do('lying');
21-
});
22-
I.do('waving');
23-
});
20+
I.do('lying')
21+
})
22+
I.do('waving')
23+
})
2424

2525
Scenario('session defined not used @2', ({ I }) => {
26-
session('davert');
27-
I.do('writing');
28-
I.do('playing');
26+
session('davert')
27+
I.do('writing')
28+
I.do('playing')
2929
session('john', () => {
30-
I.do('crying');
31-
});
30+
I.do('crying')
31+
})
3232
session('davert', () => {
33-
I.do('smiling');
34-
});
35-
I.do('laughing');
33+
I.do('smiling')
34+
})
35+
I.do('laughing')
3636
session('davert', () => {
37-
I.do('singing');
38-
});
39-
I.do('waving');
40-
});
37+
I.do('singing')
38+
})
39+
I.do('waving')
40+
})
41+
42+
Scenario('tryTo inside session @3', ({ I }) => {
43+
const { tryTo } = require('../../../lib/effects')
44+
I.do('before session')
45+
session('tryTo-test', async () => {
46+
I.do('inside session')
47+
await tryTo(() => {
48+
I.do('inside tryTo')
49+
})
50+
I.do('after tryTo')
51+
})
52+
I.do('after session')
53+
})
54+
55+
Scenario('session inside tryTo @4', ({ I }) => {
56+
const { tryTo } = require('../../../lib/effects')
57+
I.do('before tryTo')
58+
tryTo(async () => {
59+
I.do('inside tryTo')
60+
await session('nested-session', () => {
61+
I.do('inside nested session')
62+
})
63+
I.do('after session')
64+
})
65+
I.do('after tryTo')
66+
})

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /