fix(build): Fix unevaluated being passed to _ref transformer.

This commit is contained in:
SamTolmay 2021-08-20 16:46:04 +02:00
parent 28c862abc0
commit 537a776512
No known key found for this signature in database
GPG Key ID: 655CB3F5AA745CF8
4 changed files with 71 additions and 3 deletions

View File

@ -671,6 +671,49 @@ const:
text: 'Hello',
});
});
test('buildRefs pass vars two levels with a transformer', async () => {
const files = [
{
path: 'lowdefy.yaml',
content: `
ref1:
_ref:
path: file1.yaml
vars:
var1: Hello`,
},
{
path: 'file1.yaml',
content: `
ref2:
_ref:
path: file2.yaml
transformer: src/test/buildRefs/testBuildRefsTransformIdentity.js
vars:
var2:
_var: var1`,
},
{
path: 'file2.yaml',
content: `a: 1`,
},
];
mockReadConfigFile.mockImplementation(readConfigFileMockImplementation(files));
const res = await buildRefs({ context });
expect(res).toEqual({
ref1: {
ref2: {
obj: {
a: 1,
},
vars: {
var2: 'Hello',
},
},
},
});
});
});
describe('transformer functions', () => {

View File

@ -53,7 +53,7 @@ async function recursiveParseFile({ context, refDef, count, referencedFrom }) {
const transformedFile = await runTransformer({
context,
parsedFile,
refDef: newRefDef,
refDef: parsedRefDef,
});
parsedFiles[newRefDef.id] = transformedFile;

View File

@ -0,0 +1,24 @@
/*
Copyright 2020-2021 Lowdefy, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
function transformer(obj, vars) {
return {
obj,
vars,
};
}
module.exports = transformer;

View File

@ -15,6 +15,7 @@
*/
const transformer = (_, obj) => {
console.log('transformer', _, obj);
const examples = {
id: 'examples',
type: 'Box',
@ -29,7 +30,7 @@ const transformer = (_, obj) => {
type: 'Markdown',
properties: {
content: `##### ${example.title}
${example.description || ''}
`,
},
@ -55,7 +56,7 @@ ${example.description || ''}
properties: {
content: {
_nunjucks: {
template: `
template: `
\`\`\`yaml
{{ block }}
\`\`\`