1- const Promise = require ( 'bluebird' ) ;
21const http = require ( 'http' ) ;
3- const { MongoClient } = require ( 'mongodb' ) ;
42const { ParseServer } = require ( 'parse-server' ) ;
53const { config, app } = require ( '../../index.js' ) ;
64const Config = require ( '../../node_modules/parse-server/lib/Config' ) ;
75
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-
376let parseServerState = { } ;
38-
397const dropDB = async ( ) => {
408 await Parse . User . logOut ( ) ;
419 const app = Config . get ( 'test' ) ;
@@ -48,54 +16,25 @@ const dropDB = async () => {
4816 * @return {Promise } Runner state
4917 */
5018async 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' ,
5522 masterKey : 'test' ,
5623 javascriptKey : 'test' ,
5724 appId : 'test' ,
5825 port : 30001 ,
5926 mountPath : '/test' ,
6027 serverURL : `http://localhost:30001/test` ,
6128 logLevel : 'error' ,
62- silent : true ,
29+ silent : true
6330 } ) ;
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- ) ;
8631 const parseServer = new ParseServer ( parseServerOptions ) ;
87- app . use ( mountPath , parseServer ) ;
88-
32+ app . use ( parseServerOptions . mountPath , parseServer ) ;
8933 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 ) ) ;
9535 Object . assign ( parseServerState , {
9636 parseServer,
9737 httpServer,
98- mongoConnection,
9938 expressApp : app ,
10039 parseServerOptions,
10140 } ) ;
@@ -106,12 +45,10 @@ async function startParseServer() {
10645 * Stops the ParseServer instance
10746 * @return {Promise }
10847 */
109- function stopParseServer ( ) {
48+ async function stopParseServer ( ) {
11049 const { httpServer } = parseServerState ;
111- return httpServer
112- . closeAsync ( )
113- . then ( stopDB )
114- . then ( ( ) => ( parseServerState = { } ) ) ;
50+ await new Promise ( ( resolve ) => httpServer . close ( resolve ) ) ;
51+ parseServerState = { } ;
11552}
11653
11754module . exports = {
0 commit comments