Thanks to visit codestin.com
Credit goes to github.com

Skip to content

It's currently not possible to write e2e tests for Application Commands #29

@TomerRon

Description

@TomerRon

Background

Currently e2e tests are done by creating 2 clients:

  • One client is a cordless bot, initialized as normal with init()
  • Another client is a simple discord.js client that pretends to be a real user

In the e2e tests, these two clients "talk" to each other - for example, we subscribe the cordless bot to a messageCreate event with a condition of message.content === 'ping', and test the function callbacks by having the "fake user" send a ping message and assert that the cordless bot responded with a pong.

Problem

With the introduction of Application Commands, it's not possible to test them with a bot pretending to be a user. This is because Bots can not interact with other Bots through commands.

For example, we might register a /ping command in the cordless bot. When the "fake user" sends /ping, it will simply send it as a message and not create the interaction. So it is not possible to assert that the command works.

Solution

Not really sure at the moment.

We could probably simulate a browser and login into a "real" user (with Cypress for example), but that would be cumbersome and definitely against the Discord ToS, so that's not a viable option.

Another option might be to query the Discord API to get back information about the bot's commands. We can create snapshots of the JSON response for different scenarios (e.g., no commands registered, simple commands, commands with options, etc). That still won't let us test the command handling itself (and anything involved in the process, like interactive buttons and how they are handled), but at least we can assert that the commands are registered properly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions