Skip to content

fix(#304): テスト実行時のNODE_ENV分離とenv.test.ts環境変数クリーンアップ#320

Merged
Kewton merged 3 commits intodevelopfrom
feature/304-worktree
Feb 19, 2026
Merged

fix(#304): テスト実行時のNODE_ENV分離とenv.test.ts環境変数クリーンアップ#320
Kewton merged 3 commits intodevelopfrom
feature/304-worktree

Conversation

@Kewton
Copy link
Owner

@Kewton Kewton commented Feb 19, 2026

Summary

  • package.json の6つのテストスクリプトに NODE_ENV=test プレフィックスを追加し、シェル環境の NODE_ENV=production 残留によるUIテスト全滅を防止
  • tests/unit/env.test.tscleanEnvVars() ヘルパーを追加し、.env ファイル由来の環境変数汚染による9テスト失敗を修正
  • tests/unit/lib/worktree-path-validator.test.tsALLOWED_WORKTREE_PATHS のdelete処理を追加

Changes

対策1: package.json テストスクリプト修正

  • test, test:ui, test:coverage, test:unit, test:integration, test:watchNODE_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 passed
  • NODE_ENV=production npm run test:integration → passed
  • NODE_ENV=test npx vitest run tests/unit/env.test.ts → 25/25 passed
  • npx tsc --noEmit → 0 errors
  • npm run lint → 0 errors

Closes #304

🤖 Generated with Claude Code

Kewton and others added 3 commits February 20, 2026 01:41
…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>
@Kewton Kewton merged commit bc6bd9a into develop Feb 19, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant