test(core): Mock filesystem in tests (#10823)

This commit is contained in:
Iván Ovejero 2024-09-17 09:15:09 +02:00 committed by GitHub
parent a6e1064985
commit d14bb36300
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 6 additions and 2 deletions

View file

@ -1,7 +1,7 @@
import { rmSync } from 'fs'; import { rmSync } from 'fs';
import { writeFile as fsWriteFile, rm as fsRm } from 'fs/promises';
import { Credentials, InstanceSettings } from 'n8n-core'; import { Credentials, InstanceSettings } from 'n8n-core';
import { ApplicationError, type ICredentialDataDecryptedObject } from 'n8n-workflow'; import { ApplicationError, type ICredentialDataDecryptedObject } from 'n8n-workflow';
import { writeFile as fsWriteFile, rm as fsRm } from 'node:fs/promises';
import path from 'path'; import path from 'path';
import Container, { Service } from 'typedi'; import Container, { Service } from 'typedi';

View file

@ -1,9 +1,9 @@
// eslint-disable-next-line n8n-local-rules/misplaced-n8n-typeorm-import // eslint-disable-next-line n8n-local-rules/misplaced-n8n-typeorm-import
import { In } from '@n8n/typeorm'; import { In } from '@n8n/typeorm';
import glob from 'fast-glob'; import glob from 'fast-glob';
import { readFile as fsReadFile } from 'fs/promises';
import { Credentials, InstanceSettings } from 'n8n-core'; import { Credentials, InstanceSettings } from 'n8n-core';
import { ApplicationError, jsonParse, ErrorReporterProxy as ErrorReporter } from 'n8n-workflow'; import { ApplicationError, jsonParse, ErrorReporterProxy as ErrorReporter } from 'n8n-workflow';
import { readFile as fsReadFile } from 'node:fs/promises';
import path from 'path'; import path from 'path';
import { Container, Service } from 'typedi'; import { Container, Service } from 'typedi';

View file

@ -21,6 +21,8 @@ import type { SuperAgentTest } from './shared/types';
import { initActiveWorkflowManager } from './shared/utils'; import { initActiveWorkflowManager } from './shared/utils';
import { mockInstance } from '../shared/mocking'; import { mockInstance } from '../shared/mocking';
jest.unmock('node:fs');
mockInstance(Telemetry); mockInstance(Telemetry);
describe('Webhook API', () => { describe('Webhook API', () => {

View file

@ -5,3 +5,5 @@ jest.mock('@n8n_io/license-sdk');
jest.mock('@/telemetry'); jest.mock('@/telemetry');
jest.mock('@/eventbus/message-event-bus/message-event-bus'); jest.mock('@/eventbus/message-event-bus/message-event-bus');
jest.mock('@/push'); jest.mock('@/push');
jest.mock('node:fs');
jest.mock('node:fs/promises');