mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-28 22:19:41 -08:00
test: Fix task runner tests on node 18 and 22 (#12243)
This commit is contained in:
parent
2ce1644d01
commit
271401d882
|
@ -1,5 +1,6 @@
|
|||
/** @type {import('jest').Config} */
|
||||
module.exports = {
|
||||
...require('../../../jest.config'),
|
||||
setupFilesAfterEnv: ['n8n-workflow/test/setup.ts'],
|
||||
testTimeout: 10_000,
|
||||
};
|
||||
|
|
|
@ -36,7 +36,11 @@ describe('ExecutionError', () => {
|
|||
|
||||
it('should serialize correctly', () => {
|
||||
const error = new Error('a.unknown is not a function');
|
||||
error.stack = defaultStack;
|
||||
Object.defineProperty(error, 'stack', {
|
||||
value: defaultStack,
|
||||
enumerable: true,
|
||||
});
|
||||
// error.stack = defaultStack;
|
||||
|
||||
const executionError = new ExecutionError(error, 1);
|
||||
|
||||
|
|
|
@ -10,8 +10,6 @@ export class ExecutionError extends SerializableError {
|
|||
|
||||
context: { itemIndex: number } | undefined = undefined;
|
||||
|
||||
stack = '';
|
||||
|
||||
lineNumber: number | undefined = undefined;
|
||||
|
||||
constructor(error: ErrorLike, itemIndex?: number) {
|
||||
|
@ -22,7 +20,12 @@ export class ExecutionError extends SerializableError {
|
|||
this.context = { itemIndex: this.itemIndex };
|
||||
}
|
||||
|
||||
this.stack = error.stack ?? '';
|
||||
// Override the stack trace with the given error's stack trace. Since
|
||||
// node v22 it's not writable, so we can't assign it directly
|
||||
Object.defineProperty(this, 'stack', {
|
||||
value: error.stack,
|
||||
enumerable: true,
|
||||
});
|
||||
|
||||
this.populateFromStack();
|
||||
}
|
||||
|
@ -31,7 +34,7 @@ export class ExecutionError extends SerializableError {
|
|||
* Populate error `message` and `description` from error `stack`.
|
||||
*/
|
||||
private populateFromStack() {
|
||||
const stackRows = this.stack.split('\n');
|
||||
const stackRows = (this.stack ?? '').split('\n');
|
||||
|
||||
if (stackRows.length === 0) {
|
||||
this.message = 'Unknown error';
|
||||
|
|
5
packages/@n8n/task-runner/src/polyfills.ts
Normal file
5
packages/@n8n/task-runner/src/polyfills.ts
Normal file
|
@ -0,0 +1,5 @@
|
|||
// WebCrypto Polyfill for older versions of Node.js 18
|
||||
if (!globalThis.crypto?.getRandomValues) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-var-requires, @typescript-eslint/no-unsafe-member-access
|
||||
globalThis.crypto = require('node:crypto').webcrypto;
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
import './polyfills';
|
||||
import type { ErrorReporter } from 'n8n-core';
|
||||
import { ensureError, setGlobalState } from 'n8n-workflow';
|
||||
import Container from 'typedi';
|
||||
|
|
Loading…
Reference in a new issue