Testing your configuration
App-Compose checks the configuration on every .run():
- the same Task added twice
- two Wires writing into the same Tag
- a Task reading from a Tag that’s never wired
- an unused Wire
“Same” means the same instance, not the same name.
.guard() runs the same check stricter, in a test: unused Wires throw instead of warning. All others throw in both.
Guard reports the first error it finds — fix and re-run to see the next.
Writing the test
Section titled “Writing the test”In any test framework, call .guard() and assert it doesn’t throw.
import { createWire, literal, compose, tag, createTask } from "@grlt-hub/app-compose"
const apiUrl = tag("apiUrl")
const auth = createTask({ name: "auth", run: { context: { url: apiUrl.value }, fn: ({ url }) => ({ token: "secret", url }), },})
const dashboard = createTask({ name: "dashboard", run: { context: { token: auth.result.token }, fn: ({ token }) => console.log(`token=${token}`), },})
const orphanTag = tag("orphan")
const app = compose() // 👇 comment out — apiUrl never gets wired .step(createWire({ from: literal("<url>"), to: apiUrl }))
// 👇 uncomment — apiUrl wired twice // .step(createWire({ from: literal("<other-url>"), to: apiUrl }))
.step(auth)
// 👇 uncomment — auth registered twice // .step(auth)
// 👇 uncomment — orphan Wire (nothing reads it) // .step(createWire({ from: literal(null), to: orphanTag }))
.step(dashboard)
describe("app configuration", () => { it("is valid", () => { expect(() => app.guard()).not.toThrow() })})