From 0fca639626c22425ad3becc074a3cfff216e1a5a Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Thu, 5 Oct 2023 17:26:51 +0200 Subject: [PATCH] scaffolder-backend: refactor rename action tests to avoid mock-fs Signed-off-by: Patrik Oldsberg --- .../actions/builtin/filesystem/rename.test.ts | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/filesystem/rename.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/filesystem/rename.test.ts index 6804c9f5a9..d37e967f43 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/filesystem/rename.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/filesystem/rename.test.ts @@ -14,20 +14,19 @@ * limitations under the License. */ -import * as os from 'os'; -import mockFs from 'mock-fs'; import { resolve as resolvePath } from 'path'; import { createFilesystemRenameAction } from './rename'; import { getVoidLogger } from '@backstage/backend-common'; import { PassThrough } from 'stream'; import fs from 'fs-extra'; - -const root = os.platform() === 'win32' ? 'C:\\rootDir' : '/rootDir'; -const workspacePath = resolvePath(root, 'my-workspace'); +import { createMockDirectory } from '@backstage/backend-test-utils'; describe('fs:rename', () => { const action = createFilesystemRenameAction(); + const mockDir = createMockDirectory(); + const workspacePath = resolvePath(mockDir.path, 'workspace'); + const mockInputFiles = [ { from: 'unit-test-a.js', @@ -56,7 +55,7 @@ describe('fs:rename', () => { beforeEach(() => { jest.restoreAllMocks(); - mockFs({ + mockDir.setContent({ [workspacePath]: { 'unit-test-a.js': 'hello', 'unit-test-b.js': 'world', @@ -68,10 +67,6 @@ describe('fs:rename', () => { }); }); - afterEach(() => { - mockFs.restore(); - }); - it('should throw an error when files is not an array', async () => { await expect( action.handler({