Skip to content

Add Jest tests for musicutils.js to address zero test coverage#6470

Open
swapnachoudhary43 wants to merge 11 commits intosugarlabs:masterfrom
swapnachoudhary43:test/musicutils-jest-coverage
Open

Add Jest tests for musicutils.js to address zero test coverage#6470
swapnachoudhary43 wants to merge 11 commits intosugarlabs:masterfrom
swapnachoudhary43:test/musicutils-jest-coverage

Conversation

@swapnachoudhary43
Copy link
Copy Markdown
Contributor

@swapnachoudhary43 swapnachoudhary43 commented Apr 1, 2026

What this PR does

Adds proper Jest test coverage for js/utils/musicutils.js

Background

musicutils.js is one of the largest and most critical files in the
codebase (4427 lines) containing core music utility functions —
MUSICALMODES, PITCHES, key signature logic, and interval calculations.
Without any test coverage, regressions in these functions enter
production silently.

What this adds

Updated file js/utils/tests/musicutils.test.js covering:

  • Real imports of exported functions and constants
  • MUSICALMODES validation (major, minor, chromatic, ionian, aeolian)
  • _calculate_pitch_number with enharmonic consistency checks
  • getPitchInfo for string and numeric inputs
  • setOctaveRatio / getOctaveRatio behavior
  • reducedFraction with correct string output assertions
  • NOTESSHARP and NOTESFLAT array validation
  • isInt and noteIsSolfege utility checks

Changes made

  • Removed unrelated files (tempCodeRunnerFile.js, themes.css)
  • Replaced string-based file assertions with real function imports
  • Tests now validate actual exported behavior, not just file contents

Tests

All 349 tests pass.
Full suite: 1 suite passing, 0 failures.

Related

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

✅ All Jest tests passed! This PR is ready to merge.

@mahesh-09-12
Copy link
Copy Markdown
Contributor

@swapnachoudhary43 I had pointed out earlier about unrelated files, they're still present here, so please clean those up first. Also, the 0% coverage claim doesn't match what I'm seeing locally for musicutils.js, so it would be good to re-check how coverage was measured before adding more tests.

@Chaitu7032
Copy link
Copy Markdown
Contributor

@swapnachoudhary43

Please keep this PR focused on musicutils.js tests, remove the accidental temp file, and replace string-based assertions with tests that actually import and validate the exported behavior of musicutils.js functions/constants.

@Ashutoshx7
Copy link
Copy Markdown
Contributor

Unrelated changes in the pr
please remove it

Remove tempCodeRunnerFile.js from PR
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 4, 2026

✅ All Jest tests passed! This PR is ready to merge.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 4, 2026

✅ All Jest tests passed! This PR is ready to merge.

1 similar comment
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 4, 2026

✅ All Jest tests passed! This PR is ready to merge.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 4, 2026

✅ All Jest tests passed! This PR is ready to merge.

@github-actions github-actions bot added tests Adds or updates test coverage size/XL Extra large: 500-999 lines changed area/javascript Changes to JS source files area/css Changes to CSS/SASS style files area/tests Changes to test files labels Apr 4, 2026
Copy link
Copy Markdown
Contributor

@mahesh-09-12 mahesh-09-12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@swapnachoudhary43 this PR includes unrelated files and commits, since the goal is to add tests for musicutils.js, the diff should be scoped only to that, please clean up the history and remove unrelated changes.
and also it looks like some of these tests already exist or overlap with current coverage. Can you clarify what new behavior is actually being tested here?

@github-actions github-actions bot added size/XXL XXL: 1000+ lines changed and removed size/XL Extra large: 500-999 lines changed labels Apr 5, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 5, 2026

✅ All Jest tests passed! This PR is ready to merge.

Copy link
Copy Markdown
Contributor

@vanshika2720 vanshika2720 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @swopnachoudhary43! While testing #6471, I found an issue in noteToPitchOctave it doesn’t handle multi-digit octaves (e.g., C10) or double sharps (e.g., Cx4).
To make this PR more robust, it would be great to switch to _parse_pitch_string and export core constants like A0 and SOLFEGECONVERSIONTABLE for better edge-case coverage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/css Changes to CSS/SASS style files area/javascript Changes to JS source files area/tests Changes to test files size/XXL XXL: 1000+ lines changed tests Adds or updates test coverage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]musicutils.js has zero Jest test coverage — regression risk for core music functions

5 participants