« get me outta code hell

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:
Diffstat (limited to 'test/lib')
-rw-r--r--test/lib/content-function.js30
-rw-r--r--test/lib/wiki-data.js15
2 files changed, 32 insertions, 13 deletions
diff --git a/test/lib/content-function.js b/test/lib/content-function.js
index a46d18c9..49fe5c95 100644
--- a/test/lib/content-function.js
+++ b/test/lib/content-function.js
@@ -11,16 +11,21 @@ import {quickEvaluate} from '#content-function';
 import * as html from '#html';
 import {internalDefaultStringsFile, processLanguageFile} from '#language';
 import {empty} from '#sugar';
-import {generateURLs, thumb, urlSpec} from '#urls';
+
+import {
+  applyLocalizedWithBaseDirectory,
+  generateURLs,
+  internalDefaultURLSpecFile,
+  processURLSpecFromFileSync,
+  thumb,
+} from '#urls';
 
 import mock from './generic-mock.js';
 
 const __dirname = path.dirname(fileURLToPath(import.meta.url));
 
-function cleanURLSpec(reference) {
-  const prepared = structuredClone(reference);
-
-  for (const spec of Object.values(prepared)) {
+function cleanURLSpec(urlSpec) {
+  for (const spec of Object.values(urlSpec)) {
     if (spec.prefix) {
       // Strip out STATIC_VERSION. This updates fairly regularly and we
       // don't want it to affect snapshot tests.
@@ -28,12 +33,23 @@ function cleanURLSpec(reference) {
         .replace(/static-\d+[a-z]\d+/i, 'static');
     }
   }
+}
+
+function urlsPlease() {
+  const {aggregate: urlsAggregate, result: urlSpec} =
+    processURLSpecFromFileSync(internalDefaultURLSpecFile);
+
+  urlsAggregate.close();
+
+  applyLocalizedWithBaseDirectory(urlSpec);
+
+  cleanURLSpec(urlSpec);
 
-  return prepared;
+  return generateURLs(urlSpec);
 }
 
 export function testContentFunctions(t, message, fn) {
-  const urls = generateURLs(cleanURLSpec(urlSpec));
+  const urls = urlsPlease();
 
   t.test(message, async t => {
     let loadedContentDependencies;
diff --git a/test/lib/wiki-data.js b/test/lib/wiki-data.js
index 7c3d2147..f0ee0ef5 100644
--- a/test/lib/wiki-data.js
+++ b/test/lib/wiki-data.js
@@ -1,5 +1,6 @@
 import CacheableObject from '#cacheable-object';
-import find from '#find';
+import find, {bindFind} from '#find';
+import {bindReverse} from '#reverse';
 import {withEntries} from '#sugar';
 import Thing from '#thing';
 import thingConstructors from '#things';
@@ -9,11 +10,13 @@ export function linkAndBindWikiData(wikiData, {
   inferAlbumsOwnTrackData = true,
 } = {}) {
   function customLinkWikiDataArrays(wikiData, options = {}) {
-    linkWikiDataArrays(
-      (options.XXX_decacheWikiData
-        ? withEntries(wikiData, entries => entries
-            .map(([key, value]) => [key, value.slice()]))
-        : wikiData));
+    if (options.XXX_decacheWikiData) {
+      wikiData =
+        withEntries(wikiData, entries => entries
+          .map(([key, value]) => [key, value.slice()]));
+    }
+
+    linkWikiDataArrays(wikiData, {bindFind, bindReverse});
   }
 
   customLinkWikiDataArrays(wikiData);