mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-03 17:07:29 -08:00
fix(core): Ensure runners do not throw on unsupported console methods (#12167)
This commit is contained in:
parent
28f1f6b561
commit
57c6a6167d
|
@ -136,6 +136,36 @@ describe('JsTaskRunner', () => {
|
||||||
]);
|
]);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
it('should not throw when using unsupported console methods', async () => {
|
||||||
|
const task = newTaskWithSettings({
|
||||||
|
code: `
|
||||||
|
console.warn('test');
|
||||||
|
console.error('test');
|
||||||
|
console.info('test');
|
||||||
|
console.debug('test');
|
||||||
|
console.trace('test');
|
||||||
|
console.dir({});
|
||||||
|
console.time('test');
|
||||||
|
console.timeEnd('test');
|
||||||
|
console.timeLog('test');
|
||||||
|
console.assert(true);
|
||||||
|
console.clear();
|
||||||
|
console.group('test');
|
||||||
|
console.groupEnd();
|
||||||
|
console.table([]);
|
||||||
|
return {json: {}}
|
||||||
|
`,
|
||||||
|
nodeMode: 'runOnceForAllItems',
|
||||||
|
});
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
execTaskWithParams({
|
||||||
|
task,
|
||||||
|
taskData: newDataRequestResponse([wrapIntoJson({})]),
|
||||||
|
}),
|
||||||
|
).resolves.toBeDefined();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('built-in methods and variables available in the context', () => {
|
describe('built-in methods and variables available in the context', () => {
|
||||||
|
|
|
@ -121,7 +121,13 @@ export class JsTaskRunner extends TaskRunner {
|
||||||
nodeTypes: this.nodeTypes,
|
nodeTypes: this.nodeTypes,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const noOp = () => {};
|
||||||
const customConsole = {
|
const customConsole = {
|
||||||
|
// all except `log` are dummy methods that disregard without throwing, following existing Code node behavior
|
||||||
|
...Object.keys(console).reduce<Record<string, () => void>>((acc, name) => {
|
||||||
|
acc[name] = noOp;
|
||||||
|
return acc;
|
||||||
|
}, {}),
|
||||||
// Send log output back to the main process. It will take care of forwarding
|
// Send log output back to the main process. It will take care of forwarding
|
||||||
// it to the UI or printing to console.
|
// it to the UI or printing to console.
|
||||||
log: (...args: unknown[]) => {
|
log: (...args: unknown[]) => {
|
||||||
|
|
Loading…
Reference in a new issue