Merge pull request #8226 from backstage/blam/relax-log-lines

Fixing superfluous log lines by changing the check to see if it's a template string for Scaffolder v3 templates
This commit is contained in:
Ben Lambert
2021-11-24 16:34:39 +01:00
committed by GitHub
3 changed files with 32 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-scaffolder-backend': patch
---
Fix bug where there was error log lines written when failing to `JSON.parse` things that were not `JSON` values.
@@ -270,6 +270,31 @@ describe('DefaultWorkflowRunner', () => {
);
});
it('should not try and parse something that is not parsable', async () => {
jest.spyOn(logger, 'error');
const task = createMockTaskWithSpec({
apiVersion: 'scaffolder.backstage.io/v1beta3',
steps: [
{
id: 'test',
name: 'name',
action: 'jest-mock-action',
input: {
foo: 'bob',
},
},
],
output: {},
parameters: {
input: 'BACKSTAGE',
},
});
await runner.execute(task);
expect(logger.error).not.toHaveBeenCalled();
});
it('should keep the original types for the input and not parse things that arent meant to be parsed', async () => {
const task = createMockTaskWithSpec({
apiVersion: 'scaffolder.backstage.io/v1beta3',
@@ -114,9 +114,10 @@ export class NunjucksWorkflowRunner implements WorkflowRunner {
private isSingleTemplateString(input: string) {
const { parser, nodes } = require('nunjucks');
const parsed = parser.parse(input, {}, this.nunjucksOptions);
return (
parsed.children.length === 1 &&
!(parsed.children[0] instanceof nodes.TemplateData)
!(parsed.children[0]?.children?.[0] instanceof nodes.TemplateData)
);
}