lighthouse-matchers 1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f51726040b980a9839d9d977ed5c4d33970143487d99e45a232b14ed1285f676
4
+ data.tar.gz: 76d4e7ebca933f34aca2493b3a7b2835f3ad40eb2e7e85c9941edf34cd612556
5
+ SHA512:
6
+ metadata.gz: bf67b535c041abfd96e076e785b427591c0a6deed1b0c0143ba59ef3925d6ee0da5c2908482fe09ecc2509c1d13b77c8e919da1d394305868dadf59cfe969e91
7
+ data.tar.gz: fd2c2314d4c48911b64b664580a71b26c7296af56053dba9c904bb68f6406039acaa8d98bc7870c77dc428c36a58ee30c062c2a9ec062de0745e4f75eca06a89
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,6 @@
1
+ Metrics/BlockLength:
2
+ Exclude:
3
+ - 'spec/**/*_spec.rb'
4
+ - 'lighthouse-matchers.gemspec'
5
+ Metrics/LineLength:
6
+ Max: 100
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.4.6
4
+ - 2.5.5
5
+ - 2.6.3
6
+ cache: bundler
7
+ before_install:
8
+ - gem update --system --no-document
9
+ - gem install bundler --no-document
10
+ install: "bin/setup"
11
+ script: "bin/ci-run"
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in lighthouse-matchers.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,51 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ lighthouse-matchers (1.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.0)
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)
15
+ rainbow (3.0.0)
16
+ rake (10.5.0)
17
+ rspec (3.8.0)
18
+ rspec-core (~> 3.8.0)
19
+ rspec-expectations (~> 3.8.0)
20
+ rspec-mocks (~> 3.8.0)
21
+ rspec-core (3.8.0)
22
+ rspec-support (~> 3.8.0)
23
+ rspec-expectations (3.8.3)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.8.0)
26
+ rspec-mocks (3.8.0)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.8.0)
29
+ rspec-support (3.8.0)
30
+ rubocop (0.70.0)
31
+ jaro_winkler (~> 1.5.1)
32
+ parallel (~> 1.10)
33
+ parser (>= 2.6)
34
+ rainbow (>= 2.2.2, < 4.0)
35
+ 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)
39
+
40
+ PLATFORMS
41
+ ruby
42
+
43
+ DEPENDENCIES
44
+ bundler (~> 2.0)
45
+ lighthouse-matchers!
46
+ rake (~> 10.0)
47
+ rspec (~> 3.0)
48
+ rubocop
49
+
50
+ BUNDLED WITH
51
+ 2.0.1
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Ackama
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,133 @@
1
+ # 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)
2
+
3
+ Lighthouse Matchers provides single-line RSpec matchers for
4
+ expectations against the result of [Lighthouse](https://developers.google.com/web/tools/lighthouse/)
5
+ audit checks.
6
+
7
+ ## Getting Started
8
+
9
+ ### RSpec
10
+
11
+ Start by including the gem in your Gemfile:
12
+
13
+ ``` ruby
14
+ group :test do
15
+ gem 'lighthouse-matchers'
16
+ end
17
+ ```
18
+
19
+ Next, you need to require the matchers in your `spec_helper.rb` or `rails_helper.rb`:
20
+
21
+ ``` ruby
22
+ require "lighthouse/matchers/rspec"
23
+ ```
24
+
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:
27
+
28
+ * `npm install --save-dev lighthouse`
29
+ * `yarn add --dev ligththouse`
30
+
31
+ If you have the `lighthouse` CLI tool installed, but available elsewhere on your system, you can set the location manually.
32
+ See [Configuration](#configuration) for further instructions.
33
+
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
36
+ change the definition of your system test Chrome browser arguments to define a "remote debugging port". Without
37
+ defining this port, The `lighthouse` audit tool cannot connect to your existing Chrome session and will begin a new
38
+ one, clearing any session information.
39
+
40
+ An example of such a configuration is:
41
+
42
+ ``` ruby
43
+ # spec/spec_helper.rb
44
+
45
+ Capybara.register_driver :headless_chrome do |app|
46
+ capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
47
+ chromeOptions: { args: %w(headless remote-debugging-port=9222) }
48
+ )
49
+
50
+ Capybara::Selenium::Driver.new app,
51
+ browser: :chrome,
52
+ desired_capabilities: capabilities
53
+ end
54
+
55
+ Capybara.javascript_driver = :headless_chrome
56
+ Lighthouse::Matchers.remote_debugging_port = 9222
57
+ ```
58
+
59
+ ### Test::Unit
60
+
61
+ Test::Unit support is planning and is coming soon!
62
+
63
+ ## Matchers
64
+
65
+ ### `pass_lighthouse_audit`
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
70
+ entirely.
71
+
72
+ #### Examples
73
+
74
+ * Assert that a URL fully passes all audits:
75
+ ```
76
+ it { expect("http://mysite.com").to pass_lighthouse_audit }
77
+ ```
78
+ * Assert that a Capybara page object passes a performance audit only:
79
+ ```
80
+ it { expect(page).to pass_lighthouse_audit(:performance) }
81
+ ```
82
+ * Assert that a Capybara page object passes all audits with a minimum score of 60:
83
+ ```
84
+ it { expect(page).to pass_lighthouse_audit(score: 60) }
85
+ ```
86
+ * Assert that a URL passes the PWA audit with a minimum score of 90:
87
+ ```
88
+ it { expect("http://pwa.mysite.com").to pass_lighthouse_audit(:pwa, score: 90) }
89
+ ```
90
+
91
+ ## Configuration
92
+
93
+ All configuration keys are accessible against the `Lighthouse::Matchers` object. Configuration options include:
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
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
100
+ Selenium webdrivers are being used.
101
+ * **`lighthouse_cli`:** The path to the Lighthouse CLI tool. By default, we will check `$PATH` and `node_modules/.bin/`
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.
104
+ The default value of this configuration setting is '100' - e.g. audits must fully comply to pass.
105
+
106
+ ## Compatibility
107
+
108
+ * Lighthouse Matchers is tested and supported against Ruby 2.0+ and RSpec 3.x.
109
+ * The `lighthouse` CLI tool must be installed for these matchers to function.
110
+ * The [`capybara`](https://rubygems.org/gems/capybara) gem is required to make assertions
111
+ by passing in a `Capybara::Session`.
112
+
113
+ ## Contributing
114
+
115
+ Contributions are welcome.
116
+ Please see the [contribution guidelines](https://github.com/ackama/lighthouse-matchers/blob/master/CONTRIBUTING.md)
117
+ for detailed instructions.
118
+
119
+ ## Versioning
120
+
121
+ This gem endeavours to follow Semantic Versioning 2.0 as defined at https://semver.org/.
122
+
123
+ ## License
124
+
125
+ lighthouse-matchers is copyright © 2019 Ackama Group Ltd.
126
+ It is free software, and may be redistributed under the terms specified in the
127
+ [LICENSE](https://github.com/ackama/lighthouse-matchers/blob/master/LICENSE.txt) file.
128
+
129
+
130
+ ## About Ackama
131
+
132
+ Lighthouse Matchers is created and maintained by Ackama Group using our investment time scheme.
133
+ We are passionate about using and contributing back to the open source community, and are available for hire.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/ci-run ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env bash
2
+
3
+ bundle exec rspec spec
4
+ bundle exec rubocop
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'lighthouse/audit/matchers'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rspec/expectations'
4
+ require 'lighthouse/matchers'
5
+ require 'json'
6
+
7
+ RSpec::Matchers.define :pass_lighthouse_audit do |audit, score: nil|
8
+ match do |target|
9
+ score ||= Lighthouse::Matchers.minimum_score
10
+ port = Lighthouse::Matchers.remote_debugging_port
11
+ runner = Lighthouse::Matchers.runner
12
+
13
+ url = target.respond_to?(:current_url) ? target.current_url : target
14
+ opts = "'#{url}' --quiet --output=json"
15
+ opts << " --port '#{port}'" if port
16
+ cmd = Lighthouse::Matchers.lighthouse_cli
17
+ output = runner.call("#{cmd} #{opts}")
18
+ results = JSON.parse(output)
19
+ actual_score = results.dig('categories', audit.to_s, 'score') * 100
20
+ actual_score >= score
21
+ end
22
+
23
+ failure_message do |target|
24
+ url = target.respond_to?(:current_url) ? target.current_url : target
25
+ <<~FAIL
26
+ expected #{url} to pass Lighthouse #{audit} audit
27
+ with a minimum score of #{score}
28
+ FAIL
29
+ end
30
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lighthouse
4
+ module Matchers
5
+ VERSION = '1.0.0'
6
+ end
7
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'lighthouse/matchers/version'
4
+
5
+ module Lighthouse
6
+ ##
7
+ # Defines configuration and behaviours that are shared across the entire
8
+ # Lighthouse::Matchers namespace
9
+ module Matchers
10
+ class Error < StandardError; end
11
+ class << self
12
+ attr_writer :minimum_score,
13
+ :remote_debugging_port,
14
+ :lighthouse_cli,
15
+ :runner
16
+ attr_reader :remote_debugging_port
17
+
18
+ def minimum_score
19
+ @minimum_score ||= default_minimum_score
20
+ end
21
+
22
+ def lighthouse_cli
23
+ @lighthouse_cli ||= lighthouse_cli
24
+ end
25
+
26
+ def runner
27
+ @runner ||= Kernel.method(:system)
28
+ end
29
+
30
+ private
31
+
32
+ def guess_lighthouse_cli
33
+ [
34
+ `which lighthouse` || '',
35
+ 'node_modules/.bin/lighthouse',
36
+ 'node_modules/bin/lighthouse'
37
+ ].find { |loc| File.exist?(loc) }
38
+ end
39
+
40
+ def default_minimum_score
41
+ 100
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'lighthouse/matchers/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'lighthouse-matchers'
9
+ spec.version = Lighthouse::Matchers::VERSION
10
+ spec.authors = ['Josh McArthur on behalf of Ackama']
11
+ spec.email = ['josh.mcarthur@ackama.com']
12
+
13
+ spec.summary = <<~DESC
14
+ Provides RSpec matchers for executing and evaluating Lighthouse audit scores
15
+ DESC
16
+ spec.homepage = 'https://github.com/ackama/lighthouse-matchers'
17
+
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['homepage_uri'] = spec.homepage
20
+ spec.metadata['source_code_uri'] = 'https://github.com/ackama/lighthouse-matchers'
21
+ spec.metadata['changelog_uri'] = 'https://github.com/ackama/lighthouse-matchers/blob/master/CHANGELOG.md'
22
+ else
23
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
24
+ 'public gem pushes.'
25
+ end
26
+
27
+ # Specify which files should be added to the gem when it is released.
28
+ # The `git ls-files -z` loads the files in the RubyGem that have been added
29
+ # into git.
30
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
31
+ `git ls-files -z`.split("\x0").reject do |f|
32
+ f.match(%r{^(test|spec|features)/})
33
+ end
34
+ end
35
+ spec.bindir = 'exe'
36
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
+ spec.require_paths = ['lib']
38
+
39
+ spec.add_development_dependency 'bundler', '~> 2.0'
40
+ spec.add_development_dependency 'rake', '~> 10.0'
41
+ spec.add_development_dependency 'rspec', '~> 3.0'
42
+ spec.add_development_dependency 'rubocop'
43
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lighthouse-matchers
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Josh McArthur on behalf of Ackama
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-05-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - josh.mcarthur@ackama.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".rubocop.yml"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - LICENSE
83
+ - README.md
84
+ - Rakefile
85
+ - bin/ci-run
86
+ - bin/console
87
+ - bin/setup
88
+ - lib/lighthouse/matchers.rb
89
+ - lib/lighthouse/matchers/rspec.rb
90
+ - lib/lighthouse/matchers/version.rb
91
+ - lighthouse-matchers.gemspec
92
+ homepage: https://github.com/ackama/lighthouse-matchers
93
+ licenses: []
94
+ metadata:
95
+ homepage_uri: https://github.com/ackama/lighthouse-matchers
96
+ source_code_uri: https://github.com/ackama/lighthouse-matchers
97
+ changelog_uri: https://github.com/ackama/lighthouse-matchers/blob/master/CHANGELOG.md
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubygems_version: 3.0.3
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Provides RSpec matchers for executing and evaluating Lighthouse audit scores
117
+ test_files: []