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

[WIP] CodeceptJS 3.7.x: "tryTo" and "session" do not work together #5120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
kobenguyent merged 2 commits into 3.x from copilot/fix-5116
Sep 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions lib/recorder.js
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ let running = false
let errFn
let queueId = 0
let sessionId = null
let sessionStack = [] // Stack to support nested sessions
let asyncErr = null
let ignoredErrs = []

Expand Down Expand Up @@ -89,6 +90,7 @@ module.exports = {
if (promise && running) this.catch()
queueId++
sessionId = null
sessionStack = [] // Clear the session stack
asyncErr = null
log(`${currentQueue()} Starting recording promises`)
promise = Promise.resolve()
Expand Down Expand Up @@ -123,8 +125,13 @@ module.exports = {
*/
start(name) {
if (sessionId) {
debug(`${currentQueue()}Session already started as ${sessionId}`)
this.restore(sessionId)
debug(`${currentQueue()}Session already started as ${sessionId}, nesting session ${name}`)
// Push current session to stack instead of restoring it
sessionStack.push({
id: sessionId,
promise: promise,
running: this.running,
})
}
debug(`${currentQueue()}Starting <${name}> session`)
tasks.push('--->')
Expand All @@ -142,9 +149,18 @@ module.exports = {
tasks.push('<---')
debug(`${currentQueue()}Finalize <${name}> session`)
this.running = false
sessionId = null
this.catch(errFn)
promise = promise.then(() => oldPromises.pop())

// Restore parent session from stack if available
if (sessionStack.length > 0) {
const parentSession = sessionStack.pop()
sessionId = parentSession.id
this.running = parentSession.running
debug(`${currentQueue()}Restored parent session <${sessionId}>`)
} else {
sessionId = null
}
},

/**
Expand Down
82 changes: 54 additions & 28 deletions test/data/sandbox/base_test_session.js
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,40 +1,66 @@
Feature('Session');
Feature('Session')

Scenario('basic session @1', ({ I }) => {
I.do('writing');
I.do('writing')
session('davert', () => {
I.do('reading');
});
I.do('playing');
I.do('reading')
})
I.do('playing')
session('john', () => {
I.do('crying');
});
I.do('crying')
})
session('davert', () => {
I.do('smiling');
});
I.do('laughing');
I.do('smiling')
})
I.do('laughing')
session('mike', () => {
I.do('spying');
});
I.do('spying')
})
session('john', () => {
I.do('lying');
});
I.do('waving');
});
I.do('lying')
})
I.do('waving')
})

Scenario('session defined not used @2', ({ I }) => {
session('davert');
I.do('writing');
I.do('playing');
session('davert')
I.do('writing')
I.do('playing')
session('john', () => {
I.do('crying');
});
I.do('crying')
})
session('davert', () => {
I.do('smiling');
});
I.do('laughing');
I.do('smiling')
})
I.do('laughing')
session('davert', () => {
I.do('singing');
});
I.do('waving');
});
I.do('singing')
})
I.do('waving')
})

Scenario('tryTo inside session @3', ({ I }) => {
const { tryTo } = require('../../../lib/effects')
I.do('before session')
session('tryTo-test', async () => {
I.do('inside session')
await tryTo(() => {
I.do('inside tryTo')
})
I.do('after tryTo')
})
I.do('after session')
})

Scenario('session inside tryTo @4', ({ I }) => {
const { tryTo } = require('../../../lib/effects')
I.do('before tryTo')
tryTo(async () => {
I.do('inside tryTo')
await session('nested-session', () => {
I.do('inside nested session')
})
I.do('after session')
})
I.do('after tryTo')
})

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