« get me outta code hell

test: evaluate.snapshot: support description & multiple option - 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-04-04 13:29:37 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-04-04 13:29:37 -0300
commit22032daecb05f55c31fe469ea6070b98c98d7c1d (patch)
treead6b11ad6b7d8b7eede326421cae79f8d96ce985
parenta93d8afa984f3a4cf5ad1064f8e991544b5ebc5d (diff)
test: evaluate.snapshot: support description & multiple option
-rw-r--r--test/lib/content-function.js22
1 files changed, 19 insertions, 3 deletions
diff --git a/test/lib/content-function.js b/test/lib/content-function.js
index a6ff64af..b6177e46 100644
--- a/test/lib/content-function.js
+++ b/test/lib/content-function.js
@@ -65,13 +65,29 @@ export function testContentFunctions(t, message, fn) {
         quickLoadContentDependencies(opts));
     };
 
-    evaluate.snapshot = (opts, fn) => {
+    evaluate.snapshot = (...args) => {
       if (!loadedContentDependencies) {
         throw new Error(`Await .load() before performing tests`);
       }
 
-      const result = (fn ? fn(evaluate(opts)) : evaluate(opts));
-      t.matchSnapshot(result.toString(), 'output');
+      const [description, opts, fn] =
+        (typeof args[0] === 'string'
+          ? args
+          : ['output', ...args]);
+
+      let result = evaluate(opts);
+
+      if (fn) {
+        result = fn(result);
+      }
+
+      if (opts.multiple) {
+        result = result.map(item => item.toString()).join('\n');
+      } else {
+        result = result.toString();
+      }
+
+      t.matchSnapshot(result, description);
     };
 
     evaluate.mock = (...opts) => {