lighthouse-matchers 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d59475b53e41779753dc20a7d0775dc4300494da79af101d2671b235d9952192
4
- data.tar.gz: 41d0d01d7494075bc18d6dc3bca107f5de9ec3400cf89eac689c8834fd24efdd
3
+ metadata.gz: 1b73401322398ad659f111555923e60f2859c90e1e24893c209686842340de06
4
+ data.tar.gz: 2fec0776316b961004e8254ab49f374dc56eff5096a3336d2216294b10cbe13c
5
5
  SHA512:
6
- metadata.gz: 201ae5239f163fc312f4edb460b7e9a5969757c06b7093792b7f0ff8cff7e5baccf9ec8aa8c5ac612d537bb6a371fb605c6099d833ca7b5ed918abbde2932ede
7
- data.tar.gz: 2879723cd480d9e67e2578c5e89f78e6251350cd01702a3cd7150705fdf2e3245ed9319a44b929280e65d8640a4d6508b876065f9dbb5e1bbc434149e96bfe4a
6
+ metadata.gz: f847e1a748e9097df8a7345e60f3249f15ae9c3031885a756c9ce2a6bf582032d4de281c2f2b6c088a73baca86a7158f3101f637f9c376298b665848d1f9f7c2
7
+ data.tar.gz: f461dd4cc3b146228986c833857421a9861b9b65d0b1095b90f10dae40bed454009c83fc5b1dadb60ca246a43768fec984226933fd980abe81aa990681c3c715
@@ -22,24 +22,35 @@ permissions:
22
22
  contents: read # to fetch code (actions/checkout)
23
23
 
24
24
  jobs:
25
+ lint:
26
+ runs-on: ubuntu-latest
27
+ steps:
28
+ - uses: actions/checkout@v4
29
+ with:
30
+ persist-credentials: false
31
+ - uses: ruby/setup-ruby@v1
32
+ with:
33
+ ruby-version: '3.2'
34
+ bundler-cache: true
35
+ - run: bundle exec rubocop
25
36
  test:
26
37
  runs-on: ubuntu-latest
27
38
  strategy:
28
39
  fail-fast: false
29
40
  matrix:
30
- ruby-version: ['2.5', '2.6', '2.7', '3.0', '3.1']
41
+ ruby-version: ['2.5', '2.6', '2.7', '3.0', '3.1', '3.2', '3.3']
31
42
  steps:
32
- - uses: actions/checkout@v3
43
+ - uses: actions/checkout@v4
33
44
  with:
34
45
  persist-credentials: false
35
46
  - uses: ruby/setup-ruby@v1
36
47
  with:
37
48
  ruby-version: ${{ matrix.ruby-version }}
38
49
  bundler-cache: true # runs 'bundle install' and caches installed gems automatically
39
- - uses: actions/setup-node@v3
50
+ - uses: actions/setup-node@v4
40
51
  with:
41
52
  cache: 'npm'
42
53
  - run: npm ci
43
- - run: npm test
54
+ - run: bundle exec rake spec
44
55
  env:
45
56
  CI_CHROME_FLAGS: "--headless"
