11var fs = require ( 'fs' ) ;
2+ var sizeOf = require ( 'image-size' ) ;
23
34var getMockList = require ( './assets/get_mock_list' ) ;
45var getRequestOpts = require ( './assets/get_image_request_options' ) ;
@@ -19,7 +20,11 @@ var FORMATS = ['svg', 'pdf', 'eps'];
1920// non-exhaustive list of mocks to test
2021var DEFAULT_LIST = [ '0' , 'geo_first' , 'gl3d_z-range' , 'text_export' , 'layout_image' ] ;
2122
22- // minimum satisfactory file size
23+ // return dimensions [in px]
24+ var WIDTH = 700 ;
25+ var HEIGHT = 500 ;
26+
27+ // minimum satisfactory file size [in bytes]
2328var MIN_SIZE = 100 ;
2429
2530/**
@@ -72,18 +77,32 @@ function runInBatch(mockList) {
7277// The tests below determine whether the images are properly
7378// exported by (only) checking the file size of the generated images.
7479function testExport ( mockName , format , t ) {
75- var requestOpts = getRequestOpts ( { mockName : mockName , format : format } ) ,
80+ var specs = {
81+ mockName : mockName ,
82+ format : format ,
83+ width : WIDTH ,
84+ height : HEIGHT
85+ } ;
86+
87+ var requestOpts = getRequestOpts ( specs ) ,
7688 imagePaths = getImagePaths ( mockName , format ) ,
7789 saveImageStream = fs . createWriteStream ( imagePaths . test ) ;
7890
7991 function checkExport ( err ) {
8092 if ( err ) throw err ;
8193
82- fs . stat ( imagePaths . test , function ( err , stats ) {
83- var didExport = stats . size > MIN_SIZE ;
94+ var didExport ;
8495
85- t . ok ( didExport , mockName + ' should be properly exported as a ' + format ) ;
86- } ) ;
96+ if ( format === 'svg' ) {
97+ var dims = sizeOf ( imagePaths . test ) ;
98+ didExport = ( dims . width === WIDTH ) && ( dims . height === HEIGHT ) ;
99+ }
100+ else {
101+ var stats = fs . statSync ( imagePaths . test ) ;
102+ didExport = stats . size > MIN_SIZE ;
103+ }
104+
105+ t . ok ( didExport , mockName + ' should be properly exported as a ' + format ) ;
87106 }
88107
89108 request ( requestOpts )
0 commit comments