Class: RSpecTracer::Reporters::HtmlReporter Private
- Defined in:
- lib/rspec_tracer/reporters/html_reporter.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Renders a single-page HTML report at <report_dir>/index.html
consuming the canonical payload built by PayloadBuilder
(shared with JsonReporter).
Build output - the frontend bundle at
lib/rspec_tracer/reporters/html/dist/ - is committed to the
repo; users never run npm. At emit time this reporter:
1. Reads the template at `html/dist/index.html`.
2. Replaces the `<!-- RSPEC_TRACER_FALLBACK -->` marker with
server-rendered `<table>` HTML for each of the 5 report
types (satisfies the "works without JavaScript" AC; the
Preact bundle removes these on hydrate).
3. Replaces the body of `<script id="report-data">` with the
full payload JSON.
4. Copies `html/dist/assets/` next to the output.
5. Writes the finished file.
Failure modes are graceful: the Registry wraps #generate in
an isolated rescue, so a template-missing or template-corrupt
condition logs a warning and returns nil rather than propagating
a non-zero exit into the user's test suite.
Constant Summary collapse
- FILENAME =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Internal constant.
'index.html'- ASSETS_DIR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Internal constant.
'assets'- FALLBACK_MARKER =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Internal constant.
'<!-- RSPEC_TRACER_FALLBACK -->'- REPORT_DATA_REGEX =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Internal constant.
%r{<script id="report-data" type="application/json">.*?</script>}m- DIST_DIR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Absolute path to the committed frontend build under
lib/rspec_tracer/reporters/html/dist/. Computed once at load time so tests can stubDIST_DIRif they need a different template root. File.('html/dist', __dir__)
Instance Attribute Summary
Attributes inherited from Base
#logger, #options, #report_dir, #run_metadata, #snapshot
Instance Method Summary collapse
-
#generate ⇒ String?
private
Concrete implementation of Base#generate.
Methods inherited from Base
Constructor Details
This class inherits a constructor from RSpecTracer::Reporters::Base
Instance Method Details
#generate ⇒ String?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Concrete implementation of Base#generate.
Renders the bundled HTML template with the run payload and writes
index.html (plus the asset directory) under Base#report_dir.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/rspec_tracer/reporters/html_reporter.rb', line 62 def generate return nil if no_op? template = read_template return nil if template.nil? payload_json = PayloadBuilder.build( snapshot: snapshot, run_metadata: , generated_at: generated_at_override ) rendered = inject(template, payload_json) FileUtils.mkdir_p(report_dir) copy_assets path = File.join(report_dir, FILENAME) File.write(path, rendered, encoding: 'UTF-8') logger&.debug("rspec-tracer: wrote HTML report to #{path}") path end |