Merge pull request #2565 from serverless/horike37-issue-2490

Fixes file variable fallback if the file doesn't exist
This commit is contained in:
Maciej Winnicki 2016-10-28 11:49:27 +02:00 committed by GitHub
commit cf9be9b7ab
3 changed files with 15 additions and 1 deletions

View File

@ -2,5 +2,5 @@
module.exports.run = () => {
const time = new Date();
console.log(`Your cron ran ${time}`);
console.log(`Your cron ran ${time}`); // eslint-disable-line no-console
};

View File

@ -156,6 +156,10 @@ class Variables {
const referencedFileFullPath = path.join(this.serverless.config.servicePath,
referencedFileRelativePath);
if (!this.serverless.utils.fileExistsSync(referencedFileFullPath)) {
return undefined;
}
let valueToPopulate = this.serverless.utils.readFileSync(referencedFileFullPath);
if (matchedFileRefString !== variableString) {
let deepProperties = variableString

View File

@ -385,6 +385,16 @@ describe('Variables', () => {
expect(valueToPopulate).to.deep.equal(configYml);
});
it('should get undefined if non existing file and the second argument is true', () => {
const serverless = new Serverless();
const tmpDirPath = testUtils.getTmpDirPath();
serverless.config.update({ servicePath: tmpDirPath });
const valueToPopulate = serverless.variables.getValueFromFile('file(./config.yml)');
expect(valueToPopulate).to.be.equal(undefined);
});
it('should populate non json/yml files', () => {
const serverless = new Serverless();
const SUtils = new Utils();