Open kevinlul opened 1 year ago
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.
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.
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. https://github.com/discordjs/discord.js/pull/7693 some other Discord.js dev test https://github.com/discordjs/discord.js/discussions/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