fix(Variables): Properly resolve vars if prototype in path

This commit is contained in:
Piotr Grzesik 2021-02-17 14:11:41 +01:00
parent 5057f9ab86
commit 496d3574c6
3 changed files with 10 additions and 1 deletions

View File

@ -308,7 +308,10 @@ class Variables {
return BbPromise.all(populations).then((results) =>
results.forEach((result) => {
if (result.value !== result.populated) {
_.set(target, result.path, result.populated);
const pathArray = Array.isArray(result.path) ? result.path : result.path.split('.');
let obj = target;
for (const property of pathArray.slice(0, -1)) obj = obj[property];
obj[_.last(pathArray)] = result.populated;
}
})
);

View File

@ -17,3 +17,5 @@ custom:
nestedVal:
prop: resolvedNested
nestedReference: ${self:custom.${self:custom.nestedRef}.prop}
prototype:
nestedInPrototype: ${file(config.json):foo}-in-prototype

View File

@ -2816,6 +2816,10 @@ describe('test/unit/lib/classes/Variables.test.js', () => {
expect(processedConfig.custom.nestedReference).to.equal('resolvedNested');
});
it('should handle resolving variables when `prototype` is part of the path', async () => {
expect(processedConfig.custom.prototype.nestedInPrototype).to.equal('bar-in-prototype');
});
describe('variable resolving', () => {
describe('when unresolvedVariablesNotificationMode is set to "error"', () => {
it('should error for missing "environment variable" type variables', async () => {