From 47de3823f3fe3d954c89177687fde35da7977e10 Mon Sep 17 00:00:00 2001 From: aki Date: Wed, 23 Apr 2025 21:54:52 +0800 Subject: [PATCH] test(startup): add startup test for missing DISCORD_TOKEN --- package.json | 10 +++++++--- tests/startup.test.js | 13 +++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 tests/startup.test.js diff --git a/package.json b/package.json index 2d99eab..13182ec 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/tests/startup.test.js b/tests/startup.test.js new file mode 100644 index 0000000..0e6fe49 --- /dev/null +++ b/tests/startup.test.js @@ -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/); + }); +});