@@ -9,24 +9,29 @@ var request = require('request');
99var test = require ( 'tape' ) ;
1010var gm = require ( 'gm' ) ;
1111
12+ var touch = function ( fileName ) {
13+ fs . closeSync ( fs . openSync ( fileName , 'w' ) ) ;
14+ } ;
15+
1216
1317// 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+ }
1624
1725var userFileName = process . argv [ 2 ] ;
1826
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 ( ) ;
2429else runSingle ( userFileName ) ;
2530
2631function runAll ( ) {
2732 test ( 'testing mocks' , function ( t ) {
2833
29- var files = fs . readdirSync ( constants . pathToTestImageMocks ) ;
34+ var allMocks = fs . readdirSync ( constants . pathToTestImageMocks ) ;
3035
3136 /*
3237 * Some test cases exhibit run-to-run randomness;
@@ -35,15 +40,34 @@ function runAll () {
3540 * More info:
3641 * https://github.com/plotly/plotly.js/issues/62
3742 *
38- * 40 test cases are removed:
43+ * 41 test cases are removed:
3944 * - font-wishlist (1 test case)
4045 * - all gl2d (38)
41- * - gl2d_bunny-hull (1)
46+ * - gl3d_bunny-hull (1)
47+ * - polar_scatter (1)
4248 */
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 ) ;
4467
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 ) ;
4771 }
4872
4973 } ) ;
@@ -57,15 +81,6 @@ function runSingle (userFileName) {
5781}
5882
5983function 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-
6984 var figure = require ( path . join ( constants . pathToTestImageMocks , fileName ) ) ;
7085 var bodyMock = {
7186 figure : figure ,
0 commit comments