lighthouse-matchers 1.0.3 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4875808814d5062e018b2b97ca213d4970410e17d8815384faecf8515d7c3a54
4
- data.tar.gz: 0c5987ca693dfb3fcf082ee4ae66453094b5c3a9421d72a6ee91b25b65d9767c
3
+ metadata.gz: 1b73401322398ad659f111555923e60f2859c90e1e24893c209686842340de06
4
+ data.tar.gz: 2fec0776316b961004e8254ab49f374dc56eff5096a3336d2216294b10cbe13c
5
5
  SHA512:
6
- metadata.gz: 111ac3364c7917956c736fea0dd651df06219a4aef9ab5f7a9390bfa2a3707389aab6f53328da636f08909e545fbe520b5e3b55454d2fe07d441a5f9167f611c
7
- data.tar.gz: 2b9dc90ee947fa25ab8c7103da174b068d893693a49496dd5d0fb7c946fcdc17413e7a6f99f08e29cbf3fefc430f157a902c946a14eb7dd5049a633f1178568e
6
+ metadata.gz: f847e1a748e9097df8a7345e60f3249f15ae9c3031885a756c9ce2a6bf582032d4de281c2f2b6c088a73baca86a7158f3101f637f9c376298b665848d1f9f7c2
7
+ data.tar.gz: f461dd4cc3b146228986c833857421a9861b9b65d0b1095b90f10dae40bed454009c83fc5b1dadb60ca246a43768fec984226933fd980abe81aa990681c3c715
@@ -0,0 +1,56 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: CI
9
+
10
+ on:
11
+ push:
12
+ branches: [ main ]
13
+ pull_request:
14
+ branches: [ main ]
15
+
16
+ concurrency:
17
+ # Pushing new changes to a branch will cancel any in-progress CI runs
18
+ group: ${{ github.ref }}
19
+ cancel-in-progress: true
20
+
21
+ permissions:
22
+ contents: read # to fetch code (actions/checkout)
23
+
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
36
+ test:
37
+ runs-on: ubuntu-latest
38
+ strategy:
39
+ fail-fast: false
40
+ matrix:
41
+ ruby-version: ['2.5', '2.6', '2.7', '3.0', '3.1', '3.2', '3.3']
42
+ steps:
43
+ - uses: actions/checkout@v4
44
+ with:
45
+ persist-credentials: false
46
+ - uses: ruby/setup-ruby@v1
47
+ with:
48
+ ruby-version: ${{ matrix.ruby-version }}
49
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
50
+ - uses: actions/setup-node@v4
51
+ with:
52
+ cache: 'npm'
53
+ - run: npm ci
54
+ - run: bundle exec rake spec
55
+ env:
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/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+ node_modules
data/.rubocop.yml CHANGED
@@ -1,6 +1,9 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.5
3
+ NewCops: enable
1
4
  Metrics/BlockLength:
2
- Exclude:
5
+ Exclude:
3
6
  - 'spec/**/*_spec.rb'
4
7
  - 'lighthouse-matchers.gemspec'
5
- Metrics/LineLength:
8
+ Layout/LineLength:
6
9
  Max: 100
data/CHANGELOG.md CHANGED
@@ -6,21 +6,28 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
- ## [1.0.0] - 2019-05-24
10
- ### Added
11
- - Initial version release with minimal viable matcher
12
-
13
- ## [1.0.1] - 2019-05-24
9
+ ## [1.2.0] - 2024-07-13
14
10
  ### Changed
15
- - Apply bug fixes based on integration with a Ruby on Rails project
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))
16
13
 
17
- ## [1.0.2] - 2019-08-16
14
+ ## [1.1.0] - 2023-08-27
18
15
  ### Changed
