test(startup): add startup test for missing DISCORD_TOKEN

This commit is contained in:
2025-04-23 21:54:52 +08:00
parent 74dfdbf667
commit 47de3823f3
2 changed files with 20 additions and 3 deletions

13
tests/startup.test.js Normal file
View File

@@ -0,0 +1,13 @@
const { spawnSync } = require('child_process');
describe('Bot Startup', () => {
test('exits with code 1 if DISCORD_TOKEN is missing', () => {
// Clear DISCORD_TOKEN
const env = { ...process.env };
delete env.DISCORD_TOKEN;
const result = spawnSync('node', ['src/index.js'], { env, encoding: 'utf-8' });
expect(result.status).toBe(1);
expect(result.stderr || result.stdout).toMatch(/DISCORD_TOKEN is missing/);
});
});