cypress_rails 0.2.0 → 0.3.0

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
  SHA1:
3
- metadata.gz: 80aae4380a1af0433ae1b914dbcbc6ee37263132
4
- data.tar.gz: b564ccbc5a13d27a1f37dafab087c9147b7d5aea
3
+ metadata.gz: d9622fc9e2ab6e48541a371469cfc42bbb523daf
4
+ data.tar.gz: b7321531f8e5cc10cfd62c08c49a4e6da498d32c
5
5
  SHA512:
6
- metadata.gz: 1340b659aab5c49c6958dbdefc3a02986987e0ca03ddd9c98ca78f13507be7513d9ce76d4a8cce7e3e9eb338dafb2c582f0cbc62ad9a3ef0694a3f433c68b417
7
- data.tar.gz: e58a245a1965c6a022c7bbb82a8e200755a1f5114c270d7ee588368e6fb676282c212d74b4e5d0afe2d079eac38d60968ce11d3258100b693f96467570032307
6
+ metadata.gz: d11841e68726c53d368fd0c9917763de6b33b86cdf23d7676d2f3b745138615ad0c3bca154e072ca78d72e7f455cde0594a669179b0354aa09dcae07cc32e08e
7
+ data.tar.gz: 1ae36bfde43f2a76aef98393f14bb4c5f5cad9ee75d3bdd0122d1733461bc0e52ccfe78fac7419a560005555d34594acd5ffa455ee80bcb3865e5708ee233cdf
data/ChangeLog.md CHANGED
@@ -1,4 +1,15 @@
1
- ### 0.1.0 / 2018-05-04
1
+ ### 0.3.0 / 2018-05-16
2
+
3
+ * Added more options to the CLI
4
+ * Added `#run` and `#open` methods to the Runner
5
+
6
+ ### 0.2.0 / 2018-05-08
2
7
 
3
- * Initial release:
8
+ * Added `CypressRails::Runner` class that runs Cypress with the specified command inside the
9
+ `CypressRails::Server.start` block
10
+ * Runner returns the status code of the Cypress process
11
+
12
+ ### 0.1.0 / 2018-05-04
4
13
 
14
+ * Initial release
15
+ * Added `CypressRails::Server` class that starts the application to test under the specified address
@@ -5,15 +5,15 @@ require "cypress_rails/runner"
5
5
  require "cypress_rails/server"
6
6
 
7
7
  module CypressRails
8
- Config = Struct.new(:command, :cypress_command, :host, :log_path, :test_path)
8
+ Config = Struct.new(:command, :cypress_bin_path, :host, :log_path, :tests_path)
9
9
 
10
10
  class CLI < Thor
11
11
  class_option :command,
12
- required: true,
13
12
  type: :string,
14
13
  desc: "command to start the server",
14
+ default: "bundle exec rails server",
15
15
  aliases: %w(-c)
16
- class_option :cypress_command,
16
+ class_option :cypress_bin_path,
17
17
  type: :string,
18
18
  desc: "command to run cypress",
19
19
  default: "npx cypress",
@@ -28,22 +28,28 @@ module CypressRails
28
28
  desc: "path to the log file for the server",
29
29
  default: "/dev/null",
30
30
  aliases: %w(-l)
31
- class_option :test_path,
31
+ class_option :tests_path,
32
32
  type: :string,
33
33
  desc: "path to Cypress tests",
34
- default: "./spec/cypress",
34
+ default: "./spec",
35
35
  aliases: %w(-t)
36
36
 
37
37
  desc "test", "Run all tests in headless mode"
38
38
  def test
39
39
  server.start do |host, port|
40
- exit Runner.new(host: host, port: port, command: config.cypress_command).run
40
+ exit Runner.new(
41
+ host: host, port: port, bin_path: config.cypress_bin_path, tests_path: config.tests_path
42
+ ).run
41
43
  end
42
44
  end
43
45
 
44
46
  desc "open", "Start the server and open Cypress Dashboard"
45
47
  def open
46
- puts options
48
+ server.start do |host, port|
49
+ exit Runner.new(
50
+ host: host, port: port, bin_path: config.cypress_bin_path, tests_path: config.tests_path
51
+ ).open
52
+ end
47
53
  end
48
54
 
49
55
  private
@@ -54,7 +60,7 @@ module CypressRails
54
60
 
55
61
  def config
56
62
  @config ||= Config.new(
57
- *options.values_at(:command, :cypress_command, :host, :log_path, :test_path)
63
+ *options.values_at(:command, :cypress_bin_path, :host, :log_path, :tests_path)
58
64
  )
59
65
  end
60
66
  end
@@ -2,10 +2,11 @@
2
2
 
3
3
  module CypressRails
4
4
  class Runner
5
- def initialize(host:, port:, command: "npx cypress", output: IO.new(1))
5
+ def initialize(host:, port:, bin_path: "npx cypress", tests_path:, output: IO.new(1))
6
6
  @host = host
7
7
  @port = port
