Add JS unit tests and GitHub Actions CI - #4
Merged
Conversation
Extracts timer logic from the inline <script> in index.html into a standalone timer.js that exports formatTime and initTimer for testing. initTimer accepts injectable opts (now, onRestEnd, onExerciseComplete) so tests can control the clock and assert on callbacks without needing a real browser. 20 Jest tests cover: formatTime formatting, set-counter state transitions, rest-timer start/block/reset, exercise completion, and the wall-clock accuracy + background-chime-suppression behaviour. GitHub Actions workflow runs the suite on every push and PR. https://claude.ai/code/session_01NRGYpoWMBRkqdbZsKa887v
There was a problem hiding this comment.
Pull request overview
Extracts the timer logic from the HTML inline script into a standalone JS module that can be unit-tested in Node, adds a Jest test suite, and wires up GitHub Actions CI to run those tests on pushes/PRs.
Changes:
- Added
app/src/main/assets/timer.jscontainingformatTimeandinitTimerwith injectable dependencies for deterministic tests. - Updated
app/src/main/assets/index.htmlto loadtimer.jsand delegate UI behavior toinitTimer. - Added Jest setup (
package.json,package-lock.json), a 20-test suite (tests/timer.test.js), and a CI workflow (.github/workflows/js-tests.yml); updated.gitignorefornode_modules.
Reviewed changes
Copilot reviewed 5 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| app/src/main/assets/timer.js | New extracted timer module with callbacks/clock injection for testability. |
| app/src/main/assets/index.html | Loads the new module and wires DOM events to initTimer methods. |
| tests/timer.test.js | Jest unit tests for formatting and timer state/wall-clock behavior. |
| package.json | Adds Jest as a dev dependency and defines the npm test script/config. |
| package-lock.json | Locks Jest and its dependency graph for reproducible installs. |
| .github/workflows/js-tests.yml | Runs npm ci + npm test in GitHub Actions. |
| .gitignore | Ignores node_modules for the new JS toolchain. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Stringify textContent assignments (TARGET_SETS, setCount) — DOM always coerces to string; being explicit avoids type mismatches in plain-object test mocks and matches real browser behaviour - Close AudioContext after all tones finish to avoid hitting browser limits on concurrent contexts - Store button elements in variables before passing to initTimer so addEventListener calls reuse the same references instead of doing redundant getElementById lookups - Update test expectation for setTotalDisplay to match string '5' https://claude.ai/code/session_01NRGYpoWMBRkqdbZsKa887v
Use Math.ceil instead of Math.round so the rest countdown never hits zero while up to ~0.5s of time still remains. Update makeDom() in tests to match index.html's initial state (timerLabel/resetBtn hidden, timerLabel text set). https://claude.ai/code/session_01RkZzre56VRXz3JYn2v3U4P
Comment on lines
+172
to
+174
| if (typeof module !== 'undefined') { | ||
| module.exports = { formatTime, initTimer }; | ||
| } |
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.
Extracts the timer logic from the inline
<script>inindex.htmlinto a standalonetimer.jsthat can be imported by Jest. Adds 20 tests and a CI workflow.What changed
app/src/main/assets/timer.js— new file with all timer logic (formatTime,initTimer).initTimeraccepts injectable opts (now,onRestEnd,onExerciseComplete) so tests can control the clock and assert on callbacks without a real browser. Exports viamodule.exportswhen running in Node.app/src/main/assets/index.html— inline script replaced with<script src="timer.js">+ a small wiring block that callsinitTimerand attaches event listeners.tests/timer.test.js— 20 Jest tests across three suites:formatTime— boundary and padding casesinitTimerstate — set counting, rest start/block/reset, exercise completion,setConfigrestEndTimeset correctly,timeRemainingderived from clock, rest expiry, foreground chime fires, background chime suppressedpackage.json+package-lock.json— Jest dev dependency.github/workflows/js-tests.yml— runsnpm ci && npm teston every push and PRTest run
https://claude.ai/code/session_01NRGYpoWMBRkqdbZsKa887v
Generated by Claude Code