ackama / lighthouse-matchers

Provides RSpec matchers for executing and evaluating Google Chrome Lighthouse audit scores
MIT License
15 stars 1 forks source link
ackama lighthouse-audits lighthouse-matchers rspec rspec-matchers ruby

Lighthouse Matchers Gem Version Maintainability Build Status

Lighthouse Matchers provides single-line RSpec matchers for expectations against the result of Lighthouse audit checks.

Getting Started

RSpec

Start by including the gem in your Gemfile:

group :test do
  gem 'lighthouse-matchers'
end

Next, you need to require the matchers in your spec_helper.rb or rails_helper.rb:

require "lighthouse/matchers/rspec"

You also need to have the lighthouse CLI tool available. The matchers will automatically pick up the tool if you have added it to your $PATH, or if you have installed the tool using:

If you have the lighthouse CLI tool installed, but available elsewhere on your system, you can set the location manually. See Configuration for further instructions.

The matchers are now available to use. If you wish for your Lighthouse audits to use the same Chrome session as your system tests (e.g. the page requires a logged-in user), then you should change the definition of your system test Chrome browser arguments to define a "remote debugging port". Without defining this port, The lighthouse audit tool cannot connect to your existing Chrome session and will begin a new one, clearing any session information.

An example of such a configuration is:

# spec/spec_helper.rb

Capybara.register_driver :headless_chrome do |app|
  capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
    chromeOptions: { args: %w(headless remote-debugging-port=9222) }
  )

  Capybara::Selenium::Driver.new app,
    browser: :chrome,
    desired_capabilities: capabilities
end

Capybara.javascript_driver = :headless_chrome
Lighthouse::Matchers.remote_debugging_port = 9222

Test::Unit

Test::Unit support is planned and is coming soon!

Matchers

pass_lighthouse_audit

This matcher accepts an optional audit type, and minimum score. If no audit type is passed in, then all audits are run. If a minimum score is not provided, then the score defined in Lighthouse::Matchers.minimum_score is used. The default value of this attribute is 100 - i.e. the audit must pass entirely.

Examples

Configuration

All configuration keys are accessible against the Lighthouse::Matchers object. Configuration options include:

Compatibility

Contributing

Contributions are welcome. Please see the contribution guidelines for detailed instructions.

Versioning

This gem endeavours to follow Semantic Versioning 2.0 as defined at https://semver.org/.

Releasing

Releases are done automatically by GitHub Actions when a new tag is pushed to the repository.

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.

License

lighthouse-matchers is copyright © 2019 Ackama Group Ltd. It is free software, and may be redistributed under the terms specified in the LICENSE file.

About Ackama

Lighthouse Matchers is created and maintained by Ackama Group using our investment time scheme. We are passionate about using and contributing back to the open source community, and are available for hire.