@@ -0,0 +1,30 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - v*
7
+
8
+ permissions:
9
+ contents: read # to fetch code (actions/checkout)
10
+
11
+ jobs:
12
+ push:
13
+ permissions:
14
+ contents: write
15
+ id-token: write
16
+ if: github.repository == 'ackama/lighthouse-matchers'
17
+ runs-on: ubuntu-latest
18
+ steps:
19
+ - name: Harden Runner
20
+ uses: step-security/harden-runner@v2
21
+ with:
22
+ egress-policy: audit
23
+ - uses: actions/checkout@v4
24
+ with:
25
+ persist-credentials: false
26
+ - uses: ruby/setup-ruby@v1
27
+ with:
28
+ ruby-version: '3.2'
29
+ bundler-cache: true
30
+ - uses: rubygems/release-gem@v1
data/CHANGELOG.md CHANGED
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.2.0] - 2024-07-13
10
+ ### Changed
11
+ - Raise an explict error when the audit category is not found ([#56](https://github.com/ackama/lighthouse-matchers/pull/56))
12
+ - Print run warnings from Lighthouse ([#55](https://github.com/ackama/lighthouse-matchers/pull/55))
13
+
9
14
  ## [1.1.0] - 2023-08-27
10
15
  ### Changed
11
16
  - Only run audits for categories that are requested to improve performance ([#28](https://github.com/ackama/lighthouse-matchers/pull/28))
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lighthouse-matchers (1.1.0)
4
+ lighthouse-matchers (1.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -14,7 +14,8 @@ GEM
14
14
  rainbow (3.0.0)
15
15
  rake (13.0.1)
16
16
  regexp_parser (2.2.0)
17
- rexml (3.2.5)
17
+ rexml (3.2.8)
18
+ strscan (>= 3.0.9)
18
19
  rspec (3.8.0)
19
20
  rspec-core (~> 3.8.0)
20
21
  rspec-expectations (~> 3.8.0)
@@ -42,6 +43,7 @@ GEM
42
43
  rubocop-ast (1.15.1)
43
44
  parser (>= 3.0.1.1)
44
45
  ruby-progressbar (1.11.0)
46
+ strscan (3.1.0)
45
47
  unicode-display_width (2.1.0)
46
48
  webrick (1.7.0)
47
49
 
data/README.md CHANGED
@@ -121,6 +121,12 @@ for detailed instructions.
121
121
 
122
122
  This gem endeavours to follow Semantic Versioning 2.0 as defined at https://semver.org/.
123
123
 
124
+ ## Releasing
125
+
126
+ Releases are done automatically by GitHub Actions when a new tag is pushed to the repository.
127
+
128
+ To release a new version, create a pull request updating the "Unreleased" section of `CHANGELOG.md` file to reflect the upcoming version and expected release date, and to update the version number in `lib/lighthouse/matchers/version.rb`. Once the pull request is merged, create a new tag in the format `vX.Y.Z`, which will trigger GitHub Actions to publish the new version to RubyGems.
129
+
124
130
  ## License
125
131
 
126
132
  lighthouse-matchers is copyright © 2019 Ackama Group Ltd.
@@ -5,6 +5,8 @@ require 'stringio'
5
5
 
6
6
  # Compares a url's actual score to the expected score.
7
7
  class AuditService
8
+ class Error < StandardError; end
9
+
8
10
  def initialize(url, audit, score)
9
11
  @url = url
10
12
  @audit = audit
@@ -20,11 +22,25 @@ class AuditService
20
22
  end
21
23
 
22
24
  def measured_score
23
- results.dig('categories', @audit.to_s, 'score') * 100
25
+ category['score'] * 100
26
+ end
27
+
28
+ def run_warnings
29
+ results['runWarnings']
24
30
  end
25
31
 
26
32
  private
27
33
 
34
+ def category
35
+ category = results.dig('categories', @audit.to_s)
36
+
37
+ if category.nil?
38
+ raise Error, "Category '#{@audit}' not found in Lighthouse results - maybe it was removed?"
39
+ end
40
+
41
+ category
42
+ end
43
+
28
44
  def opts
29
45
  "'#{@url}'".tap do |builder|
30
46
  builder << ' --quiet'
@@ -40,6 +56,6 @@ class AuditService
40
56
  end
41
57
 
42
58
  def results
43
- JSON.parse(output)
59
+ @results ||= JSON.parse(output)
44
60
  end
45
61
  end
@@ -11,6 +11,12 @@ RSpec::Matchers.define :pass_lighthouse_audit do |audit, args = {}|
11
11
  match do |target|
12
12
  audit_service = AuditService.new(url(target), audit, score)
13
13
 
14
+ audit_service.run_warnings.each do |warning|
15
+ RSpec.configuration.reporter.message(
16
+ "#{RSpec.current_example.location}: [lighthouse] #{warning}"
17
+ )
18
+ end
19
+
14
20
  @measured_score = audit_service.measured_score
15
21
 
16
22
  audit_service.passing_score?
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lighthouse
4
4
  module Matchers
5
- VERSION = '1.1.0'
5
+ VERSION = '1.2.0'
6
6
  end
7
7
  end