MCPcopy Index your code
hub / github.com/codeceptjs/CodeceptJS / _finishRun

Method _finishRun

lib/workers.js:770–815  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

768 }
769
770 _finishRun() {
771 event.dispatcher.emit(event.workers.after, { tests: this.workers.map(worker => worker.tests) })
772 if (Container.result().hasFailed || this.errors.length > 0) {
773 process.exitCode = 1
774 } else {
775 process.exitCode = 0
776 }
777
778 // Emit states for all tracked tests before emitting results
779 if (this._testStates) {
780 for (const [uid, { states, lastData, workerIndex }] of this._testStates) {
781 // Set correct worker index for output
782 output.process(workerIndex)
783
784 // For tests with retries configured, emit all failures + final success
785 // For tests without retries, emit only final state
786 const lastState = states[states.length - 1]
787
788 // Check if this test had retries by looking for failure followed by success
789 const hasRetryPattern = states.length > 1 && states.some((s, i) => s.isFailed && i < states.length - 1 && !states[i + 1].isFailed)
790
791 if (hasRetryPattern) {
792 // Emit all intermediate failures and final success for retries
793 for (const state of states) {
794 if (state.isFailed) {
795 this.emit(event.test.failed, deserializeTest(state.data))
796 } else {
797 this.emit(event.test.passed, deserializeTest(state.data))
798 }
799 }
800 } else {
801 // For non-retries (like step failures), emit only the final state
802 if (lastState.isFailed) {
803 this.emit(event.test.failed, deserializeTest(lastState.data))
804 } else {
805 this.emit(event.test.passed, deserializeTest(lastState.data))
806 }
807 }
808 }
809 this._testStates.clear()
810 }
811
812 this.emit(event.all.result, Container.result())
813 event.dispatcher.emit(event.workers.result, Container.result())
814 this.emit('end') // internal event
815 }
816
817 printResults() {
818 const result = Container.result()

Callers 1

_listenWorkerEventsMethod · 0.95

Calls 3

deserializeTestFunction · 0.90
resultMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected