lighthouse-matchers 1.0.3 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +45 -0
- data/.github/workflows/codeql.yml +74 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +5 -2
- data/CHANGELOG.md +13 -11
- data/CONTRIBUTING.md +22 -12
- data/Gemfile.lock +25 -15
- data/README.md +23 -23
- data/Rakefile +10 -0
- data/bin/ci-run +4 -2
- data/bin/setup +1 -0
- data/lib/lighthouse/audit_service.rb +6 -5
- data/lib/lighthouse/matchers/rspec.rb +8 -4
- data/lib/lighthouse/matchers/version.rb +1 -1
- data/lib/lighthouse/matchers.rb +2 -6
- data/lighthouse-matchers.gemspec +7 -2
- data/package-lock.json +959 -0
- data/package.json +32 -0
- metadata +39 -7
- data/.travis.yml +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d59475b53e41779753dc20a7d0775dc4300494da79af101d2671b235d9952192
|
4
|
+
data.tar.gz: 41d0d01d7494075bc18d6dc3bca107f5de9ec3400cf89eac689c8834fd24efdd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 201ae5239f163fc312f4edb460b7e9a5969757c06b7093792b7f0ff8cff7e5baccf9ec8aa8c5ac612d537bb6a371fb605c6099d833ca7b5ed918abbde2932ede
|
7
|
+
data.tar.gz: 2879723cd480d9e67e2578c5e89f78e6251350cd01702a3cd7150705fdf2e3245ed9319a44b929280e65d8640a4d6508b876065f9dbb5e1bbc434149e96bfe4a
|
@@ -0,0 +1,45 @@
|
|
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
|
+
test:
|
26
|
+
runs-on: ubuntu-latest
|
27
|
+
strategy:
|
28
|
+
fail-fast: false
|
29
|
+
matrix:
|
30
|
+
ruby-version: ['2.5', '2.6', '2.7', '3.0', '3.1']
|
31
|
+
steps:
|
32
|
+
- uses: actions/checkout@v3
|
33
|
+
with:
|
34
|
+
persist-credentials: false
|
35
|
+
- uses: ruby/setup-ruby@v1
|
36
|
+
with:
|
37
|
+
ruby-version: ${{ matrix.ruby-version }}
|
38
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
39
|
+
- uses: actions/setup-node@v3
|
40
|
+
with:
|
41
|
+
cache: 'npm'
|
42
|
+
- run: npm ci
|
43
|
+
- run: npm test
|
44
|
+
env:
|
45
|
+
CI_CHROME_FLAGS: "--headless"
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# For most projects, this workflow file will not need changing; you simply need
|
2
|
+
# to commit it to your repository.
|
3
|
+
#
|
4
|
+
# You may wish to alter this file to override the set of languages analyzed,
|
5
|
+
# or to provide custom queries or build logic.
|
6
|
+
#
|
7
|
+
# ******** NOTE ********
|
8
|
+
# We have attempted to detect the languages in your repository. Please check
|
9
|
+
# the `language` matrix defined below to confirm you have the correct set of
|
10
|
+
# supported CodeQL languages.
|
11
|
+
#
|
12
|
+
name: "CodeQL"
|
13
|
+
|
14
|
+
on:
|
15
|
+
push:
|
16
|
+
branches: [ "main" ]
|
17
|
+
pull_request:
|
18
|
+
# The branches below must be a subset of the branches above
|
19
|
+
branches: [ "main" ]
|
20
|
+
schedule:
|
21
|
+
- cron: '32 23 * * 1'
|
22
|
+
|
23
|
+
jobs:
|
24
|
+
analyze:
|
25
|
+
name: Analyze
|
26
|
+
runs-on: ubuntu-latest
|
27
|
+
permissions:
|
28
|
+
actions: read
|
29
|
+
contents: read
|
30
|
+
security-events: write
|
31
|
+
|
32
|
+
strategy:
|
33
|
+
fail-fast: false
|
34
|
+
matrix:
|
35
|
+
language: [ 'ruby' ]
|
36
|
+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
|
37
|
+
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
|
38
|
+
|
39
|
+
steps:
|
40
|
+
- name: Checkout repository
|
41
|
+
uses: actions/checkout@v3
|
42
|
+
|
43
|
+
# Initializes the CodeQL tools for scanning.
|
44
|
+
- name: Initialize CodeQL
|
45
|
+
uses: github/codeql-action/init@v2
|
46
|
+
with:
|
47
|
+
languages: ${{ matrix.language }}
|
48
|
+
# If you wish to specify custom queries, you can do so here or in a config file.
|
49
|
+
# By default, queries listed here will override any specified in a config file.
|
50
|
+
# Prefix the list here with "+" to use these queries and those in the config file.
|
51
|
+
|
52
|
+
# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
|
53
|
+
# queries: security-extended,security-and-quality
|
54
|
+
|
55
|
+
|
56
|
+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
57
|
+
# If this step fails, then you should remove it and run the build manually (see below)
|
58
|
+
- name: Autobuild
|
59
|
+
uses: github/codeql-action/autobuild@v2
|
60
|
+
|
61
|
+
# ℹ️ Command-line programs to run using the OS shell.
|
62
|
+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
|
63
|
+
|
64
|
+
# If the Autobuild fails above, remove it and uncomment the following three lines.
|
65
|
+
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
|
66
|
+
|
67
|
+
# - run: |
|
68
|
+
# echo "Run, Build Application using script"
|
69
|
+
# ./location_of_script_within_repo/buildscript.sh
|
70
|
+
|
71
|
+
- name: Perform CodeQL Analysis
|
72
|
+
uses: github/codeql-action/analyze@v2
|
73
|
+
with:
|
74
|
+
category: "/language:${{matrix.language}}"
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -6,21 +6,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
-
## [1.
|
10
|
-
### Added
|
11
|
-
- Initial version release with minimal viable matcher
|
12
|
-
|
13
|
-
## [1.0.1] - 2019-05-24
|
9
|
+
## [1.1.0] - 2023-08-27
|
14
10
|
### Changed
|
15
|
-
-
|
11
|
+
- Only run audits for categories that are requested to improve performance ([#28](https://github.com/ackama/lighthouse-matchers/pull/28))
|
12
|
+
- Include measured score in failure message ([#26](https://github.com/ackama/lighthouse-matchers/pull/26))
|
16
13
|
|
17
|
-
## [1.0.2] - 2019-08-16
|
18
|
-
### Changed
|
19
|
-
- Refactored auditing into a service object (@CaraHill)
|
20
|
-
-
|
21
14
|
## [1.0.3] - 2019-08-27
|
22
15
|
### Added
|
23
|
-
|
24
16
|
- **chrome_flags** option to allow the Chrome launch behaviour of the `lighthouse` command. (#8)
|
25
17
|
|
18
|
+
## [1.0.2] - 2019-08-16
|
19
|
+
### Changed
|
20
|
+
- Refactored auditing into a service object (@CaraHill)
|
21
|
+
|
22
|
+
## [1.0.1] - 2019-05-24
|
23
|
+
### Changed
|
24
|
+
- Apply bug fixes based on integration with a Ruby on Rails project
|
26
25
|
|
26
|
+
## [1.0.0] - 2019-05-24
|
27
|
+
### Added
|
28
|
+
- 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
|
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 [
|
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][
|
156
|
+
[monitor as it progresses][actions].
|
145
157
|
|
146
|
-
[
|
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,20 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
lighthouse-matchers (1.0
|
4
|
+
lighthouse-matchers (1.1.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
ast (2.4.
|
9
|
+
ast (2.4.2)
|
10
10
|
diff-lcs (1.3)
|
11
|
-
|
12
|
-
|
13
|
-
|
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 (
|
15
|
+
rake (13.0.1)
|
16
|
+
regexp_parser (2.2.0)
|
17
|
+
rexml (3.2.5)
|
17
18
|
rspec (3.8.0)
|
18
19
|
rspec-core (~> 3.8.0)
|
19
20
|
rspec-expectations (~> 3.8.0)
|
@@ -26,16 +27,23 @@ GEM
|
|
26
27
|
rspec-mocks (3.8.0)
|
27
28
|
diff-lcs (>= 1.2.0, < 2.0)
|
28
29
|
rspec-support (~> 3.8.0)
|
30
|
+
rspec-retry (0.6.2)
|
31
|
+
rspec-core (> 3.3)
|
29
32
|
rspec-support (3.8.0)
|
30
|
-
rubocop (
|
31
|
-
jaro_winkler (~> 1.5.1)
|
33
|
+
rubocop (1.24.1)
|
32
34
|
parallel (~> 1.10)
|
33
|
-
parser (>=
|
35
|
+
parser (>= 3.0.0.0)
|
34
36
|
rainbow (>= 2.2.2, < 4.0)
|
37
|
+
regexp_parser (>= 1.8, < 3.0)
|
38
|
+
rexml
|
39
|
+
rubocop-ast (>= 1.15.1, < 2.0)
|
35
40
|
ruby-progressbar (~> 1.7)
|
36
|
-
unicode-display_width (>= 1.4.0, <
|
37
|
-
|
38
|
-
|
41
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
42
|
+
rubocop-ast (1.15.1)
|
43
|
+
parser (>= 3.0.1.1)
|
44
|
+
ruby-progressbar (1.11.0)
|
45
|
+
unicode-display_width (2.1.0)
|
46
|
+
webrick (1.7.0)
|
39
47
|
|
40
48
|
PLATFORMS
|
41
49
|
ruby
|
@@ -43,9 +51,11 @@ PLATFORMS
|
|
43
51
|
DEPENDENCIES
|
44
52
|
bundler (~> 2.0)
|
45
53
|
lighthouse-matchers!
|
46
|
-
rake (~>
|
54
|
+
rake (~> 13.0)
|
47
55
|
rspec (~> 3.0)
|
56
|
+
rspec-retry
|
48
57
|
rubocop
|
58
|
+
webrick
|
49
59
|
|
50
60
|
BUNDLED WITH
|
51
|
-
2.
|
61
|
+
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://
|
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
|
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,29 +92,29 @@ 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
|
@@ -124,11 +124,11 @@ This gem endeavours to follow Semantic Versioning 2.0 as defined at https://semv
|
|
124
124
|
## License
|
125
125
|
|
126
126
|
lighthouse-matchers is copyright © 2019 Ackama Group Ltd.
|
127
|
-
It is free software, and may be redistributed under the terms specified in the
|
127
|
+
It is free software, and may be redistributed under the terms specified in the
|
128
128
|
[LICENSE](https://github.com/ackama/lighthouse-matchers/blob/master/LICENSE.txt) file.
|
129
129
|
|
130
130
|
|
131
131
|
## About Ackama
|
132
132
|
|
133
|
-
Lighthouse Matchers is created and maintained by Ackama Group using our investment time scheme.
|
133
|
+
Lighthouse Matchers is created and maintained by Ackama Group using our investment time scheme.
|
134
134
|
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/ci-run
CHANGED
data/bin/setup
CHANGED
@@ -19,26 +19,27 @@ class AuditService
|
|
19
19
|
measured_score >= @score
|
20
20
|
end
|
21
21
|
|
22
|
+
def measured_score
|
23
|
+
results.dig('categories', @audit.to_s, 'score') * 100
|
24
|
+
end
|
25
|
+
|
22
26
|
private
|
23
27
|
|
24
28
|
def opts
|
25
29
|
"'#{@url}'".tap do |builder|
|
26
30
|
builder << ' --quiet'
|
27
31
|
builder << ' --output=json'
|
32
|
+
builder << " --only-categories=#{@audit}"
|
28
33
|
builder << " --port=#{@port}" if @port
|
29
34
|
builder << " --chrome-flags='#{@chrome_flags}'" if @chrome_flags
|
30
35
|
end.strip
|
31
36
|
end
|
32
37
|
|
33
38
|
def output
|
34
|
-
@runner.call("#{@cmd} #{opts}")
|
39
|
+
@output ||= @runner.call("#{@cmd} #{opts}")
|
35
40
|
end
|
36
41
|
|
37
42
|
def results
|
38
43
|
JSON.parse(output)
|
39
44
|
end
|
40
|
-
|
41
|
-
def measured_score
|
42
|
-
results.dig('categories', @audit.to_s, 'score') * 100
|
43
|
-
end
|
44
45
|
end
|
@@ -5,17 +5,21 @@ require 'lighthouse/matchers'
|
|
5
5
|
require 'lighthouse/audit_service'
|
6
6
|
require 'json'
|
7
7
|
|
8
|
-
RSpec::Matchers.define :pass_lighthouse_audit do |audit,
|
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)
|
12
|
+
audit_service = AuditService.new(url(target), audit, score)
|
13
|
+
|
14
|
+
@measured_score = audit_service.measured_score
|
15
|
+
|
16
|
+
audit_service.passing_score?
|
13
17
|
end
|
14
18
|
|
15
19
|
failure_message do |target|
|
16
20
|
<<~FAIL
|
17
21
|
expected #{url(target)} to pass Lighthouse #{audit} audit
|
18
|
-
with a minimum score of #{score}
|
22
|
+
with a minimum score of #{score}, but only scored #{@measured_score.to_i}
|
19
23
|
FAIL
|
20
24
|
end
|
21
25
|
|
data/lib/lighthouse/matchers.rb
CHANGED
@@ -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
|
-
|
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
|
data/lighthouse-matchers.gemspec
CHANGED
@@ -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
|
-
|
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', '~>
|
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
|