Show a message if cloud functions are duplicated (#6963)
* Update triggers.js * Update CloudCode.spec.js * Logger changes * Update CloudCode.spec.js
This commit is contained in:
@@ -56,6 +56,21 @@ describe('Cloud Code', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('show warning on duplicate cloud functions', done => {
|
||||||
|
const logger = require('../lib/logger').logger;
|
||||||
|
spyOn(logger, 'warn').and.callFake(() => {});
|
||||||
|
Parse.Cloud.define('hello', () => {
|
||||||
|
return 'Hello world!';
|
||||||
|
});
|
||||||
|
Parse.Cloud.define('hello', () => {
|
||||||
|
return 'Hello world!';
|
||||||
|
});
|
||||||
|
expect(logger.warn).toHaveBeenCalledWith(
|
||||||
|
'Warning: Duplicate cloud functions exist for hello. Only the last one will be used and the others will be ignored.'
|
||||||
|
);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
it('is cleared cleared after the previous test', done => {
|
it('is cleared cleared after the previous test', done => {
|
||||||
Parse.Cloud.run('hello', {}).catch(error => {
|
Parse.Cloud.run('hello', {}).catch(error => {
|
||||||
expect(error.code).toEqual(141);
|
expect(error.code).toEqual(141);
|
||||||
|
|||||||
@@ -98,6 +98,11 @@ function getStore(category, name, applicationId) {
|
|||||||
function add(category, name, handler, applicationId) {
|
function add(category, name, handler, applicationId) {
|
||||||
const lastComponent = name.split('.').splice(-1);
|
const lastComponent = name.split('.').splice(-1);
|
||||||
const store = getStore(category, name, applicationId);
|
const store = getStore(category, name, applicationId);
|
||||||
|
if (store[lastComponent]) {
|
||||||
|
logger.warn(
|
||||||
|
`Warning: Duplicate cloud functions exist for ${lastComponent}. Only the last one will be used and the others will be ignored.`
|
||||||
|
);
|
||||||
|
}
|
||||||
store[lastComponent] = handler;
|
store[lastComponent] = handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user