From 90b0f3ebb163e05aa47aec66bf16ddaa03739546 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 31 Mar 2026 19:53:51 -0300 Subject: test: move lib functions into one (short!) file --- test/lib/composite.js | 33 ---------------- test/lib/index.js | 4 -- test/lib/strict-match-error.js | 50 ------------------------ test/test-lib.js | 86 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 86 insertions(+), 87 deletions(-) delete mode 100644 test/lib/composite.js delete mode 100644 test/lib/index.js delete mode 100644 test/lib/strict-match-error.js create mode 100644 test/test-lib.js (limited to 'test') diff --git a/test/lib/composite.js b/test/lib/composite.js deleted file mode 100644 index 359d364d..00000000 --- a/test/lib/composite.js +++ /dev/null @@ -1,33 +0,0 @@ -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 deleted file mode 100644 index 657bfe78..00000000 --- a/test/lib/index.js +++ /dev/null @@ -1,4 +0,0 @@ -Error.stackTraceLimit = Infinity; - -export * from './composite.js'; -export * from './strict-match-error.js'; diff --git a/test/lib/strict-match-error.js b/test/lib/strict-match-error.js deleted file mode 100644 index e3b36e93..00000000 --- a/test/lib/strict-match-error.js +++ /dev/null @@ -1,50 +0,0 @@ -export function strictlyThrows(t, fn, pattern) { - const error = catchErrorOrNull(fn); - - t.currentAssert = strictlyThrows; - - if (error === null) { - t.fail(`expected to throw`); - return; - } - - const nameAndMessage = `${pattern.constructor.name} ${pattern.message}`; - t.match( - prepareErrorForMatch(error), - prepareErrorForMatch(pattern), - (pattern instanceof AggregateError - ? `expected to throw: ${nameAndMessage} (${pattern.errors.length} error(s))` - : `expected to throw: ${nameAndMessage}`)); -} - -function prepareErrorForMatch(error) { - if (error instanceof RegExp) { - return { - message: error, - }; - } - - if (!(error instanceof Error)) { - return error; - } - - const matchable = { - name: error.constructor.name, - message: error.message, - }; - - if (error instanceof AggregateError) { - matchable.errors = error.errors.map(prepareErrorForMatch); - } - - return matchable; -} - -function catchErrorOrNull(fn) { - try { - fn(); - return null; - } catch (error) { - return error; - } -} diff --git a/test/test-lib.js b/test/test-lib.js new file mode 100644 index 00000000..a12974cd --- /dev/null +++ b/test/test-lib.js @@ -0,0 +1,86 @@ +import {compositeFrom} from '#composite'; + +Error.stackTraceLimit = Infinity; + +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); + }; +} + +export function strictlyThrows(t, fn, pattern) { + const error = catchErrorOrNull(fn); + + t.currentAssert = strictlyThrows; + + if (error === null) { + t.fail(`expected to throw`); + return; + } + + const nameAndMessage = `${pattern.constructor.name} ${pattern.message}`; + t.match( + prepareErrorForMatch(error), + prepareErrorForMatch(pattern), + (pattern instanceof AggregateError + ? `expected to throw: ${nameAndMessage} (${pattern.errors.length} error(s))` + : `expected to throw: ${nameAndMessage}`)); +} + +function prepareErrorForMatch(error) { + if (error instanceof RegExp) { + return { + message: error, + }; + } + + if (!(error instanceof Error)) { + return error; + } + + const matchable = { + name: error.constructor.name, + message: error.message, + }; + + if (error instanceof AggregateError) { + matchable.errors = error.errors.map(prepareErrorForMatch); + } + + return matchable; +} + +function catchErrorOrNull(fn) { + try { + fn(); + return null; + } catch (error) { + return error; + } +} -- cgit 1.3.0-6-gf8a5