Skip to content

fix: repair four pre-existing failing test suites#65

Merged
natashaannn merged 5 commits into
mainfrom
fix/pre-existing-failing-test-suites
May 9, 2026
Merged

fix: repair four pre-existing failing test suites#65
natashaannn merged 5 commits into
mainfrom
fix/pre-existing-failing-test-suites

Conversation

@natashaannn
Copy link
Copy Markdown
Member

@natashaannn natashaannn commented May 9, 2026

Fix pre-existing failing test suites

Background

Four test suites were failing before this branch was created. All four cover live production features. This PR fixes each one, migrates the misplaced integration test to the correct location per TESTING_STANDARDS.md, and resolves two related test-infrastructure issues found during review.


What was broken and why

CaptionExtractor.test.js

The suite failed to run due to a stale mock path for the youtube-transcript module. Updated the mock target and restructured the beforeEach setup so the HTML-parsing fallback path is exercised by default.

generate-carousel.test.jsimport.meta SyntaxError

generate-carousel.js uses import.meta.url to detect whether it is the CLI entry point. Babel's @babel/plugin-syntax-import-meta only parses import.meta — it leaves it in the CJS output, so Node throws SyntaxError: Cannot use 'import.meta' outside a module at test time.

  • Replaced the syntax-only plugin with babel-plugin-transform-import-meta, which rewrites import.meta.url to require('url').pathToFileURL(__filename).
  • Changed the ESM guard in generate-carousel.js from typeof import.meta !== 'undefined' (un-transformable) to typeof require === 'undefined' so the guard short-circuits at runtime in CJS/Jest before the right-hand side is evaluated.

CarouselGenerator.test.js — six failures from source/test drift

The source was refactored (switched from puppeteer-extra to plain puppeteer, simplified frame-extraction logic, added options to page.goto) but the tests were not updated.

Failure Root cause Fix
initmockBrowser.launch not a function init() calls await import('puppeteer') but only puppeteer-extra was mocked Added jest.mock('puppeteer'); set launch via jest.requireMock in beforeEach
generateCtaSlidefetch not called Source reads thumbnail from thumbnailPath via fs.readFile, not from a URL via fetch Updated test config and assertion to use thumbnailPath / fs.readFile
goto assertion fails Source now calls page.goto(url, { waitUntil: 'load', timeout: 60000 }) Updated assertion to toHaveBeenCalledWith(stringContaining(...), expect.any(Object))
seekAndExtractFrame null crash screenshot() returning null hit elementShot.length before the retry continue Added null guard in CarouselGenerator.js; retries correctly
Wrong error message Expected 'Could not extract video frame'; source throws 'Could not extract a non-blank video frame' Updated expected substring
Stale "video reset / YouTube error" tests Tested reload and hasErrorElements logic removed from source Rewrote to test real current behaviour: null-screenshot retry and video-element-not-found

transcript-caption.test.js — wrong location

The test reads public/transcribe/output/transcript.json from disk — real I/O. Per TESTING_STANDARDS.md, tests with real file I/O belong in tests/integration/, not next to source files. Moved and added the fixture transcript.json it depends on.

tests/setup.js — parallel-Jest ENOENT race

The shared Jest setup had beforeAll/afterAll hooks that created and deleted a test-output/ directory. No test file ever read or wrote to that directory. Under parallel Jest execution this caused a non-deterministic race: one suite's afterAll would delete the directory while another suite's beforeAll was still creating it, producing intermittent ENOENT failures in edit-transcript.test.js. Removed the dead infrastructure entirely.


Files changed

File Change
.babelrc Swap syntax-only plugin → babel-plugin-transform-import-meta transform plugin; restore trailing newline
package.json / package-lock.json Add babel-plugin-transform-import-meta dev dependency
scripts/carousel/generate-carousel.js Replace typeof import.meta guard with typeof require === 'undefined'
scripts/carousel/CarouselGenerator.js Null-guard screenshot() result; fix unused catch bindings
scripts/__tests__/CaptionExtractor.test.js Fix mock path; restructure beforeEach
scripts/__tests__/CarouselGenerator.test.js Align mocks and assertions with current source
scripts/__tests__/generate-carousel.test.js No logic changes — now parses cleanly with the transform plugin
tests/integration/transcript-caption.test.js Moved from scripts/transcript-caption.test.js
tests/setup.js Remove dead test-output/ lifecycle that caused parallel-Jest ENOENT race
public/transcribe/output/transcript.json Fixture for integration test regression cases
remotion/Root.tsx Lint-staged artifact: eslint-disable comment relocated closer to usage (cosmetic, ESLint-clean)
remotion/components/SegmentPlayer.tsx Lint-staged artifact: dead eslint-disable-next-line no-console comments removed; whitespace-only replacement lines cleaned up (ESLint-clean)

Test plan

  • npm test — all 230 tests across all suites pass (2 pre-existing skips)
  • npx tsc --noEmit — no type errors
  • npx eslint --max-warnings=0 on changed files — clean
  • Pre-commit hook runs lint-staged + jest --findRelatedTests without errors

Issues

Closes #64

natashaannn and others added 5 commits May 9, 2026 20:57
- install babel-plugin-transform-import-meta; replace plugin-syntax-import-meta
  so import.meta.url in generate-carousel.js is transformed for CJS/Jest
- guard the typeof import.meta check using typeof require === 'undefined'
  so the ESM branch is invisible to Babel and avoids a runtime SyntaxError
- add jest.mock('puppeteer') so CarouselGenerator.init() dynamic import
  is properly intercepted; update init test assertion accordingly
- update CarouselGenerator seekAndExtractFrame: null-guard screenshot
  result before accessing .length; fix unused catch bindings (catch {} style)
- align test expectations with current source: thumbnailPath vs thumbnailUrl,
  slide-cta.png filename, goto two-arg call, non-blank error message
- rewrite stale seekAndExtractFrame tests to exercise real source paths:
  null-screenshot retry and video-element-not-found error
- migrate transcript-caption.test.js to tests/integration/ (real file I/O)
- add fixture transcript.json for regression tests

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
….tsx; add babelrc EOF newline

SegmentPlayer.tsx: lint-staged eslint --fix auto-removed two dead
eslint-disable-next-line comments but left whitespace-only replacement
lines. Remove those lines entirely.

.babelrc: the babel-plugin-transform-import-meta addition dropped the
trailing newline; restore it.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…etup

tests/setup.js created and deleted a test-output/ directory in
beforeAll/afterAll. No test file ever reads or writes to that directory,
so the setup was dead infrastructure. In parallel Jest execution it
caused a race: one suite's afterAll would delete the directory while
another suite's beforeAll was still running, causing ENOENT failures
non-deterministically across the edit-transcript.test.js suite.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@natashaannn natashaannn merged commit bfc3e8d into main May 9, 2026
1 check passed
@natashaannn natashaannn deleted the fix/pre-existing-failing-test-suites branch May 9, 2026 13:37
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.

Fix pre-existing failing test suites

1 participant