1
- const Promise = require ( 'bluebird' ) ;
2
1
const http = require ( 'http' ) ;
3
- const { MongoClient } = require ( 'mongodb' ) ;
4
2
const { ParseServer } = require ( 'parse-server' ) ;
5
3
const { config, app } = require ( '../../index.js' ) ;
6
4
const Config = require ( '../../node_modules/parse-server/lib/Config' ) ;
7
5
8
- const mongoDBRunnerStart = require ( 'mongodb-runner/mocha/before' ) . bind ( {
9
- timeout ( ) { } ,
10
- slow ( ) { } ,
11
- } ) ;
12
- const mongoDBRunnerStop = require ( 'mongodb-runner/mocha/after' ) ;
13
-
14
- const startDB = ( ) =>
15
- new Promise ( ( done , reject ) => {
16
- done . fail = reject ;
17
- mongoDBRunnerStart ( done ) ;
18
- } ) ;
19
-
20
- const stopDB = ( ) =>
21
- new Promise ( ( done , reject ) => {
22
- done . fail = reject ;
23
- mongoDBRunnerStop ( done ) ;
24
- } ) ;
25
-
26
- const connectDB = databaseURI =>
27
- new Promise ( ( resolve , reject ) => {
28
- MongoClient . connect ( databaseURI , ( err , db ) => {
29
- if ( err ) {
30
- reject ( err ) ;
31
- } else {
32
- resolve ( db ) ;
33
- }
34
- } ) ;
35
- } ) ;
36
-
37
6
let parseServerState = { } ;
38
-
39
7
const dropDB = async ( ) => {
40
8
await Parse . User . logOut ( ) ;
41
9
const app = Config . get ( 'test' ) ;
@@ -48,54 +16,25 @@ const dropDB = async () => {
48
16
* @return {Promise } Runner state
49
17
*/
50
18
async function startParseServer ( ) {
51
- const mongodbPort = process . env . MONGODB_PORT || 27017 ;
52
- let parseServerOptions = Object . assign ( config , {
53
- databaseName : 'parse-test' ,
54
- databaseURI : `mongodb://localhost:${ mongodbPort } /parse-test` ,
19
+ delete config . databaseAdapter ;
20
+ const parseServerOptions = Object . assign ( config , {
21
+ databaseURI : 'mongodb://localhost:27017/parse-test' ,
55
22
masterKey : 'test' ,
56
23
javascriptKey : 'test' ,
57
24
appId : 'test' ,
58
25
port : 30001 ,
59
26
mountPath : '/test' ,
60
27
serverURL : `http://localhost:30001/test` ,
61
28
logLevel : 'error' ,
62
- silent : true ,
29
+ silent : true
63
30
} ) ;
64
- const {
65
- databaseURI,
66
- masterKey,
67
- javascriptKey,
68
- appId,
69
- port,
70
- serverURL,
71
- mountPath,
72
- } = parseServerOptions ;
73
- await startDB ( ) ;
74
- const mongoConnection = await connectDB ( databaseURI ) ;
75
- parseServerOptions = Object . assign (
76
- {
77
- masterKey,
78
- javascriptKey,
79
- appId,
80
- serverURL,
81
- databaseURI,
82
- silent : process . env . VERBOSE !== '1' ,
83
- } ,
84
- parseServerOptions
85
- ) ;
86
31
const parseServer = new ParseServer ( parseServerOptions ) ;
87
- app . use ( mountPath , parseServer ) ;
88
-
32
+ app . use ( parseServerOptions . mountPath , parseServer ) ;
89
33
const httpServer = http . createServer ( app ) ;
90
-
91
- Promise . promisifyAll ( httpServer ) ;
92
- Promise . promisifyAll ( mongoConnection ) ;
93
- await httpServer . listenAsync ( port ) ;
94
-
34
+ await new Promise ( ( resolve ) => httpServer . listen ( parseServerOptions . port , resolve ) ) ;
95
35
Object . assign ( parseServerState , {
96
36
parseServer,
97
37
httpServer,
98
- mongoConnection,
99
38
expressApp : app ,
100
39
parseServerOptions,
101
40
} ) ;
@@ -106,12 +45,10 @@ async function startParseServer() {
106
45
* Stops the ParseServer instance
107
46
* @return {Promise }
108
47
*/
109
- function stopParseServer ( ) {
48
+ async function stopParseServer ( ) {
110
49
const { httpServer } = parseServerState ;
111
- return httpServer
112
- . closeAsync ( )
113
- . then ( stopDB )
114
- . then ( ( ) => ( parseServerState = { } ) ) ;
50
+ await new Promise ( ( resolve ) => httpServer . close ( resolve ) ) ;
51
+ parseServerState = { } ;
115
52
}
116
53
117
54
module . exports = {
0 commit comments