8
8
*
9
9
*/
10
10
11
- /*global jasmine, jest, describe, pit , expect, afterEach*/
11
+ /*global jasmine, jest, describe, it , expect, afterEach*/
12
12
13
- // Increase default timeout (5000ms) for Travis
14
- jasmine . getEnv ( ) . defaultTimeoutInterval = 10000 ;
13
+ const TEST_TIMEOUT = 120000 ;
15
14
16
- jest . autoMockOff ( ) ;
15
+ jasmine . DEFAULT_TIMEOUT_INTERVAL = TEST_TIMEOUT ;
16
+
17
+ jest . disableAutomock ( ) ;
17
18
18
19
var fs = require ( 'fs' ) ;
19
20
var path = require ( 'path' ) ;
20
21
var rimraf = require ( 'rimraf' ) ;
21
22
var temp = require ( 'temp' ) ;
22
- var spawn = require ( 'cross-spawn-async ' ) ;
23
+ var spawn = require ( 'cross-spawn' ) ;
23
24
24
25
function run ( args , stdin ) {
25
26
return new Promise ( resolve => {
@@ -32,6 +33,7 @@ function run(args, stdin) {
32
33
docgen . stdout . on ( 'data' , data => stdout += data ) ;
33
34
docgen . stderr . on ( 'data' , data => stderr += data ) ;
34
35
docgen . on ( 'close' , ( ) => resolve ( [ stdout , stderr ] ) ) ;
36
+ docgen . on ( 'error' , ( e ) => { throw e ; } ) ;
35
37
if ( stdin ) {
36
38
docgen . stdin . write ( stdin ) ;
37
39
}
@@ -88,37 +90,37 @@ describe('react-docgen CLI', () => {
88
90
rimraf . sync ( tempDir ) ;
89
91
}
90
92
tempDir = null ;
91
- tempComponents . length = 0 ;
92
- tempNoComponents . length = 0 ;
93
+ tempComponents = [ ] ;
94
+ tempNoComponents = [ ] ;
93
95
} ) ;
94
96
95
- pit ( 'reads from stdin' , ( ) => {
97
+ it ( 'reads from stdin' , ( ) => {
96
98
return run ( [ ] , component ) . then ( ( [ stdout , stderr ] ) => {
97
99
expect ( stdout . length > 0 ) . toBe ( true ) ;
98
100
expect ( stderr . length ) . toBe ( 0 ) ;
99
101
} ) ;
100
- } ) ;
102
+ } , TEST_TIMEOUT ) ;
101
103
102
- pit ( 'reads files provided as command line arguments' , ( ) => {
104
+ it ( 'reads files provided as command line arguments' , ( ) => {
103
105
createTempfiles ( ) ;
104
106
return run ( tempComponents . concat ( tempNoComponents ) ) . then (
105
107
( [ stdout , stderr ] ) => {
106
108
expect ( stdout ) . toContain ( 'Component' ) ;
107
109
expect ( stderr ) . toContain ( 'NoComponent' ) ;
108
110
}
109
111
) ;
110
- } ) ;
112
+ } , TEST_TIMEOUT ) ;
111
113
112
- pit ( 'reads directories provided as command line arguments' , ( ) => {
113
- tempDir = createTempfiles ( ) ;
114
+ it ( 'reads directories provided as command line arguments' , ( ) => {
115
+ createTempfiles ( ) ;
114
116
return run ( [ tempDir ] ) . then ( ( [ stdout , stderr ] ) => {
115
117
expect ( stdout ) . toContain ( 'Component' ) ;
116
118
expect ( stderr ) . toContain ( 'NoComponent' ) ;
117
119
} ) ;
118
- } ) ;
120
+ } , TEST_TIMEOUT ) ;
119
121
120
- pit ( 'considers js and jsx by default' , ( ) => {
121
- tempDir = createTempfiles ( ) ;
122
+ it ( 'considers js and jsx by default' , ( ) => {
123
+ createTempfiles ( ) ;
122
124
createTempfiles ( 'jsx' ) ;
123
125
createTempfiles ( 'foo' ) ;
124
126
return run ( [ tempDir ] ) . then ( ( [ stdout , stderr ] ) => {
@@ -130,9 +132,9 @@ describe('react-docgen CLI', () => {
130
132
expect ( stderr ) . toContain ( 'NoComponent.jsx' ) ;
131
133
expect ( stderr ) . not . toContain ( 'NoComponent.foo' ) ;
132
134
} ) ;
133
- } ) ;
135
+ } , TEST_TIMEOUT ) ;
134
136
135
- pit ( 'considers files with the specified extension' , ( ) => {
137
+ it ( 'considers files with the specified extension' , ( ) => {
136
138
createTempfiles ( 'foo' ) ;
137
139
createTempfiles ( 'bar' ) ;
138
140
@@ -144,24 +146,23 @@ describe('react-docgen CLI', () => {
144
146
expect ( stderr ) . toContain ( 'NoComponent.bar' ) ;
145
147
} ;
146
148
147
-
148
149
return Promise . all ( [
149
150
run ( [ '--extension=foo' , '--extension=bar' , tempDir ] ) . then ( verify ) ,
150
151
run ( [ '-x' , 'foo' , '-x' , 'bar' , tempDir ] ) . then ( verify ) ,
151
152
] ) ;
152
- } ) ;
153
+ } , TEST_TIMEOUT ) ;
153
154
154
- pit ( 'ignores files in node_modules and __tests__ by default' , ( ) => {
155
+ it ( 'ignores files in node_modules and __tests__ by default' , ( ) => {
155
156
createTempfiles ( null , 'node_modules' ) ;
156
157
createTempfiles ( null , '__tests__' ) ;
157
158
158
159
return run ( [ tempDir ] ) . then ( ( [ stdout , stderr ] ) => {
159
160
expect ( stdout ) . toBe ( '' ) ;
160
161
expect ( stderr ) . toBe ( '' ) ;
161
162
} ) ;
162
- } ) ;
163
+ } , TEST_TIMEOUT ) ;
163
164
164
- pit ( 'ignores specified folders' , ( ) => {
165
+ it ( 'ignores specified folders' , ( ) => {
165
166
createTempfiles ( null , 'foo' ) ;
166
167
167
168
var verify = ( [ stdout , stderr ] ) => {
@@ -173,23 +174,23 @@ describe('react-docgen CLI', () => {
173
174
run ( [ '--ignore=foo' , tempDir ] ) . then ( verify ) ,
174
175
run ( [ '-i' , 'foo' , tempDir ] ) . then ( verify ) ,
175
176
] ) ;
176
- } ) ;
177
+ } , TEST_TIMEOUT ) ;
177
178
178
- pit ( 'writes to stdout' , ( ) => {
179
+ it ( 'writes to stdout' , ( ) => {
179
180
return run ( [ ] , component ) . then ( ( [ stdout , stderr ] ) => {
180
181
expect ( stdout . length > 0 ) . toBe ( true ) ;
181
182
expect ( stderr . length ) . toBe ( 0 ) ;
182
183
} ) ;
183
- } ) ;
184
+ } , TEST_TIMEOUT ) ;
184
185
185
- pit ( 'writes to stderr' , ( ) => {
186
+ it ( 'writes to stderr' , ( ) => {
186
187
return run ( [ ] , '{}' ) . then ( ( [ stdout , stderr ] ) => {
187
188
expect ( stderr . length > 0 ) . toBe ( true ) ;
188
189
expect ( stdout . length ) . toBe ( 0 ) ;
189
190
} ) ;
190
- } ) ;
191
+ } , TEST_TIMEOUT ) ;
191
192
192
- pit ( 'writes to a file if provided' , function ( ) {
193
+ it ( 'writes to a file if provided' , ( ) => {
193
194
var outFile = temp . openSync ( ) ;
194
195
createTempfiles ( ) ;
195
196
@@ -202,10 +203,10 @@ describe('react-docgen CLI', () => {
202
203
run ( [ '--out=' + outFile . path , tempDir ] ) . then ( verify ) ,
203
204
run ( [ '-o' , outFile . path , tempDir ] ) . then ( verify ) ,
204
205
] ) ;
205
- } ) ;
206
+ } , TEST_TIMEOUT ) ;
206
207
207
208
describe ( '--resolver' , ( ) => {
208
- pit ( 'accepts the names of built in resolvers' , ( ) => {
209
+ it ( 'accepts the names of built in resolvers' , ( ) => {
209
210
return Promise . all ( [
210
211
// No option passed: same as --resolver=findExportedComponentDefinition
211
212
run ( [
@@ -229,9 +230,9 @@ describe('react-docgen CLI', () => {
229
230
expect ( stdout ) . toContain ( 'ComponentB' ) ;
230
231
} ) ,
231
232
] ) ;
232
- } ) ;
233
+ } , TEST_TIMEOUT ) ;
233
234
234
- pit ( 'accepts a path to a resolver function' , ( ) => {
235
+ it ( 'accepts a path to a resolver function' , ( ) => {
235
236
return Promise . all ( [
236
237
run ( [
237
238
'--resolver=' + path . join ( __dirname , './example/customResolver.js' ) ,
@@ -241,7 +242,7 @@ describe('react-docgen CLI', () => {
241
242
expect ( stdout ) . toContain ( 'Custom' ) ;
242
243
} ) ,
243
244
] ) ;
244
- } ) ;
245
+ } , TEST_TIMEOUT ) ;
245
246
} ) ;
246
247
247
248
} ) ;
0 commit comments