1
1
'use strict' ;
2
2
3
- var assert = require ( 'assert' ) ;
4
- var run = require ( './helpers' ) . runMochaJSON ;
3
+ var helpers = require ( './helpers' ) ;
4
+ var run = helpers . runMochaJSON ;
5
+ var runMocha = helpers . runMocha ;
6
+ var invokeNode = helpers . invokeNode ;
5
7
var args = [ ] ;
6
8
7
9
describe ( 'uncaught exceptions' , function ( ) {
8
10
it ( 'handles uncaught exceptions from hooks' , function ( done ) {
9
- run ( 'uncaught- hook.fixture.js' , args , function ( err , res ) {
11
+ run ( 'uncaught/ hook.fixture.js' , args , function ( err , res ) {
10
12
if ( err ) {
11
- done ( err ) ;
12
- return ;
13
+ return done ( err ) ;
13
14
}
14
- assert . strictEqual ( res . stats . pending , 0 ) ;
15
- assert . strictEqual ( res . stats . passes , 0 ) ;
16
- assert . strictEqual ( res . stats . failures , 1 ) ;
17
-
18
- assert . strictEqual (
19
- res . failures [ 0 ] . fullTitle ,
20
- 'uncaught "before each" hook for "test"'
21
- ) ;
22
- assert . strictEqual ( res . code , 1 ) ;
15
+
16
+ expect ( res , 'to have failed with error' , 'oh noes' )
17
+ . and ( 'to have passed test count' , 0 )
18
+ . and ( 'to have pending test count' , 0 )
19
+ . and ( 'to have failed test count' , 1 )
20
+ . and ( 'to have failed test' , '"before each" hook for "test"' ) ;
21
+
23
22
done ( ) ;
24
23
} ) ;
25
24
} ) ;
26
25
27
26
it ( 'handles uncaught exceptions from async specs' , function ( done ) {
28
- run ( 'uncaught.fixture.js' , args , function ( err , res ) {
27
+ run ( 'uncaught/double .fixture.js' , args , function ( err , res ) {
29
28
if ( err ) {
30
- done ( err ) ;
31
- return ;
29
+ return done ( err ) ;
32
30
}
33
- assert . strictEqual ( res . stats . pending , 0 ) ;
34
- assert . strictEqual ( res . stats . passes , 0 ) ;
35
- assert . strictEqual ( res . stats . failures , 2 ) ;
36
-
37
- assert . strictEqual (
38
- res . failures [ 0 ] . title ,
39
- 'fails exactly once when a global error is thrown first'
40
- ) ;
41
- assert . strictEqual (
42
- res . failures [ 1 ] . title ,
43
- 'fails exactly once when a global error is thrown second'
44
- ) ;
45
- assert . strictEqual ( res . code , 2 ) ;
31
+
32
+ expect ( res , 'to have failed with error' , 'global error' , 'test error' )
33
+ . and ( 'to have passed test count' , 0 )
34
+ . and ( 'to have pending test count' , 0 )
35
+ . and ( 'to have failed test count' , 2 )
36
+ . and (
37
+ 'to have failed test' ,
38
+ 'fails exactly once when a global error is thrown first' ,
39
+ 'fails exactly once when a global error is thrown second'
40
+ ) ;
41
+
46
42
done ( ) ;
47
43
} ) ;
48
44
} ) ;
49
45
50
46
it ( 'handles uncaught exceptions from which Mocha cannot recover' , function ( done ) {
51
- run ( 'uncaught- fatal.fixture.js' , args , function ( err , res ) {
47
+ run ( 'uncaught/ fatal.fixture.js' , args , function ( err , res ) {
52
48
if ( err ) {
53
49
return done ( err ) ;
54
50
}
55
51
56
52
var testName = 'should bail if a successful test asynchronously fails' ;
57
- expect ( res , 'to have failed' )
53
+ expect ( res , 'to have failed with error' , 'global error ')
58
54
. and ( 'to have passed test count' , 1 )
59
55
. and ( 'to have failed test count' , 1 )
60
56
. and ( 'to have passed test' , testName )
@@ -65,12 +61,12 @@ describe('uncaught exceptions', function() {
65
61
} ) ;
66
62
67
63
it ( 'handles uncaught exceptions within pending tests' , function ( done ) {
68
- run ( 'uncaught- pending.fixture.js' , args , function ( err , res ) {
64
+ run ( 'uncaught/ pending.fixture.js' , args , function ( err , res ) {
69
65
if ( err ) {
70
66
return done ( err ) ;
71
67
}
72
68
73
- expect ( res , 'to have failed' )
69
+ expect ( res , 'to have failed with error' , 'I am uncaught! ')
74
70
. and ( 'to have passed test count' , 3 )
75
71
. and ( 'to have pending test count' , 1 )
76
72
. and ( 'to have failed test count' , 1 )
@@ -115,13 +111,66 @@ describe('uncaught exceptions', function() {
115
111
} ) ;
116
112
117
113
it ( 'removes uncaught exceptions handlers correctly' , function ( done ) {
118
- run ( 'uncaught/listeners.fixture.js' , args , function ( err , res ) {
114
+ var path = require . resolve ( './fixtures/uncaught/listeners.fixture.js' ) ;
115
+ invokeNode ( [ path ] , function ( err , res ) {
119
116
if ( err ) {
120
117
return done ( err ) ;
121
118
}
122
119
123
- expect ( res , 'to have passed' ) . and ( 'to have passed test count' , 0 ) ;
120
+ expect ( res , 'to have passed' ) ;
121
+ done ( ) ;
122
+ } ) ;
123
+ } ) ;
124
124
125
+ it ( "handles uncaught exceptions after runner's end" , function ( done ) {
126
+ runMocha (
127
+ 'uncaught/after-runner.fixture.js' ,
128
+ args ,
129
+ function ( err , res ) {
130
+ if ( err ) {
131
+ return done ( err ) ;
132
+ }
133
+
134
+ expect ( res , 'to have failed' ) . and ( 'to satisfy' , {
135
+ failing : 0 ,
136
+ passing : 1 ,
137
+ pending : 0 ,
138
+ output : expect . it ( 'to contain' , 'Error: Unexpected crash' )
139
+ } ) ;
140
+
141
+ done ( ) ;
142
+ } ,
143
+ 'pipe'
144
+ ) ;
145
+ } ) ;
146
+
147
+ it ( 'issue-1327: should run the first test and then bail' , function ( done ) {
148
+ run ( 'uncaught/issue-1327.fixture.js' , args , function ( err , res ) {
149
+ if ( err ) {
150
+ return done ( err ) ;
151
+ }
152
+ expect ( res , 'to have failed with error' , 'Too bad' )
153
+ . and ( 'to have passed test count' , 1 )
154
+ . and ( 'to have failed test count' , 1 )
155
+ . and ( 'to have passed test' , 'test 1' )
156
+ . and ( 'to have failed test' , 'test 1' ) ;
157
+ done ( ) ;
158
+ } ) ;
159
+ } ) ;
160
+
161
+ it ( 'issue-1417: uncaught exceptions from async specs' , function ( done ) {
162
+ run ( 'uncaught/issue-1417.fixture.js' , args , function ( err , res ) {
163
+ if ( err ) {
164
+ return done ( err ) ;
165
+ }
166
+ expect ( res , 'to have failed with errors' , 'sync error a' , 'sync error b' )
167
+ . and ( 'to have exit code' , 2 )
168
+ . and ( 'not to have passed tests' )
169
+ . and ( 'not to have pending tests' )
170
+ . and ( 'to have failed test order' , [
171
+ 'fails exactly once when a global error is thrown synchronously and done errors' ,
172
+ 'fails exactly once when a global error is thrown synchronously and done completes'
173
+ ] ) ;
125
174
done ( ) ;
126
175
} ) ;
127
176
} ) ;
0 commit comments