Skip to content

Commit f50f308

Browse files
committed
fix: avoid recorder hang by not calling _beforeSuite directly in tests
When running with codeceptjs run/run-workers, calling helper._beforeSuite() directly can cause hangs because the method gets queued in the recorder but doesn't return a promise, leaving the recorder waiting indefinitely. Fixed by: - Manually setting up JSONResponse callback instead of calling _beforeSuite() - Adding await for Container.create() in both REST and GraphQL tests - Ensures tests work in both unit test mode and full codeceptjs environment This resolves the hang issue where mocha would trap unhandled rejection and the process would hang after 'Running | hook JSONResponse._beforeSuite()'.
1 parent d6cc654 commit f50f308

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

test/graphql/GraphQL_test.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ describe('GraphQL', () => {
107107
describe('JSONResponse integration', () => {
108108
let jsonResponse
109109

110-
beforeEach(() => {
111-
Container.create({
110+
beforeEach(async () => {
111+
await Container.create({
112112
helpers: {
113113
GraphQL: {
114114
endpoint: graphql_url,
@@ -120,7 +120,14 @@ describe('GraphQL', () => {
120120
})
121121
I = Container.helpers('GraphQL')
122122
jsonResponse = Container.helpers('JSONResponse')
123-
jsonResponse._beforeSuite()
123+
// Manually set up JSONResponse to capture GraphQL responses
124+
// This avoids calling _beforeSuite() which may be wrapped by recorder
125+
jsonResponse.response = null
126+
const origOnResponse = I.config.onResponse
127+
I.config.onResponse = response => {
128+
jsonResponse.response = response
129+
if (typeof origOnResponse === 'function') origOnResponse(response)
130+
}
124131
})
125132

126133
afterEach(() => {

test/rest/REST_test.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ describe('REST', () => {
140140
let jsonResponse
141141

142142
beforeEach(async () => {
143-
Container.create({
143+
await Container.create({
144144
helpers: {
145145
REST: {},
146146
JSONResponse: {},
@@ -149,7 +149,14 @@ describe('REST', () => {
149149
await Container.started()
150150
I = Container.helpers('REST')
151151
jsonResponse = Container.helpers('JSONResponse')
152-
jsonResponse._beforeSuite()
152+
// Manually set up JSONResponse to capture REST responses
153+
// This avoids calling _beforeSuite() which may be wrapped by recorder
154+
jsonResponse.response = null
155+
const origOnResponse = I.config.onResponse
156+
I.config.onResponse = response => {
157+
jsonResponse.response = response
158+
if (typeof origOnResponse === 'function') origOnResponse(response)
159+
}
153160
})
154161

155162
afterEach(() => {

0 commit comments

Comments
 (0)