From 339dd63bec3d12ee3fbaa71cf8737db02cac1ef0 Mon Sep 17 00:00:00 2001 From: Rob Herley Date: Wed, 2 Mar 2022 23:56:30 -0500 Subject: [PATCH] summary: method to clear file and buffer --- packages/core/__tests__/markdown-summary.test.ts | 7 +++++++ packages/core/src/markdown-summary.ts | 11 ++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/core/__tests__/markdown-summary.test.ts b/packages/core/__tests__/markdown-summary.test.ts index 7d7b12e7..00f4ad6c 100644 --- a/packages/core/__tests__/markdown-summary.test.ts +++ b/packages/core/__tests__/markdown-summary.test.ts @@ -151,6 +151,13 @@ describe('@actions/core/src/markdown-summary', () => { expect(markdownSummary.isEmptyBuffer()).toBe(true) }) + it('clears a buffer and summary file', async () => { + await fs.promises.writeFile(testFilePath, 'content', {encoding: 'utf8'}) + await markdownSummary.clear() + await assertSummary('') + expect(markdownSummary.isEmptyBuffer()).toBe(true) + }) + it('adds EOL', async () => { await markdownSummary .addRaw(fixtures.text) diff --git a/packages/core/src/markdown-summary.ts b/packages/core/src/markdown-summary.ts index 76e994eb..6a4ae9f9 100644 --- a/packages/core/src/markdown-summary.ts +++ b/packages/core/src/markdown-summary.ts @@ -151,6 +151,15 @@ class MarkdownSummary { return this.emptyBuffer() } + /** + * Clears the summary buffer and wipes the summary file + * + * @returns {MarkdownSummary} markdown summary instance + */ + async clear(): Promise { + return this.emptyBuffer().write(true) + } + /** * Returns the current summary buffer as a string * @@ -170,7 +179,7 @@ class MarkdownSummary { } /** - * Clears the summary buffer without writing to summary file + * Resets the summary buffer without writing to summary file * * @returns {MarkdownSummary} markdown summary instance */