Skip to content

Test an OpenShop app

OpenShop exposes app test helpers from openshop/test.

import { createTestContext } from 'openshop/test'
const ctx = await createTestContext({ accessToken: 'test-access-token' })

The context starts an isolated test app surface and provides fakes, clients, and helpers for signed requests.

ctx.fakes.warehouse.push.returns(undefined)
const result = await ctx.runFlow('syncOrders', { limit: 10 })
assert.equal(result.status, 'completed')
assert.isTrue(ctx.fakes.warehouse.push.called)

The proxy client signs app proxy HMAC parameters automatically:

const res = await ctx.proxy
.get('/reviews')
.asCustomer('123')
.qs({ page: '1' })
.send()

Use ctx.authorizationHeader() to create a signed Shopify session token:

await fetch(`${ctx.url}/api/runs`, {
headers: { Authorization: ctx.authorizationHeader() },
})

Run the template test script:

Terminal window
pnpm run test

Keep tests close to behavior: unit-test pure helpers, and use OpenShop test context for runtime contracts such as signed proxy requests, flow execution, and API authorization.