8
- @command = command
8
+ @bin_path = bin_path
9
+ @tests_path = tests_path
9
10
  @output = output
10
11
  end
11
12
 
@@ -15,7 +16,7 @@ module CypressRails
15
16
  "CYPRESS_app_host" => host,
16
17
  "CYPRESS_app_port" => port.to_s,
17
18
  },
18
- command,
19
+ [bin_path, "run", "-P #{tests_path}"].join(" "),
19
20
  out: output,
20
21
  err: [:child, :out]
21
22
  )
@@ -24,8 +25,22 @@ module CypressRails
24
25
  status.exitstatus
25
26
  end
26
27
 
28
+ def open
29
+ pid = Process.spawn(
30
+ {
31
+ "CYPRESS_app_host" => host,
32
+ "CYPRESS_app_port" => port.to_s,
33
+ },
34
+ [bin_path, "open", "-P #{tests_path}"].join(" "),
35
+ out: output,
36
+ err: [:child, :out]
37
+ )
38
+ output.close
39
+ Process.wait(pid)
40
+ end
41
+
27
42
  private
28
43
 
29
- attr_reader :host, :port, :command, :output
44
+ attr_reader :host, :port, :bin_path, :tests_path, :output
30
45
  end
31
46
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module CypressRails
4
4
  # cypress_rails version
5
- VERSION = "0.2.0"
5
+ VERSION = "0.3.0"
6
6
  end
@@ -7,19 +7,23 @@ require "cypress_rails/runner"
7
7
  RSpec.describe CypressRails::Runner do
8
8
  let(:host) { "localhost" }
9
9
  let(:log_path) { "/dev/null" }
10
+ let(:bin_path) { "cd #{project_path} && npx cypress" }
11
+ let(:tests_path) { "." }
10
12
  let(:pipe) { IO.pipe }
11
13
  let(:w) { pipe[1] }
12
14
  let(:r) { pipe[0] }
13
15
 
14
16
  context "when tests are passing" do
15
- let(:command) { "rackup spec/support/dummy_passing/config.ru" }
17
+ let(:project_path) { "spec/support/dummy_passing" }
18
+ let(:server) { "rackup #{project_path}/config.ru" }
16
19
 
17
20
  it "runs cypress correctly" do
18
- CypressRails::Server.new(host, command, log_path).start do |host, port|
21
+ CypressRails::Server.new(host, server, log_path).start do |host, port|
19
22
  CypressRails::Runner.new(
20
23
  host: host,
21
24
  port: port,
22
- command: "cd spec/support/dummy_passing && npx cypress run",
25
+ bin_path: bin_path,
26
+ tests_path: tests_path,
23
27
  output: w
24
28
  ).run
25
29
  end
@@ -32,11 +36,12 @@ RSpec.describe CypressRails::Runner do
32
36
 
33
37
  it "returns status code 0" do
34
38
  status = nil
35
- CypressRails::Server.new(host, command, log_path).start do |host, port|
39
+ CypressRails::Server.new(host, server, log_path).start do |host, port|
36
40
  status = CypressRails::Runner.new(
37
41
  host: host,
38
42
  port: port,
39
- command: "cd spec/support/dummy_passing && npx cypress run",
43
+ bin_path: bin_path,
44
+ tests_path: tests_path,
40
45
  output: w
41
46
  ).run
42
47
  end
@@ -47,14 +52,16 @@ RSpec.describe CypressRails::Runner do
47
52
  end
48
53
 
49
54
  context "when tests are failing" do
50
- let(:command) { "rackup spec/support/dummy_failing/config.ru" }
55
+ let(:project_path) { "spec/support/dummy_failing" }
56
+ let(:server) { "rackup #{project_path}/config.ru" }
51
57
 
52
58
  it "runs cypress correctly" do
53
- CypressRails::Server.new(host, command, log_path).start do |host, port|
59
+ CypressRails::Server.new(host, server, log_path).start do |host, port|
54
60
  CypressRails::Runner.new(
55
61
  host: host,
56
62
  port: port,
57
- command: "cd spec/support/dummy_failing && npx cypress run",
63
+ bin_path: bin_path,
64
+ tests_path: tests_path,
58
65
  output: w
59
66
  ).run
60
67
  end
@@ -67,11 +74,12 @@ RSpec.describe CypressRails::Runner do
67
74
 
68
75
  it "returns non-zero status code" do
69
76
  status = nil
70
- CypressRails::Server.new(host, command, log_path).start do |host, port|
77
+ CypressRails::Server.new(host, server, log_path).start do |host, port|
71
78
  status = CypressRails::Runner.new(
72
79
  host: host,
73
80
  port: port,
74
- command: "cd spec/support/dummy_failing && npx cypress run",
81
+ bin_path: bin_path,
82
+ tests_path: tests_path,
75
83
  output: w
76
84
  ).run
77
85
  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.2.0
4
+ version: 0.3.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-05-08 00:00:00.000000000 Z
11
+ date: 2018-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor