From 758ba7b049615eb0201f5f06a904bee413545ed4 Mon Sep 17 00:00:00 2001 From: David Bolack Date: Thu, 27 Aug 2026 15:51:38 -0500 Subject: [PATCH 1/3] Add additional coverage tests for shared/helpers.js --- package.json | 1 + shared/helpers.js | 3 +- tests/html/helpers.test.js | 124 +++++++++++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 tests/html/helpers.test.js diff --git a/package.json b/package.json index 29318f4ee..ff2fc7051 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "test:emojis": "jest tests/markdown/emojis.test.js --verbose --noStackTrace", "test:route": "jest tests/routes/static-pages.test.js --verbose", "test:safehtml": "jest tests/html/safeHTML.test.js --verbose", + "test:helpers": "jest tests/html/helpers.test.js --verbose", "phb": "node --experimental-require-module scripts/phb.js", "prod": "set NODE_ENV=production && npm run build", "postinstall": "npm run build", diff --git a/shared/helpers.js b/shared/helpers.js index 667d7b6b1..d84c4ef0f 100644 --- a/shared/helpers.js +++ b/shared/helpers.js @@ -229,5 +229,6 @@ export { printCurrentBrew, fetchThemeBundle, brewSnippetsToJSON, - debugTextMismatch + debugTextMismatch, + yamlSnippetsToText }; diff --git a/tests/html/helpers.test.js b/tests/html/helpers.test.js new file mode 100644 index 000000000..13560442a --- /dev/null +++ b/tests/html/helpers.test.js @@ -0,0 +1,124 @@ +import { + fetchThemeBundle, + brewSnippetsToJSON, + debugTextMismatch, + yamlSnippetsToText, +} from '../../shared/helpers.js'; + +import dedent from 'dedent'; + +// Marked.js adds line returns after closing tags on some default tokens. +// This removes those line returns for comparison sake. +String.prototype.trimReturns = function(){ + return this.replace(/\r?\n|\r/g, ''); +}; + +const emoji = 'df_d12_2'; + +const brewSnippetsThemeTest = [ + { + name : 'Test Theme', + snippets : dedent `\snippet First Theme Snippet +I am the first theme snippet! + +\snippet Second Theme Snippet +I am the second theme Snippet! + +`, + } +]; + +const brewSnippetsBrewTest = dedent` +\snippet First Brew Snippet +I am the first brew snippet! + +\snippet Second Brew Snippet +I am the second brew Snippet! + +`; + +describe(`Helper function tests`, ()=>{ + it('brewSnippetsToJSON without theme snippets', function() { + const testMenuObject = { + groupName : 'Brew Snippets', + icon : 'fas fa-th-list', + snippets : [ + { + name : 'Test Snippets JSON without theme snippets', + subsnippets : [ + { + gen : 'I am the first brew snippet!\n', + name : 'First Brew Snippet' + }, { + gen : 'I am the second brew Snippet!', + name: 'Second Brew Snippet' + } + ] + } + ], + view : 'text' + }; + const rendered = brewSnippetsToJSON(`Test Snippets JSON without theme snippets`, brewSnippetsBrewTest, null, true); + expect(rendered, `Input:\n${brewSnippetsBrewTest}\n${brewSnippetsThemeTest}`, { showPrefix: false }).toStrictEqual(testMenuObject); + }); + + it('brewSnippetsToJSON with theme snippets', function() { + const testMenuObject = { + groupName : 'Brew Snippets', + icon : 'fas fa-th-list', + snippets : [ + { + gen : '', + icon : '', + name : 'Test Theme', + subsnippets : [ + { + gen : 'I am the first theme snippet!\n', + icon : '', + name : 'First Theme Snippet', + }, + { + gen : 'I am the second theme Snippet!', + icon : '', + name : 'Second Theme Snippet', + }, + ], + }, + { + name : 'Test Snippets JSON without theme snippets', + subsnippets : [ + { + gen : 'I am the first brew snippet!\n', + name : 'First Brew Snippet' + }, { + gen : 'I am the second brew Snippet!', + name: 'Second Brew Snippet' + } + ] + } + ], + view : 'text' + }; + const rendered = brewSnippetsToJSON(`Test Snippets JSON without theme snippets`, brewSnippetsBrewTest, brewSnippetsThemeTest, true); + expect(rendered, `Input:\n${brewSnippetsBrewTest}\n${brewSnippetsThemeTest}`, { showPrefix: false }).toStrictEqual(testMenuObject); + }); + + it('Yaml SnippetstoText ', function() { + const brewSnippetsBrewTestAsYAML = [ + { + subsnippets : [ + { + gen : 'I am the first brew snippet!\n', + name : 'First Brew Snippet' + }, { + gen : 'I am the second brew Snippet!', + name: 'Second Brew Snippet' + } + ] + } + ]; + const rendered = yamlSnippetsToText(brewSnippetsBrewTestAsYAML); + expect(rendered, `Input:\n${brewSnippetsBrewTestAsYAML}\n`, { showPrefix: false }).toBe(`${brewSnippetsBrewTest}\n`); + }); + +}); \ No newline at end of file From 2a4897e0c567fee064e77fe057872803b0d96ac6 Mon Sep 17 00:00:00 2001 From: David Bolack Date: Thu, 27 Aug 2026 15:56:02 -0500 Subject: [PATCH 2/3] Add circle CI call to new tests --- .circleci/config.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5effc0bb2..cc6bd8d82 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -82,6 +82,9 @@ jobs: - run: name: Test - HTML sanitization command: npm run test:safehtml + - run: + name: Test - Helpers + command: npm run test:helpers - run: name: Test - Coverage command: npm run test:coverage From 7a864b319fc00e8053198e0cc31fe522dc33ca5d Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Tue, 22 Sep 2026 20:14:12 -0400 Subject: [PATCH 3/3] Clean up spaces/tabs for legibility --- tests/html/helpers.test.js | 158 +++++++++++++++++-------------------- 1 file changed, 74 insertions(+), 84 deletions(-) diff --git a/tests/html/helpers.test.js b/tests/html/helpers.test.js index 13560442a..a81a62173 100644 --- a/tests/html/helpers.test.js +++ b/tests/html/helpers.test.js @@ -18,94 +18,30 @@ const emoji = 'df_d12_2'; const brewSnippetsThemeTest = [ { name : 'Test Theme', - snippets : dedent `\snippet First Theme Snippet -I am the first theme snippet! + snippets : dedent ` + \snippet First Theme Snippet + I am the first theme snippet! -\snippet Second Theme Snippet -I am the second theme Snippet! - -`, + \snippet Second Theme Snippet + I am the second theme Snippet!`, } ]; const brewSnippetsBrewTest = dedent` -\snippet First Brew Snippet -I am the first brew snippet! + \snippet First Brew Snippet + I am the first brew snippet! -\snippet Second Brew Snippet -I am the second brew Snippet! + \snippet Second Brew Snippet + I am the second brew Snippet!`; -`; - -describe(`Helper function tests`, ()=>{ - it('brewSnippetsToJSON without theme snippets', function() { +describe(`brewSnippetsToJSON`, ()=>{ + it('converts raw brew snippets without theme snippets to JSON', function() { const testMenuObject = { groupName : 'Brew Snippets', - icon : 'fas fa-th-list', - snippets : [ - { - name : 'Test Snippets JSON without theme snippets', - subsnippets : [ - { - gen : 'I am the first brew snippet!\n', - name : 'First Brew Snippet' - }, { - gen : 'I am the second brew Snippet!', - name: 'Second Brew Snippet' - } - ] - } - ], - view : 'text' - }; - const rendered = brewSnippetsToJSON(`Test Snippets JSON without theme snippets`, brewSnippetsBrewTest, null, true); - expect(rendered, `Input:\n${brewSnippetsBrewTest}\n${brewSnippetsThemeTest}`, { showPrefix: false }).toStrictEqual(testMenuObject); - }); - - it('brewSnippetsToJSON with theme snippets', function() { - const testMenuObject = { - groupName : 'Brew Snippets', - icon : 'fas fa-th-list', - snippets : [ - { - gen : '', - icon : '', - name : 'Test Theme', - subsnippets : [ - { - gen : 'I am the first theme snippet!\n', - icon : '', - name : 'First Theme Snippet', - }, - { - gen : 'I am the second theme Snippet!', - icon : '', - name : 'Second Theme Snippet', - }, - ], - }, - { - name : 'Test Snippets JSON without theme snippets', - subsnippets : [ - { - gen : 'I am the first brew snippet!\n', - name : 'First Brew Snippet' - }, { - gen : 'I am the second brew Snippet!', - name: 'Second Brew Snippet' - } - ] - } - ], - view : 'text' - }; - const rendered = brewSnippetsToJSON(`Test Snippets JSON without theme snippets`, brewSnippetsBrewTest, brewSnippetsThemeTest, true); - expect(rendered, `Input:\n${brewSnippetsBrewTest}\n${brewSnippetsThemeTest}`, { showPrefix: false }).toStrictEqual(testMenuObject); - }); - - it('Yaml SnippetstoText ', function() { - const brewSnippetsBrewTestAsYAML = [ - { + icon : 'fas fa-th-list', + view : 'text', + snippets : [{ + name : 'Test Snippets JSON without theme snippets', subsnippets : [ { gen : 'I am the first brew snippet!\n', @@ -114,11 +50,65 @@ describe(`Helper function tests`, ()=>{ gen : 'I am the second brew Snippet!', name: 'Second Brew Snippet' } - ] - } - ]; - const rendered = yamlSnippetsToText(brewSnippetsBrewTestAsYAML); - expect(rendered, `Input:\n${brewSnippetsBrewTestAsYAML}\n`, { showPrefix: false }).toBe(`${brewSnippetsBrewTest}\n`); + ]}] + }; + const rendered = brewSnippetsToJSON(`Test Snippets JSON without theme snippets`, brewSnippetsBrewTest, null, true); + expect(rendered).toStrictEqual(testMenuObject); }); + it('converts raw brew snippets with theme snippets to JSON', function() { + const testMenuObject = { + groupName : 'Brew Snippets', + icon : 'fas fa-th-list', + view : 'text', + snippets : [{ + gen : '', + icon : '', + name : 'Test Theme', + subsnippets : [ + { + gen : 'I am the first theme snippet!\n', + icon : '', + name : 'First Theme Snippet', + }, + { + gen : 'I am the second theme Snippet!', + icon : '', + name : 'Second Theme Snippet', + }, + ]}, + { + name : 'Test Snippets JSON with theme snippets', + subsnippets : [ + { + gen : 'I am the first brew snippet!\n', + name : 'First Brew Snippet' + }, + { + gen : 'I am the second brew Snippet!', + name: 'Second Brew Snippet' + } + ] + }]}; + const rendered = brewSnippetsToJSON(`Test Snippets JSON with theme snippets`, brewSnippetsBrewTest, brewSnippetsThemeTest, true); + expect(rendered).toStrictEqual(testMenuObject); + }); +}); + +describe(`YAMLSnippetsToText`, ()=>{ + it('converts brew snippet YAML to a string ', function() { + const brewSnippetsYAML = [{ + subsnippets : [ + { + gen : 'I am the first brew snippet!\n', + name : 'First Brew Snippet' + }, { + gen : 'I am the second brew Snippet!', + name: 'Second Brew Snippet' + } + ] + }]; + const rendered = yamlSnippetsToText(brewSnippetsYAML); + expect(rendered).toBe(`${brewSnippetsBrewTest}\n`); + }); }); \ No newline at end of file