@@ -51,7 +51,7 @@ if (process.env.PARSE_SERVER_TEST_DB === 'postgres') {
51
51
startDB = require ( 'mongodb-runner/mocha/before' ) . bind ( {
52
52
timeout : ( ) => { } ,
53
53
slow : ( ) => { }
54
- } ) ;
54
+ } )
55
55
stopDB = require ( 'mongodb-runner/mocha/after' ) ;
56
56
databaseAdapter = new MongoStorageAdapter ( {
57
57
uri : mongoURI ,
@@ -118,44 +118,40 @@ if (process.env.PARSE_SERVER_TEST_CACHE === 'redis') {
118
118
const openConnections = { } ;
119
119
120
120
// Set up a default API server for testing with default configuration.
121
- var app = express ( ) ;
122
- var api = new ParseServer ( defaultConfiguration ) ;
123
- app . use ( '/1' , api ) ;
124
- app . use ( '/1' , ( ) => {
125
- fail ( 'should not call next' ) ;
126
- } ) ;
127
- var server = app . listen ( port ) ;
128
- server . on ( 'connection' , connection => {
129
- const key = `${ connection . remoteAddress } :${ connection . remotePort } ` ;
130
- openConnections [ key ] = connection ;
131
- connection . on ( 'close' , ( ) => { delete openConnections [ key ] } ) ;
132
- } ) ;
121
+ var app ;
122
+ var api ;
123
+ var server ;
124
+
133
125
// Allows testing specific configurations of Parse Server
134
126
const reconfigureServer = changedConfiguration => {
135
127
return new Promise ( ( resolve , reject ) => {
136
- server . close ( ( ) => {
137
- try {
138
- const newConfiguration = Object . assign ( { } , defaultConfiguration , changedConfiguration , {
139
- __indexBuildCompletionCallbackForTests : indexBuildPromise => indexBuildPromise . then ( resolve , reject )
140
- } ) ;
141
- cache . clear ( ) ;
142
- app = express ( ) ;
143
- api = new ParseServer ( newConfiguration ) ;
144
- api . use ( require ( './testing-routes' ) . router ) ;
145
- app . use ( '/1' , api ) ;
146
- app . use ( '/1' , ( ) => {
147
- fail ( 'should not call next' ) ;
148
- } ) ;
149
- server = app . listen ( port ) ;
150
- server . on ( 'connection' , connection => {
151
- const key = `${ connection . remoteAddress } :${ connection . remotePort } ` ;
152
- openConnections [ key ] = connection ;
153
- connection . on ( 'close' , ( ) => { delete openConnections [ key ] } ) ;
154
- } ) ;
155
- } catch ( error ) {
156
- reject ( error ) ;
157
- }
158
- } ) ;
128
+ if ( server ) {
129
+ return server . close ( ( ) => {
130
+ server = undefined ;
131
+ reconfigureServer ( changedConfiguration ) . then ( resolve , reject ) ;
132
+ } ) ;
133
+ }
134
+ try {
135
+ const newConfiguration = Object . assign ( { } , defaultConfiguration , changedConfiguration , {
136
+ __indexBuildCompletionCallbackForTests : indexBuildPromise => indexBuildPromise . then ( resolve , reject )
137
+ } ) ;
138
+ cache . clear ( ) ;
139
+ app = express ( ) ;
140
+ api = new ParseServer ( newConfiguration ) ;
141
+ api . use ( require ( './testing-routes' ) . router ) ;
142
+ app . use ( '/1' , api ) ;
143
+ app . use ( '/1' , ( ) => {
144
+ fail ( 'should not call next' ) ;
145
+ } ) ;
146
+ server = app . listen ( port ) ;
147
+ server . on ( 'connection' , connection => {
148
+ const key = `${ connection . remoteAddress } :${ connection . remotePort } ` ;
149
+ openConnections [ key ] = connection ;
150
+ connection . on ( 'close' , ( ) => { delete openConnections [ key ] } ) ;
151
+ } ) ;
152
+ } catch ( error ) {
153
+ reject ( error ) ;
154
+ }
159
155
} ) ;
160
156
}
161
157
0 commit comments