« get me outta code hell

data steps: more "quick" functions & basic snapshot test demo - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/test
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-03-25 15:00:01 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-03-25 15:05:30 -0300
commitd1e586bd401a6d83ecabafb3b833a5ae65b6e05f (patch)
tree81a97f0f678f9618ed0a66d1e5ef9d35dbf79a2a /test
parentfc5d4d057b1e18e3e5c91bce1ddb545bc9d91db9 (diff)
data steps: more "quick" functions & basic snapshot test demo
Diffstat (limited to 'test')
-rw-r--r--test/snapshots/_support.js55
-rw-r--r--test/snapshots/linkArtist.js26
2 files changed, 81 insertions, 0 deletions
diff --git a/test/snapshots/_support.js b/test/snapshots/_support.js
new file mode 100644
index 0000000..b51f284
--- /dev/null
+++ b/test/snapshots/_support.js
@@ -0,0 +1,55 @@
+import {quickEvaluate} from '../../src/content-function.js';
+import {quickLoadContentDependencies} from '../../src/content/dependencies/index.js';
+
+import chroma from 'chroma-js';
+import * as html from '../../src/util/html.js';
+import urlSpec from '../../src/url-spec.js';
+import {getColors} from '../../src/util/colors.js';
+import {generateURLs} from '../../src/util/urls.js';
+
+export function testContentFunctions(t, message, fn) {
+  const urls = generateURLs(urlSpec);
+
+  t.test(message, async t => {
+    const loadedContentDependencies = await quickLoadContentDependencies();
+
+    const evaluate = ({
+      from = 'localized.home',
+      contentDependencies = {},
+      extraDependencies = {},
+      ...opts
+    }) => {
+      const {to} = urls.from(from);
+
+      try {
+        return quickEvaluate({
+          ...opts,
+          contentDependencies: {
+            ...contentDependencies,
+            ...loadedContentDependencies,
+          },
+          extraDependencies: {
+            html,
+            to,
+            urls,
+            appendIndexHTML: false,
+            getColors: c => getColors(c, {chroma}),
+            ...extraDependencies,
+          },
+        });
+      } catch (error) {
+        if (error instanceof AggregateError) {
+          error = new Error(`AggregateError: ${error.message}\n${error.errors.map(err => `** ${err}`).join('\n')}`);
+        }
+        throw error;
+      }
+    };
+
+    evaluate.snapshot = (opts, fn) => {
+      const result = (fn ? fn(evaluate(opts)) : evaluate(opts));
+      t.matchSnapshot(result.toString(), 'output');
+    };
+
+    return fn(t, evaluate);
+  });
+}
diff --git a/test/snapshots/linkArtist.js b/test/snapshots/linkArtist.js
new file mode 100644
index 0000000..43fee88
--- /dev/null
+++ b/test/snapshots/linkArtist.js
@@ -0,0 +1,26 @@
+import t from 'tap';
+
+import {testContentFunctions} from './_support.js';
+
+testContentFunctions(t, 'linkArtist', (t, evaluate) => {
+  evaluate.snapshot({
+    name: 'linkArtist',
+    args: [
+      {
+        name: `Toby Fox`,
+        directory: `toby-fox`,
+      }
+    ],
+  });
+
+  evaluate.snapshot({
+    name: 'linkArtist',
+    args: [
+      {
+        name: 'ICCTTCMDMIROTMCWMWFTPFTDDOTARHPOESWGBTWEATFCWSEBTSSFOFG',
+        nameShort: '55gore',
+        directory: '55gore',
+      },
+    ],
+  }, v => v.slot('preferShortName', true));
+});