cypress_rails 0.5.0 → 0.6.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
  SHA1:
3
- metadata.gz: 3368e52934ad619056582bd906ea33b0b27a1168
4
- data.tar.gz: bdf8ca62c0c646c3197dedd7496db37f86df8797
3
+ metadata.gz: 70d8ba1c2c997e512573b35b6823f9b14f930262
4
+ data.tar.gz: b75040d5e579711328d36e3691fc92aa9361505a
5
5
  SHA512:
6
- metadata.gz: 347ff016801044922dfc9c6b67311b5302663911159b1d1fe70261840a54c9c1270a86b7e07fa1f7d1d1f182e3f955a3c3223159620338bd7fbd6e1958e65643
7
- data.tar.gz: 94fc750a210c5d306e91b32cad21608123c360403b543fce286bc60907e76f8927394f11f949c81453df522c37d148ac39bc75dc379f4fa8a215c8640dfa454a
6
+ metadata.gz: 6481e794afc07e83d8786feccf7883b4cf9c8f35a8a156aae299dbe31d01fe2d42d1b332f3ca4da9e1f43b2faf67a5f031a403cd0d625c0a40b655d57ee0d280
7
+ data.tar.gz: 2018f01916a2632972d136936679b39b7c8d15b90b49399d464d5a9af7ca2c73a2192443d352212cee4f5640cf4df3c1c34665b4f58a32341e9faecf13f12a06
@@ -5,7 +5,9 @@ require "cypress_rails/runner"
5
5
  require "cypress_rails/server"
6
6
 
7
7
  module CypressRails
8
- Config = Struct.new(:command, :cypress_bin_path, :host, :log_path, :tests_path)
8
+ Config = Struct.new(
9
+ :command, :cypress_bin_path, :host, :log_path, :tests_path, :healthcheck_url
10
+ )
9
11
 
10
12
  class CLI < Thor
11
13
  class_option :command,
@@ -33,6 +35,12 @@ module CypressRails
33
35
  desc: "path to Cypress tests",
34
36
  default: "./spec",
35
37
  aliases: %w(-t)
