lighthouse-matchers 1.0.1 → 1.0.2
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 +4 -4
- data/CHANGELOG.md +7 -1
- data/Gemfile.lock +2 -2
- data/lib/lighthouse/audit_service.rb +37 -0
- data/lib/lighthouse/matchers/rspec.rb +11 -13
- data/lib/lighthouse/matchers/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39bae0e8641dae16dd253b900d90ccf0e96008353bebff86bacfc7007d4131ca
|
4
|
+
data.tar.gz: 5ec2143cae768123fe66d882800513e1cf4d2e6194d74bb9297fde83bab999f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e537f89cf5cb908ec7f4afe6ddfce0cdca25ac710ac7e8ee7365a53630e8b854ba9155f33c1e9c37ed59eae19d62e6194198715ad466f7268b5dd3e45ec66d36
|
7
|
+
data.tar.gz: d9ce149527bf757d862d93baf1a1fdc3a5b60064c73d50d5304f5c5ffa36edde525b00a38ce6dc3c96c7516240e8e6b7a7c55a1ec4381a05275dde330da7b346
|
data/CHANGELOG.md
CHANGED
@@ -12,4 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
12
12
|
|
13
13
|
## [1.0.1] - 2019-05-24
|
14
14
|
### Changed
|
15
|
-
- Apply bug fixes based on integration with a Ruby on Rails project
|
15
|
+
- Apply bug fixes based on integration with a Ruby on Rails project
|
16
|
+
|
17
|
+
## [1.0.2] - 2019-08-16
|
18
|
+
### Changed
|
19
|
+
- Refactored auditing into a service object (@CaraHill)
|
20
|
+
-
|
21
|
+
|
data/Gemfile.lock
CHANGED
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
# Compares a url's actual score to the expected score.
|
6
|
+
class AuditService
|
7
|
+
def initialize(url, audit, score)
|
8
|
+
@url = url
|
9
|
+
@audit = audit
|
10
|
+
@score = score
|
11
|
+
@port = Lighthouse::Matchers.remote_debugging_port
|
12
|
+
@runner = Lighthouse::Matchers.runner
|
13
|
+
@cmd = Lighthouse::Matchers.lighthouse_cli
|
14
|
+
end
|
15
|
+
|
16
|
+
def passing_score?
|
17
|
+
measured_score >= @score
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def opts
|
23
|
+
"'#{@url}' --quiet --output=json #{"--port=#{@port}" if @port}".strip
|
24
|
+
end
|
25
|
+
|
26
|
+
def output
|
27
|
+
@runner.call("#{@cmd} #{opts}")
|
28
|
+
end
|
29
|
+
|
30
|
+
def results
|
31
|
+
JSON.parse(output)
|
32
|
+
end
|
33
|
+
|
34
|
+
def measured_score
|
35
|
+
results.dig('categories', @audit.to_s, 'score') * 100
|
36
|
+
end
|
37
|
+
end
|
@@ -2,28 +2,26 @@
|
|
2
2
|
|
3
3
|
require 'rspec/expectations'
|
4
4
|
require 'lighthouse/matchers'
|
5
|
+
require 'lighthouse/audit_service'
|
5
6
|
require 'json'
|
6
7
|
|
7
8
|
RSpec::Matchers.define :pass_lighthouse_audit do |audit, score: nil|
|
8
|
-
|
9
|
-
score ||= Lighthouse::Matchers.minimum_score
|
10
|
-
port = Lighthouse::Matchers.remote_debugging_port
|
11
|
-
runner = Lighthouse::Matchers.runner
|
9
|
+
score ||= Lighthouse::Matchers.minimum_score
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
cmd = Lighthouse::Matchers.lighthouse_cli
|
16
|
-
output = runner.call("#{cmd} #{opts}")
|
17
|
-
results = JSON.parse(output)
|
18
|
-
actual_score = results.dig('categories', audit.to_s, 'score') * 100
|
19
|
-
actual_score >= score
|
11
|
+
match do |target|
|
12
|
+
AuditService.new(url(target), audit, score).passing_score?
|
20
13
|
end
|
21
14
|
|
22
15
|
failure_message do |target|
|
23
|
-
url = target.respond_to?(:current_url) ? target.current_url : target
|
24
16
|
<<~FAIL
|
25
|
-
expected #{url} to pass Lighthouse #{audit} audit
|
17
|
+
expected #{url(target)} to pass Lighthouse #{audit} audit
|
26
18
|
with a minimum score of #{score}
|
27
19
|
FAIL
|
28
20
|
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def url(target)
|
25
|
+
target.respond_to?(:current_url) ? target.current_url : target
|
26
|
+
end
|
29
27
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lighthouse-matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh McArthur on behalf of Ackama
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -88,6 +88,7 @@ files:
|
|
88
88
|
- bin/ci-run
|
89
89
|
- bin/console
|
90
90
|
- bin/setup
|
91
|
+
- lib/lighthouse/audit_service.rb
|
91
92
|
- lib/lighthouse/matchers.rb
|
92
93
|
- lib/lighthouse/matchers/rspec.rb
|
93
94
|
- lib/lighthouse/matchers/version.rb
|