Add unit tests for subtitle timing functions in subtitle-renderer.ts

Open Beginner friendly
#27 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
95/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript
Domain
frontend, testing

Research direction

Start by reading frontend/src/engine/subtitle-renderer.ts and the three specified functions, then follow the test setup in CONTRIBUTING.md. Create frontend/src/engine/subtitle-renderer.test.ts with the listed timing, fallback, skip, window, and boundary cases. Run npx vitest run src/engine/subtitle-renderer.test.ts; the test should pass without changes to production code.

Written by the indexing model from the issue text.

Description

engine good first issue testing
Context

Every MP4 the app exports burns captions in using these three pure functions, and none of them is tested. wordTimingsFromChunks is what lines captions up with real Whisper timestamps on the audio-to-video flow (one of the flows the ROADMAP lists as proven), so a regression here silently desyncs captions.

Where
  • frontend/src/engine/subtitle-renderer.ts:128-158: wordTimingsFromChunks(chunks, fallbackWordDuration)
  • :161-180: generateWordTimings(text, start, duration)
  • :183-208: getCurrentSubtitleText(timings, t, windowSize)
  • The file has no imports, so it can be tested directly
What to do

Create src/engine/subtitle-renderer.test.ts covering:

  1. generateWordTimings: empty or whitespace text → []; words split evenly; the last endTime === start + duration.
  2. wordTimingsFromChunks: normal chunks; a chunk with a null/NaN end falls back to words * fallbackWordDuration; a missing start continues from the previous chunk's end; empty-text chunks are skipped.
  3. getCurrentSubtitleText: before the first word → {text:'', activeWordIndex:-1}; a mid-stream window is centred; near the end the window is truncated (record the current behaviour; open a follow-up issue if you think it should backfill).
  4. Boundary: currentTime === endTime belongs to the next word.
Acceptance criteria
  • npx vitest run src/engine/subtitle-renderer.test.ts passes
  • No production code changed, or any change is a separate commit with a test that justifies it
  • Paste the test output in the PR
Getting started

Read CONTRIBUTING.md for dev setup and the quality bar (no facades, evidence before done). Comment here to claim the issue.

Dominant language
TypeScript
Stars
0
Forks
3
Avg merge
1d 4h
Merged PRs (30d)
5

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from BeyondITL/contentine-create

All issues in BeyondITL/contentine-create

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.