fix(#304): テスト実行時のNODE_ENV分離とenv.test.ts環境変数クリーンアップ#320
Merged
Conversation
…tests - Add NODE_ENV=test prefix to 6 test scripts in package.json (test, test:ui, test:coverage, test:unit, test:integration, test:watch) to prevent production React build from being used during tests - Add cleanEnvVars() helper to env.test.ts that removes CM_*/MCBD_*/ DATABASE_PATH env vars in beforeEach of 7 describe blocks - Add delete process.env.ALLOWED_WORKTREE_PATHS to worktree-path-validator test beforeEach for environment isolation - Confirmed db-migration-path.test.ts already has proper cleanup (no change) Resolves #304 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…v.test.ts Extract duplicated test setup/teardown into file-level beforeEach/afterEach hooks, eliminating 7 repeated const originalEnv declarations, 7 identical afterEach blocks, and 7 near-identical common setup patterns. Each describe block now only declares its own specific reset calls (resetWarnedKeys, resetDatabasePathWarning) in a nested beforeEach. Improvements: - Remove ~90 lines of duplicated boilerplate - Apply DRY principle to test setup/teardown - Maintain all 25 existing test cases unchanged Quality Metrics: - Tests: 25/25 passed (including NODE_ENV=production) - TypeScript errors: 0 - ESLint errors: 0 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
package.jsonの6つのテストスクリプトにNODE_ENV=testプレフィックスを追加し、シェル環境のNODE_ENV=production残留によるUIテスト全滅を防止tests/unit/env.test.tsにcleanEnvVars()ヘルパーを追加し、.envファイル由来の環境変数汚染による9テスト失敗を修正tests/unit/lib/worktree-path-validator.test.tsにALLOWED_WORKTREE_PATHSのdelete処理を追加Changes
対策1: package.json テストスクリプト修正
test,test:ui,test:coverage,test:unit,test:integration,test:watchにNODE_ENV=testプレフィックス追加test:e2eはPlaywright/ブラウザ環境のためスコープ外対策2: テストファイルの環境変数分離
env.test.ts:ENV_VARS_TO_CLEAN定数 +cleanEnvVars()関数をファイルレベルのbeforeEach/afterEachに集約(リファクタリングで55行削減)worktree-path-validator.test.ts:delete process.env.ALLOWED_WORKTREE_PATHS追加db-migration-path.test.ts: 既存のdelete process.env.DATABASE_PATHで十分 → 変更不要Test plan
NODE_ENV=production npm run test:unit→ 3618 passedNODE_ENV=production npm run test:integration→ passedNODE_ENV=test npx vitest run tests/unit/env.test.ts→ 25/25 passednpx tsc --noEmit→ 0 errorsnpm run lint→ 0 errorsCloses #304
🤖 Generated with Claude Code