38
+ class_option :healthcheck_url,
39
+ type: :string,
40
+ desc: <<~DESC,
41
+ url to ping the server before running tests (you don't need the port, it will be injected)
42
+ DESC
43
+ aliases: %w(-u)
36
44
 
37
45
  desc "test", "Run all tests in headless mode"
38
46
  def test
@@ -55,12 +63,14 @@ module CypressRails
55
63
  private
56
64
 
57
65
  def server
58
- @server ||= Server.new(config.host, config.command, config.log_path)
66
+ @server ||= Server.new(config.host, config.command, config.healthcheck_url, config.log_path)
59
67
  end
60
68
 
61
69
  def config
62
70
  @config ||= Config.new(
63
- *options.values_at(:command, :cypress_bin_path, :host, :log_path, :tests_path)
71
+ *options.values_at(
72
+ :command, :cypress_bin_path, :host, :log_path, :tests_path, :healthcheck_url
73
+ )
64
74
  )
65
75
  end
66
76
  end
@@ -1,24 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "socket"
4
+ require "uri"
4
5
 
5
6
  module CypressRails
6
7
  class Server
7
8
  extend Forwardable
8
9
 
9
- attr_reader :host, :port, :command, :log_path
10
+ attr_reader :host, :port, :command, :healthcheck_url, :log_path
10
11
 
11
- def initialize(host, command, log_path)
12
+ def initialize(host, command, healthcheck_url, log_path)
12
13
  @host = host
13
14
  @port = find_free_port
14
15
  @command = command
16
+ @healthcheck_url = URI(healthcheck_url || "http://#{host}").tap { |uri| uri.port = port }
15
17
  @log_path = log_path
16
18
  end
17
19
 
18
20
  def start
19
21
  spawn_server
20
22
  until server_responsive?
21
- sleep 0.1
23
+ puts "Pinging #{healthcheck_url.to_s}..."
24
+ sleep 1
22
25
  end
23
26
  yield(host, port) if block_given?
24
27
  ensure
@@ -43,7 +46,7 @@ module CypressRails
43
46
  end
44
47
 
45
48
  def server_responsive?
46
- system("curl #{host}:#{port}", [:out, :err] => "/dev/null")
49
+ system("curl #{healthcheck_url}", [:out, :err] => "/dev/null")
47
50
  end
48
51
 
49
52
  def stop_server
@@ -2,5 +2,5 @@
2
2
 
3
3
  module CypressRails
4
4
  # cypress_rails version
5
- VERSION = "0.5.0"
5
+ VERSION = "0.6.0"
6
6
  end
@@ -18,7 +18,7 @@ RSpec.describe CypressRails::Runner do
18
18
  let(:server) { "rackup #{project_path}/config.ru" }
19
19
 
20
20
  it "runs cypress correctly" do
21
- CypressRails::Server.new(host, server, log_path).start do |host, port|
21
+ CypressRails::Server.new(host, server, nil, log_path).start do |host, port|
22
22
  CypressRails::Runner.new(
23
23
  host: host,
24
24
  port: port,
@@ -36,7 +36,7 @@ RSpec.describe CypressRails::Runner do
36
36
 
37
37
  it "returns status code 0" do
38
38
  status = nil
39
- CypressRails::Server.new(host, server, log_path).start do |host, port|
39
+ CypressRails::Server.new(host, server, nil, log_path).start do |host, port|
40
40
  status = CypressRails::Runner.new(
41
41
  host: host,
42
42
  port: port,
@@ -56,7 +56,7 @@ RSpec.describe CypressRails::Runner do
56
56
  let(:server) { "rackup #{project_path}/config.ru" }
57
57
 
58
58
  it "runs cypress correctly" do
59
- CypressRails::Server.new(host, server, log_path).start do |host, port|
59
+ CypressRails::Server.new(host, server, nil, log_path).start do |host, port|
60
60
  CypressRails::Runner.new(
61
61
  host: host,
62
62
  port: port,
@@ -74,7 +74,7 @@ RSpec.describe CypressRails::Runner do
74
74
 
75
75
  it "returns non-zero status code" do
76
76
  status = nil
77
- CypressRails::Server.new(host, server, log_path).start do |host, port|
77
+ CypressRails::Server.new(host, server, nil, log_path).start do |host, port|
78
78
  status = CypressRails::Runner.new(
79
79
  host: host,
80
80
  port: port,
@@ -8,16 +8,15 @@ RSpec.describe CypressRails::Server do
8
8
  let(:host) { "localhost" }
9
9
  let(:command) { "rackup spec/support/dummy_passing/config.ru" }
10
10
  let(:log_path) { "/dev/null" }
11
+ let(:server) { described_class.new(host, command, nil, log_path) }
11
12
 
12
13
  describe "#port" do
13
- subject(:port) { described_class.new(host, command, log_path).port }
14
+ subject(:port) { server.port }
14
15
 
15
16
  it { is_expected.to be_open_port }
16
17
  end
17
18
 
18
19
  describe "#start" do
19
- subject(:server) { described_class.new(host, command, log_path) }
20
-
21
20
  it "starts the server and blocks until it is ready" do
22
21
  response = nil
23
22
  server.start {
@@ -26,6 +25,19 @@ RSpec.describe CypressRails::Server do
26
25
  expect(response.status).to include "200"
27
26
  end
28
27
 
28
+ context "when a healthcheck url is passed" do
29
+ let(:command) { "rackup spec/support/dummy_healthcheck/config.ru" }
30
+ let(:server) { described_class.new(host, command, "http://localhost/foobar", log_path) }
31
+
32
+ it "pings the provided url" do
33
+ response = nil
34
+ server.start {
35
+ response = open("http://localhost:#{server.port}/foobar")
36
+ }
37
+ expect(response.status).to include "200"
38
+ end
39
+ end
40
+
29
41
  it "yields the port number and host into the block" do
30
42
  expect { |b| server.start(&b) }.to yield_with_args("localhost", server.port)
31
43
  end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ run ->(env) {
4
+ sleep 0.2
5
+ request = Rack::Request.new(env)
6
+ if request.path == "/foobar"
7
+ [
8
+ 200,
9
+ { "Content-Type" => "text/html" },
10
+ [
11
+ <<~HTML
12
+ <html>
13
+ <head><title>Dummy app</title></head>
14
+ <body>
15
+ <h1>Hello Dummy!</h1>
16
+ </body>
17
+ </html>
18
+ HTML
19
+ ]
20
+ ]
21
+ else
22
+ [
23
+ 404,
24
+ { "Content-Type" => "text/html" },
25
+ [""]
26
+ ]
27
+ end
28
+ }
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.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Szymon Szeliga
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-14 00:00:00.000000000 Z
11
+ date: 2018-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -218,6 +218,7 @@ files:
218
218
  - spec/support/dummy_failing/cypress/support/index.js
219
219
  - spec/support/dummy_failing/package.json
220
220
  - spec/support/dummy_failing/yarn.lock
221
+ - spec/support/dummy_healthcheck/config.ru
221
222
  - spec/support/dummy_passing/config.ru
222
223
  - spec/support/dummy_passing/cypress.json
223
224
  - spec/support/dummy_passing/cypress/integration/basic_spec.js
@@ -264,6 +265,7 @@ test_files:
264
265
  - spec/support/dummy_failing/cypress/support/index.js
265
266
  - spec/support/dummy_failing/package.json
266
267
  - spec/support/dummy_failing/yarn.lock
268
+ - spec/support/dummy_healthcheck/config.ru
267
269
  - spec/support/dummy_passing/config.ru
268
270
  - spec/support/dummy_passing/cypress.json
269
271
  - spec/support/dummy_passing/cypress/integration/basic_spec.js