@@ -31,6 +31,7 @@ function Api(files, options) {
31
31
this . stats = [ ] ;
32
32
this . tests = [ ] ;
33
33
this . files = files || [ ] ;
34
+ this . base = '' ;
34
35
35
36
Object . keys ( Api . prototype ) . forEach ( function ( key ) {
36
37
this [ key ] = this [ key ] . bind ( this ) ;
@@ -99,24 +100,34 @@ Api.prototype._handleTest = function (test) {
99
100
this . emit ( 'test' , test ) ;
100
101
} ;
101
102
103
+ Api . prototype . _findBase = function ( files ) {
104
+ this . base = files . reduce ( function ( base , file ) {
105
+ file = path . relative ( '.' , file ) ;
106
+ file = file . split ( path . sep ) ;
107
+ if ( base === false ) return file ;
108
+ return base . filter ( function ( part , i ) {
109
+ return file [ i ] . toLowerCase ( ) === part . toLowerCase ( ) ;
110
+ } ) ;
111
+ } , false ) . join ( path . sep ) ;
112
+
113
+ if ( this . base === '' || this . base === '.' ) {
114
+ this . base = this . files [ 0 ] || 'test' ;
115
+ }
116
+
117
+ this . base += path . sep ;
118
+ } ;
119
+
102
120
Api . prototype . _prefixTitle = function ( file ) {
103
121
if ( this . fileCount === 1 ) {
104
122
return '' ;
105
123
}
106
124
107
125
var separator = ' ' + chalk . gray . dim ( figures . pointerSmall ) + ' ' ;
108
126
109
- var base = path . dirname ( this . files [ 0 ] ) ;
110
-
111
- if ( base === '.' ) {
112
- base = this . files [ 0 ] || 'test' ;
113
- }
114
-
115
- base += path . sep ;
116
-
117
127
var prefix = path . relative ( '.' , file )
118
- . replace ( base , '' )
128
+ . replace ( this . base , '' )
119
129
. replace ( / \. s p e c / , '' )
130
+ . replace ( / \. t e s t / , '' )
120
131
. replace ( / t e s t \- / g, '' )
121
132
. replace ( / \. j s $ / , '' )
122
133
. split ( path . sep )
@@ -143,6 +154,8 @@ Api.prototype.run = function () {
143
154
144
155
self . fileCount = files . length ;
145
156
157
+ self . _findBase ( files ) ;
158
+
146
159
var tests = files . map ( self . _runFile ) ;
147
160
148
161
// receive test count from all files and then run the tests
0 commit comments