Class: Browsable::TestReport

Inherits:
Object
  • Object
show all
Defined in:
lib/browsable/test_report.rb

Overview

The end-of-suite reporting layer for runtime mode.

TestReport reads the AuditLog, invokes the v0.1 analyzers **in batch** —one stylelint call, one eslint call regardless of suite size — then groups the resulting findings by endpoint and renders them. It is the only place in runtime mode where a subprocess is spawned.

The per-endpoint policy is applied when grouping findings: a CSS feature that flagged the batch target is attributed to every endpoint that loaded the file. HTML findings, which carry exact required versions, can be re-evaluated against each endpoint’s specific policy (TODO: v0.2.1).

Defined Under Namespace

Classes: EndpointReport

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(audit_log: Browsable.audit_log, config: nil, root: nil) ⇒ TestReport

Returns a new instance of TestReport.



25
26
27
28
29
30
# File 'lib/browsable/test_report.rb', line 25

def initialize(audit_log: Browsable.audit_log, config: nil, root: nil)
  @audit_log = audit_log
  @root = root || (defined?(Rails) && Rails.application ? Rails.root.to_s : Dir.pwd)
  @config = config || Config.load(root: @root)
  @analyzed = false
end

Instance Attribute Details

#audit_logObject (readonly)

Returns the value of attribute audit_log.



23
24
25
# File 'lib/browsable/test_report.rb', line 23

def audit_log
  @audit_log
end

#configObject (readonly)

Returns the value of attribute config.



23
24
25
# File 'lib/browsable/test_report.rb', line 23

def config
  @config
end

#rootObject (readonly)

Returns the value of attribute root.



23
24
25
# File 'lib/browsable/test_report.rb', line 23

def root
  @root
end

Instance Method Details

#endpoint_reportsObject

Findings grouped per observed endpoint, sorted by endpoint name.



39
40
41
42
# File 'lib/browsable/test_report.rb', line 39

def endpoint_reports
  analyze_if_needed
  @endpoint_reports
end

#errors?Boolean

Returns:

  • (Boolean)


51
52
53
54
# File 'lib/browsable/test_report.rb', line 51

def errors?
  analyze_if_needed
  @findings.any?(&:error?)
end

#fail_suite_if_errors!(fail_on: :error) ⇒ Object

Convenience: exit non-zero when any error finding exists. Drivers call this from their after(:suite) hook when configured to fail on errors.



90
91
92
93
94
95
96
97
98
99
# File 'lib/browsable/test_report.rb', line 90

def fail_suite_if_errors!(fail_on: :error)
  should_fail =
    case fail_on.to_s
    when "warning" then errors? || warnings?
    when "error"   then errors?
    else                false
    end

  Kernel.exit(1) if should_fail
end

#findingsObject

Findings (Array<Finding>) discovered across the whole suite.



33
34
35
36
# File 'lib/browsable/test_report.rb', line 33

def findings
  analyze_if_needed
  @findings
end

#render(format: :human) ⇒ Object

Render the report as a string in the requested format.



77
78
79
# File 'lib/browsable/test_report.rb', line 77

def render(format: :human)
  formatter_for(format).new(to_report).render
end

#skipped_assetsObject

Asset paths that could not be resolved against the host app — surfaced as skipped entries so the user understands what the audit could not cover.



46
47
48
49
# File 'lib/browsable/test_report.rb', line 46

def skipped_assets
  analyze_if_needed
  @skipped_assets
end

#to_json(*_args) ⇒ Object



81
82
83
84
85
86
# File 'lib/browsable/test_report.rb', line 81

def to_json(*_args)
  JSON.pretty_generate(to_report.as_json.merge(
    endpoints: endpoint_reports.map { |er| endpoint_as_json(er) },
    skipped_assets: skipped_assets
  ))
end

#to_reportObject

Build a Report whose shape v0.1’s formatters can consume, so runtime output can use the same Human/Json/Github renderers as the CLI.



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/browsable/test_report.rb', line 63

def to_report
  analyze_if_needed
  Report.new(
    findings: @findings,
    skips: @skips,
    notes: @notes,
    policies: PolicyScanner.call(root),
    target: batch_target,
    root: root,
    config_file: config.config_file
  )
end

#warnings?Boolean

Returns:

  • (Boolean)


56
57
58
59
# File 'lib/browsable/test_report.rb', line 56

def warnings?
  analyze_if_needed
  @findings.any?(&:warning?)
end