1
1
var mocha = require ( '..' ) ;
2
2
var utils = mocha . utils ;
3
+ var path = require ( 'path' ) ;
3
4
var JSON = require ( 'json3' ) ;
4
5
5
6
describe ( 'utils' , function ( ) {
@@ -97,62 +98,120 @@ describe('utils', function() {
97
98
describe ( '.stackTraceFilter()' , function ( ) {
98
99
describe ( 'on node' , function ( ) {
99
100
var filter = utils . stackTraceFilter ( ) ;
100
- it ( 'should get a stack-trace as a string and prettify it' , function ( ) {
101
- var stack = [ 'AssertionError: foo bar'
102
- , 'at EventEmitter.<anonymous> (/usr/local/dev/test.js:16:12)'
103
- , 'at Context.<anonymous> (/usr/local/dev/test.js:19:5)'
104
- , 'Test.Runnable.run (/usr/local/lib/node_modules/mocha/lib/runnable.js:244:7)'
105
- , 'Runner.runTest (/usr/local/lib/node_modules/mocha/lib/runner.js:374:10)'
106
- , '/usr/local/lib/node_modules/mocha/lib/runner.js:452:12'
107
- , 'next (/usr/local/lib/node_modules/mocha/lib/runner.js:299:14)'
108
- , '/usr/local/lib/node_modules/mocha/lib/runner.js:309:7'
109
- , 'next (/usr/local/lib/node_modules/mocha/lib/runner.js:248:23)'
110
- , 'Immediate._onImmediate (/usr/local/lib/node_modules/mocha/lib/runner.js:276:5)'
111
- , 'at processImmediate [as _immediateCallback] (timers.js:321:17)' ] ;
112
- filter ( stack . join ( '\n' ) ) . should . equal ( stack . slice ( 0 , 3 ) . join ( '\n' ) ) ;
113
-
114
- stack = [ 'AssertionError: bar baz'
115
- , 'at /usr/local/dev/some-test-file.js:25:8'
116
- , 'at tryCatcher (/usr/local/dev/own/tmp/node_modules/bluebird/js/main/util.js:24:31)'
117
- , 'at Promise._resolveFromResolver (/usr/local/dev/own/tmp/node_modules/bluebird/js/main/promise.js:439:31)'
118
- , 'at new Promise (/usr/local/dev/own/tmp/node_modules/bluebird/js/main/promise.js:53:37)'
119
- , 'at yourFunction (/usr/local/dev/own/tmp/test1.js:24:13)'
120
- , 'at Context.<anonymous> (/usr/local/dev/some-test-file:30:4)'
121
- , 'Test.Runnable.run (/usr/local/lib/node_modules/mocha/lib/runnable.js:218:15)'
122
- , 'next (/usr/local/lib/node_modules/mocha/lib/runner.js:248:23)'
123
- , 'Immediate._onImmediate (/usr/local/lib/node_modules/mocha/lib/runner.js:276:5)'
124
- , 'at processImmediate [as _immediateCallback] (timers.js:321:17)' ] ;
125
101
126
- filter ( stack . join ( '\n' ) ) . should . equal ( stack . slice ( 0 , 7 ) . join ( '\n' ) ) ;
127
- } ) ;
102
+ describe ( 'on POSIX OS' , function ( ) {
103
+ before ( function ( ) {
104
+ if ( path . sep !== '/' ) {
105
+ this . skip ( ) ;
106
+ }
107
+ } ) ;
128
108
129
- it ( 'does not ignore other bower_components and components' , function ( ) {
130
- var stack = [ 'Error: failed'
131
- , 'at assert (index.html:11:26)'
132
- , 'at Context.<anonymous> (test.js:17:18)'
133
- , 'at bower_components/should/should.js:4827:7'
134
- , 'at next (file:///.../bower_components/should/should.js:4766:23)'
135
- , 'at components/should/5.0.0/should.js:4827:7'
136
- , 'at next (file:///.../components/should/5.0.0/should.js:4766:23)'
137
- , 'at file:///.../bower_components/mocha/mocha.js:4794:5'
138
- , 'at timeslice (.../components/mocha/mocha.js:6218:27)'
139
- , 'at Test.require.register.Runnable.run (file:///.../components/mochajs/mocha/2.1.0/mocha.js:4463:15)'
140
- , 'at Runner.require.register.Runner.runTest (file:///.../components/mochajs/mocha/2.1.0/mocha.js:4892:10)'
141
- , 'at file:///.../components/mochajs/mocha/2.1.0/mocha.js:4970:12'
142
- , 'at next (file:///.../components/mochajs/mocha/2.1.0/mocha.js:4817:14)' ] ;
143
- filter ( stack . join ( '\n' ) ) . should . equal ( stack . slice ( 0 , 7 ) . join ( '\n' ) ) ;
144
- } ) ;
109
+ it ( 'should get a stack-trace as a string and prettify it' , function ( ) {
110
+ var stack = [
111
+ 'AssertionError: foo bar' ,
112
+ 'at EventEmitter.<anonymous> (/usr/local/dev/test.js:16:12)' ,
113
+ 'at Context.<anonymous> (/usr/local/dev/test.js:19:5)' ,
114
+ 'Test.Runnable.run (/usr/local/lib/node_modules/mocha/lib/runnable.js:244:7)' ,
115
+ 'Runner.runTest (/usr/local/lib/node_modules/mocha/lib/runner.js:374:10)' ,
116
+ '/usr/local/lib/node_modules/mocha/lib/runner.js:452:12' ,
117
+ 'next (/usr/local/lib/node_modules/mocha/lib/runner.js:299:14)' ,
118
+ '/usr/local/lib/node_modules/mocha/lib/runner.js:309:7' ,
119
+ 'next (/usr/local/lib/node_modules/mocha/lib/runner.js:248:23)' ,
120
+ 'Immediate._onImmediate (/usr/local/lib/node_modules/mocha/lib/runner.js:276:5)' ,
121
+ 'at processImmediate [as _immediateCallback] (timers.js:321:17)'
122
+ ] ;
123
+ filter ( stack . join ( '\n' ) )
124
+ . should
125
+ . equal ( stack . slice ( 0 , 3 )
126
+ . join ( '\n' ) ) ;
127
+
128
+ stack = [
129
+ 'AssertionError: bar baz' ,
130
+ 'at /usr/local/dev/some-test-file.js:25:8' ,
131
+ 'at tryCatcher (/usr/local/dev/own/tmp/node_modules/bluebird/js/main/util.js:24:31)' ,
132
+ 'at Promise._resolveFromResolver (/usr/local/dev/own/tmp/node_modules/bluebird/js/main/promise.js:439:31)' ,
133
+ 'at new Promise (/usr/local/dev/own/tmp/node_modules/bluebird/js/main/promise.js:53:37)' ,
134
+ 'at yourFunction (/usr/local/dev/own/tmp/test1.js:24:13)' ,
135
+ 'at Context.<anonymous> (/usr/local/dev/some-test-file:30:4)' ,
136
+ 'Test.Runnable.run (/usr/local/lib/node_modules/mocha/lib/runnable.js:218:15)' ,
137
+ 'next (/usr/local/lib/node_modules/mocha/lib/runner.js:248:23)' ,
138
+ 'Immediate._onImmediate (/usr/local/lib/node_modules/mocha/lib/runner.js:276:5)' ,
139
+ 'at processImmediate [as _immediateCallback] (timers.js:321:17)'
140
+ ] ;
141
+
142
+ filter ( stack . join ( '\n' ) )
143
+ . should
144
+ . equal ( stack . slice ( 0 , 7 )
145
+ . join ( '\n' ) ) ;
146
+ } ) ;
147
+
148
+ it ( 'does not ignore other bower_components and components' ,
149
+ function ( ) {
150
+ var stack = [
151
+ 'Error: failed' ,
152
+ 'at assert (index.html:11:26)' ,
153
+ 'at Context.<anonymous> (test.js:17:18)' ,
154
+ 'at bower_components/should/should.js:4827:7' ,
155
+ 'at next (file:///.../bower_components/should/should.js:4766:23)' ,
156
+ 'at components/should/5.0.0/should.js:4827:7' ,
157
+ 'at next (file:///.../components/should/5.0.0/should.js:4766:23)' ,
158
+ 'at file:///.../bower_components/mocha/mocha.js:4794:5' ,
159
+ 'at timeslice (.../components/mocha/mocha.js:6218:27)' ,
160
+ 'at Test.require.register.Runnable.run (file:///.../components/mochajs/mocha/2.1.0/mocha.js:4463:15)' ,
161
+ 'at Runner.require.register.Runner.runTest (file:///.../components/mochajs/mocha/2.1.0/mocha.js:4892:10)' ,
162
+ 'at file:///.../components/mochajs/mocha/2.1.0/mocha.js:4970:12' ,
163
+ 'at next (file:///.../components/mochajs/mocha/2.1.0/mocha.js:4817:14)'
164
+ ] ;
165
+ filter ( stack . join ( '\n' ) )
166
+ . should
167
+ . equal ( stack . slice ( 0 , 7 )
168
+ . join ( '\n' ) ) ;
169
+ } ) ;
145
170
146
- it ( 'should replace absolute with relative paths' , function ( ) {
147
- var stack = [ 'Error: ' + process . cwd ( ) + '/bla.js has a problem'
148
- , 'at foo (' + process . cwd ( ) + '/foo/index.js:13:226)'
149
- , 'at bar (/usr/local/dev/own/tmp/node_modules/bluebird/js/main/promise.js:11:26)' ] ;
171
+ it ( 'should replace absolute with relative paths' , function ( ) {
172
+ var stack = [
173
+ 'Error: ' + process . cwd ( ) + '/bla.js has a problem' ,
174
+ 'at foo (' + process . cwd ( ) + '/foo/index.js:13:226)' ,
175
+ 'at bar (/usr/local/dev/own/tmp/node_modules/bluebird/js/main/promise.js:11:26)'
176
+ ] ;
177
+
178
+ var expected = [
179
+ 'Error: ' + process . cwd ( ) + '/bla.js has a problem' ,
180
+ 'at foo (foo/index.js:13:226)' ,
181
+ 'at bar (/usr/local/dev/own/tmp/node_modules/bluebird/js/main/promise.js:11:26)'
182
+ ] ;
183
+
184
+ filter ( stack . join ( '\n' ) )
185
+ . should
186
+ . equal ( expected . join ( '\n' ) ) ;
187
+ } ) ;
188
+ } ) ;
150
189
151
- var expected = [ 'Error: ' + process . cwd ( ) + '/bla.js has a problem'
152
- , 'at foo (foo/index.js:13:226)'
153
- , 'at bar (/usr/local/dev/own/tmp/node_modules/bluebird/js/main/promise.js:11:26)' ] ;
190
+ describe ( 'on Windows' , function ( ) {
191
+ before ( function ( ) {
192
+ if ( path . sep === '/' ) {
193
+ this . skip ( ) ;
194
+ }
195
+ } ) ;
154
196
155
- filter ( stack . join ( '\n' ) ) . should . equal ( expected . join ( '\n' ) ) ;
197
+ it ( 'should work on Windows' , function ( ) {
198
+ var stack = [
199
+ 'Error: failed' ,
200
+ 'at Context.<anonymous> (C:\\Users\\ishida\\src\\test\\test\\mytest.js:5:9)' ,
201
+ 'at callFn (C:\\Users\\ishida\\src\\test\\node_modules\\mocha\\lib\\runnable.js:326:21)' ,
202
+ 'at Test.Runnable.run (C:\\Users\\ishida\\src\\test\\node_modules\\mocha\\lib\\runnable.js:319:7)' ,
203
+ 'at Runner.runTest (C:\\Users\\ishida\\src\\test\\node_modules\\mocha\\lib\\runner.js:422:10)' ,
204
+ 'at C:\\Users\\ishida\\src\\test\\node_modules\\mocha\\lib\\runner.js:528:12' ,
205
+ 'at next (C:\\Users\\ishida\\src\\test\\node_modules\\mocha\\lib\\runner.js:342:14)' ,
206
+ 'at C:\\Users\\ishida\\src\\test\\node_modules\\mocha\\lib\\runner.js:352:7' ,
207
+ 'at next (C:\\Users\\ishida\\src\\test\\node_modules\\mocha\\lib\\runner.js:284:14)' ,
208
+ 'at Immediate._onImmediate (C:\\Users\\ishida\\src\\test\\node_modules\\mocha\\lib\\runner.js:320:5)'
209
+ ] ;
210
+ filter ( stack . join ( '\n' ) )
211
+ . should
212
+ . equal ( stack . slice ( 0 , 2 )
213
+ . join ( '\n' ) ) ;
214
+ } ) ;
156
215
} ) ;
157
216
} ) ;
158
217
@@ -163,7 +222,7 @@ describe('utils', function() {
163
222
global . location = { href : 'localhost:3000/foo/bar/index.html' } ;
164
223
filter = utils . stackTraceFilter ( ) ;
165
224
} ) ;
166
- it ( 'does not strip out other bower_components and components ' , function ( ) {
225
+ it ( 'does not strip out other bower_components' , function ( ) {
167
226
var stack = [ 'Error: failed'
168
227
, 'at assert (index.html:11:26)'
169
228
, 'at Context.<anonymous> (test.js:17:18)'
0 commit comments