-
-
Notifications
You must be signed in to change notification settings - Fork 0
Add test coverage on main script file #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds comprehensive test coverage for the main script file using Jest, along with supporting configuration for SonarQube analysis. The purpose is to improve code quality metrics and ensure the countdown timer functionality is properly tested.
- Adds Jest test suite covering the
countUpFromTimefunction with various scenarios including leap years, DST changes, and edge cases - Configures package.json with Jest setup and test scripts for coverage reporting
- Updates CI/CD pipeline to run tests and generate coverage reports for SonarQube integration
Reviewed Changes
Copilot reviewed 6 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/script.test.js | Comprehensive test suite with DOM mocking and various test scenarios for the timer function |
| src/script.js | Adds CommonJS export for Node.js compatibility in test environment |
| package.json | Jest configuration with coverage settings and test scripts |
| sonar-project.properties | SonarQube configuration for source paths and coverage reporting |
| README.md | Documentation updates with test running instructions and coverage badge |
| .github/workflows/sonarscan.yml | CI pipeline updates to run tests and generate coverage before SonarQube scan |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 6 out of 8 changed files in this pull request and generated 3 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…DOM elements gracefully; add corresponding tests for robustness
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 6 out of 8 changed files in this pull request and generated 2 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…enhance module.exports coverage in tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 6 out of 8 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
tests/script.test.js:1
- The assertion
expect(exported.countUpFromTime).toBe('function')is incorrect. It should useexpect(typeof exported.countUpFromTime).toBe('function')to check the type, similar to line 5.
describe('Main Script Tests', () => {
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 6 out of 8 changed files in this pull request and generated 2 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| const mockEl = createMockDOM(); | ||
| global.document.getElementById = jest.fn(() => mockEl); | ||
| script.countUpFromTime('Sep 13, 2025 11:59:00', 'countup1'); | ||
| expect(mockEl.years.innerHTML).toBe(0); |
Copilot
AI
Sep 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent type checking - line 170 expects a number (0) but other lines in the same test convert to Number() first. Either convert to Number() here or use string comparison '0' for consistency.
| expect(mockEl.years.innerHTML).toBe(0); | |
| expect(Number(mockEl.years.innerHTML)).toBe(0); |
| test('module.exports is set correctly', () => { | ||
| const exported = require('../src/script.js'); | ||
| expect(exported.countUpFromTime).toBeDefined(); | ||
| expect(typeof exported.countUpFromTime).toBe('function'); |
Copilot
AI
Sep 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect assertion - line 13 should use typeof operator like line 5, but line 13 is missing typeof and will fail since the function object is not equal to the string 'function'.



No description provided.