From ddd5c87ffb49fc313d27181d8855dbd3054cb016 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?MALIN=20WID=C3=88N?= Date: Tue, 22 Nov 2022 15:35:50 +0100 Subject: [PATCH] Change Buffer.from to window.btoa MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MALIN WIDÈN --- .../components/TemplateEditorPage/DryRunContext.test.tsx | 4 ++-- .../src/components/TemplateEditorPage/DryRunContext.tsx | 6 +++--- .../DryRunResults/DryRunResultsView.test.tsx | 3 +-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/plugins/scaffolder/src/components/TemplateEditorPage/DryRunContext.test.tsx b/plugins/scaffolder/src/components/TemplateEditorPage/DryRunContext.test.tsx index 91fb3d934f..36a62f1b8a 100644 --- a/plugins/scaffolder/src/components/TemplateEditorPage/DryRunContext.test.tsx +++ b/plugins/scaffolder/src/components/TemplateEditorPage/DryRunContext.test.tsx @@ -25,7 +25,7 @@ describe('base64EncodeContent', () => { it('encodes text files', () => { expect(base64EncodeContent('abc')).toBe('YWJj'); expect(base64EncodeContent('abc'.repeat(1000000))).toBe( - Buffer.from('').toString('base64'), + window.btoa(''), ); }); @@ -38,7 +38,7 @@ describe('base64EncodeContent', () => { ); // Triggers size check expect(base64EncodeContent('😅'.repeat(1000000))).toBe( - Buffer.from('').toString('base64'), + window.btoa(''), ); }); }); diff --git a/plugins/scaffolder/src/components/TemplateEditorPage/DryRunContext.tsx b/plugins/scaffolder/src/components/TemplateEditorPage/DryRunContext.tsx index 17e077e47c..3534b62c39 100644 --- a/plugins/scaffolder/src/components/TemplateEditorPage/DryRunContext.tsx +++ b/plugins/scaffolder/src/components/TemplateEditorPage/DryRunContext.tsx @@ -59,11 +59,11 @@ interface DryRunProviderProps { export function base64EncodeContent(content: string): string { if (content.length > MAX_CONTENT_SIZE) { - return Buffer.from('').toString('base64'); + return window.btoa(''); } try { - return Buffer.from(content).toString('base64'); + return window.btoa(content); } catch { const decoder = new TextEncoder(); const buffer = decoder.encode(content); @@ -74,7 +74,7 @@ export function base64EncodeContent(content: string): string { String.fromCharCode(...buffer.slice(offset, offset + CHUNK_SIZE)), ); } - return Buffer.from(chunks.join('')).toString('base64'); + return window.btoa(chunks.join('')); } } diff --git a/plugins/scaffolder/src/components/TemplateEditorPage/DryRunResults/DryRunResultsView.test.tsx b/plugins/scaffolder/src/components/TemplateEditorPage/DryRunResults/DryRunResultsView.test.tsx index 106ee0379f..c709adfd68 100644 --- a/plugins/scaffolder/src/components/TemplateEditorPage/DryRunResults/DryRunResultsView.test.tsx +++ b/plugins/scaffolder/src/components/TemplateEditorPage/DryRunResults/DryRunResultsView.test.tsx @@ -58,8 +58,7 @@ describe('DryRunResultsView', () => { directoryContents: [ { path: 'foo.txt', - base64Content: - Buffer.from('Foo Content').toString('base64'), + base64Content: window.btoa('Foo Content'), executable: false, }, ],