Repository navigation
[jsweep] Clean performance_now.cjs - #29042
Conversation
Add comprehensive test coverage for performance_now.cjs which lacked tests: - Verify nowMs() returns a number - Verify nowMs() is close to Date.now() - Verify successive calls return non-decreasing values - Verify it uses performance.timeOrigin + performance.now() - Verify sub-millisecond precision support - Verify epoch-scale return values (year 2020–2100 range) - Verify correct addition when performance.now() is zero Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds Vitest test coverage for the pure Node.js helper performance_now.cjs (nowMs()), which previously had no dedicated tests.
Changes:
- Introduces
actions/setup/js/performance_now.test.cjswith 9 unit tests covering basic export/type checks, monotonicity, implementation formula, and a few boundary/edge cases.
Show a summary per file
| File | Description |
|---|---|
| actions/setup/js/performance_now.test.cjs | Adds a new Vitest test suite for nowMs() behavior and implementation details. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 1
| it("returns a value close to Date.now()", () => { | ||
| const { nowMs } = req("./performance_now.cjs"); | ||
| const before = Date.now(); | ||
| const result = nowMs(); | ||
| const after = Date.now(); | ||
| // Allow 5ms slack for test execution overhead | ||
| expect(result).toBeGreaterThanOrEqual(before - 5); | ||
| expect(result).toBeLessThanOrEqual(after + 5); |
There was a problem hiding this comment.
The assertion that nowMs() is within ±5ms of Date.now() can be flaky and may fail even when the implementation is correct: performance.timeOrigin + performance.now() is based on the wall clock at process start plus a monotonic clock, so it won’t track later system clock adjustments (e.g., NTP/time drift), while Date.now() will. Consider loosening this to a much larger tolerance (e.g., seconds) or rewriting the check to avoid relying on live wall-clock alignment.
| it("returns a value close to Date.now()", () => { | |
| const { nowMs } = req("./performance_now.cjs"); | |
| const before = Date.now(); | |
| const result = nowMs(); | |
| const after = Date.now(); | |
| // Allow 5ms slack for test execution overhead | |
| expect(result).toBeGreaterThanOrEqual(before - 5); | |
| expect(result).toBeLessThanOrEqual(after + 5); | |
| it("returns a value within the current performance-based epoch range", () => { | |
| const { nowMs } = req("./performance_now.cjs"); | |
| const before = perfHooks.performance.timeOrigin + perfHooks.performance.now(); | |
| const result = nowMs(); | |
| const after = perfHooks.performance.timeOrigin + perfHooks.performance.now(); | |
| expect(result).toBeGreaterThanOrEqual(before); | |
| expect(result).toBeLessThanOrEqual(after); |
🧪 Test Quality Sentinel ReportTest Quality Score: 87/100✅ Excellent test quality
Test Classification DetailsView all 9 test classifications
Flagged Tests — Requires ReviewNo tests flagged. All tests verify observable behavioral contracts. Language SupportTests analyzed:
Verdict
📖 Understanding Test ClassificationsDesign Tests (High Value) verify what the system does:
Implementation Tests (Low Value) verify how the system does it:
Goal: Shift toward tests that describe the system's behavioral contract — the promises it makes to its users and collaborators.
|
|
@copilot review all comments |
…et test Agent-Logs-Url: https://github.com/github/gh-aw/sessions/7724fa1c-419a-4d83-9c59-d5c79a08ee45 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Addressed the flaky test in ad5ef12. Replaced the Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Summary
Adds comprehensive test coverage for
performance_now.cjs, which previously had no tests.File:
performance_now.cjsContext: Pure Node.js module (not github-script context).
Changes:
performance_now.test.cjswith 9 test casesTest improvements
Created
performance_now.test.cjsfrom scratch with 9 meaningful tests:exports nowMs as a function— basic export checkreturns a number— return type checkreturns a value close to Date.now()— sanity check against wall clockreturns an increasing value on successive calls— monotonicityuses performance.timeOrigin + performance.now()— verifies the implementation formulareturns a floating-point value when performance.now() has sub-ms precision— precision checkreturns epoch-scale milliseconds (greater than year 2020)— lower-bound epoch checkreturns epoch-scale milliseconds (less than year 2100)— upper-bound epoch checkhandles zero performance.now() value— edge case with zero elapsed timeValidation checks
npm run format:cjs✓npm run lint:cjs✓npm run typecheck✓npm run test:js— 9/9 tests passed ✓