@@ -59,13 +59,34 @@ function tryTest(fn) {
59
59
args . push ( arguments [ i ] ) ;
60
60
}
61
61
62
+ let commitCalled = false ;
63
+ let discarded = false ;
64
+ let finished = false ;
65
+
66
+ const commitFn = ( ret , toCommit ) => {
67
+ if ( commitCalled ) {
68
+ this . saveFirstError ( new Error ( 'Either commit() or discard() was already called' ) ) ;
69
+ return ;
70
+ }
71
+ commitCalled = true ;
72
+
73
+ if ( ret . passed ) {
74
+ this . countFinishedAttemptAssertion ( toCommit ) ;
75
+ } else {
76
+ this . countFailedAttemptAssertion ( ret . error , toCommit ) ;
77
+ }
78
+
79
+ if ( toCommit ) {
80
+ for ( const log of ret . logs ) {
81
+ this . addLog ( log ) ;
82
+ }
83
+ }
84
+ } ;
85
+
62
86
const running = this
63
87
. forAttempt ( t => fn . apply ( null , [ t ] . concat ( args ) ) )
64
88
. run ( ) ;
65
89
66
- let commitCalled = false ;
67
- let discarded = false ;
68
-
69
90
this . addPendingAttemptAssertion ( running . then ( ret => {
70
91
if ( ! discarded && ! ret . passed ) {
71
92
throw ret . error ;
@@ -77,29 +98,10 @@ function tryTest(fn) {
77
98
return null ;
78
99
}
79
100
80
- const commitFn = toCommit => {
81
- if ( commitCalled ) {
82
- this . saveFirstError ( new Error ( 'Either commit() or discard() was already called' ) ) ;
83
- return ;
84
- }
85
- commitCalled = true ;
86
-
87
- if ( ret . passed ) {
88
- this . countFinishedAttemptAssertion ( toCommit ) ;
89
- } else {
90
- this . countFailedAttemptAssertion ( ret . error , toCommit ) ;
91
- }
92
-
93
- if ( toCommit ) {
94
- for ( const log of ret . logs ) {
95
- this . addLog ( log ) ;
96
- }
97
- }
98
- } ;
99
-
101
+ finished = true ;
100
102
return Object . assign ( { } , ret , {
101
- commit : ( ) => commitFn ( true ) ,
102
- discard : ( ) => commitFn ( false )
103
+ commit : ( ) => commitFn ( ret , true ) ,
104
+ discard : ( ) => commitFn ( ret , false )
103
105
} ) ;
104
106
} ) ;
105
107
0 commit comments