From bbda4d2857c8cf99347f648ed056d1e112842205 Mon Sep 17 00:00:00 2001 From: Peter Keffer <8448727+PeterKeffer@users.noreply.github.com> Date: Sun, 21 Dec 2025 13:15:57 +0000 Subject: [PATCH] fix(tests): improve comments test stability and CI compatibility - Use delete for Python env vars instead of empty string assignment - Make integration tests opt-in via RUN_INTEGRATION_TESTS=1 env var - Fix regex null coalescing for author matching in tests --- CHANGELOG.md | 5 +++++ src/__tests__/comments.test.ts | 17 +++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0b4418..81b3079 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add Claude Code settings (.claude/, CLAUDE.md) to .gitignore - Add development guideline to always update CHANGELOG.md - Move integration test scripts to `tests/` directory for cleaner root +- Comments integration tests are now opt-in via `RUN_INTEGRATION_TESTS=1` env var for CI stability + +### Fixed +- Fixed comments test Python environment handling (use `delete` instead of empty string assignment) +- Fixed regex null coalescing in comments test for author matching --- diff --git a/src/__tests__/comments.test.ts b/src/__tests__/comments.test.ts index 6d9249a..94893ea 100644 --- a/src/__tests__/comments.test.ts +++ b/src/__tests__/comments.test.ts @@ -5,11 +5,14 @@ import { getVideoComments, getVideoCommentsSummary } from '../modules/comments.j import type { CommentsResponse } from '../modules/comments.js'; import { CONFIG } from '../config.js'; -// Set Python environment -process.env.PYTHONPATH = ''; -process.env.PYTHONHOME = ''; +// Clear Python environment to avoid yt-dlp issues +delete process.env.PYTHONPATH; +delete process.env.PYTHONHOME; -describe('Video Comments Extraction', () => { +// Integration tests require network access - opt-in via RUN_INTEGRATION_TESTS=1 +const RUN_INTEGRATION = process.env.RUN_INTEGRATION_TESTS === '1'; + +(RUN_INTEGRATION ? describe : describe.skip)('Video Comments Extraction', () => { // Using a popular video that should have comments enabled const testUrl = 'https://www.youtube.com/watch?v=jNQXAC9IVRw'; @@ -93,10 +96,8 @@ describe('Video Comments Extraction', () => { const summary = await getVideoCommentsSummary(testUrl, 3, CONFIG); // Count occurrences of "Author:" to verify number of comments - const authorMatches = summary.match(/Author:/g); - if (authorMatches) { - expect(authorMatches.length).toBeLessThanOrEqual(3); - } + const authorMatches = summary.match(/Author:/g) ?? []; + expect(authorMatches.length).toBeLessThanOrEqual(3); }, 60000); test('should throw error for invalid URL', async () => {