lighthouse-ruby 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c84dba7f164d2947db4d34b0743b2fa62e251e6552d8170b76ec9f57cd48021e
4
- data.tar.gz: bba2e92af4b23e65ae628ef529f901bee480b51cdeabbdcb7b318f2fce3e24e6
3
+ metadata.gz: 9e7b870fb6324f0497790a8e4a5b5924e1340aaa4d33465f114e5dfe4d499b44
4
+ data.tar.gz: 744b5ed24dae228555193ecf6e0a0f36de24f3d33665e75549f33e657fcc89a4
5
5
  SHA512:
6
- metadata.gz: 0133d7c2fa5dca6e292472fe10ed78ac0f25e4e4ce368a01a45ca3a9cd21fbfa0bae830837d49cb1e309b1d7fafa974069d35ed888a648d4852b98a567a6e2ad
7
- data.tar.gz: 69eea8a370f6c87b1c49c59f8cedb115793d33458a406c7b52c41d909a4e27ab56233410c118b979468cf11c929c387a946dc1456fdd9415324e2208bd5fe32b
6
+ metadata.gz: 284a6301e0f4f28eac94f8ede197aaaba6e367282edf5eaaa99c2d35b038fe1f991ccc5a4e6b1aed03d3388cf61e962de11436b97d8df6a826a2392cbee8cb20
7
+ data.tar.gz: 7646a486ae91c4a7a878558e18160af35b226a586e4d6f1e26b791e7d023e06daf830bd6cfda36955ccaf0a43e0957c46f222bc3030b953db62f93630fba1d85
data/README.md CHANGED
@@ -9,7 +9,9 @@ TODO: Delete this and the text above, and describe your gem
9
9
  Add this line to your application's Gemfile:
10
10
 
11
11
  ```ruby
12
- gem 'lighthouse-ruby'
12
+ group :test do
13
+ gem 'lighthouse-ruby'
14
+ end
13
15
  ```
14
16
 
15
17
  And then execute:
@@ -20,15 +22,80 @@ Or install it yourself as:
20
22
 
21
23
  $ gem install lighthouse-ruby
22
24
 
23
- ## Usage
25
+ Another dependency you also need to have the `lighthouse` CLI tool available. The gem will automatically pick up the tool
26
+ if `lighthouse` already installed, or if there are no executable lighthouse file then it will automatically install for you.
27
+ Additionally if you want install it manually and added to dev dependency on the`package.sjon`, feel free to use any of this commands:
28
+
29
+ * `npm install --save-dev lighthouse`
30
+ * `yarn add --dev lighthouse`
24
31
 