19
- - Refactored auditing into a service object (@CaraHill)
20
- -
16
+ - Only run audits for categories that are requested to improve performance ([#28](https://github.com/ackama/lighthouse-matchers/pull/28))
17
+ - Include measured score in failure message ([#26](https://github.com/ackama/lighthouse-matchers/pull/26))
18
+
21
19
  ## [1.0.3] - 2019-08-27
22
20
  ### Added
23
-
24
21
  - **chrome_flags** option to allow the Chrome launch behaviour of the `lighthouse` command. (#8)
25
22
 
23
+ ## [1.0.2] - 2019-08-16
24
+ ### Changed
25
+ - Refactored auditing into a service object (@CaraHill)
26
+
27
+ ## [1.0.1] - 2019-05-24
28
+ ### Changed
29
+ - Apply bug fixes based on integration with a Ruby on Rails project
26
30
 
31
+ ## [1.0.0] - 2019-05-24
32
+ ### Added
33
+ - Initial version release with minimal viable matcher
data/CONTRIBUTING.md CHANGED
@@ -1,4 +1,4 @@
1
- # Contributing
1
+ # Contributing
2
2
 
3
3
  Although we are always happy to make improvements, we also
4
4
  welcome changes and improvements from the community!
@@ -19,7 +19,7 @@ you think would be useful? Here's what you need to do:
19
19
  API](#documentation).
20
20
  1. [Refrain from updating the changelog.](#changelog)
21
21
  1. Push to your fork and submit a pull request.
22
- 1. [Ensure that the test suite passes on Travis and make any necessary changes
22
+ 1. [Ensure that the test suite passes CI and make any necessary changes
23
23
  to your branch to bring it to green.](#continuous-integration)
24
24
 
25
25
  Although we maintain this gem in our free time, we try to respond to
@@ -64,7 +64,7 @@ In addition, tests are broken up into two categories:
64
64
  interested in these). These tests typically stub out actual requests to the Lighthouse CLI.
65
65
  * Integration tests — high-level tests to ensure that the gem works against the CLI tool. These tests are not updated frequently but are important to make sure that changes to the CLI interface do not cause this library to break.
66
66
 
67
- Our approach to testing tends to iterate over time. The best approach for writing tests is to copy an existing test in the same file as where you want to add a new test. We may suggest changes to bring the tests in line with
67
+ Our approach to testing tends to iterate over time. The best approach for writing tests is to copy an existing test in the same file as where you want to add a new test. We may suggest changes to bring the tests in line with
68
68
  our current approach.
69
69
 
70
70
  ## Code style
@@ -73,7 +73,7 @@ We follow a derivative of the [unofficial Ruby style guide] created by the
73
73
  Rubocop developers. You can view our Rubocop configuration [here], but here are
74
74
  some key differences:
75
75
 
76
- * We allow longer blocks in spec files. This is because `RSpec.describe` blocks can
76
+ * We allow longer blocks in spec files. This is because `RSpec.describe` blocks can
77
77
  quite easily go over the default Rubocop limit.
78
78
  * We have increased the maximum line length to 100 characters.
79
79
 
@@ -93,9 +93,15 @@ To run a unit test, you might say something like:
93
93
  bundle exec rspec spec/lighthouse/matchers/rspec_spec.rb
94
94
  ```
95
95
 
96
+ You can run all unit tests (fast) using a special rake task:
97
+
98
+ ```bash
99
+ bundle exec rake spec:unit
100
+ ```
101
+
96
102
  ### Integration tests
97
103
 
98
- The integration tests exercise matchers using real Lighthouse audit results. We aim to
104
+ The integration tests exercise matchers using real Lighthouse audit results. We aim to
99
105
  select reasonably complex well-known projects that are know to have good audit scores to exercise
100
106
  that our matchers correctly catch pass and fail conditions.
101
107
 
@@ -105,6 +111,12 @@ To run an integration test, you might say something like:
105
111
  bundle exec rspec spec/integration/lighthouse_matchers_spec.rb
106
112
  ```
107
113
 
114
+ You can run all integration tests (slow) using a special rake task:
115
+
116
+ ```bash
117
+ bundle exec rake spec:integration
118
+ ```
119
+
108
120
  ### All tests
109
121
 
110
122
  In order to run all of the tests, simply run:
@@ -122,9 +134,9 @@ bundle exec rake
122
134
  ## Documentation
123
135
 
124
136
  As you navigate the codebase, you may notice certain classes and methods that
125
- are prefaced with inline documentation.
137
+ are prefaced with inline documentation.
126
138
 
127
- If your changes end up extending or updating the API, it helps greatly to update the
139
+ If your changes end up extending or updating the API, it helps greatly to update the
128
140
  docs at the same time for future developers and other readers of the source code.
129
141
 
130
142
  ## A word on the changelog
@@ -138,16 +150,14 @@ about this — we'll take care of it when we release a new version.
138
150
  While running `bundle exec rake` is a great way to check your work, this command
139
151
  will only run your tests against the latest supported Ruby and Rails version.
140
152
  Ultimately, though, you'll want to ensure that your changes work in all possible
141
- environments. We make use of [Travis][travis] to do this work for us. Travis
153
+ environments. We make use of [Github Actions][actions] to do this work for us. This
142
154
  will kick in after you push up a branch or open a PR. It takes a few minutes to
143
155
  run a complete build, which you are free to
144
- [monitor as it progresses][travis-project].
156
+ [monitor as it progresses][actions].
145
157
 
146
- [travis-project]: https://travis-ci.org/ackama/lighthouse-matchers
158
+ [actions]: https://github.com/ackama/lighthouse-matchers/actions
147
159
 
148
160
  What happens if the build fails in some way? Don't fear! Click on a failed job
149
161
  and scroll through its output to determine the cause of the failure. You'll want
150
162
  to make changes to your branch and push them up until the entire build is green.
151
163
  It may take a bit of time, but overall it is worth it and it helps us immensely!
152
-
153
- [travis]: https://travis-ci.org/
data/Gemfile.lock CHANGED
@@ -1,19 +1,21 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lighthouse-matchers (1.0.3)
4
+ lighthouse-matchers (1.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- ast (2.4.0)
9
+ ast (2.4.2)
10
10
  diff-lcs (1.3)
11
- jaro_winkler (1.5.2)
12
- parallel (1.17.0)
13
- parser (2.6.3.0)
14
- ast (~> 2.4.0)
11
+ parallel (1.21.0)
12
+ parser (3.0.3.2)
13
+ ast (~> 2.4.1)
15
14
  rainbow (3.0.0)
16
- rake (10.5.0)
15
+ rake (13.0.1)
16
+ regexp_parser (2.2.0)
17
+ rexml (3.2.8)
18
+ strscan (>= 3.0.9)
17
19
  rspec (3.8.0)
18
20
  rspec-core (~> 3.8.0)
19
21
  rspec-expectations (~> 3.8.0)
@@ -26,16 +28,24 @@ GEM
26
28
  rspec-mocks (3.8.0)
27
29
  diff-lcs (>= 1.2.0, < 2.0)
28
30
  rspec-support (~> 3.8.0)
31
+ rspec-retry (0.6.2)
32
+ rspec-core (> 3.3)
29
33
  rspec-support (3.8.0)
30
- rubocop (0.70.0)
31
- jaro_winkler (~> 1.5.1)
34
+ rubocop (1.24.1)
32
35
  parallel (~> 1.10)
33
- parser (>= 2.6)
36
+ parser (>= 3.0.0.0)
34
37
  rainbow (>= 2.2.2, < 4.0)
38
+ regexp_parser (>= 1.8, < 3.0)
39
+ rexml
40
+ rubocop-ast (>= 1.15.1, < 2.0)
35
41
  ruby-progressbar (~> 1.7)
36
- unicode-display_width (>= 1.4.0, < 1.7)
37
- ruby-progressbar (1.10.0)
38
- unicode-display_width (1.6.0)
42
+ unicode-display_width (>= 1.4.0, < 3.0)
43
+ rubocop-ast (1.15.1)
44
+ parser (>= 3.0.1.1)
45
+ ruby-progressbar (1.11.0)
46
+ strscan (3.1.0)
47
+ unicode-display_width (2.1.0)
48
+ webrick (1.7.0)
39
49
 
40
50
  PLATFORMS
41
51
  ruby
@@ -43,9 +53,11 @@ PLATFORMS
43
53
  DEPENDENCIES
44
54
  bundler (~> 2.0)
45
55
  lighthouse-matchers!
46
- rake (~> 10.0)
56
+ rake (~> 13.0)
47
57
  rspec (~> 3.0)
58
+ rspec-retry
48
59
  rubocop
60
+ webrick
49
61
 
50
62
  BUNDLED WITH
51
- 2.0.2
63
+ 2.2.32
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
- # Lighthouse Matchers [![Gem Version](https://badge.fury.io/rb/lighthouse-matchers.svg)](https://badge.fury.io/rb/lighthouse-matchers) [![Maintainability](https://api.codeclimate.com/v1/badges/2f1df198307f6a0489fc/maintainability)](https://codeclimate.com/github/ackama/lighthouse-matchers/maintainability) [![Build Status](https://travis-ci.org/ackama/lighthouse-matchers.svg?branch=master)](https://travis-ci.org/ackama/lighthouse-matchers)
1
+ # Lighthouse Matchers [![Gem Version](https://badge.fury.io/rb/lighthouse-matchers.svg)](https://badge.fury.io/rb/lighthouse-matchers) [![Maintainability](https://api.codeclimate.com/v1/badges/2f1df198307f6a0489fc/maintainability)](https://codeclimate.com/github/ackama/lighthouse-matchers/maintainability) [![Build Status](https://github.com/ackama/lighthouse-matchers/actions/workflows/ci.yml/badge.svg)](https://github.com/ackama/lighthout-matchers/actions)
2
2
 
3
- Lighthouse Matchers provides single-line RSpec matchers for
4
- expectations against the result of [Lighthouse](https://developers.google.com/web/tools/lighthouse/)
3
+ Lighthouse Matchers provides single-line RSpec matchers for
4
+ expectations against the result of [Lighthouse](https://developers.google.com/web/tools/lighthouse/)
5
5
  audit checks.
6
6
 
7
7
  ## Getting Started
@@ -23,16 +23,16 @@ require "lighthouse/matchers/rspec"
23
23
  ```
24
24
 
25
25
  You also need to have the `lighthouse` CLI tool available. The matchers will automatically pick up the tool
26
- if you have added it to your `$PATH`, or if you have installed the tool using:
26
+ if you have added it to your `$PATH`, or if you have installed the tool using:
27
27
 
28
- * `npm install --save-dev lighthouse`
28
+ * `npm install --save-dev lighthouse`
29
29
  * `yarn add --dev lighthouse`
30
30
 
31
31
  If you have the `lighthouse` CLI tool installed, but available elsewhere on your system, you can set the location manually.
32
32
  See [Configuration](#configuration) for further instructions.
33
33
 
34
34
  The matchers are now available to use. If you wish for your Lighthouse audits to use the same Chrome session
35
- as your system tests (e.g. the page requires a logged-in user), then you should
35
+ as your system tests (e.g. the page requires a logged-in user), then you should
36
36
  change the definition of your system test Chrome browser arguments to define a "remote debugging port". Without
37
37
  defining this port, The `lighthouse` audit tool cannot connect to your existing Chrome session and will begin a new
38
38
  one, clearing any session information.
@@ -58,15 +58,15 @@ Lighthouse::Matchers.remote_debugging_port = 9222
58
58
 
59
59
  ### Test::Unit
60
60
 
61
- Test::Unit support is planning and is coming soon!
61
+ Test::Unit support is planned and is coming soon!
62
62
 
63
63
  ## Matchers
64
64
 
65
- ### `pass_lighthouse_audit`
65
+ ### `pass_lighthouse_audit`
66
66
 
67
- This matcher accepts an optional audit type, and minimum score.
68
- If no audit type is passed in, then all audits are run. If a minimum score is not provided, then the score defined
69
- in `Lighthouse::Matchers.minimum_score` is used. The default value of this attribute is 100 - i.e. the audit must pass
67
+ This matcher accepts an optional audit type, and minimum score.
68
+ If no audit type is passed in, then all audits are run. If a minimum score is not provided, then the score defined
69
+ in `Lighthouse::Matchers.minimum_score` is used. The default value of this attribute is 100 - i.e. the audit must pass
70
70
  entirely.
71
71
 
72
72
  #### Examples
@@ -80,7 +80,7 @@ entirely.
80
80
  it { expect(page).to pass_lighthouse_audit(:performance) }
81
81
  ```
82
82
  * Assert that a Capybara page object passes all audits with a minimum score of 60:
83
- ```
83
+ ```
84
84
  it { expect(page).to pass_lighthouse_audit(score: 60) }
85
85
  ```
86
86
  * Assert that a URL passes the PWA audit with a minimum score of 90:
@@ -92,43 +92,49 @@ entirely.
92
92
 
93
93
  All configuration keys are accessible against the `Lighthouse::Matchers` object. Configuration options include:
94
94
 
95
- * **`remote_debugging_port`:** If defined, Lighthouse will connect to this Chrome debugging port.
96
- This allows the audit to run in the same context as the Chrome session that created the port
97
- (for example, in Capybara, this would be the current state of the page under test). This setting is useful for
95
+ * **`remote_debugging_port`:** If defined, Lighthouse will connect to this Chrome debugging port.
96
+ This allows the audit to run in the same context as the Chrome session that created the port
97
+ (for example, in Capybara, this would be the current state of the page under test). This setting is useful for
98
98
  running a Lighthouse audit against the _current state_ of a page, rather than it's initial load state. This setting
99
- must match up with the remote debugging port that has been configured for the Chrome browser instance if
99
+ must match up with the remote debugging port that has been configured for the Chrome browser instance if
100
100
  Selenium webdrivers are being used.
101
101
  * **`lighthouse_cli`:** The path to the Lighthouse CLI tool. By default, we will check `$PATH` and `node_modules/.bin/`
102
102
  for the CLI. This setting can be used if the Lighthouse tool is installed in a non-standard location.
103
- * **`minimum_score`:** The default minimum score that audits must meet for the matcher to pass.
103
+ * **`minimum_score`:** The default minimum score that audits must meet for the matcher to pass.
104
104
  The default value of this configuration setting is '100' - e.g. audits must fully comply to pass.
105
105
  * **`chrome_flags`:** Any additional flags that should be passed to Chrome when Lighthouse launches a browser instance. As an example, running Lighthouse in Docker requires the normal headless Chrome flags (`--headless`, `--no-sandbox`) for Chrome to successfully start. Chrome flags can either be specified as an array (`["headless", "no-sandbox"]`) or as a string (`--headless --no-sandbox`).
106
106
 
107
107
  ## Compatibility
108
108
 
109
- * Lighthouse Matchers is tested and supported against Ruby 2.0+ and RSpec 3.x.
109
+ * Lighthouse Matchers is tested and supported against Ruby 2.0+ and RSpec 3.x.
110
110
  * The `lighthouse` CLI tool must be installed for these matchers to function.
111
- * The [`capybara`](https://rubygems.org/gems/capybara) gem is required to make assertions
111
+ * The [`capybara`](https://rubygems.org/gems/capybara) gem is required to make assertions
112
112
  by passing in a `Capybara::Session`.
113
113
 
114
114
  ## Contributing
115
115
 
116
- Contributions are welcome.
117
- Please see the [contribution guidelines](https://github.com/ackama/lighthouse-matchers/blob/master/CONTRIBUTING.md)
116
+ Contributions are welcome.
117
+ Please see the [contribution guidelines](https://github.com/ackama/lighthouse-matchers/blob/master/CONTRIBUTING.md)
118
118
  for detailed instructions.
119
119
 
120
120
  ## Versioning
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.
127
- It is free software, and may be redistributed under the terms specified in the
133
+ It is free software, and may be redistributed under the terms specified in the
128
134
  [LICENSE](https://github.com/ackama/lighthouse-matchers/blob/master/LICENSE.txt) file.
129
135
 
130
136
 
131
137
  ## About Ackama
132
138
 
133
- Lighthouse Matchers is created and maintained by Ackama Group using our investment time scheme.
139
+ Lighthouse Matchers is created and maintained by Ackama Group using our investment time scheme.
134
140
  We are passionate about using and contributing back to the open source community, and are available for hire.
data/Rakefile CHANGED
@@ -5,4 +5,14 @@ require 'rspec/core/rake_task'
5
5
 
6
6
  RSpec::Core::RakeTask.new(:spec)
7
7
 
8
+ namespace :spec do
9
+ RSpec::Core::RakeTask.new(:integration) do |t|
10
+ t.rspec_opts = '--tag type:integration'
11
+ end
12
+
13
+ RSpec::Core::RakeTask.new(:unit) do |t|
14
+ t.rspec_opts = '--tag ~type:integration'
15
+ end
16
+ end
17
+
8
18
  task default: :spec
data/bin/setup CHANGED
@@ -4,3 +4,4 @@ IFS=$'\n\t'
4
4
  set -vx
5
5
 
6
6
  bundle install
7
+ npm ci
@@ -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
@@ -19,26 +21,41 @@ class AuditService
19
21
  measured_score >= @score
20
22
  end
21
23
 
24
+ def measured_score
25
+ category['score'] * 100
26
+ end
27
+
28
+ def run_warnings
29
+ results['runWarnings']
30
+ end
31
+
22
32
  private
23
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
+
24
44
  def opts
25
45
  "'#{@url}'".tap do |builder|
26
46
  builder << ' --quiet'
27
47
  builder << ' --output=json'
48
+ builder << " --only-categories=#{@audit}"
28
49
  builder << " --port=#{@port}" if @port
29
50
  builder << " --chrome-flags='#{@chrome_flags}'" if @chrome_flags
30
51
  end.strip
31
52
  end
32
53
 
33
54
  def output
34
- @runner.call("#{@cmd} #{opts}")
55
+ @output ||= @runner.call("#{@cmd} #{opts}")
35
56
  end
36
57
 
37
58
  def results
38
- JSON.parse(output)
39
- end
40
-
41
- def measured_score
42
- results.dig('categories', @audit.to_s, 'score') * 100
59
+ @results ||= JSON.parse(output)
43
60
  end
44
61
  end
@@ -5,17 +5,27 @@ require 'lighthouse/matchers'
5
5
  require 'lighthouse/audit_service'
6
6
  require 'json'
7
7
 
8
- RSpec::Matchers.define :pass_lighthouse_audit do |audit, score: nil|
9
- score ||= Lighthouse::Matchers.minimum_score
8
+ RSpec::Matchers.define :pass_lighthouse_audit do |audit, args = {}|
9
+ score ||= args.fetch(:score, Lighthouse::Matchers.minimum_score)
10
10
 
11
11
  match do |target|
12
- AuditService.new(url(target), audit, score).passing_score?
12
+ audit_service = AuditService.new(url(target), audit, score)
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
+
20
+ @measured_score = audit_service.measured_score
21
+
22
+ audit_service.passing_score?
13
23
  end
14
24
 
15
25
  failure_message do |target|
16
26
  <<~FAIL
17
27
  expected #{url(target)} to pass Lighthouse #{audit} audit
18
- with a minimum score of #{score}
28
+ with a minimum score of #{score}, but only scored #{@measured_score.to_i}
19
29
  FAIL
20
30
  end
21
31
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lighthouse
4
4
  module Matchers
5
- VERSION = '1.0.3'
5
+ VERSION = '1.2.0'
6
6
  end
7
7
  end
@@ -9,12 +9,8 @@ module Lighthouse
9
9
  module Matchers # rubocop:disable Style/Documentation
10
10
  class Error < StandardError; end
11
11
  class << self
12
- attr_writer :minimum_score,
13
- :remote_debugging_port,
14
- :lighthouse_cli,
15
- :runner,
16
- :chrome_flags
17
- attr_reader :remote_debugging_port
12
+ attr_writer :minimum_score, :lighthouse_cli, :runner, :chrome_flags
13
+ attr_accessor :remote_debugging_port
18
14
 
19
15
  def minimum_score
20
16
  @minimum_score ||= default_minimum_score
@@ -19,9 +19,10 @@ Gem::Specification.new do |spec|
19
19
  spec.metadata['homepage_uri'] = spec.homepage
20
20
  spec.metadata['source_code_uri'] = 'https://github.com/ackama/lighthouse-matchers'
21
21
  spec.metadata['changelog_uri'] = 'https://github.com/ackama/lighthouse-matchers/blob/master/CHANGELOG.md'
22
+ spec.metadata['rubygems_mfa_required'] = 'true'
22
23
  else
23
24
  raise 'RubyGems 2.0 or newer is required to protect against ' \
24
- 'public gem pushes.'
25
+ 'public gem pushes.'
25
26
  end
26
27
 
27
28
  # Specify which files should be added to the gem when it is released.
@@ -36,8 +37,12 @@ Gem::Specification.new do |spec|
36
37
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
38
  spec.require_paths = ['lib']
38
39
 
40
+ spec.required_ruby_version = '>= 2.5.0'
41
+
39
42
  spec.add_development_dependency 'bundler', '~> 2.0'
40
- spec.add_development_dependency 'rake', '~> 10.0'
43
+ spec.add_development_dependency 'rake', '~> 13.0'
41
44
  spec.add_development_dependency 'rspec', '~> 3.0'
45
+ spec.add_development_dependency 'rspec-retry'
42
46
  spec.add_development_dependency 'rubocop'
47
+ spec.add_development_dependency 'webrick'
43
48
  end