« get me outta code hell

test: quickCheckCompositeOutputs utility function - 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>2024-06-12 17:19:13 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-06-12 17:26:05 -0300
commit78e510bf42ac4b85a7709aaeff13221ecc4bcc90 (patch)
tree79d1c938ad0ca9e06b61cd3142eaf4afa6aa117a /test/lib
parent4978997510906f73f83328caf5927ac4c4268c91 (diff)
test: quickCheckCompositeOutputs utility function
Diffstat (limited to 'test/lib')
-rw-r--r--test/lib/composite.js33
-rw-r--r--test/lib/index.js1
2 files changed, 34 insertions, 0 deletions
diff --git a/test/lib/composite.js b/test/lib/composite.js
new file mode 100644
index 00000000..359d364d
--- /dev/null
+++ b/test/lib/composite.js
@@ -0,0 +1,33 @@
+import {compositeFrom} from '#composite';
+
+export function quickCheckCompositeOutputs(t, dependencies) {
+  return (step, outputDict) => {
+    t.same(
+      Object.keys(step.toDescription().outputs),
+      Object.keys(outputDict));
+
+    const composite = compositeFrom({
+      compose: false,
+      steps: [
+        step,
+
+        {
+          dependencies: Object.keys(outputDict),
+
+          // Access all dependencies by their expected keys -
+          // the composition runner actually provides a proxy
+          // and is checking that *we* access the dependencies
+          // we've specified.
+          compute: dependencies =>
+            Object.fromEntries(
+              Object.keys(outputDict)
+                .map(key => [key, dependencies[key]])),
+        },
+      ],
+    });
+
+    t.same(
+      composite.expose.compute(dependencies),
+      outputDict);
+  };
+}
diff --git a/test/lib/index.js b/test/lib/index.js
index 5fb5bf78..4c9ee23f 100644
--- a/test/lib/index.js
+++ b/test/lib/index.js
@@ -1,5 +1,6 @@
 Error.stackTraceLimit = Infinity;
 
+export * from './composite.js';
 export * from './content-function.js';
 export * from './generic-mock.js';
 export * from './wiki-data.js';