Files
discordeno/packages/rest/tests/e2e/utils.ts
Fleny 27c261fee2 formatter: Use semicolons (#4686)
I prefer semicolors, they also help avoiding certain pitfalls in JavaScript/TypeScript, such as the following code sample:
```js
const xyz = "test"
(something.else as string) = "another"
```
This results in a TypeError: "test" is not a function, this is because js thinks we are trying to call the string "test" as a function.
To fix this it requires a `;` somewhere before the `(`, such as `;(something ... ` which in my opinion is ugly and less clean overall.
2026-01-17 21:54:15 +01:00

53 lines
1.3 KiB
TypeScript

import { after } from 'mocha';
import { createRestManager } from '../../src/manager.js';
import { E2E_TEST_GUILD_ID, token } from './constants.js';
// For debugging purposes
// logger.setLevel(LogLevels.Debug)
export const rest = createRestManager({
token,
});
rest.deleteQueueDelay = 10000;
const guild = await rest.getGuild(E2E_TEST_GUILD_ID);
if (!guild) throw new Error('E2E_TEST_GUILD_ID does not exist or is not accessible.');
const channel = await rest.createChannel(guild.id, {
name: 'discordeno-e2e',
});
after(async () => {
// Clean up the channel created for testing
if (channel.id) {
await rest.deleteChannel(channel.id);
}
});
export const e2eCache = {
guildId: E2E_TEST_GUILD_ID,
guild,
channel,
};
// Some resources created during tests need to be disposed of afterwards, as they will persist otherwise (e.g., emojis, roles, automod rules)
export const toDispose = new Set<() => Promise<void>>();
afterEach(async () => {
let aggregateError: AggregateError | null = null;
for (const dispose of toDispose) {
try {
await dispose();
} catch (error) {
console.error('Error during cleanup:', error);
aggregateError ??= new AggregateError([], 'Errors occurred during cleanup');
aggregateError.errors.push(error);
}
}
toDispose.clear();
if (aggregateError) throw aggregateError;
});