cypress-on-rails 1.15.0 → 1.16.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bc763de97980a2be63d8eac1ca850d9695c7e1778c8678d83cec0de7c8270b37
4
- data.tar.gz: 9c830d9c70faebc8aac3891caa6ab3547cdf66fe9c89d3eda131248086ff55a2
3
+ metadata.gz: 2dc7073afd439183f15dbe8e33fd275ec4ec4121c2640e026ed5d7f80bc2736c
4
+ data.tar.gz: 2361d555bab1bae7072d8909275669a139b9c2ee255f5f8195660189208591fa
5
5
  SHA512:
6
- metadata.gz: 88104bb87f1ab6933c17495ff3cbe112a27fc8daa5ee97752eb25e72e46d1ca6e2b54b907857650d49455ca3cb30534e6a6e4d02a6d5f240ddc69ea9d9c5cdac
7
- data.tar.gz: 61f547751df2b0500d15b3480732823916a6b3ce0a768cbed696764ec9ddb3853b0d4919e9f2a8249803830b70334f0914c8075d0eb97d84abf68c9835747d1a
6
+ metadata.gz: 717a48f1352f07b052683ba0699d2806191aed7ebc249e6c0f319af8f2e47d3eb0062787fa6d847ce326afe66325c59859806c9f93f3f95a8276e6aec85d580f
7
+ data.tar.gz: abee0f60bec8a8eca395b6a621c33c0caa731452f5e253d27b80c967cd7138a992cb29c68fa41bafcddc85a3f02e6767f6a3f5bcf77ffbaad543264c31d5630a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## [1.16.0]
2
+ [Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.15.1...v1.16.0
3
+
4
+ ### Added
5
+ * Add support for `before_request` options on the middleware, for authentication [PR 138](https://github.com/shakacode/cypress-on-rails/pull/138) by [RomainEndelin]
6
+
7
+ ## [1.15.1]
8
+ [Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.15.0...v1.15.1
9
+
10
+ ### Fixed
11
+ * fix cypress_folder deprecation warning by internal code [PR 136](https://github.com/shakacode/cypress-on-rails/pull/136)
12
+
1
13
  ## [1.15.0]
2
14
  [Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.14.0...v1.15.0
3
15
 
data/README.md CHANGED
@@ -17,7 +17,7 @@ Need help with cypress-on-rails? Contact [ShakaCode](mailto:justin@shakacode.com
17
17
  # Totally new to Cypress?
18
18
  Suggest you first learn the basics of Cypress before attempting to integrate with Ruby on Rails
19
19
 
20
- * [Good start Here](https://docs.cypress.io/examples/examples/tutorials.html#Best-Practices)
20
+ * [Good start Here](https://docs.cypress.io/examples/tutorials.html#Best-Practices)
21
21
 
22
22
  # Totally new to Playwright?
23
23
  Suggest you first learn the basics of Playwright before attempting to integrate with Ruby on Rails
@@ -395,6 +395,47 @@ describe('My First Test', () => {
395
395
  })
396
396
  ```
397
397
 
398
+ ## `before_request` configuration
399
+
400
+ You may perform any custom action before running a CypressOnRails command, such as authentication, or sending metrics. Please set `before_request` as part of the CypressOnRails configuration.
401
+
402
+ You should get familiar with [Rack middlewares](https://www.rubyguides.com/2018/09/rack-middleware/).
403
+ If your function returns a `[status, header, body]` response, CypressOnRails will halt, and your command will not be executed. To execute the command, `before_request` should return `nil`.
404
+
405
+ ### Authenticate CypressOnRails
406
+
407
+ ```ruby
408
+ CypressOnRails.configure do |c|
409
+ # ...
410
+
411
+ # Refer to https://www.rubydoc.info/gems/rack/Rack/Request for the `request` argument.
412
+ c.before_request = lambda { |request|
413
+ body = JSON.parse(request.body.string)
414
+ if body['cypress_token'] != ENV.fetch('SWEEP_CYPRESS_SECRET_TOKEN')
415
+ # You may also use warden for authentication:
416
+ # if !request.env['warden'].authenticate(:secret_key)
417
+ return [401, {}, ['unauthorized']]
418
+ end
419
+
420
+ }
421
+ end
422
+ ```
423
+
424
+ ### Send usage metrics
425
+
426
+ ```ruby
427
+ CypressOnRails.configure do |c|
428
+ # ...
429
+
430
+ # Refer to https://www.rubydoc.info/gems/rack/Rack/Request for the `request` argument.
431
+ c.before_request = lambda { |request|
432
+ statsd = Datadog::Statsd.new('localhost', 8125)
433
+
434
+ statsd.increment('cypress_on_rails.requests')
435
+ }
436
+ end
437
+ ```
438
+
398
439
  ## Usage with other rack applications
399
440
 
400
441
  Add CypressOnRails to your config.ru
@@ -477,6 +518,11 @@ In `config/initializers/cypress_on_rails.rb`, add this line:
477
518
  <img alt="ScoutAPM" src="https://user-images.githubusercontent.com/4244251/184881152-9f2d8fba-88ac-4ba6-873b-22387f8711c5.png" height="120px">
478
519
  </picture>
479
520
  </a>
521
+ <a href="https://controlplane.com">
522
+ <picture>
523
+ <img alt="Control Plane" src="https://github.com/shakacode/.github/assets/20628911/90babd87-62c4-4de3-baa4-3d78ef4bec25" height="120px">
524
+ </picture>
525
+ </a>
480
526
  <br />
481
527
  <a href="https://www.browserstack.com">
482
528
  <picture>
@@ -15,12 +15,12 @@ module CypressOnRails
15
15
 
16
16
  def self.load_e2e_helper
17
17
  e2e_helper_file = "#{configuration.install_folder}/e2e_helper.rb"
18
- cypress_helper_file = "#{configuration.cypress_folder}/cypress_helper.rb"
18
+ cypress_helper_file = "#{configuration.install_folder}/cypress_helper.rb"
19
19
  if File.exist?(e2e_helper_file)
20
20
  Kernel.require e2e_helper_file
21
21
  elsif File.exist?(cypress_helper_file)
22
22
  Kernel.require cypress_helper_file
23
- warn "cypress_helper.rb and cypress_folder are deprecated, please use the install generator to create e2e_helper.rb using install_folder"
23
+ warn "cypress_helper.rb is deprecated, please rename the file to e2e_helper.rb"
24
24
  else
25
25
  logger.warn "could not find #{e2e_helper_file} nor #{cypress_helper_file}"
26
26
  end
@@ -6,6 +6,7 @@ module CypressOnRails
6
6
  attr_accessor :install_folder
7
7
  attr_accessor :use_middleware
8
8
  attr_accessor :use_vcr_middleware
9
+ attr_accessor :before_request
9
10
  attr_accessor :logger
10
11
 
11
12
  # Attributes for backwards compatibility
@@ -30,6 +31,7 @@ module CypressOnRails
30
31
  self.install_folder = 'spec/e2e'
31
32
  self.use_middleware = true
32
33
  self.use_vcr_middleware = false
34
+ self.before_request = -> (request) {}
33
35
  self.logger = Logger.new(STDOUT)
34
36
  end
35
37
 
@@ -47,6 +47,10 @@ module CypressOnRails
47
47
  end
48
48
 
49
49
  def handle_command(req)
50
+ maybe_env = configuration.before_request.call(req)
51
+ # Halt the middleware if an Rack Env was returned by `before_request`
52
+ return maybe_env unless maybe_env.nil?
53
+
50
54
  body = JSON.parse(req.body.read)
51
55
  logger.info "handle_command: #{body}"
52
56
  commands = Command.from_body(body, configuration)
@@ -1,3 +1,3 @@
1
1
  module CypressOnRails
2
- VERSION = '1.15.0'.freeze
2
+ VERSION = '1.16.0'.freeze
3
3
  end
@@ -7,6 +7,15 @@ if defined?(CypressOnRails)
7
7
  c.use_middleware = !Rails.env.production?
8
8
  <% unless options.experimental %># <% end %> c.use_vcr_middleware = !Rails.env.production?
9
9
  c.logger = Rails.logger
10
+
11
+ # If you want to enable a before_request logic, such as authentication, logging, sending metrics, etc.
12
+ # Refer to https://www.rubydoc.info/gems/rack/Rack/Request for the `request` argument.
13
+ # Return nil to continue through the Cypress command. Return a response [status, header, body] to halt.
14
+ # c.before_request = lambda { |request|
15
+ # unless request.env['warden'].authenticate(:secret_key)
16
+ # return [403, {}, ["forbidden"]]
17
+ # end
18
+ # }
10
19
  end
11
20
 
12
21
  # # if you compile your asssets on CI
@@ -8,19 +8,23 @@ RSpec.describe CypressOnRails::Configuration do
8
8
  expect(CypressOnRails.configuration.install_folder).to eq('spec/e2e')
9
9
  expect(CypressOnRails.configuration.use_middleware?).to eq(true)
10
10
  expect(CypressOnRails.configuration.logger).to_not be_nil
11
+ expect(CypressOnRails.configuration.before_request).to_not be_nil
11
12
  end
12
13
 
13
14
  it 'can be configured' do
14
15
  my_logger = Logger.new(STDOUT)
16
+ before_request_lambda = -> (_) { return [200, {}, ['hello world']] }
15
17
  CypressOnRails.configure do |config|
16
18
  config.api_prefix = '/api'
17
19
  config.install_folder = 'my/path'
18
20
  config.use_middleware = false
19
21
  config.logger = my_logger
22
+ config.before_request = before_request_lambda
20
23
  end
21
24
  expect(CypressOnRails.configuration.api_prefix).to eq('/api')
22
25
  expect(CypressOnRails.configuration.install_folder).to eq('my/path')
23
26
  expect(CypressOnRails.configuration.use_middleware?).to eq(false)
24
27
  expect(CypressOnRails.configuration.logger).to eq(my_logger)
28
+ expect(CypressOnRails.configuration.before_request).to eq(before_request_lambda)
25
29
  end
26
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cypress-on-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.15.0
4
+ version: 1.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - miceportal team
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-07-05 00:00:00.000000000 Z
12
+ date: 2023-10-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack