« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--tap-snapshots/test/snapshot/generatePreviousNextLinks.js.test.cjs12
-rw-r--r--test/lib/content-function.js21
2 files changed, 26 insertions, 7 deletions
diff --git a/tap-snapshots/test/snapshot/generatePreviousNextLinks.js.test.cjs b/tap-snapshots/test/snapshot/generatePreviousNextLinks.js.test.cjs
index 07268581..fa641830 100644
--- a/tap-snapshots/test/snapshot/generatePreviousNextLinks.js.test.cjs
+++ b/tap-snapshots/test/snapshot/generatePreviousNextLinks.js.test.cjs
@@ -6,13 +6,13 @@
  */
 'use strict'
 exports[`test/snapshot/generatePreviousNextLinks.js TAP generatePreviousNextLinks (snapshot) > basic behavior 1`] = `
-previous: {"tooltip":true,"color":false,"attributes":{"id":"previous-button"},"content":"Previous"}
-next: {"tooltip":true,"color":false,"attributes":{"id":"next-button"},"content":"Next"}
+previous: { tooltip: true, color: false, attributes: { id: 'previous-button' }, content: 'Previous' }
+next: { tooltip: true, color: false, attributes: { id: 'next-button' }, content: 'Next' }
 `
 
 exports[`test/snapshot/generatePreviousNextLinks.js TAP generatePreviousNextLinks (snapshot) > disable id 1`] = `
-previous: {"tooltip":true,"color":false,"attributes":{"id":false},"content":"Previous"}
-next: {"tooltip":true,"color":false,"attributes":{"id":false},"content":"Next"}
+previous: { tooltip: true, color: false, attributes: { id: false }, content: 'Previous' }
+next: { tooltip: true, color: false, attributes: { id: false }, content: 'Next' }
 `
 
 exports[`test/snapshot/generatePreviousNextLinks.js TAP generatePreviousNextLinks (snapshot) > neither link present 1`] = `
@@ -20,9 +20,9 @@ exports[`test/snapshot/generatePreviousNextLinks.js TAP generatePreviousNextLink
 `
 
 exports[`test/snapshot/generatePreviousNextLinks.js TAP generatePreviousNextLinks (snapshot) > next missing 1`] = `
-previous: {"tooltip":true,"color":false,"attributes":{"id":"previous-button"},"content":"Previous"}
+previous: { tooltip: true, color: false, attributes: { id: 'previous-button' }, content: 'Previous' }
 `
 
 exports[`test/snapshot/generatePreviousNextLinks.js TAP generatePreviousNextLinks (snapshot) > previous missing 1`] = `
-next: {"tooltip":true,"color":false,"attributes":{"id":"next-button"},"content":"Next"}
+next: { tooltip: true, color: false, attributes: { id: 'next-button' }, content: 'Next' }
 `
diff --git a/test/lib/content-function.js b/test/lib/content-function.js
index bb12be82..b706cd8c 100644
--- a/test/lib/content-function.js
+++ b/test/lib/content-function.js
@@ -1,5 +1,6 @@
 import * as path from 'node:path';
 import {fileURLToPath} from 'node:url';
+import {inspect} from 'node:util';
 
 import chroma from 'chroma-js';
 
@@ -99,7 +100,7 @@ export function testContentFunctions(t, message, fn) {
 
         constructor() {
           super({
-            content: () => `${name}: ${JSON.stringify(this.#slotValues)}`,
+            content: () => this.#getContent(this),
           });
         }
 
@@ -110,6 +111,24 @@ export function testContentFunctions(t, message, fn) {
         setSlot(slotName, slotValue) {
           this.#slotValues[slotName] = slotValue;
         }
+
+        #getContent() {
+          const toInspect =
+            Object.fromEntries(
+              Object.entries(this.#slotValues)
+                .filter(([key, value]) => value !== null));
+
+          const inspected =
+            inspect(toInspect, {
+              breakLength: Infinity,
+              colors: false,
+              compact: true,
+              depth: Infinity,
+              sort: true,
+            });
+
+          return `${name}: ${inspected}`;
+        }
       });
     };