Skip to content
GitHub

findRouteConflicts

function in meocord/testing Since 4.0.0

findRouteConflicts(app: ControllerClass): RouteConflict[]

Finds component patterns that rank equally and can match the same customId, which MeoCord otherwise only warns about at startup.

Use it in a test to keep the warning from reaching production. Patterns rank segment by segment, a literal before a param and then the narrower type, so two collide only with the same literals and equally narrow params at each position, such as {action:close|reopen} and {step:close|confirm}, which both take close; the one listed first runs. Patterns are compared within a component type.

Parameters

NameTypeDescription
appControllerClass

The application class decorated with @MeoCord.

Returns

RouteConflict[]

Each pair of patterns that rank equally and can match the same customId, with its component type.

Examples

TypeScript
import { expect } from 'vitest'

@Controller()
class TicketController {
  @Command('ticket/{action:close|reopen}', CommandType.BUTTON)
  async act(interaction: ButtonInteraction) { await respond(interaction).send('Done.') }
  @Command('ticket/{step:close|confirm}', CommandType.BUTTON)
  async step(interaction: ButtonInteraction) { await respond(interaction).send('Next.') }
}
@MeoCord({ controllers: [TicketController], clientOptions: { intents: [] } })
class App {}
expect(findRouteConflicts(App)).toHaveLength(1)