From 357178d83b0ac6f8714f3950951bf52f0a9e5294 Mon Sep 17 00:00:00 2001 From: Omar Ajoue Date: Fri, 12 Nov 2021 14:28:49 +0100 Subject: [PATCH] :zap: New JSON attributes are now considered warnings in testing workflows (#2432) --- packages/cli/commands/executeBatch.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/cli/commands/executeBatch.ts b/packages/cli/commands/executeBatch.ts index 4834e69d65..587f91c2a9 100644 --- a/packages/cli/commands/executeBatch.ts +++ b/packages/cli/commands/executeBatch.ts @@ -817,10 +817,22 @@ export class ExecuteBatch extends Command { const changes = diff(JSON.parse(contents), data, { keysOnly: true }); if (changes !== undefined) { - // we have structural changes. Report them. - executionResult.error = `Workflow may contain breaking changes`; - executionResult.changes = changes; - executionResult.executionStatus = 'error'; + // If we had only additions with no removals + // Then we treat as a warning and not an error. + // To find this, we convert the object to JSON + // and search for the `__deleted` string + const changesJson = JSON.stringify(changes); + if (changesJson.includes('__deleted')) { + // we have structural changes. Report them. + executionResult.error = 'Workflow may contain breaking changes'; + executionResult.changes = changes; + executionResult.executionStatus = 'error'; + } else { + executionResult.error = + 'Workflow contains new data that previously did not exist.'; + executionResult.changes = changes; + executionResult.executionStatus = 'warning'; + } } else { executionResult.executionStatus = 'success'; }