mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-23 10:32:17 -08:00
fix: JS Task Runner not having access to Buffer (no-changelog) (#11285)
Some checks are pending
Test Master / install-and-build (push) Waiting to run
Test Master / Unit tests (18.x) (push) Blocked by required conditions
Test Master / Unit tests (20.x) (push) Blocked by required conditions
Test Master / Unit tests (22.4) (push) Blocked by required conditions
Test Master / Lint (push) Blocked by required conditions
Test Master / Notify Slack on failure (push) Blocked by required conditions
Some checks are pending
Test Master / install-and-build (push) Waiting to run
Test Master / Unit tests (18.x) (push) Blocked by required conditions
Test Master / Unit tests (20.x) (push) Blocked by required conditions
Test Master / Unit tests (22.4) (push) Blocked by required conditions
Test Master / Lint (push) Blocked by required conditions
Test Master / Notify Slack on failure (push) Blocked by required conditions
This commit is contained in:
parent
d37acdb873
commit
5c370c9235
|
@ -281,6 +281,20 @@ describe('JsTaskRunner', () => {
|
|||
expect(outcome.result).toEqual([wrapIntoJson({ val: undefined })]);
|
||||
});
|
||||
});
|
||||
|
||||
it('should allow access to Node.js Buffers', async () => {
|
||||
const outcome = await execTaskWithParams({
|
||||
task: newTaskWithSettings({
|
||||
code: 'return { val: Buffer.from("test-buffer").toString() }',
|
||||
nodeMode: 'runOnceForAllItems',
|
||||
}),
|
||||
taskData: newAllCodeTaskData(inputItems.map(wrapIntoJson), {
|
||||
envProviderState: undefined,
|
||||
}),
|
||||
});
|
||||
|
||||
expect(outcome.result).toEqual([wrapIntoJson({ val: 'test-buffer' })]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('runOnceForAllItems', () => {
|
||||
|
@ -755,8 +769,6 @@ describe('JsTaskRunner', () => {
|
|||
},
|
||||
}),
|
||||
);
|
||||
|
||||
console.log('DONE');
|
||||
}, 1000);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -181,6 +181,17 @@ export class JsTaskRunner extends TaskRunner {
|
|||
module: {},
|
||||
console: customConsole,
|
||||
|
||||
// Exposed Node.js globals in vm2
|
||||
Buffer,
|
||||
Function,
|
||||
eval,
|
||||
setTimeout,
|
||||
setInterval,
|
||||
setImmediate,
|
||||
clearTimeout,
|
||||
clearInterval,
|
||||
clearImmediate,
|
||||
|
||||
items: inputItems,
|
||||
...dataProxy,
|
||||
...this.buildRpcCallObject(taskId),
|
||||
|
@ -188,7 +199,7 @@ export class JsTaskRunner extends TaskRunner {
|
|||
|
||||
try {
|
||||
const result = (await runInNewContext(
|
||||
`module.exports = async function VmCodeWrapper() {${settings.code}\n}()`,
|
||||
`globalThis.global = globalThis; module.exports = async function VmCodeWrapper() {${settings.code}\n}()`,
|
||||
context,
|
||||
)) as TaskResultData['result'];
|
||||
|
||||
|
|
Loading…
Reference in a new issue