Remap
An integration names the keys it provides. remap wraps one integration and changes those keys: rename one, lift a nested value to the top, drop one, or add one of your own.
import { initialize, remap } from "@ghostry/harness";
import { integration as externIntegration } from "@ghostry/extern/harnessing";
export const { describe, it, expect } = initialize({
framework,
integrations: [
remap(externIntegration(), {
provides: { mock: ({ provided }) => provided.extern.mock },
}),
],
});Tests now read context.mock, and context.extern is gone.
How it works
provideslists the new keys. A key it doesn't name is dropped, and a key the integration never had is added.- Each new provider gets
provided, the wrapped integration's own context, typed from the integration you passed, with nothing to annotate. It also getsidentityandestablished, like any provider. namerenames the integration itself, which shows up in error messages.
The result is an ordinary integration. Its new keys go through the same checks as any other. The wrapped frame still runs and still establishes what it did, and an integration with no frame still has none. Each of the wrapped integration's providers still runs once per test, however many new keys read from it.
remap composes, so you can remap a remapped integration. A remapping that names no keys provides nothing but still runs the wrapped frame.
Two integrations, one key
initialize throws IntegrationKeyCollisionError when two integrations provide the same key. remap is how you use both: rename one side.
integrations: [
postgres(),
remap(redis(), {
name: "redis (as cache)",
provides: { cache: ({ provided }) => provided.db },
}),
];Give it a name here, so any later error tells the two apart.
Limits
A remap wraps one integration, so a new key can't combine values from two integrations. Read both in the test instead.
