Skip to content

Commit e1f0486

Browse files
committed
Emit coverage.json timestamp with millisecond precision
The concurrent-overwrite warning compares the timestamp in an existing `coverage.json` against `PROCESS_START_TIME`. `Time.now` has sub-second precision, but `iso8601` (no arg) truncates to whole seconds on the way out, so a sibling writer landing inside the same wall-clock second as when we started could slip past the check. Switch `meta.timestamp` to `iso8601(3)` so the round-trip keeps millisecond fidelity, and update the JSON fixtures and the `json_formatter_spec` assertion to match.
1 parent 3a6dad0 commit e1f0486

7 files changed

Lines changed: 7 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Unreleased
99
* Removed `docile` gem dependency. The `SimpleCov.configure` DSL block is now evaluated via `instance_exec` with instance variable proxying.
1010

1111
## Enhancements
12+
* JSON formatter: `meta.timestamp` is now emitted with millisecond precision (`iso8601(3)`) so the concurrent-overwrite warning can distinguish writes within the same wall-clock second
1213
* JSON formatter: added `total` section with aggregate coverage statistics (covered, missed, total, percent, strength) for line, branch, and method coverage. Line stats additionally include `omitted` (count of blank/comment lines, i.e. lines that cannot be covered)
1314
* JSON formatter: per-file output now includes `lines_covered_percent`, and when enabled: `branches_covered_percent`, `methods` array, and `methods_covered_percent`
1415
* JSON formatter: group stats now include full statistics for all enabled coverage types, not just line coverage percent

lib/simplecov/formatter/json_formatter/result_hash_formatter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def format_meta
9393
simplecov_version: SimpleCov::VERSION,
9494
command_name: @result.command_name,
9595
project_name: SimpleCov.project_name,
96-
timestamp: @result.created_at.iso8601,
96+
timestamp: @result.created_at.iso8601(3),
9797
root: SimpleCov.root,
9898
branch_coverage: SimpleCov.branch_coverage?,
9999
method_coverage: SimpleCov.method_coverage?

spec/fixtures/json/sample.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"simplecov_version": "0.22.0",
44
"command_name": "STUB_COMMAND_NAME",
55
"project_name": "STUB_PROJECT_NAME",
6-
"timestamp": "2024-01-01T00:00:00+00:00",
6+
"timestamp": "2024-01-01T00:00:00.000+00:00",
77
"root": "/STUB_WORKING_DIRECTORY",
88
"branch_coverage": false,
99
"method_coverage": false

spec/fixtures/json/sample_groups.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"simplecov_version": "0.22.0",
44
"command_name": "STUB_COMMAND_NAME",
55
"project_name": "STUB_PROJECT_NAME",
6-
"timestamp": "2024-01-01T00:00:00+00:00",
6+
"timestamp": "2024-01-01T00:00:00.000+00:00",
77
"root": "/STUB_WORKING_DIRECTORY",
88
"branch_coverage": false,
99
"method_coverage": false

spec/fixtures/json/sample_with_branch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"simplecov_version": "0.22.0",
44
"command_name": "STUB_COMMAND_NAME",
55
"project_name": "STUB_PROJECT_NAME",
6-
"timestamp": "2024-01-01T00:00:00+00:00",
6+
"timestamp": "2024-01-01T00:00:00.000+00:00",
77
"root": "/STUB_WORKING_DIRECTORY",
88
"branch_coverage": true,
99
"method_coverage": false

spec/fixtures/json/sample_with_method.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"simplecov_version": "0.22.0",
44
"command_name": "STUB_COMMAND_NAME",
55
"project_name": "STUB_PROJECT_NAME",
6-
"timestamp": "2024-01-01T00:00:00+00:00",
6+
"timestamp": "2024-01-01T00:00:00.000+00:00",
77
"root": "/STUB_WORKING_DIRECTORY",
88
"branch_coverage": false,
99
"method_coverage": true

spec/json_formatter_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@
331331
it "still writes the new file" do
332332
capture_stderr { subject.format(result) }
333333

334-
expect(json_output.fetch("meta").fetch("timestamp")).to eq(fixed_time.iso8601)
334+
expect(json_output.fetch("meta").fetch("timestamp")).to eq(fixed_time.iso8601(3))
335335
end
336336
end
337337

0 commit comments

Comments
 (0)