« get me outta code hell

infra, test: cleaner output for stubTemplate - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-09-05 19:03:44 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-09-05 20:11:18 -0300
commitddaf34d6e97269719107398569716fc1f1e98073 (patch)
tree2d9d455afd39ea4387c4770ef79c70f6d417944e
parentd194fc4f537ee79b0558b54ff2e1fdc3e9cbf4d9 (diff)
infra, test: cleaner output for stubTemplate
-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}`;
+        }
       });
     };