@@ -6,13 +6,15 @@ const port = Number(process.env.PORT) || 8080;
6
6
const validData = {
7
7
opened : false ,
8
8
pending : false ,
9
- plots : [ { data : [ { x : [ 1 ] , y : [ 2 ] } ] } ]
9
+ plots : [ { data : [ { x : [ 1 ] , y : [ 2 ] } ] } ] ,
10
10
} ;
11
11
12
12
jest . mock ( 'child_process' ) ;
13
- jest . mock ( 'fs' , ( ) => ( { readFile : ( path : any , options : any , callback : ( err : any , data : any ) => void ) => {
14
- callback ( 'Error' , null ) ;
15
- } } ) ) ;
13
+ jest . mock ( 'fs' , ( ) => ( {
14
+ readFile : ( path : any , options : any , callback : ( err : any , data : any ) => void ) => {
15
+ callback ( 'Error' , null ) ;
16
+ } ,
17
+ } ) ) ;
16
18
17
19
describe ( 'Server' , ( ) => {
18
20
let server : any ;
@@ -26,81 +28,96 @@ describe('Server', () => {
26
28
} ) ;
27
29
28
30
it ( 'should call opn once when spawning a plot' , ( ) => {
29
- server . spawn ( { 0 : {
30
- opened : false ,
31
- pending : false ,
32
- plots : [ ]
33
- } } ) ;
31
+ server . spawn ( {
32
+ 0 : {
33
+ opened : false ,
34
+ pending : false ,
35
+ plots : [ ] ,
36
+ } ,
37
+ } ) ;
34
38
35
39
expect ( exec ) . toHaveBeenCalledTimes ( 1 ) ;
36
40
} ) ;
37
41
38
- it ( 'should serve the data' , ( done ) => {
39
- server . spawn ( { 0 : validData } ) ;
42
+ it ( 'should serve the data' , done => {
43
+ server . spawn ( { 0 : validData } ) ;
40
44
41
45
request ( `http://localhost:${ port } /data/0` , ( err , response , body ) => {
42
- expect ( JSON . parse ( body ) ) . toEqual ( [ { data : [ { x : [ 1 ] , y : [ 2 ] } ] } ] ) ;
46
+ expect ( JSON . parse ( body ) ) . toEqual ( [ { data : [ { x : [ 1 ] , y : [ 2 ] } ] } ] ) ;
43
47
done ( ) ;
44
48
} ) ;
45
49
} ) ;
46
50
47
- it ( 'should spawn two times but listen just once' , ( done ) => {
48
- const data = { 0 : validData } ;
51
+ it ( 'should spawn two times but listen just once' , done => {
52
+ const data = { 0 : validData } ;
49
53
50
54
server . spawn ( data ) ;
51
55
server . spawn ( data ) ;
52
56
53
57
request ( `http://localhost:${ port } /data/0` , ( err , response , body ) => {
54
- expect ( JSON . parse ( body ) ) . toEqual ( [ { data : [ { x : [ 1 ] , y : [ 2 ] } ] } ] ) ;
58
+ expect ( JSON . parse ( body ) ) . toEqual ( [ { data : [ { x : [ 1 ] , y : [ 2 ] } ] } ] ) ;
55
59
done ( ) ;
56
60
} ) ;
57
61
} ) ;
58
62
59
- it ( 'should serve the website and return 404 if html file not found' , ( done ) => {
60
- server . spawn ( { 0 : validData } ) ;
63
+ it ( 'should serve the website and return 404 if html file not found' , done => {
64
+ server . spawn ( { 0 : validData } ) ;
61
65
62
66
request ( `http://localhost:${ port } /plots/0/index.html` , ( err , response , body ) => {
63
67
expect ( response . statusCode ) . toBe ( 404 ) ;
64
68
done ( ) ;
65
69
} ) ;
66
70
} ) ;
67
71
68
- it ( 'should serve the nodeplotlib script and return 404 if file not found' , ( done ) => {
69
- server . spawn ( { 0 : validData } ) ;
72
+ it ( 'should serve the nodeplotlib script and return 404 if file not found' , done => {
73
+ server . spawn ( { 0 : validData } ) ;
70
74
71
75
request ( `http://localhost:${ port } /plots/0/nodeplotlib.min.js` , ( err , response , body ) => {
72
76
expect ( response . statusCode ) . toBe ( 404 ) ;
73
77
done ( ) ;
74
78
} ) ;
75
79
} ) ;
76
80
77
- it ( 'should serve the plotly.min.js script and return 404 if file not found' , ( done ) => {
78
- server . spawn ( { 0 : validData } ) ;
81
+ it ( 'should serve the plotly.min.js script and return 404 if file not found' , done => {
82
+ server . spawn ( { 0 : validData } ) ;
79
83
80
84
request ( `http://localhost:${ port } /plots/0/plotly.min.js` , ( err , response , body ) => {
81
85
expect ( response . statusCode ) . toBe ( 404 ) ;
82
86
done ( ) ;
83
87
} ) ;
84
88
} ) ;
85
89
86
- it ( ' should not close the webserver, if one plot hasn\ 't got its data' , ( done ) => {
90
+ it ( " should not close the webserver, if one plot hasn't got its data" , done => {
87
91
server . spawn ( {
88
- 0 : { pending : false , opened : false , plots : [ { data : [ { x : [ 1 ] , y : [ 2 ] } ] } ] } ,
89
- 1 : { pending : false , opened : false , plots : [ { data : [ { x : [ 1 ] , y : [ 3 ] } ] } ] }
92
+ 0 : { pending : false , opened : false , plots : [ { data : [ { x : [ 1 ] , y : [ 2 ] } ] } ] } ,
93
+ 1 : { pending : false , opened : false , plots : [ { data : [ { x : [ 1 ] , y : [ 3 ] } ] } ] } ,
90
94
} ) ;
91
95
92
96
request ( `http://localhost:${ port } /data/0` , ( err , response , body ) => {
93
- expect ( JSON . parse ( body ) ) . toEqual ( [ { data : [ { x : [ 1 ] , y : [ 2 ] } ] } ] ) ;
97
+ expect ( JSON . parse ( body ) ) . toEqual ( [ { data : [ { x : [ 1 ] , y : [ 2 ] } ] } ] ) ;
94
98
95
99
request ( `http://localhost:${ port } /data/1` , ( err1 , response1 , body1 ) => {
96
- expect ( JSON . parse ( body1 ) ) . toEqual ( [ { data : [ { x : [ 1 ] , y : [ 3 ] } ] } ] ) ;
100
+ expect ( JSON . parse ( body1 ) ) . toEqual ( [ { data : [ { x : [ 1 ] , y : [ 3 ] } ] } ] ) ;
97
101
done ( ) ;
98
102
} ) ;
99
103
} ) ;
100
104
} ) ;
101
105
102
- it ( 'should return 404 if routes not matching' , ( done ) => {
103
- const data = { 0 : validData } ;
106
+ it ( 'should not close webserver until plot data is entirely transferred' , done => {
107
+ const elements = 100000 ;
108
+ const plot = [ { data : [ { x : new Array ( elements ) . fill ( 1 ) , y : new Array ( elements ) . fill ( 1 ) } ] } ] ;
109
+ server . spawn ( {
110
+ 0 : { pending : false , opened : false , plots : plot } ,
111
+ } ) ;
112
+
113
+ request ( `http://localhost:${ port } /data/0` , ( err , response , body ) => {
114
+ expect ( JSON . parse ( body ) ) . toEqual ( plot ) ;
115
+ done ( ) ;
116
+ } ) ;
117
+ } ) ;
118
+
119
+ it ( 'should return 404 if routes not matching' , done => {
120
+ const data = { 0 : validData } ;
104
121
105
122
server . spawn ( data ) ;
106
123
0 commit comments