@@ -8,35 +8,45 @@ const httpRequest = require("../src/cloud-code/httpRequest"),
8
8
const port = 13371 ;
9
9
const httpRequestServer = "http://localhost:" + port ;
10
10
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
+ } ) ;
21
17
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
+ } ) ;
27
22
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
+ } ) ;
31
28
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
+ } ) ;
35
32
36
- app . listen ( 13371 ) ;
33
+ app . get ( '/qs' , function ( req , res ) {
34
+ res . json ( req . query ) ;
35
+ } ) ;
37
36
37
+ return app . listen ( 13371 , undefined , done ) ;
38
+ }
38
39
39
40
describe ( "httpRequest" , ( ) => {
41
+ let server ;
42
+ beforeAll ( ( done ) => {
43
+ server = startServer ( done ) ;
44
+ } ) ;
45
+
46
+ afterAll ( ( done ) => {
47
+ server . close ( done ) ;
48
+ } ) ;
49
+
40
50
it ( "should do /hello" , ( done ) => {
41
51
httpRequest ( {
42
52
url : httpRequestServer + "/hello"
0 commit comments