mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
Merge pull request #2565 from serverless/horike37-issue-2490
Fixes file variable fallback if the file doesn't exist
This commit is contained in:
commit
cf9be9b7ab
@ -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
|
||||
};
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user