From 8e183acc9cee145f665b4c0c9d2ca997e2171b50 Mon Sep 17 00:00:00 2001 From: blam Date: Wed, 7 Jul 2021 11:02:31 +0200 Subject: [PATCH] chore: code review comments Signed-off-by: blam --- .../builtin/fetch/cookiecutter.test.ts | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/cookiecutter.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/cookiecutter.test.ts index 1ef1e1a940..86f953a6a5 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/cookiecutter.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/cookiecutter.test.ts @@ -28,7 +28,7 @@ import { } from '@backstage/backend-common'; import { ConfigReader, JsonObject } from '@backstage/config'; import { ScmIntegrations } from '@backstage/integration'; -import mock from 'mock-fs'; +import mockFs from 'mock-fs'; import os from 'os'; import { PassThrough } from 'stream'; import { createFetchCookiecutterAction } from './cookiecutter'; @@ -94,14 +94,14 @@ describe('fetch:cookiecutter', () => { }; // mock the temp directory - mock({ [mockTmpDir]: {} }); - mock({ [`${join(mockTmpDir, 'template')}`]: {} }); + mockFs({ [mockTmpDir]: {} }); + mockFs({ [`${join(mockTmpDir, 'template')}`]: {} }); commandExists.mockResolvedValue(null); // Mock when run container is called it creates some new files in the mock filesystem containerRunner.runContainer.mockImplementation(async () => { - mock({ + mockFs({ [`${join(mockTmpDir, 'intermediate')}`]: { 'testfile.json': '{}', }, @@ -110,7 +110,7 @@ describe('fetch:cookiecutter', () => { // Mock when runCommand is called it creats some new files in the mock filesystem runCommand.mockImplementation(async () => { - mock({ + mockFs({ [`${join(mockTmpDir, 'intermediate')}`]: { 'testfile.json': '{}', }, @@ -119,26 +119,22 @@ describe('fetch:cookiecutter', () => { }); afterEach(() => { - mock.restore(); + mockFs.restore(); }); it('should throw an error when copyWithoutRender is not an array', async () => { (mockContext.input as any).copyWithoutRender = 'not an array'; - await expect( - action.handler(mockContext), - ).rejects.toThrowErrorMatchingInlineSnapshot( - `"Fetch action input copyWithoutRender must be an Array"`, + await expect(action.handler(mockContext)).rejects.toThrowError( + /Fetch action input copyWithoutRender must be an Array/, ); }); it('should throw an error when extensions is not an array', async () => { (mockContext.input as any).extensions = 'not an array'; - await expect( - action.handler(mockContext), - ).rejects.toThrowErrorMatchingInlineSnapshot( - `"Fetch action input extensions must be an Array"`, + await expect(action.handler(mockContext)).rejects.toThrowError( + /Fetch action input extensions must be an Array/, ); });