cypress-rails 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +3 -3
- data/CHANGELOG.md +11 -0
- data/Gemfile.lock +6 -26
- data/LICENSE.txt +5 -1
- data/README.md +8 -7
- data/bin/console +1 -1
- data/cypress-rails.gemspec +1 -4
- data/lib/cypress-rails/launches_cypress.rb +2 -2
- data/lib/cypress-rails/server/checker.rb +42 -0
- data/lib/cypress-rails/server/middleware.rb +67 -0
- data/lib/cypress-rails/server/puma.rb +30 -0
- data/lib/cypress-rails/server/timer.rb +24 -0
- data/lib/cypress-rails/server.rb +122 -0
- data/lib/cypress-rails/starts_rails_server.rb +6 -29
- data/lib/cypress-rails/version.rb +1 -1
- metadata +10 -48
- data/lib/cypress-rails/configures_test_server.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b33dbd1979a98b1861627988fa032b18348f43c6f38844437026db52b2aa3811
|
4
|
+
data.tar.gz: 90f192c528beda78245b68791e58ee91f7d0d24a4821d0dcd9a54f471ca00540
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80b6ac651dd318df4f95d243b50116e1a28db6afdde2c78fbb4d9b21c7e83785c6777afb346d24cae3a5f69baa1149dabe72e8fa227e118487b10fadba88c414
|
7
|
+
data.tar.gz: e3b3a56a658d0f74c89011a1aa193b0e449c9db6ace90daf9cfcfa93f31b473497e6af9f6e3f5ef0e2a25f7869e14b5189be9b16298edbdc7d8f5aa3cbe83e65
|
data/.circleci/config.yml
CHANGED
@@ -33,9 +33,9 @@ jobs:
|
|
33
33
|
# Yarn dependencies
|
34
34
|
- restore_cache:
|
35
35
|
keys:
|
36
|
-
-
|
36
|
+
- v2-yarn-{{ checksum "example/an_app/package.json" }}
|
37
37
|
# fallback to using the latest cache if no exact match is found
|
38
|
-
-
|
38
|
+
- v2-yarn-
|
39
39
|
|
40
40
|
- run: |
|
41
41
|
cd example/an_app
|
@@ -45,7 +45,7 @@ jobs:
|
|
45
45
|
paths:
|
46
46
|
- example/an_app/node_modules
|
47
47
|
- ~/.cache
|
48
|
-
key:
|
48
|
+
key: v2-yarn-{{ checksum "example/an_app/package.json" }}
|
49
49
|
|
50
50
|
- run: bundle exec rake
|
51
51
|
- run: ./script/test_example_app
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 0.1.2
|
4
|
+
|
5
|
+
* Drop the hard deps on capybara and selenium-webdrivers (instead inlining
|
6
|
+
portions of the Capybara server logic). Additionally, add a hard dep on puma
|
7
|
+
since this gem is useless without it
|
8
|
+
|
9
|
+
## 0.1.1
|
10
|
+
|
11
|
+
* Fix the `before_server_stop` hook by rolling back transactions first so that
|
12
|
+
it can clean out test data
|
13
|
+
|
3
14
|
## 0.1.0
|
4
15
|
|
5
16
|
* **[Breaking]** Remove `CypressRails::TestCase`. Use `rake cypress:run` instead
|
data/Gemfile.lock
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
cypress-rails (0.1.
|
5
|
-
|
4
|
+
cypress-rails (0.1.2)
|
5
|
+
puma (>= 3.8.0)
|
6
6
|
railties (>= 5.2.0)
|
7
|
-
selenium-webdriver
|
8
7
|
|
9
8
|
GEM
|
10
9
|
remote: https://rubygems.org/
|
@@ -28,19 +27,8 @@ GEM
|
|
28
27
|
minitest (~> 5.1)
|
29
28
|
tzinfo (~> 1.1)
|
30
29
|
zeitwerk (~> 2.2)
|
31
|
-
addressable (2.7.0)
|
32
|
-
public_suffix (>= 2.0.2, < 5.0)
|
33
30
|
ast (2.4.0)
|
34
31
|
builder (3.2.4)
|
35
|
-
capybara (3.31.0)
|
36
|
-
addressable
|
37
|
-
mini_mime (>= 0.1.3)
|
38
|
-
nokogiri (~> 1.8)
|
39
|
-
rack (>= 1.6.0)
|
40
|
-
rack-test (>= 0.6.3)
|
41
|
-
regexp_parser (~> 1.5)
|
42
|
-
xpath (~> 3.2)
|
43
|
-
childprocess (3.0.0)
|
44
32
|
concurrent-ruby (1.1.6)
|
45
33
|
crass (1.0.6)
|
46
34
|
erubi (1.9.0)
|
@@ -51,15 +39,16 @@ GEM
|
|
51
39
|
crass (~> 1.0.2)
|
52
40
|
nokogiri (>= 1.5.9)
|
53
41
|
method_source (0.9.2)
|
54
|
-
mini_mime (1.0.2)
|
55
42
|
mini_portile2 (2.4.0)
|
56
43
|
minitest (5.14.0)
|
44
|
+
nio4r (2.5.2)
|
57
45
|
nokogiri (1.10.9)
|
58
46
|
mini_portile2 (~> 2.4.0)
|
59
47
|
parallel (1.19.1)
|
60
48
|
parser (2.7.0.4)
|
61
49
|
ast (~> 2.4.0)
|
62
|
-
|
50
|
+
puma (4.3.3)
|
51
|
+
nio4r (~> 2.0)
|
63
52
|
rack (2.2.2)
|
64
53
|
rack-test (1.1.0)
|
65
54
|
rack (>= 1.0, < 3)
|
@@ -76,7 +65,6 @@ GEM
|
|
76
65
|
thor (>= 0.20.3, < 2.0)
|
77
66
|
rainbow (3.0.0)
|
78
67
|
rake (13.0.1)
|
79
|
-
regexp_parser (1.7.0)
|
80
68
|
rubocop (0.79.0)
|
81
69
|
jaro_winkler (~> 1.5.1)
|
82
70
|
parallel (~> 1.10)
|
@@ -87,11 +75,7 @@ GEM
|
|
87
75
|
rubocop-performance (1.5.2)
|
88
76
|
rubocop (>= 0.71.0)
|
89
77
|
ruby-progressbar (1.10.1)
|
90
|
-
|
91
|
-
selenium-webdriver (3.142.7)
|
92
|
-
childprocess (>= 0.5, < 4.0)
|
93
|
-
rubyzip (>= 1.2.2)
|
94
|
-
standard (0.2.0)
|
78
|
+
standard (0.2.1)
|
95
79
|
rubocop (~> 0.79.0)
|
96
80
|
rubocop-performance (~> 1.5.1)
|
97
81
|
thor (1.0.1)
|
@@ -99,17 +83,13 @@ GEM
|
|
99
83
|
tzinfo (1.2.6)
|
100
84
|
thread_safe (~> 0.1)
|
101
85
|
unicode-display_width (1.6.1)
|
102
|
-
xpath (3.2.0)
|
103
|
-
nokogiri (~> 1.8)
|
104
86
|
zeitwerk (2.3.0)
|
105
87
|
|
106
88
|
PLATFORMS
|
107
89
|
ruby
|
108
90
|
|
109
91
|
DEPENDENCIES
|
110
|
-
actionpack
|
111
92
|
bundler (~> 1.17)
|
112
|
-
capybara
|
113
93
|
cypress-rails!
|
114
94
|
minitest (~> 5.0)
|
115
95
|
rake (~> 13.0)
|
data/LICENSE.txt
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
The MIT License (MIT)
|
2
2
|
|
3
|
-
Copyright (c) 2019 Test Double, LLC
|
3
|
+
Copyright (c) 2019-2020 Test Double, LLC
|
4
|
+
|
5
|
+
Portions of the CypressRails::Server component:
|
6
|
+
Copyright (c) 2009-2018 Thomas Walpole, Jonas Nicklas
|
7
|
+
|
4
8
|
|
5
9
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
10
|
of this software and associated documentation files (the "Software"), to deal
|
data/README.md
CHANGED
@@ -7,6 +7,14 @@ This is a simple gem to make it easier to start writing browser tests with
|
|
7
7
|
regardless of whether your app is server-side rendered HTML, completely
|
8
8
|
client-side JavaScript, or something in-between.
|
9
9
|
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
**tl;dr**:
|
13
|
+
|
14
|
+
1. Install the npm package `cypress`
|
15
|
+
2. Install this gem `cypress-rails`
|
16
|
+
3. Run `rake cypress:init`
|
17
|
+
|
10
18
|
### Installing Cypress itself
|
11
19
|
|
12
20
|
The first step is making sure Cypress is installed (that's up to you, this
|
@@ -297,12 +305,5 @@ adopting Cypress and writing a bunch of browser tests for every application.
|
|
297
305
|
But, if the above points sound like solutions to problems you experience, you
|
298
306
|
might consider trying it out.
|
299
307
|
|
300
|
-
## Installation
|
301
|
-
|
302
|
-
**tl;dr**:
|
303
|
-
|
304
|
-
1. Install the npm package `cypress`
|
305
|
-
2. Install this gem `cypress-rails`
|
306
|
-
3. Run `rake cypress:init`
|
307
308
|
|
308
309
|
|
data/bin/console
CHANGED
data/cypress-rails.gemspec
CHANGED
@@ -22,13 +22,10 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
24
|
spec.add_dependency "railties", ">= 5.2.0"
|
25
|
-
spec.add_dependency "
|
26
|
-
spec.add_dependency "selenium-webdriver"
|
25
|
+
spec.add_dependency "puma", ">= 3.8.0"
|
27
26
|
|
28
27
|
spec.add_development_dependency "bundler", "~> 1.17"
|
29
28
|
spec.add_development_dependency "rake", "~> 13.0"
|
30
29
|
spec.add_development_dependency "minitest", "~> 5.0"
|
31
30
|
spec.add_development_dependency "standard", ">= 0.2.0"
|
32
|
-
spec.add_development_dependency "actionpack"
|
33
|
-
spec.add_development_dependency "capybara"
|
34
31
|
end
|
@@ -19,7 +19,7 @@ module CypressRails
|
|
19
19
|
if config.transactional_server
|
20
20
|
@manages_transactions.begin_transaction
|
21
21
|
end
|
22
|
-
@starts_rails_server.call(
|
22
|
+
server = @starts_rails_server.call(
|
23
23
|
port: config.port,
|
24
24
|
transactional_server: config.transactional_server
|
25
25
|
)
|
@@ -32,7 +32,7 @@ module CypressRails
|
|
32
32
|
end
|
33
33
|
|
34
34
|
system <<~EXEC
|
35
|
-
CYPRESS_BASE_URL=http://#{
|
35
|
+
CYPRESS_BASE_URL=http://#{server.host}:#{server.port} #{bin} #{command} --project "#{config.dir}" #{config.cypress_cli_opts}
|
36
36
|
EXEC
|
37
37
|
end
|
38
38
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module CypressRails
|
2
|
+
class Server
|
3
|
+
class Checker
|
4
|
+
TRY_HTTPS_ERRORS = [EOFError, Net::ReadTimeout, Errno::ECONNRESET].freeze
|
5
|
+
|
6
|
+
def initialize(host, port)
|
7
|
+
@host, @port = host, port
|
8
|
+
@ssl = false
|
9
|
+
end
|
10
|
+
|
11
|
+
def request(&block)
|
12
|
+
ssl? ? https_request(&block) : http_request(&block)
|
13
|
+
rescue *TRY_HTTPS_ERRORS
|
14
|
+
res = https_request(&block)
|
15
|
+
@ssl = true
|
16
|
+
res
|
17
|
+
end
|
18
|
+
|
19
|
+
def ssl?
|
20
|
+
@ssl
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def http_request(&block)
|
26
|
+
make_request(read_timeout: 2, &block)
|
27
|
+
end
|
28
|
+
|
29
|
+
def https_request(&block)
|
30
|
+
make_request(**ssl_options, &block)
|
31
|
+
end
|
32
|
+
|
33
|
+
def make_request(**options, &block)
|
34
|
+
Net::HTTP.start(@host, @port, options.merge(max_retries: 0), &block)
|
35
|
+
end
|
36
|
+
|
37
|
+
def ssl_options
|
38
|
+
{use_ssl: true, verify_mode: OpenSSL::SSL::VERIFY_NONE}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module CypressRails
|
2
|
+
class Server
|
3
|
+
class Middleware
|
4
|
+
class Counter
|
5
|
+
def initialize
|
6
|
+
@value = []
|
7
|
+
@mutex = Mutex.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def increment(uri)
|
11
|
+
@mutex.synchronize { @value.push(uri) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def decrement(uri)
|
15
|
+
@mutex.synchronize { @value.delete_at(@value.index(uri) || @value.length) }
|
16
|
+
end
|
17
|
+
|
18
|
+
def positive?
|
19
|
+
@mutex.synchronize { @value.length.positive? }
|
20
|
+
end
|
21
|
+
|
22
|
+
def value
|
23
|
+
@mutex.synchronize { @value.dup }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
attr_reader :error
|
28
|
+
|
29
|
+
def initialize(app, server_errors, extra_middleware = [])
|
30
|
+
@app = app
|
31
|
+
@extended_app = extra_middleware.inject(@app) { |ex_app, klass|
|
32
|
+
klass.new(ex_app)
|
33
|
+
}
|
34
|
+
@counter = Counter.new
|
35
|
+
@server_errors = server_errors
|
36
|
+
end
|
37
|
+
|
38
|
+
def pending_requests
|
39
|
+
@counter.value
|
40
|
+
end
|
41
|
+
|
42
|
+
def pending_requests?
|
43
|
+
@counter.positive?
|
44
|
+
end
|
45
|
+
|
46
|
+
def clear_error
|
47
|
+
@error = nil
|
48
|
+
end
|
49
|
+
|
50
|
+
def call(env)
|
51
|
+
if env["PATH_INFO"] == "/__identify__"
|
52
|
+
[200, {}, [@app.object_id.to_s]]
|
53
|
+
else
|
54
|
+
@counter.increment(env["REQUEST_URI"])
|
55
|
+
begin
|
56
|
+
@extended_app.call(env)
|
57
|
+
rescue *@server_errors => e
|
58
|
+
@error ||= e
|
59
|
+
raise e
|
60
|
+
ensure
|
61
|
+
@counter.decrement(env["REQUEST_URI"])
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module CypressRails
|
2
|
+
class Server
|
3
|
+
module Puma
|
4
|
+
def self.create(app, port, host)
|
5
|
+
require "rack/handler/puma"
|
6
|
+
|
7
|
+
# If we just run the Puma Rack handler it installs signal handlers which prevent us from being able to interrupt tests.
|
8
|
+
# Therefore construct and run the Server instance ourselves.
|
9
|
+
# Rack::Handler::Puma.run(app, { Host: host, Port: port, Threads: "0:4", workers: 0, daemon: false }.merge(options))
|
10
|
+
default_options = {Host: host, Port: port, Threads: "0:4", workers: 0, daemon: false}
|
11
|
+
options = default_options # .merge(options)
|
12
|
+
|
13
|
+
conf = Rack::Handler::Puma.config(app, options)
|
14
|
+
events = ::Puma::Events.stdio
|
15
|
+
|
16
|
+
puma_ver = Gem::Version.new(::Puma::Const::PUMA_VERSION)
|
17
|
+
require_relative "patches/puma_ssl" if (Gem::Version.new("4.0.0")...Gem::Version.new("4.1.0")).cover? puma_ver
|
18
|
+
|
19
|
+
events.log "Starting Puma..."
|
20
|
+
events.log "* Version #{::Puma::Const::PUMA_VERSION} , codename: #{::Puma::Const::CODE_NAME}"
|
21
|
+
events.log "* Min threads: #{conf.options[:min_threads]}, max threads: #{conf.options[:max_threads]}"
|
22
|
+
|
23
|
+
::Puma::Server.new(conf.app, events, conf.options).tap do |s|
|
24
|
+
s.binder.parse conf.options[:binds], s.events
|
25
|
+
s.min_threads, s.max_threads = conf.options[:min_threads], conf.options[:max_threads]
|
26
|
+
end.run.join
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module CypressRails
|
2
|
+
class Server
|
3
|
+
class Timer
|
4
|
+
def initialize(expire_in)
|
5
|
+
@start = current
|
6
|
+
@expire_in = expire_in
|
7
|
+
end
|
8
|
+
|
9
|
+
def expired?
|
10
|
+
current - @start >= @expire_in
|
11
|
+
end
|
12
|
+
|
13
|
+
def stalled?
|
14
|
+
@start == current
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def current
|
20
|
+
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "uri"
|
4
|
+
require "net/http"
|
5
|
+
require "rack"
|
6
|
+
require_relative "server/middleware"
|
7
|
+
require_relative "server/checker"
|
8
|
+
require_relative "server/timer"
|
9
|
+
require_relative "server/puma"
|
10
|
+
|
11
|
+
module CypressRails
|
12
|
+
class Server
|
13
|
+
class << self
|
14
|
+
def ports
|
15
|
+
@ports ||= {}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
attr_reader :app, :port, :host
|
20
|
+
|
21
|
+
def initialize(app,
|
22
|
+
port:,
|
23
|
+
host: "127.0.0.1",
|
24
|
+
reportable_errors: [Exception],
|
25
|
+
extra_middleware: [])
|
26
|
+
@app = app
|
27
|
+
@extra_middleware = extra_middleware
|
28
|
+
@server_thread = nil # suppress warnings
|
29
|
+
@host = host
|
30
|
+
@reportable_errors = reportable_errors
|
31
|
+
@port = port
|
32
|
+
@port ||= Server.ports[port_key]
|
33
|
+
@port ||= find_available_port(host)
|
34
|
+
@checker = Checker.new(@host, @port)
|
35
|
+
end
|
36
|
+
|
37
|
+
def reset_error!
|
38
|
+
middleware.clear_error
|
39
|
+
end
|
40
|
+
|
41
|
+
def error
|
42
|
+
middleware.error
|
43
|
+
end
|
44
|
+
|
45
|
+
def using_ssl?
|
46
|
+
@checker.ssl?
|
47
|
+
end
|
48
|
+
|
49
|
+
def responsive?
|
50
|
+
return false if @server_thread&.join(0)
|
51
|
+
|
52
|
+
res = @checker.request { |http| http.get("/__identify__") }
|
53
|
+
|
54
|
+
return res.body == app.object_id.to_s if res.is_a?(Net::HTTPSuccess) || res.is_a?(Net::HTTPRedirection)
|
55
|
+
rescue SystemCallError, Net::ReadTimeout, OpenSSL::SSL::SSLError
|
56
|
+
false
|
57
|
+
end
|
58
|
+
|
59
|
+
def wait_for_pending_requests
|
60
|
+
timer = Timer.new(60)
|
61
|
+
while pending_requests?
|
62
|
+
raise "Requests did not finish in 60 seconds: #{middleware.pending_requests}" if timer.expired?
|
63
|
+
|
64
|
+
sleep 0.01
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def boot
|
69
|
+
unless responsive?
|
70
|
+
Server.ports[port_key] = port
|
71
|
+
|
72
|
+
@server_thread = Thread.new {
|
73
|
+
Puma.create(middleware, port, host)
|
74
|
+
}
|
75
|
+
|
76
|
+
timer = Timer.new(60)
|
77
|
+
until responsive?
|
78
|
+
raise "Rack application timed out during boot" if timer.expired?
|
79
|
+
|
80
|
+
@server_thread.join(0.1)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
self
|
85
|
+
end
|
86
|
+
|
87
|
+
def base_url
|
88
|
+
"http#{"s" if using_ssl?}://#{host}:#{port}"
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
|
93
|
+
def middleware
|
94
|
+
@middleware ||= Middleware.new(app, @reportable_errors, @extra_middleware)
|
95
|
+
end
|
96
|
+
|
97
|
+
def port_key
|
98
|
+
app.object_id # as opposed to middleware.object_id if multiple instances
|
99
|
+
end
|
100
|
+
|
101
|
+
def pending_requests?
|
102
|
+
middleware.pending_requests?
|
103
|
+
end
|
104
|
+
|
105
|
+
def find_available_port(host)
|
106
|
+
server = TCPServer.new(host, 0)
|
107
|
+
port = server.addr[1]
|
108
|
+
server.close
|
109
|
+
|
110
|
+
# Workaround issue where some platforms (mac, ???) when passed a host
|
111
|
+
# of '0.0.0.0' will return a port that is only available on one of the
|
112
|
+
# ip addresses that resolves to, but the next binding to that port requires
|
113
|
+
# that port to be available on all ips
|
114
|
+
server = TCPServer.new(host, port)
|
115
|
+
port
|
116
|
+
rescue Errno::EADDRINUSE
|
117
|
+
retry
|
118
|
+
ensure
|
119
|
+
server&.close
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -1,32 +1,14 @@
|
|
1
|
-
require_relative "configures_test_server"
|
2
1
|
require_relative "tracks_resets"
|
2
|
+
require_relative "server"
|
3
3
|
|
4
4
|
module CypressRails
|
5
5
|
class StartsRailsServer
|
6
|
-
def initialize
|
7
|
-
@configures_test_server = ConfiguresTestServer.new
|
8
|
-
end
|
9
|
-
|
10
6
|
def call(port:, transactional_server:)
|
11
|
-
@configures_test_server.call(port: port)
|
12
|
-
configure_driver!
|
13
7
|
configure_rails_to_run_our_state_reset_on_every_request!(transactional_server)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def configure_driver!
|
22
|
-
# this is only necessary b/c we're piggybacking on the capybara server
|
23
|
-
require "action_dispatch/system_testing/driver"
|
24
|
-
require "action_dispatch/system_testing/browser"
|
25
|
-
ActionDispatch::SystemTesting::Driver.new(:selenium, {
|
26
|
-
using: :headless_chrome,
|
27
|
-
screen_size: [1400, 1400],
|
28
|
-
options: {}
|
29
|
-
}).use
|
8
|
+
app = create_rack_app
|
9
|
+
Server.new(app, port: port).tap do |server|
|
10
|
+
server.boot
|
11
|
+
end
|
30
12
|
end
|
31
13
|
|
32
14
|
def configure_rails_to_run_our_state_reset_on_every_request!(transactional_server)
|
@@ -35,7 +17,7 @@ module CypressRails
|
|
35
17
|
end
|
36
18
|
end
|
37
19
|
|
38
|
-
def
|
20
|
+
def create_rack_app
|
39
21
|
Rack::Builder.new do
|
40
22
|
map "/cypress_rails_reset_state" do
|
41
23
|
run lambda { |env|
|
@@ -48,10 +30,5 @@ module CypressRails
|
|
48
30
|
end
|
49
31
|
end
|
50
32
|
end
|
51
|
-
|
52
|
-
def start_system_testing_server!
|
53
|
-
require "action_dispatch/system_testing/server"
|
54
|
-
ActionDispatch::SystemTesting::Server.new.run
|
55
|
-
end
|
56
33
|
end
|
57
34
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cypress-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Searls
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-03-
|
11
|
+
date: 2020-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -25,33 +25,19 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 5.2.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: puma
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 3.8.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: selenium-webdriver
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
40
|
+
version: 3.8.0
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: bundler
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,34 +94,6 @@ dependencies:
|
|
108
94
|
- - ">="
|
109
95
|
- !ruby/object:Gem::Version
|
110
96
|
version: 0.2.0
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: actionpack
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - ">="
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - ">="
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '0'
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: capybara
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - ">="
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: '0'
|
132
|
-
type: :development
|
133
|
-
prerelease: false
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
135
|
-
requirements:
|
136
|
-
- - ">="
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
version: '0'
|
139
97
|
description:
|
140
98
|
email:
|
141
99
|
- searls@gmail.com
|
@@ -160,7 +118,6 @@ files:
|
|
160
118
|
- exe/cypress-rails
|
161
119
|
- lib/cypress-rails.rb
|
162
120
|
- lib/cypress-rails/config.rb
|
163
|
-
- lib/cypress-rails/configures_test_server.rb
|
164
121
|
- lib/cypress-rails/env.rb
|
165
122
|
- lib/cypress-rails/finds_bin.rb
|
166
123
|
- lib/cypress-rails/init.rb
|
@@ -172,6 +129,11 @@ files:
|
|
172
129
|
- lib/cypress-rails/rake.rb
|
173
130
|
- lib/cypress-rails/resets_state.rb
|
174
131
|
- lib/cypress-rails/run.rb
|
132
|
+
- lib/cypress-rails/server.rb
|
133
|
+
- lib/cypress-rails/server/checker.rb
|
134
|
+
- lib/cypress-rails/server/middleware.rb
|
135
|
+
- lib/cypress-rails/server/puma.rb
|
136
|
+
- lib/cypress-rails/server/timer.rb
|
175
137
|
- lib/cypress-rails/starts_rails_server.rb
|
176
138
|
- lib/cypress-rails/tracks_resets.rb
|
177
139
|
- lib/cypress-rails/version.rb
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module CypressRails
|
2
|
-
class ConfiguresTestServer
|
3
|
-
def call(port:)
|
4
|
-
require "capybara"
|
5
|
-
require "selenium-webdriver"
|
6
|
-
Capybara.server_port = port || find_available_port
|
7
|
-
Capybara.always_include_port = true
|
8
|
-
Capybara.server = :puma, {Silent: false}
|
9
|
-
Capybara.current_session
|
10
|
-
|
11
|
-
true
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def find_available_port
|
17
|
-
server = TCPServer.new(Capybara.server_host, 0)
|
18
|
-
server.addr[1]
|
19
|
-
ensure
|
20
|
-
server&.close
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|