fix(core): Ensure runners do not throw on unsupported console methods (#12167)

This commit is contained in:
Iván Ovejero 2024-12-11 18:37:07 +01:00 committed by GitHub
parent 28f1f6b561
commit 57c6a6167d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 36 additions and 0 deletions

View file

@ -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', () => {

View file

@ -121,7 +121,13 @@ export class JsTaskRunner extends TaskRunner {
nodeTypes: this.nodeTypes,
});
const noOp = () => {};
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
// it to the UI or printing to console.
log: (...args: unknown[]) => {