From d14bb3630027363d02dcd4a81b1b01bd83c34311 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Tue, 17 Sep 2024 09:15:09 +0200 Subject: [PATCH] test(core): Mock filesystem in tests (#10823) --- .../source-control/source-control-export.service.ee.ts | 2 +- .../source-control/source-control-import.service.ee.ts | 2 +- packages/cli/test/integration/webhooks.api.test.ts | 2 ++ packages/cli/test/setup-mocks.ts | 2 ++ 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/environments/source-control/source-control-export.service.ee.ts b/packages/cli/src/environments/source-control/source-control-export.service.ee.ts index 6fb904b4a0..321534ff6c 100644 --- a/packages/cli/src/environments/source-control/source-control-export.service.ee.ts +++ b/packages/cli/src/environments/source-control/source-control-export.service.ee.ts @@ -1,7 +1,7 @@ import { rmSync } from 'fs'; -import { writeFile as fsWriteFile, rm as fsRm } from 'fs/promises'; import { Credentials, InstanceSettings } from 'n8n-core'; import { ApplicationError, type ICredentialDataDecryptedObject } from 'n8n-workflow'; +import { writeFile as fsWriteFile, rm as fsRm } from 'node:fs/promises'; import path from 'path'; import Container, { Service } from 'typedi'; diff --git a/packages/cli/src/environments/source-control/source-control-import.service.ee.ts b/packages/cli/src/environments/source-control/source-control-import.service.ee.ts index bf69975e2b..fb491f39d2 100644 --- a/packages/cli/src/environments/source-control/source-control-import.service.ee.ts +++ b/packages/cli/src/environments/source-control/source-control-import.service.ee.ts @@ -1,9 +1,9 @@ // eslint-disable-next-line n8n-local-rules/misplaced-n8n-typeorm-import import { In } from '@n8n/typeorm'; import glob from 'fast-glob'; -import { readFile as fsReadFile } from 'fs/promises'; import { Credentials, InstanceSettings } from 'n8n-core'; import { ApplicationError, jsonParse, ErrorReporterProxy as ErrorReporter } from 'n8n-workflow'; +import { readFile as fsReadFile } from 'node:fs/promises'; import path from 'path'; import { Container, Service } from 'typedi'; diff --git a/packages/cli/test/integration/webhooks.api.test.ts b/packages/cli/test/integration/webhooks.api.test.ts index 3e10418256..f1da8e3ab0 100644 --- a/packages/cli/test/integration/webhooks.api.test.ts +++ b/packages/cli/test/integration/webhooks.api.test.ts @@ -21,6 +21,8 @@ import type { SuperAgentTest } from './shared/types'; import { initActiveWorkflowManager } from './shared/utils'; import { mockInstance } from '../shared/mocking'; +jest.unmock('node:fs'); + mockInstance(Telemetry); describe('Webhook API', () => { diff --git a/packages/cli/test/setup-mocks.ts b/packages/cli/test/setup-mocks.ts index 63d60cd522..ddf886f557 100644 --- a/packages/cli/test/setup-mocks.ts +++ b/packages/cli/test/setup-mocks.ts @@ -5,3 +5,5 @@ jest.mock('@n8n_io/license-sdk'); jest.mock('@/telemetry'); jest.mock('@/eventbus/message-event-bus/message-event-bus'); jest.mock('@/push'); +jest.mock('node:fs'); +jest.mock('node:fs/promises');