playwright-msw
playwright-msw copied to clipboard
Behavior of handlers which has same path and different method is not same with MSW.
First, thanks to the contributors.
Because I found a behavior below, I created an issue.
- register below handlers.
import { rest } from 'msw'
const handlers = [
rest.get(`/v1/customer/:id`, (_, res, ctx) => {
return res(ctx.status(200), ctx.json({ id: 'xxx', name: 'Taro' }))
}),
rest.post(`/v1/customer/additionalInfo`, (_, res, ctx) => {
return res(ctx.status(200), ctx.json({ additionalInfoId: 'yyy' }))
}),
]
- access POST /v1/customer/additionalInfo on application with msw -> work. on playwright (with playwright-msw) -> not work
To make it work on playwright, I need to reverse handlers array or overwrite by worker.use on test case. Probably, playwright-msw's routing depends on path only? https://github.com/valendres/playwright-msw/blob/main/packages/playwright-msw/src/router.ts
I suspect this is due to a race condition when registering msw handlers. https://github.com/valendres/playwright-msw/blob/4202f690dadec92324b898c3e209b76257f89641/packages/playwright-msw/src/router.ts#L124-L139
registerMswHandler()
checks to see if there's existing route data, and if not proceeds to initialize it. However, this initialization happens asynchronously (due to L135), so two registrations happening concurrently might both think they're the first and initialize the data.