New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove duplicate-handler warnings based on community feedback. #5733

Merged
merged 2 commits into from Jan 22, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+0 −63
Diff settings

Always

Just for now

Copy path View file
@@ -210,28 +210,6 @@ class Service {
} }
}); });


const warnOnDuplicateHandlers = () => {
const functionObjs = this.getAllFunctions()
.map(name => ({
name,
body: this.getFunction(name),
}))
.filter(func => _.isString(func.body.handler));
const groupedByHandler = _.groupBy(functionObjs, func => func.body.handler);
_.entriesIn(groupedByHandler)
.filter(arg => arg[1].length >= 2)
.forEach(arg => {
const handlerName = arg[0];
const functionGroup = arg[1].map(func => func.name);
const warnMessage = [
`Warning: A handler "${handlerName}" is duplicated in functions: `,
`${functionGroup.join(', ')}.`,
].join('');
this.serverless.cli.log(warnMessage);
});
};
warnOnDuplicateHandlers();

const provider = this.serverless.getProvider('aws'); const provider = this.serverless.getProvider('aws');
if (provider) { if (provider) {
const stage = provider.getStage(); const stage = provider.getStage();
Copy path View file
@@ -9,7 +9,6 @@ const Service = require('../../lib/classes/Service');
const Utils = require('../../lib/classes/Utils'); const Utils = require('../../lib/classes/Utils');
const Serverless = require('../../lib/Serverless'); const Serverless = require('../../lib/Serverless');
const testUtils = require('../../tests/utils'); const testUtils = require('../../tests/utils');
const CLI = require('../../lib/classes/CLI');


// Configure chai // Configure chai
chai.use(require('chai-as-promised')); chai.use(require('chai-as-promised'));
@@ -724,46 +723,6 @@ describe('Service', () => {
}); });
}); });


it('should warn if multiple functions have same handler', () => {
const SUtils = new Utils();
const serverlessYml = {
service: 'testService',
provider: 'testProvider',
functions: {
functionA: {
handler: 'foo.functionA',
events: [],
},
functionB: {
handler: 'foo.functionA',
events: [],
},
function123: {
handler: 'foo.function123',
events: [],
},
function456: {
handler: 'foo.function123',
events: [],
},
},
};
SUtils.writeFileSync(path.join(tmpDirPath, 'serverless.yml'),
YAML.dump(serverlessYml));

const serverless = new Serverless({ servicePath: tmpDirPath });

class CustomCLI extends CLI {}
const consoleLogStub = sinon.stub(CustomCLI.prototype, 'log');
serverless.cli = new CustomCLI(serverless);

return expect(serverless.service.load()).to.eventually.be.fulfilled
.then(() => {
serverless.service.validate();
expect(consoleLogStub.callCount).to.equal(2);
});
});

describe('stage name validation', () => { describe('stage name validation', () => {
function simulateRun(serverless) { function simulateRun(serverless) {
return serverless.init().then(() => return serverless.init().then(() =>
ProTip! Use n and p to navigate between commits in a pull request.