@@ -4,55 +4,54 @@ const fs = require('fs');
44const path = require ( 'path' ) ;
55const async = require ( 'async' ) ;
66const { execSync } = require ( 'child_process' ) ;
7+
78const bigTableHtml = fs . readFileSync ( path . resolve ( __dirname , 'fixtures/bigTable.html' ) , 'utf-8' ) ;
89
910const parseBuffer = ( res , fn ) => { // Superagent does not detect PDF
10- const data = [ ] ;
11- res . on ( 'data' , chunk => data . push ( chunk ) ) ;
12- res . on ( 'end' , ( ) => fn ( null , Buffer . concat ( data ) ) ) ;
11+ const data = [ ] ;
12+ res . on ( 'data' , chunk => data . push ( chunk ) ) ;
13+ res . on ( 'end' , ( ) => fn ( null , Buffer . concat ( data ) ) ) ;
1314} ;
1415
1516describe ( 'stability' , ( ) => {
16- describe ( 'POST /pdf' , ( ) => {
17- it ( 'should render proper PDF\'s when posting large amounts of big HTML chunks' , function ( done ) {
18- this . timeout ( 60000 ) ;
19- this . slow ( 30000 ) ;
20-
21- const fixturePath = path . join ( __dirname , 'fixtures' ) ;
22- const examplePdfPath = path . join ( fixturePath , 'bigTable.pdf' ) ;
23- const fixture = fs . readFileSync ( examplePdfPath ) ;
24-
25- var q = async . queue ( function ( task , callback ) {
26- request
27- . post ( '/pdf' )
28- . parse ( parseBuffer ) // Superagent does not detect PDF
29- . type ( 'form' )
30- . send ( bigTableHtml )
31- . query ( { accessKey : process . env . RENDERER_ACCESS_KEY } )
32- . expect ( ( res ) => {
33- if ( res . statusCode !== 200 ) {
34- const errMsg = `Invalid response code: ${ res . statusCode } \n${ JSON . stringify ( res . body ) } ` ;
35- throw new Error ( errMsg ) ;
36- }
37-
38- if ( res . body . slice ( 150 ) . compare ( fixture . slice ( 150 ) ) === 0 ) return ; // Slice out ModDate
39-
40- fs . writeFileSync ( './bigTable_failed.pdf' , res . body ) ;
41- execSync ( 'curl --upload-file ./bigTable_failed.pdf https://transfer.sh/bigTable_failed.pdf' , { stdio : 'inherit' } ) ;
42- throw new Error ( `${ examplePdfPath } (${ task } ) does not match rendered screenshot` ) ;
43- } )
44- . end ( callback ) ;
45- } , 8 ) ;
46-
47- for ( var i = 0 ; i < 80 ; i ++ ) {
48- q . push ( i , function ( err ) {
49- if ( err ) {
50- done ( err ) ;
51- }
52- } ) ;
53- } ;
54-
55- q . drain = done ;
56- } ) ;
57- } ) ;
17+ describe ( 'POST /pdf' , ( ) => {
18+ it ( 'should render proper PDF\'s when posting large amounts of big HTML chunks' , function largeHTMLTest ( done ) {
19+ this . timeout ( 60000 ) ;
20+ this . slow ( 30000 ) ;
21+
22+ const fixturePath = path . join ( __dirname , 'fixtures' ) ;
23+ const examplePdfPath = path . join ( fixturePath , 'bigTable.pdf' ) ;
24+ const fixture = fs . readFileSync ( examplePdfPath ) ;
25+
26+ const q = async . queue ( ( task , callback ) => {
27+ request
28+ . post ( '/pdf' )
29+ . parse ( parseBuffer ) // Superagent does not detect PDF
30+ . type ( 'form' )
31+ . send ( bigTableHtml )
32+ . query ( { accessKey : process . env . RENDERER_ACCESS_KEY } )
33+ . expect ( ( res ) => {
34+ if ( res . statusCode !== 200 ) {
35+ const errMsg = `Invalid response code: ${ res . statusCode } \n${ JSON . stringify ( res . body ) } ` ;
36+ throw new Error ( errMsg ) ;
37+ }
38+
39+ if ( res . body . slice ( 150 ) . compare ( fixture . slice ( 150 ) ) === 0 ) return ; // Slice out ModDate
40+
41+ fs . writeFileSync ( './bigTable_failed.pdf' , res . body ) ;
42+ execSync ( 'curl --upload-file ./bigTable_failed.pdf https://transfer.sh/bigTable_failed.pdf' , { stdio : 'inherit' } ) ;
43+ throw new Error ( `${ examplePdfPath } (${ task } ) does not match rendered screenshot` ) ;
44+ } )
45+ . end ( callback ) ;
46+ } , 8 ) ;
47+
48+ for ( let i = 0 ; i < 80 ; i += 1 ) {
49+ q . push ( i , ( err ) => {
50+ if ( err ) done ( err ) ;
51+ } ) ;
52+ }
53+
54+ q . drain = done ;
55+ } ) ;
56+ } ) ;
5857} ) ;
0 commit comments