test(startup): add startup test for missing DISCORD_TOKEN

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

View File

@ -3,9 +3,10 @@
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"scripts": {
"start": "node src/index.js",
"test": "jest"
},
"keywords": [],
"author": "",
"license": "ISC",
@ -14,5 +15,8 @@
"dotenv": "^16.5.0",
"erela.js": "^2.4.0",
"winston": "^3.17.0"
},
"devDependencies": {
"jest": "^29.7.0"
}
}

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/);
});
});