From af97420444731c727a523432806bff8a85a37fc7 Mon Sep 17 00:00:00 2001 From: blam Date: Mon, 11 Mar 2024 16:40:23 +0100 Subject: [PATCH] chore: fixing tests Signed-off-by: blam --- .../builtin/debug/log.examples.test.ts | 18 +++++------ .../actions/builtin/debug/log.test.ts | 32 +++++++------------ 2 files changed, 19 insertions(+), 31 deletions(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/debug/log.examples.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/debug/log.examples.test.ts index 06addba98d..0c37db9eb9 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/debug/log.examples.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/debug/log.examples.test.ts @@ -15,23 +15,23 @@ */ import { createMockActionContext } from '@backstage/plugin-scaffolder-node-test-utils'; -import { Writable } from 'stream'; import { createDebugLogAction } from './log'; import { join } from 'path'; import yaml from 'yaml'; import { examples } from './log.examples'; import { createMockDirectory } from '@backstage/backend-test-utils'; +import { Logger } from 'winston'; describe('debug:log examples', () => { - const logStream = { - write: jest.fn(), - } as jest.Mocked> as jest.Mocked; + const logger = { + info: jest.fn(), + } as unknown as jest.Mocked; const mockDir = createMockDirectory(); const workspacePath = mockDir.resolve('workspace'); const mockContext = createMockActionContext({ - logStream, + logger, workspacePath, }); @@ -51,8 +51,7 @@ describe('debug:log examples', () => { input: yaml.parse(examples[0].example).steps[0].input, }); - expect(logStream.write).toHaveBeenCalledTimes(1); - expect(logStream.write).toHaveBeenCalledWith( + expect(logger.info).toHaveBeenCalledWith( expect.stringContaining('Hello Backstage!'), ); }); @@ -63,11 +62,10 @@ describe('debug:log examples', () => { input: yaml.parse(examples[1].example).steps[0].input, }); - expect(logStream.write).toHaveBeenCalledTimes(1); - expect(logStream.write).toHaveBeenCalledWith( + expect(logger.info).toHaveBeenCalledWith( expect.stringContaining('README.md'), ); - expect(logStream.write).toHaveBeenCalledWith( + expect(logger.info).toHaveBeenCalledWith( expect.stringContaining(join('a-directory', 'index.md')), ); }); diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/debug/log.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/debug/log.test.ts index 09c090582a..9c626f1dfe 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/debug/log.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/debug/log.test.ts @@ -15,21 +15,21 @@ */ import { createMockActionContext } from '@backstage/plugin-scaffolder-node-test-utils'; -import { Writable } from 'stream'; +import { Logger } from 'winston'; import { createDebugLogAction } from './log'; import { join } from 'path'; import yaml from 'yaml'; import { createMockDirectory } from '@backstage/backend-test-utils'; describe('debug:log', () => { - const logStream = { - write: jest.fn(), - } as jest.Mocked> as jest.Mocked; + const logger = { + info: jest.fn(), + } as unknown as jest.Mocked; const mockDir = createMockDirectory(); const workspacePath = mockDir.resolve('workspace'); - const mockContext = createMockActionContext({ workspacePath, logStream }); + const mockContext = createMockActionContext({ workspacePath, logger }); const action = createDebugLogAction(); @@ -41,12 +41,6 @@ describe('debug:log', () => { jest.resetAllMocks(); }); - it('should do nothing', async () => { - await action.handler(mockContext); - - expect(logStream.write).toHaveBeenCalledTimes(0); - }); - it('should log the workspace content, if active', async () => { const context = { ...mockContext, @@ -57,11 +51,10 @@ describe('debug:log', () => { await action.handler(context); - expect(logStream.write).toHaveBeenCalledTimes(1); - expect(logStream.write).toHaveBeenCalledWith( + expect(logger.info).toHaveBeenCalledWith( expect.stringContaining('README.md'), ); - expect(logStream.write).toHaveBeenCalledWith( + expect(logger.info).toHaveBeenCalledWith( expect.stringContaining(join('a-directory', 'index.md')), ); }); @@ -76,8 +69,7 @@ describe('debug:log', () => { await action.handler(context); - expect(logStream.write).toHaveBeenCalledTimes(1); - expect(logStream.write).toHaveBeenCalledWith( + expect(logger.info).toHaveBeenCalledWith( expect.stringContaining('Hello Backstage!'), ); }); @@ -94,11 +86,10 @@ describe('debug:log', () => { await action.handler(context); - expect(logStream.write).toHaveBeenCalledTimes(1); - expect(logStream.write).toHaveBeenCalledWith( + expect(logger.info).toHaveBeenCalledWith( expect.stringContaining('README.md'), ); - expect(logStream.write).toHaveBeenCalledWith( + expect(logger.info).toHaveBeenCalledWith( expect.stringContaining(join('a-directory', 'index.md')), ); }); @@ -115,8 +106,7 @@ describe('debug:log', () => { await action.handler(context); - expect(logStream.write).toHaveBeenCalledTimes(1); - expect(logStream.write).toHaveBeenCalledWith( + expect(logger.info).toHaveBeenCalledWith( expect.stringContaining('Hello Backstage!'), ); });