« get me outta code hell

reorganize test directory layout - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/test/lib
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-03-27 09:59:43 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-03-27 09:59:43 -0300
commitcb13d591c6965dc52d89ec4d1e10558e6b22456b (patch)
treec2e13e0ae7ffc83327a176f40ea4101c9a5fb200 /test/lib
parent789a26aacfd1e9f97a9395f0000b42df35a75bd7 (diff)
reorganize test directory layout
Avoids unsavory "no tests found in _support.js" message
and makes structure match src directory layout more closely
Diffstat (limited to 'test/lib')
-rw-r--r--test/lib/content-function.js55
1 files changed, 55 insertions, 0 deletions
diff --git a/test/lib/content-function.js b/test/lib/content-function.js
new file mode 100644
index 00000000..b51f2847
--- /dev/null
+++ b/test/lib/content-function.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);
+  });
+}