Add CommonJS exports and tests for functional modules#61
Merged
JorchCortez merged 5 commits intomainfrom Nov 8, 2025
Merged
Conversation
Added CommonJS export support to CopyToClipboard, Marquee, and ReadTime modules for testability. Introduced comprehensive Jest test suites for each module to verify initialization, behavior, and edge cases in a jsdom environment.
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds comprehensive test coverage for three functional modules (ReadTime, Marquee, and CopyToClipboard) and includes a bug fix for null target handling in the CopyToClipboard module.
- Adds Jest test suites with multiple test cases for each module covering various scenarios and edge cases
- Exports classes and initialization functions from each module to enable testing in Node.js environments
- Fixes a potential null reference error when
ctcTargetis missing in CopyToClipboard
Reviewed Changes
Copilot reviewed 3 out of 6 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
__tests__/ReadTime.test.js |
New test suite covering read time calculation scenarios including edge cases for sub-minute, one-minute, and multi-minute content |
__tests__/Marquee.test.js |
New test suite validating marquee initialization, scrolling behavior in both directions, element cycling, and resize handling |
__tests__/CopyToClipboard.test.js |
New test suite testing clipboard copy functionality, text updates, class toggling, and error handling for missing elements |
Dist/Functional/ReadTime.js |
Adds CommonJS module exports wrapped in try-catch for test environment compatibility |
Dist/Functional/Marquee.js |
Adds CommonJS module exports wrapped in try-catch for test environment compatibility |
Dist/Functional/CopyToClipboard.js |
Adds null check for ctcTarget to prevent errors and exports module for testing |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Jorge C. <jacortez_94@hotmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Jorge C. <jacortez_94@hotmail.com>
Added safety guards to Marquee's fillContainer to prevent infinite loops when element sizes cannot be measured. Updated tests to proactively stop marquee intervals and drain timers, and added a global Jest setup file to increase timeouts and polyfill animation frame methods for jsdom. Configured Jest to use the setup file and increased default test timeout.
…deRaccoons/WebTricks into CopyToClipboard-unit-tests
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.
This pull request adds comprehensive unit tests for three modules:
CopyToClipboard,Marquee, andReadTime. These tests use the Jest framework with a jsdom environment to simulate browser behavior and verify correct functionality, edge cases, and DOM interactions. The new tests improve confidence in the modules' reliability and help ensure future changes do not break existing features.New Test Coverage
__tests__/CopyToClipboard.test.jsto cover initialization, clipboard copying, UI updates, and error handling for theCopyToClipboardmodule.__tests__/Marquee.test.jsto verify marquee initialization, scrolling behavior in both directions, resizing logic, and DOM manipulation for theMarqueemodule.__tests__/ReadTime.test.jsto check read-time calculation, suffix handling, and display logic for theReadTimemodule, including cases with no articles.