@@ -9,24 +9,29 @@ var request = require('request');
9
9
var test = require ( 'tape' ) ;
10
10
var gm = require ( 'gm' ) ;
11
11
12
+ var touch = function ( fileName ) {
13
+ fs . closeSync ( fs . openSync ( fileName , 'w' ) ) ;
14
+ } ;
15
+
12
16
13
17
// make artifact folders
14
- if ( ! fs . existsSync ( constants . pathToTestImagesDiff ) ) fs . mkdirSync ( constants . pathToTestImagesDiff ) ;
15
- if ( ! fs . existsSync ( constants . pathToTestImages ) ) fs . mkdirSync ( constants . pathToTestImages ) ;
18
+ if ( ! fs . existsSync ( constants . pathToTestImagesDiff ) ) {
19
+ fs . mkdirSync ( constants . pathToTestImagesDiff ) ;
20
+ }
21
+ if ( ! fs . existsSync ( constants . pathToTestImages ) ) {
22
+ fs . mkdirSync ( constants . pathToTestImages ) ;
23
+ }
16
24
17
25
var userFileName = process . argv [ 2 ] ;
18
26
19
- var touch = function ( fileName ) {
20
- fs . closeSync ( fs . openSync ( fileName , 'w' ) ) ;
21
- } ;
22
-
23
- if ( ! userFileName ) runAll ( ) ;
27
+ // run the test(s)
28
+ if ( ! userFileName ) runAll ( ) ;
24
29
else runSingle ( userFileName ) ;
25
30
26
31
function runAll ( ) {
27
32
test ( 'testing mocks' , function ( t ) {
28
33
29
- var files = fs . readdirSync ( constants . pathToTestImageMocks ) ;
34
+ var allMocks = fs . readdirSync ( constants . pathToTestImageMocks ) ;
30
35
31
36
/*
32
37
* Some test cases exhibit run-to-run randomness;
@@ -35,15 +40,34 @@ function runAll () {
35
40
* More info:
36
41
* https://github.com/plotly/plotly.js/issues/62
37
42
*
38
- * 40 test cases are removed:
43
+ * 41 test cases are removed:
39
44
* - font-wishlist (1 test case)
40
45
* - all gl2d (38)
41
- * - gl2d_bunny-hull (1)
46
+ * - gl3d_bunny-hull (1)
47
+ * - polar_scatter (1)
42
48
*/
43
- t . plan ( files . length - 40 ) ;
49
+ var mocks = allMocks . filter ( function ( mock ) {
50
+ return ! (
51
+ mock === 'font-wishlist.json' ||
52
+ mock . indexOf ( 'gl2d' ) !== - 1 ||
53
+ mock === 'gl3d_bunny-hull.json' ||
54
+ mock === 'polar_scatter.json'
55
+ ) ;
56
+ } ) ;
57
+
58
+ var BASE_TIMEOUT = 500 , // base timeout time
59
+ BATCH_SIZE = 5 , // size of each test 'batch'
60
+ cnt = 0 ;
61
+
62
+ function testFunction ( ) {
63
+ testMock ( mocks [ cnt ++ ] , t ) ;
64
+ }
65
+
66
+ t . plan ( mocks . length ) ;
44
67
45
- for ( var i = 0 ; i < files . length ; i ++ ) {
46
- testMock ( files [ i ] , t ) ;
68
+ for ( var i = 0 ; i < mocks . length ; i ++ ) {
69
+ setTimeout ( testFunction ,
70
+ BASE_TIMEOUT * Math . floor ( i / BATCH_SIZE ) * BATCH_SIZE ) ;
47
71
}
48
72
49
73
} ) ;
@@ -57,15 +81,6 @@ function runSingle (userFileName) {
57
81
}
58
82
59
83
function testMock ( fileName , t ) {
60
- if ( path . extname ( fileName ) !== '.json' ) return ;
61
- if ( fileName === 'font-wishlist.json' && ! userFileName ) return ;
62
-
63
- // TODO fix race condition in gl2d image generation
64
- if ( fileName . indexOf ( 'gl2d_' ) !== - 1 ) return ;
65
-
66
- // TODO fix run-to-run randomness
67
- if ( fileName === 'gl3d_bunny-hull.json' ) return ;
68
-
69
84
var figure = require ( path . join ( constants . pathToTestImageMocks , fileName ) ) ;
70
85
var bodyMock = {
71
86
figure : figure ,
0 commit comments