Skip to content

Commit

Permalink
fix(core): Ensure runners do not throw on unsupported console methods (
Browse files Browse the repository at this point in the history
  • Loading branch information
ivov authored Dec 11, 2024
1 parent 28f1f6b commit 57c6a61
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[]) => {
Expand Down

0 comments on commit 57c6a61

Please sign in to comment.