feat: Asynchronous initialization of Parse Server (#8232)
BREAKING CHANGE: This release introduces the asynchronous initialization of Parse Server to prevent mounting Parse Server before being ready to receive request; it changes how Parse Server is imported, initialized and started; it also removes the callback `serverStartComplete`; see the [Parse Server 6 migration guide](https://github.com/parse-community/parse-server/blob/alpha/6.0.0.md) for more details (#8232)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
const Config = require('../lib/Config');
|
||||
const Parse = require('parse/node');
|
||||
const ParseServer = require('../lib/index').ParseServer;
|
||||
const request = require('../lib/request');
|
||||
const InMemoryCacheAdapter = require('../lib/Adapters/Cache/InMemoryCacheAdapter')
|
||||
.InMemoryCacheAdapter;
|
||||
@@ -39,6 +40,47 @@ describe('Cloud Code', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('can load cloud code as a module', async () => {
|
||||
process.env.npm_package_type = 'module';
|
||||
await reconfigureServer({ appId: 'test1', cloud: './spec/cloud/cloudCodeModuleFile.js' });
|
||||
const result = await Parse.Cloud.run('cloudCodeInFile');
|
||||
expect(result).toEqual('It is possible to define cloud code in a file.');
|
||||
delete process.env.npm_package_type;
|
||||
});
|
||||
|
||||
it('cloud code must be valid type', async () => {
|
||||
await expectAsync(reconfigureServer({ cloud: true })).toBeRejectedWith(
|
||||
"argument 'cloud' must either be a string or a function"
|
||||
);
|
||||
});
|
||||
|
||||
it('should wait for cloud code to load', async () => {
|
||||
await reconfigureServer({ appId: 'test3' });
|
||||
const initiated = new Date();
|
||||
const parseServer = await new ParseServer({
|
||||
...defaultConfiguration,
|
||||
appId: 'test3',
|
||||
masterKey: 'test',
|
||||
serverURL: 'http://localhost:12668/parse',
|
||||
async cloud() {
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
Parse.Cloud.beforeSave('Test', () => {
|
||||
throw 'Cannot save.';
|
||||
});
|
||||
},
|
||||
}).start();
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
app.use('/parse', parseServer.app);
|
||||
const server = app.listen(12668);
|
||||
const now = new Date();
|
||||
expect(now.getTime() - initiated.getTime() > 1000).toBeTrue();
|
||||
await expectAsync(new Parse.Object('Test').save()).toBeRejectedWith(
|
||||
new Parse.Error(141, 'Cannot save.')
|
||||
);
|
||||
await new Promise(resolve => server.close(resolve));
|
||||
});
|
||||
|
||||
it('can create functions', done => {
|
||||
Parse.Cloud.define('hello', () => {
|
||||
return 'Hello world!';
|
||||
|
||||
Reference in New Issue
Block a user