Merge pull request #6631 from serverless/improve-yaml-parse

Resolve empty config object for an empty config file
This commit is contained in:
Mariusz Nowak 2019-09-05 11:24:28 +02:00 committed by GitHub
commit 1cad7b88fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -70,7 +70,7 @@ const getServerlessConfigFile = _.memoize(
return handleJsConfigFile(configFilePath);
}
return readFile(configFilePath);
return readFile(configFilePath).then(result => result || {});
}
return '';

View File

@ -33,6 +33,20 @@ describe('#getServerlessConfigFile()', () => {
});
});
it('should return an empty object for empty configuration', () => {
const serverlessFilePath = path.join(tmpDirPath, 'serverless.yml');
writeFileSync(serverlessFilePath, '');
return expect(
getServerlessConfigFile({
processedInput: { options: {} },
config: { servicePath: tmpDirPath },
})
).to.be.fulfilled.then(result => {
expect(result).to.deep.equal({});
});
});
it('should return the file content if a serverless.yml file is found', () => {
const serverlessFilePath = path.join(tmpDirPath, 'serverless.yml');