diff --git a/.env.test b/.env.test new file mode 100644 index 0000000..a5d0f74 --- /dev/null +++ b/.env.test @@ -0,0 +1,24 @@ +# Local Environment Variables (Secrets) +# Copy this file to .env and fill in your actual values +# .env is gitignored and should NEVER be committed + +# Discord Bot Token & Application ID (REQUIRED) +# Get this from: https://discord.com/developers/applications +DISCORD_TOKEN=your-bot-token-here +CLIENT_ID=your-bot-application-id + +# Override any public config values for local testing + +# Discord Server ID (your dev server) +SERVER_ID=your-server-id + +# Channel IDs (from your dev server) +GUIDES_CHANNEL_ID=your-guide-channel-id +REPEL_LOG_CHANNEL_ID=your-repel-log-channel-id + +# Role IDs (from your dev server) +REPEL_ROLE_ID=your-repel-role-id +MODERATORS_ROLE_IDS=your-moderator-role-id + +# Other +GUIDES_TRACKER_PATH=guides-tracker.json \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 147345b..dca8271 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -35,6 +35,9 @@ jobs: - name: Lint run: npm run lint - - name: Build and test - run: npm run test:build + - name: Build + run: npm run build:ci + + - name: Test + run: npm run test:ci diff --git a/.gitignore b/.gitignore index 67b2b83..34cf7ea 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ yarn-error.log* # Public config (committed to repo) !.env.production !.env.example +!.env.test # guides tracker guides-tracker.json diff --git a/package.json b/package.json index ab2589f..5ea1b62 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,6 @@ "build:ci": "npm run build:ts && npm run build:copy", "build:dev": "pnpm run build:ts && pnpm run build:copy", "build:ts": "tsup", - "build:test": "tsup --entry 'src/**/*.ts' --entry 'test/**/*.ts'", "build:copy": "node scripts/copy-assets.js", "start": "node dist/index.js", "dev": "tsx watch src/index.ts", @@ -23,8 +22,7 @@ "check:fix": "biome check --write .", "typecheck": "tsc --noEmit", "test": "pnpm run build:dev && node --test dist/**/*.test.js", - "test:ci": "node --test $(find dist -name '*.test.js')", - "test:build": "npm run build:test && npm run test:ci", + "test:ci": "NODE_ENV=test node --test dist/**/*.test.js", "prepare": "husky", "pre-commit": "lint-staged", "sync-guides": "tsx scripts/sync-guides.js", diff --git a/src/loadEnvFile.ts b/src/loadEnvFile.ts index 793ec4f..ffdcb85 100644 --- a/src/loadEnvFile.ts +++ b/src/loadEnvFile.ts @@ -36,13 +36,16 @@ function loadEnvFile(filePath: string) { const nodeEnv = process.env.NODE_ENV || 'development'; console.log(`🌍 Environment: ${nodeEnv}`); -// Load environment-specific config first (public values, production only) -if (nodeEnv === 'production') { - const envFile = join(process.cwd(), '.env.production'); +const ENV_FILES = { + test: join(process.cwd(), '.env.test'), + production: join(process.cwd(), '.env.production'), + development: join(process.cwd(), '.env'), +}; + +const envFile = ENV_FILES[nodeEnv as keyof typeof ENV_FILES]; +if (envFile) { loadEnvFile(envFile); +} else { + console.error(`❌ Environment file ${nodeEnv} not found`); + process.exit(1); } - -// Load .env file with secrets and local config (overrides public config if any) -// Required for DISCORD_TOKEN and other secrets -const localEnvFile = join(process.cwd(), '.env'); -loadEnvFile(localEnvFile); diff --git a/test/sanity.test.ts b/src/sanity.test.ts similarity index 100% rename from test/sanity.test.ts rename to src/sanity.test.ts