mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +00:00
fix(Code Tool Node): Fix console.log output not being logged on browser (#19422)
This commit is contained in:
@@ -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', () => {
|
||||
it('should preserve canceled status when execution is aborted and output has error', async () => {
|
||||
const errorData = new ExecutionCancelledError('Execution was aborted');
|
||||
|
||||
@@ -18,7 +18,7 @@ import type {
|
||||
NodeConnectionType,
|
||||
ISourceData,
|
||||
} from 'n8n-workflow';
|
||||
import { createDeferredPromise, NodeConnectionTypes } from 'n8n-workflow';
|
||||
import { createDeferredPromise, jsonParse, NodeConnectionTypes } from 'n8n-workflow';
|
||||
|
||||
import { BaseExecuteContext } from './base-execute-context';
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user