25
- TODO: Work in progress
32
+ If you have the `lighthouse` CLI tool installed, but available somewhere on your system, you can set the location manually.
33
+ See [Configuration](#configuration) for further instructions.
26
34
 
27
- ## Development
35
+ ## Usage
36
+ After all the installation, now the `lighthouse\ruby` can be imported by adding this code to your test helper.
28
37
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
38
+ ```
39
+ require "lighthouse/ruby"
40
+ ```
41
+ The idea to have this inside your test framework without adding too much overhead and un-necessary code in order to use
42
+ the same Chrome session as your system test framework (e.g. the page requires a logged-in user), then you should change
43
+ the definition of your system test Chrome browser arguments to define a "remote debugging port". Without defining this
44
+ port, The `lighthouse/ruby` cannot connect to your existing Chrome session and will begin a new
45
+ one, clearing any session information.
46
+
47
+ ## Setup Code
48
+ ```
49
+ Capybara.register_driver :chrome do |app|
50
+ capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
51
+ chromeOptions: { args: %w(headless remote-debugging-port=9222) }
52
+ )
53
+
54
+ Capybara::Selenium::Driver.new app,
55
+ browser: :chrome,
56
+ desired_capabilities: capabilities
57
+ end
58
+
59
+ Capybara.javascript_driver = :chrome
60
+ Lighthouse::Matchers.remote_debugging_port = 9222
61
+ ```
30
62
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
63
+ #### For Rspec
64
+ Place the configuration on `spec/spec_helper.rb` or `spec/rails_helper.rb`
65
+
66
+ #### For Cucumber
67
+ Place the configuration on `features/env.rb` or where the Capybara and Chromedriver defined.
68
+
69
+ ## Configuration
70
+ There are several additional configuration that accessible and align with official `lighthouse-cli`.
71
+ All the additional options:
72
+ * **`remote_debugging_port`:** If defined, Lighthouse will connect to this Chrome debugging port.
73
+ This allows the test to run in the same session as the Chrome session that created the port
74
+ (in th case of Capybara, this will be the same _current_state_ of `page` or `Capybara::Session` under test)
75
+ by match up the remote debugging port that has been configured for the Chrome browser instance.
76
+ * **`lighthouse_path`:** The path to the Lighthouse CLI tool. By default, it will check `/usr/bin/`, `/usr/local/bin`
77
+ and `node_modules/.bin/` for the CLI. Therefor when the gem cannot find any executable file do not panic because
78
+ it will install the latest `lighthouse` from npm globally.
79
+ * **`chrome_flags`:** Any additional flags that should be passed to Chrome when Lighthouse launches a browser instance.
80
+ As an example, running Lighthouse in Docker container or CI environment might requires the headless Chrome flags
81
+ (`--headless`, `--no-sandbox`) in order Chrome to successfully start. Chrome flags can be either specified as an array
82
+ or string.(eq: `["headless", "no-sandbox"]` or `"headless", "no-sandbox"`).
83
+ * **`lighthouse_options`:** Any additional options that can be passed to Lighthouse CLI. All the options can be found by
84
+ running `lighthouse --help` in the terminal or go this [link](https://github.com/GoogleChrome/lighthouse#cli-options) for more details. For an example usage, running Lighthouse in different emulated form factor
85
+ such as: a mobile, or desktop use `emulated-form-factor=<type>`. Another usage by adding additional headers during the
86
+ erequest simply add `--extra-headers`. Also, Lighthouse options can either be specified as an array or string.
87
+ (eq: `["emulated-form-factor=desktop", "--extra-headers '{\"food\":\"burger\", \"drink\":\"coke\"}'"]` or `"emulated-form-factor=desktop", "--extra-headers '{\"food\":\"burger\", \"drink\":\"coke\"}'"`).
88
+
89
+ ## Run Test
90
+ How to get the test report simply create object for `lighthouse-ruby` with url that need to be tested.
91
+ For `Capybara::Session` then `current_url` is the URL that you want to access.
92
+ ```
93
+ report = Lighthouse::Ruby::Builder.new(current_url)
94
+ report.execute # => will get all JSON object
95
+ report.test_scores # => Will get only meaningful hash of scores such as: performance, accessibility, best-practices, and SEO
96
+ => {:url=>"http://test.example.com:3001/", :run_time=>2020-05-14 13:10:12 +0000, :performance=>100, :accessibility=>80.0, :best_practices=>77.0, :seo=>90.0}
97
+ ```
98
+ To be more flexible `report.execute` will return the JSON report and it should be easily parse into Ruby Hash as needed.
32
99
 
33
100
  ## Contributing
34
101
 
@@ -14,8 +14,12 @@ module Lighthouse
14
14
  @lighthouse_options = Lighthouse::Preferences.lighthouse_options
15
15
  end
16
16
 
17
- def run_test
18
- get_test_scores
17
+ def execute
18
+ @response = @runner.call("#{@cli} #{options}")
19
+ end
20
+
21
+ def test_scores
22
+ get_test_scores(@response)
19
23
  end
20
24
 
21
25
  private
@@ -30,9 +34,8 @@ module Lighthouse
30
34
  end.strip
31
35
  end
32
36
 
33
- def get_test_scores
34
- json_result = JSON.parse(@runner.call("#{@cli} #{options}"))
35
-
37
+ def get_test_scores(response)
38
+ json_result = JSON.parse(response)
36
39
  @test_scores = { url: @url}
37
40
  @test_scores[:run_time] = Time.now
38
41
  @test_scores[:performance] = json_result.dig("categories", "performance" , "score") * 100
@@ -1,5 +1,5 @@
1
1
  module Lighthouse
2
2
  module Ruby
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lighthouse-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Budi Sugianto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-13 00:00:00.000000000 Z
11
+ date: 2020-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler