Skip to docs content
Browse documentation
On this page

Test the workflow

One test covers one workflow: the setup, the actions, and assertions checked against something the code doesn't share.

One test is one workflow: the setup, the actions, and the assertions that prove it worked. Each assertion needs an independent oracle, something the production code doesn't share. A test that compares a constant with itself proves nothing.

Example

Minion's GitHub webhook test follows a delivery end to end. It publishes a package, mints a webhook URL, sends a correctly signed push, sends the same delivery again, drains the queue, then checks the run, the delivery record, the webhook.received event and the usage counter:

test('a signed push runs the export once, as a webhook run, and emits webhook.received', async () => {
    await publish('watcher', 'export default async function main(e) { return e.payload.webhook }', { subscriptions: { 'webhook.received': { filters: { webhook: 'github' } } } })
    const hook = await minted('gh', SRC, GITHUB)
    const body = JSON.stringify({ ref: 'refs/heads/main' })
    const headers = { 'x-github-event': 'push', 'x-github-delivery': 'd-1', 'x-hub-signature-256': githubSig(hook.signingSecret!, body), authorization: 'Bearer nope' }

The signature is computed in the test, not borrowed from the code under test. If verification changes, the test notices.

Rules

  • Inline the setup. Avoid shared mutable state between tests.
  • Don't pin exported constants, copy the production helper, or check what the type system already guarantees.
  • Assert that something is absent only on a path that could still show it.
  • Unit tests for logic. A few end-to-end flows for paths users depend on. No .only or .skip in a commit.

In your packages

Test a package the way Minion runs it: call the export from execute with a realistic input (or minion.jobs.runNow for a job), then check what it wrote or sent with minion.runs.get. For events, use synthetic event dispatch rather than waiting for the real thing.