Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing and discord.js #275

Open
kevinlul opened this issue Feb 5, 2023 · 4 comments
Open

Testing and discord.js #275

kevinlul opened this issue Feb 5, 2023 · 4 comments

Comments

@kevinlul
Copy link
Contributor

kevinlul commented Feb 5, 2023

This research applies to Emcee too.

I'm not satisfied with the approach to unit tests right now and how we are doing mocking. Relevant links for now:

From 2021:

Example of unit tests from a Discord.js core dev
https://github.com/skyra-project/skyra/blob/refactor/switch-to-v13/tests/mocks/MockInstances.ts
https://github.com/skyra-project/skyra/blob/main/tests/lib/database/settings/structures/PermissionNodeManager.test.ts
https://github.com/discordjs/discord.js-modules/blob/main/packages/rest/__tests__/RequestHandler.test.ts another one with lower level mocking at nock/msw

2023:
https://github.com/cordejs/corde integration test with a second test bot, but not updated to recent discord.js. We can easily just implement this ourselves. Only works for messages anyway because Discord does not allow bots to send application commands.
discordjs/discord.js#7693 some other Discord.js dev test
discordjs/discord.js#6179 discussion on testing. One sample with a massive amount of mocking.
https://github.com/cherryblossom000/discord.js-mock somebody's attempt in that discussion to create a mocking library, abandoned, only useful for reference if anything

@kevinlul
Copy link
Contributor Author

kevinlul commented Feb 5, 2023

Tests in the main Discord.js package are not automated unit tests. They are manually verified and require connecting to the gateway. With the exception of that cancelled CR and a whole mock server package. @discordjs/rest and @discordjs/ws do have them, but the latter is not employed yet. Sapphire framework has few tests as well.

@kevinlul
Copy link
Contributor Author

kevinlul commented Feb 5, 2023

For REST requests, undici has a native MockAgent because it does not depend on Node.js' HTTP stack. nock can mock parts of this HTTP stack for use with other libraries (node-fetch, got, etc.) but I don't believe it works with HTTP/2.

@kevinlul
Copy link
Contributor Author

kevinlul commented Feb 5, 2023

See nock/nock#1625 and nock/nock#1625

@kevinlul
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant