diff --git a/plugins/scaffolder-backend/fixtures/test-nested-template/public/react-logo192.png b/plugins/scaffolder-backend/fixtures/test-nested-template/public/react-logo192.png new file mode 100644 index 0000000000..fc44b0a379 Binary files /dev/null and b/plugins/scaffolder-backend/fixtures/test-nested-template/public/react-logo192.png differ diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/template.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/template.test.ts index 179626581a..3ab96a367e 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/template.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/fetch/template.test.ts @@ -15,6 +15,7 @@ */ import os from 'os'; +import { resolve as resolvePath } from 'path'; import fs from 'fs-extra'; import mockFs from 'mock-fs'; import { getVoidLogger, UrlReader } from '@backstage/backend-common'; @@ -24,12 +25,17 @@ import { fetchContents } from './helpers'; import { ActionContext, TemplateAction } from '../../types'; import { createFetchTemplateAction, FetchTemplateInput } from './template'; -// TODO(mtlewis/orkohunter): Test handling binary files - jest.mock('./helpers', () => ({ fetchContents: jest.fn(), })); +const aBinaryFile = fs.readFileSync( + resolvePath( + 'src', + '../fixtures/test-nested-template/public/react-logo192.png', + ), +); + const mockFetchContents = fetchContents as jest.MockedFunction< typeof fetchContents >; @@ -119,6 +125,7 @@ describe('fetch:template', () => { 'templated-content.txt': '${{ name }}: ${{ count }}', }, '.${{ name }}': '${{ itemList | dump }}', + 'a-binary-file.png': aBinaryFile, }, }); @@ -169,6 +176,12 @@ describe('fetch:template', () => { fs.readdir(`${workspacePath}/target/empty-dir-1234`, 'utf-8'), ).resolves.toEqual([]); }); + + it('copies binary files as it-is without processing them', async () => { + await expect( + fs.readFile(`${workspacePath}/target/a-binary-file.png`), + ).resolves.toEqual(aBinaryFile); + }); }); describe('copyWithoutRender', () => {