fix(Code Tool Node): Fix console.log output not being logged on browser (#19422)

This commit is contained in:
Jaakko Husso
2025-09-12 15:05:35 +03:00
committed by GitHub
parent 1a1c07d6eb
commit 1e2f4217e0
2 changed files with 49 additions and 1 deletions

View File

@@ -220,6 +220,40 @@ describe('SupplyDataContext', () => {
}); });
}); });
describe('logNodeOutput', () => {
it('it should parse JSON', () => {
const json = '{"key": "value", "nested": {"foo": "bar"}}';
const expectedParsedObject = { key: 'value', nested: { foo: 'bar' } };
const numberArg = 42;
const stringArg = 'hello world!';
const supplyDataContext = new SupplyDataContext(
workflow,
node,
additionalData,
mode,
runExecutionData,
runIndex,
connectionInputData,
inputData,
connectionType,
executeData,
[closeFn],
abortSignal,
);
const sendMessageSpy = jest.spyOn(supplyDataContext, 'sendMessageToUI');
supplyDataContext.logNodeOutput(json, numberArg, stringArg);
expect(sendMessageSpy.mock.calls[0][0]).toEqual(expectedParsedObject);
expect(sendMessageSpy.mock.calls[0][1]).toBe(numberArg);
expect(sendMessageSpy.mock.calls[0][2]).toBe(stringArg);
sendMessageSpy.mockRestore();
});
});
describe('addExecutionDataFunctions', () => { describe('addExecutionDataFunctions', () => {
it('should preserve canceled status when execution is aborted and output has error', async () => { it('should preserve canceled status when execution is aborted and output has error', async () => {
const errorData = new ExecutionCancelledError('Execution was aborted'); const errorData = new ExecutionCancelledError('Execution was aborted');

View File

@@ -18,7 +18,7 @@ import type {
NodeConnectionType, NodeConnectionType,
ISourceData, ISourceData,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { createDeferredPromise, NodeConnectionTypes } from 'n8n-workflow'; import { createDeferredPromise, jsonParse, NodeConnectionTypes } from 'n8n-workflow';
import { BaseExecuteContext } from './base-execute-context'; import { BaseExecuteContext } from './base-execute-context';
import { import {
@@ -344,4 +344,18 @@ export class SupplyDataContext extends BaseExecuteContext implements ISupplyData
}); });
} }
} }
logNodeOutput(...args: unknown[]): void {
if (this.mode === 'manual') {
const parsedLogArgs = args.map((arg) =>
typeof arg === 'string' ? jsonParse(arg, { fallbackValue: arg }) : arg,
);
this.sendMessageToUI(...parsedLogArgs);
return;
}
if (process.env.CODE_ENABLE_STDOUT === 'true') {
console.log(`[Workflow "${this.getWorkflow().id}"][Node "${this.node.name}"]`, ...args);
}
}
} }