@@ -8,35 +8,45 @@ const httpRequest = require("../src/cloud-code/httpRequest"),
88const port = 13371 ;
99const httpRequestServer = "http://localhost:" + port ;
1010
11- const app = express ( ) ;
12- app . use ( bodyParser . json ( { 'type' : '*/*' } ) ) ;
13- app . get ( "/hello" , function ( req , res ) {
14- res . json ( { response : "OK" } ) ;
15- } ) ;
16-
17- app . get ( "/404" , function ( req , res ) {
18- res . status ( 404 ) ;
19- res . send ( "NO" ) ;
20- } ) ;
11+ function startServer ( done ) {
12+ const app = express ( ) ;
13+ app . use ( bodyParser . json ( { 'type' : '*/*' } ) ) ;
14+ app . get ( "/hello" , function ( req , res ) {
15+ res . json ( { response : "OK" } ) ;
16+ } ) ;
2117
22- app . get ( "/301" , function ( req , res ) {
23- res . status ( 301 ) ;
24- res . location ( "/hello" ) ;
25- res . send ( ) ;
26- } ) ;
18+ app . get ( "/404" , function ( req , res ) {
19+ res . status ( 404 ) ;
20+ res . send ( "NO" ) ;
21+ } ) ;
2722
28- app . post ( '/echo' , function ( req , res ) {
29- res . json ( req . body ) ;
30- } ) ;
23+ app . get ( "/301" , function ( req , res ) {
24+ res . status ( 301 ) ;
25+ res . location ( "/hello" ) ;
26+ res . send ( ) ;
27+ } ) ;
3128
32- app . get ( '/qs ' , function ( req , res ) {
33- res . json ( req . query ) ;
34- } ) ;
29+ app . post ( '/echo ' , function ( req , res ) {
30+ res . json ( req . body ) ;
31+ } ) ;
3532
36- app . listen ( 13371 ) ;
33+ app . get ( '/qs' , function ( req , res ) {
34+ res . json ( req . query ) ;
35+ } ) ;
3736
37+ return app . listen ( 13371 , undefined , done ) ;
38+ }
3839
3940describe ( "httpRequest" , ( ) => {
41+ let server ;
42+ beforeAll ( ( done ) => {
43+ server = startServer ( done ) ;
44+ } ) ;
45+
46+ afterAll ( ( done ) => {
47+ server . close ( done ) ;
48+ } ) ;
49+
4050 it ( "should do /hello" , ( done ) => {
4151 httpRequest ( {
4252 url : httpRequestServer + "/hello"
0 commit comments