Skip to content

Commit 68a1b30

Browse files
authored
Show a message if cloud functions are duplicated (#6963)
* Update triggers.js * Update CloudCode.spec.js * Logger changes * Update CloudCode.spec.js
1 parent 7b7dd48 commit 68a1b30

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

spec/CloudCode.spec.js

+15
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,21 @@ describe('Cloud Code', () => {
5656
});
5757
});
5858

59+
it('show warning on duplicate cloud functions', done => {
60+
const logger = require('../lib/logger').logger;
61+
spyOn(logger, 'warn').and.callFake(() => {});
62+
Parse.Cloud.define('hello', () => {
63+
return 'Hello world!';
64+
});
65+
Parse.Cloud.define('hello', () => {
66+
return 'Hello world!';
67+
});
68+
expect(logger.warn).toHaveBeenCalledWith(
69+
'Warning: Duplicate cloud functions exist for hello. Only the last one will be used and the others will be ignored.'
70+
);
71+
done();
72+
});
73+
5974
it('is cleared cleared after the previous test', done => {
6075
Parse.Cloud.run('hello', {}).catch(error => {
6176
expect(error.code).toEqual(141);

src/triggers.js

+5
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ function getStore(category, name, applicationId) {
9898
function add(category, name, handler, applicationId) {
9999
const lastComponent = name.split('.').splice(-1);
100100
const store = getStore(category, name, applicationId);
101+
if (store[lastComponent]) {
102+
logger.warn(
103+
`Warning: Duplicate cloud functions exist for ${lastComponent}. Only the last one will be used and the others will be ignored.`
104+
);
105+
}
101106
store[lastComponent] = handler;
102107
}
103108

0 commit comments

Comments
 (0)