test(checkout): add dependency-free unit tests that pin the checkout defects

npm test runs node:test on the TypeScript sources with Node's type stripping
(Node 22.14 in the image, Node 24 locally), with no dependencies.

Node, unlike tsc, does not resolve extensionless relative imports. TypeScript
5.2 cannot emit .ts import extensions. tests/unit/support therefore registers
a small resolve hook that appends ".ts" for imports from .ts files.

- pricing, paypal-order, log-format: characterization tests of the current
  output.
- The known defects of
  libretech/mp#67 are tests of the correct
  behaviour, marked todo: null, two-line and price-null addresses and
  deliveries, a deleted product, the payment surcharge missing from the
  breakdown, and in the log line circular JSON, the Basic credentials of an
  axios error, and an Error rendered as {}.
- That the breakdown adds up to the amount holds today, including for the
  subtotals closest to a half cent, so that test is a regular one.

Refs libretech/mp#71
This commit is contained in:
2026-10-08 22:15:57 +02:00
parent 7fd4aeff17
commit cbcc54bd75
6 changed files with 361 additions and 0 deletions
+14
View File
@@ -0,0 +1,14 @@
// Module resolve hook, registered by ./register.mjs: `./vat` imported from a .ts file resolves to `./vat.ts`.
export async function resolve(specifier, context, nextResolve) {
try {
return await nextResolve(specifier, context);
} catch (error) {
const relative = specifier.startsWith("./") || specifier.startsWith("../");
if (error?.code !== "ERR_MODULE_NOT_FOUND" || !relative || !context.parentURL?.endsWith(".ts")) throw error;
try {
return await nextResolve(`${specifier}.ts`, context);
} catch {
throw error;
}
}
}