Skip to content

Commit 68231af

Browse files
committed
fix: set exit code when tests fail
The mocha.run() callback receives a 'failures' count parameter that indicates how many tests failed, but this was not being used to set process.exitCode. This caused the process to exit with code 0 even when tests failed, making CI pipelines incorrectly report success. Changes: - Accept failures parameter in mocha.run() callback - Pass failures to done() function - Set process.exitCode = 1 when failures > 0 - Ensures CI pipelines correctly fail when tests fail
1 parent a159d02 commit 68231af

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/codecept.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,17 +269,21 @@ class Codecept {
269269
})
270270
}
271271

272-
const done = async () => {
272+
const done = async (failures) => {
273273
event.emit(event.all.result, container.result())
274274
event.emit(event.all.after, this)
275275
// Wait for any recorder tasks added by event.all.after handlers
276276
await recorder.promise()
277+
// Set exit code based on test failures
278+
if (failures) {
279+
process.exitCode = 1
280+
}
277281
resolve()
278282
}
279283

280284
try {
281285
event.emit(event.all.before, this)
282-
mocha.run(async () => await done())
286+
mocha.run(async (failures) => await done(failures))
283287
} catch (e) {
284288
output.error(e.stack)
285289
reject(e)

0 commit comments

Comments
 (0)