mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 04:34:06 -08:00
fix: Add missing Node.js natives to task runners (no-changelog) (#11362)
This commit is contained in:
parent
0708b3a1f8
commit
5b98f8711f
|
@ -283,7 +283,7 @@ describe('JsTaskRunner', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should allow access to Node.js Buffers', async () => {
|
it('should allow access to Node.js Buffers', async () => {
|
||||||
const outcome = await execTaskWithParams({
|
const outcomeAll = await execTaskWithParams({
|
||||||
task: newTaskWithSettings({
|
task: newTaskWithSettings({
|
||||||
code: 'return { val: Buffer.from("test-buffer").toString() }',
|
code: 'return { val: Buffer.from("test-buffer").toString() }',
|
||||||
nodeMode: 'runOnceForAllItems',
|
nodeMode: 'runOnceForAllItems',
|
||||||
|
@ -293,7 +293,21 @@ describe('JsTaskRunner', () => {
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(outcome.result).toEqual([wrapIntoJson({ val: 'test-buffer' })]);
|
expect(outcomeAll.result).toEqual([wrapIntoJson({ val: 'test-buffer' })]);
|
||||||
|
|
||||||
|
const outcomePer = await execTaskWithParams({
|
||||||
|
task: newTaskWithSettings({
|
||||||
|
code: 'return { val: Buffer.from("test-buffer").toString() }',
|
||||||
|
nodeMode: 'runOnceForEachItem',
|
||||||
|
}),
|
||||||
|
taskData: newAllCodeTaskData(inputItems.map(wrapIntoJson), {
|
||||||
|
envProviderState: undefined,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(outcomePer.result).toEqual([
|
||||||
|
{ ...wrapIntoJson({ val: 'test-buffer' }), pairedItem: { item: 0 } },
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -153,6 +153,25 @@ export class JsTaskRunner extends TaskRunner {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getNativeVariables() {
|
||||||
|
return {
|
||||||
|
// Exposed Node.js globals in vm2
|
||||||
|
Buffer,
|
||||||
|
Function,
|
||||||
|
eval,
|
||||||
|
setTimeout,
|
||||||
|
setInterval,
|
||||||
|
setImmediate,
|
||||||
|
clearTimeout,
|
||||||
|
clearInterval,
|
||||||
|
clearImmediate,
|
||||||
|
|
||||||
|
// Missing JS natives
|
||||||
|
btoa,
|
||||||
|
atob,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the requested code for all items in a single run
|
* Executes the requested code for all items in a single run
|
||||||
*/
|
*/
|
||||||
|
@ -170,19 +189,9 @@ export class JsTaskRunner extends TaskRunner {
|
||||||
require: this.requireResolver,
|
require: this.requireResolver,
|
||||||
module: {},
|
module: {},
|
||||||
console: customConsole,
|
console: customConsole,
|
||||||
|
|
||||||
// Exposed Node.js globals in vm2
|
|
||||||
Buffer,
|
|
||||||
Function,
|
|
||||||
eval,
|
|
||||||
setTimeout,
|
|
||||||
setInterval,
|
|
||||||
setImmediate,
|
|
||||||
clearTimeout,
|
|
||||||
clearInterval,
|
|
||||||
clearImmediate,
|
|
||||||
|
|
||||||
items: inputItems,
|
items: inputItems,
|
||||||
|
|
||||||
|
...this.getNativeVariables(),
|
||||||
...dataProxy,
|
...dataProxy,
|
||||||
...this.buildRpcCallObject(taskId),
|
...this.buildRpcCallObject(taskId),
|
||||||
};
|
};
|
||||||
|
@ -232,6 +241,7 @@ export class JsTaskRunner extends TaskRunner {
|
||||||
console: customConsole,
|
console: customConsole,
|
||||||
item,
|
item,
|
||||||
|
|
||||||
|
...this.getNativeVariables(),
|
||||||
...dataProxy,
|
...dataProxy,
|
||||||
...this.buildRpcCallObject(taskId),
|
...this.buildRpcCallObject(taskId),
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue