cypress_rails 0.1.0 → 0.2.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 +4 -4
- data/.circleci/config.yml +62 -0
- data/.gitignore +3 -0
- data/README.md +1 -1
- data/bin/cypress-rails +5 -0
- data/cypress_rails.gemspec +5 -3
- data/lib/cypress_rails/cli.rb +61 -0
- data/lib/cypress_rails/runner.rb +31 -0
- data/lib/cypress_rails/server.rb +8 -15
- data/lib/cypress_rails/version.rb +1 -1
- data/lib/cypress_rails.rb +1 -23
- data/spec/cypress_rails/runner_spec.rb +83 -0
- data/spec/cypress_rails/server_spec.rb +10 -11
- data/spec/spec_helper.rb +2 -0
- data/spec/support/dummy_failing/config.ru +19 -0
- data/spec/support/dummy_failing/cypress/integration/basic_spec.js +10 -0
- data/spec/support/dummy_failing/cypress/plugins/index.js +17 -0
- data/spec/support/dummy_failing/cypress/support/commands.js +25 -0
- data/spec/support/dummy_failing/cypress/support/index.js +20 -0
- data/spec/support/dummy_failing/cypress.json +1 -0
- data/spec/support/dummy_failing/package.json +14 -0
- data/spec/support/dummy_failing/yarn.lock +1018 -0
- data/spec/support/dummy_passing/config.ru +19 -0
- data/spec/support/dummy_passing/cypress/integration/basic_spec.js +10 -0
- data/spec/support/dummy_passing/cypress/plugins/index.js +17 -0
- data/spec/support/dummy_passing/cypress/support/commands.js +25 -0
- data/spec/support/dummy_passing/cypress/support/index.js +20 -0
- data/spec/support/dummy_passing/cypress.json +1 -0
- data/spec/support/dummy_passing/package.json +14 -0
- data/spec/support/dummy_passing/yarn.lock +1018 -0
- metadata +82 -18
- data/.travis.yml +0 -9
- data/spec/support/dummy/config.ru +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80aae4380a1af0433ae1b914dbcbc6ee37263132
|
4
|
+
data.tar.gz: b564ccbc5a13d27a1f37dafab087c9147b7d5aea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1340b659aab5c49c6958dbdefc3a02986987e0ca03ddd9c98ca78f13507be7513d9ce76d4a8cce7e3e9eb338dafb2c582f0cbc62ad9a3ef0694a3f433c68b417
|
7
|
+
data.tar.gz: e58a245a1965c6a022c7bbb82a8e200755a1f5114c270d7ee588368e6fb676282c212d74b4e5d0afe2d079eac38d60968ce11d3258100b693f96467570032307
|
@@ -0,0 +1,62 @@
|
|
1
|
+
version: 2
|
2
|
+
jobs:
|
3
|
+
build:
|
4
|
+
docker:
|
5
|
+
- image: circleci/ruby:2-node
|
6
|
+
working_directory: ~/repo
|
7
|
+
steps:
|
8
|
+
- checkout
|
9
|
+
- run: sudo apt-get update
|
10
|
+
- run: sudo apt-get install xvfb libgtk2.0-0 libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2
|
11
|
+
- restore_cache:
|
12
|
+
keys:
|
13
|
+
- v1-dependencies-{{ checksum "cypress_rails.gemspec" }}
|
14
|
+
- v1-dependencies-
|
15
|
+
- restore_cache:
|
16
|
+
keys:
|
17
|
+
- v1-passing-node-modules-{{ checksum "./spec/support/dummy_passing/yarn.lock" }}
|
18
|
+
- v1-passing-node-modules-
|
19
|
+
- restore_cache:
|
20
|
+
keys:
|
21
|
+
- v1-failing-node-modules-{{ checksum "./spec/support/dummy_failing/yarn.lock" }}
|
22
|
+
- v1-failing-node-modules-
|
23
|
+
- run:
|
24
|
+
name: install dependencies
|
25
|
+
command: |
|
26
|
+
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
27
|
+
- run:
|
28
|
+
name: Install passing node dependencies
|
29
|
+
command: |
|
30
|
+
cd spec/support/dummy_passing && yarn install && npx cypress install && cd -
|
31
|
+
- run:
|
32
|
+
name: Install failing node dependencies
|
33
|
+
command: |
|
34
|
+
cd spec/support/dummy_failing && yarn install && npx cypress install && cd -
|
35
|
+
- save_cache:
|
36
|
+
paths:
|
37
|
+
- ./vendor/bundle
|
38
|
+
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
|
39
|
+
- save_cache:
|
40
|
+
paths:
|
41
|
+
- ./spec/support/dummy_passing/node_modules
|
42
|
+
key: v1-passing-node-dependencies-{{ checksum "./spec/support/dummy_passing/yarn.lock" }}
|
43
|
+
- save_cache:
|
44
|
+
paths:
|
45
|
+
- ./spec/support/dummy_failing/node_modules
|
46
|
+
key: v1-failing-node-dependencies-{{ checksum "./spec/support/dummy_failing/yarn.lock" }}
|
47
|
+
- run:
|
48
|
+
name: run tests
|
49
|
+
command: |
|
50
|
+
mkdir /tmp/test-results
|
51
|
+
TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
|
52
|
+
|
53
|
+
bundle exec rspec --format progress \
|
54
|
+
--format RspecJunitFormatter \
|
55
|
+
--out /tmp/test-results/rspec.xml \
|
56
|
+
--format progress \
|
57
|
+
$TEST_FILES
|
58
|
+
- store_test_results:
|
59
|
+
path: /tmp/test-results
|
60
|
+
- store_artifacts:
|
61
|
+
path: /tmp/test-results
|
62
|
+
destination: test-results
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
* [Documentation](http://rubydoc.info/gems/cypress_rails/frames)
|
5
5
|
* [Email](mailto:szymon@szeliga.co)
|
6
6
|
|
7
|
-
[](https://circleci.com/gh/Szeliga/cypress_rails/tree/master)
|
8
8
|
[](https://codeclimate.com/github/Szeliga/cypress_rails)
|
9
9
|
|
10
10
|
## Description
|
data/bin/cypress-rails
ADDED
data/cypress_rails.gemspec
CHANGED
@@ -29,13 +29,15 @@ Gem::Specification.new do |gem|
|
|
29
29
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
30
30
|
gem.require_paths = ["lib"]
|
31
31
|
|
32
|
+
gem.add_dependency "thor", "~> 0.20.0"
|
32
33
|
gem.add_development_dependency "bundler", "~> 1.10"
|
33
34
|
gem.add_development_dependency "codeclimate-test-reporter", "~> 0.1"
|
34
|
-
gem.add_development_dependency "pry"
|
35
|
-
gem.add_development_dependency "rack"
|
35
|
+
gem.add_development_dependency "pry", "~> 0.11.3"
|
36
|
+
gem.add_development_dependency "rack", "~> 2.0.5"
|
36
37
|
gem.add_development_dependency "rake", "~> 10.0"
|
37
38
|
gem.add_development_dependency "rdoc", "~> 4.0"
|
38
39
|
gem.add_development_dependency "rspec", "~> 3.0"
|
39
|
-
gem.add_development_dependency "rubocop"
|
40
|
+
gem.add_development_dependency "rubocop", "~> 0.55.0"
|
40
41
|
gem.add_development_dependency "rubygems-tasks", "~> 0.2"
|
42
|
+
gem.add_development_dependency "rspec_junit_formatter", "~> 0.3.0"
|
41
43
|
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "thor"
|
4
|
+
require "cypress_rails/runner"
|
5
|
+
require "cypress_rails/server"
|
6
|
+
|
7
|
+
module CypressRails
|
8
|
+
Config = Struct.new(:command, :cypress_command, :host, :log_path, :test_path)
|
9
|
+
|
10
|
+
class CLI < Thor
|
11
|
+
class_option :command,
|
12
|
+
required: true,
|
13
|
+
type: :string,
|
14
|
+
desc: "command to start the server",
|
15
|
+
aliases: %w(-c)
|
16
|
+
class_option :cypress_command,
|
17
|
+
type: :string,
|
18
|
+
desc: "command to run cypress",
|
19
|
+
default: "npx cypress",
|
20
|
+
aliases: %w(-cc)
|
21
|
+
class_option :host,
|
22
|
+
type: :string,
|
23
|
+
desc: "host on which to start the local server",
|
24
|
+
default: "localhost",
|
25
|
+
aliases: %w(-h)
|
26
|
+
class_option :log_path,
|
27
|
+
type: :string,
|
28
|
+
desc: "path to the log file for the server",
|
29
|
+
default: "/dev/null",
|
30
|
+
aliases: %w(-l)
|
31
|
+
class_option :test_path,
|
32
|
+
type: :string,
|
33
|
+
desc: "path to Cypress tests",
|
34
|
+
default: "./spec/cypress",
|
35
|
+
aliases: %w(-t)
|
36
|
+
|
37
|
+
desc "test", "Run all tests in headless mode"
|
38
|
+
def test
|
39
|
+
server.start do |host, port|
|
40
|
+
exit Runner.new(host: host, port: port, command: config.cypress_command).run
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
desc "open", "Start the server and open Cypress Dashboard"
|
45
|
+
def open
|
46
|
+
puts options
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def server
|
52
|
+
@server ||= Server.new(config.host, config.command, config.log_path)
|
53
|
+
end
|
54
|
+
|
55
|
+
def config
|
56
|
+
@config ||= Config.new(
|
57
|
+
*options.values_at(:command, :cypress_command, :host, :log_path, :test_path)
|
58
|
+
)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CypressRails
|
4
|
+
class Runner
|
5
|
+
def initialize(host:, port:, command: "npx cypress", output: IO.new(1))
|
6
|
+
@host = host
|
7
|
+
@port = port
|
8
|
+
@command = command
|
9
|
+
@output = output
|
10
|
+
end
|
11
|
+
|
12
|
+
def run
|
13
|
+
pid = Process.spawn(
|
14
|
+
{
|
15
|
+
"CYPRESS_app_host" => host,
|
16
|
+
"CYPRESS_app_port" => port.to_s,
|
17
|
+
},
|
18
|
+
command,
|
19
|
+
out: output,
|
20
|
+
err: [:child, :out]
|
21
|
+
)
|
22
|
+
output.close
|
23
|
+
_, status = Process.wait2(pid)
|
24
|
+
status.exitstatus
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
attr_reader :host, :port, :command, :output
|
30
|
+
end
|
31
|
+
end
|
data/lib/cypress_rails/server.rb
CHANGED
@@ -6,11 +6,13 @@ module CypressRails
|
|
6
6
|
class Server
|
7
7
|
extend Forwardable
|
8
8
|
|
9
|
-
attr_reader :host, :port
|
9
|
+
attr_reader :host, :port, :command, :log_path
|
10
10
|
|
11
|
-
def initialize(host)
|
11
|
+
def initialize(host, command, log_path)
|
12
12
|
@host = host
|
13
13
|
@port = find_free_port
|
14
|
+
@command = command
|
15
|
+
@log_path = log_path
|
14
16
|
end
|
15
17
|
|
16
18
|
def start
|
@@ -18,7 +20,8 @@ module CypressRails
|
|
18
20
|
until server_responsive?
|
19
21
|
sleep 0.1
|
20
22
|
end
|
21
|
-
yield if block_given?
|
23
|
+
yield(host, port) if block_given?
|
24
|
+
ensure
|
22
25
|
stop_server
|
23
26
|
end
|
24
27
|
|
@@ -26,10 +29,6 @@ module CypressRails
|
|
26
29
|
|
27
30
|
attr_reader :pid
|
28
31
|
|
29
|
-
def_delegators :configuration,
|
30
|
-
:server_command,
|
31
|
-
:log_path
|
32
|
-
|
33
32
|
def spawn_server
|
34
33
|
@pid = Process.spawn(
|
35
34
|
build_command,
|
@@ -48,13 +47,11 @@ module CypressRails
|
|
48
47
|
end
|
49
48
|
|
50
49
|
def stop_server
|
51
|
-
Process.kill("SIGINT", pid)
|
50
|
+
Process.kill("SIGINT", pid) if pid
|
52
51
|
end
|
53
52
|
|
54
53
|
def build_command
|
55
|
-
command
|
56
|
-
command << "--port #{port}"
|
57
|
-
command.join(" ")
|
54
|
+
"#{command} --port #{port}"
|
58
55
|
end
|
59
56
|
|
60
57
|
def find_free_port
|
@@ -63,9 +60,5 @@ module CypressRails
|
|
63
60
|
ensure
|
64
61
|
server.close if server
|
65
62
|
end
|
66
|
-
|
67
|
-
def configuration
|
68
|
-
CypressRails.configuration
|
69
|
-
end
|
70
63
|
end
|
71
64
|
end
|
data/lib/cypress_rails.rb
CHANGED
@@ -1,25 +1,3 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "singleton"
|
2
|
+
#
|
4
3
|
require "cypress_rails/version"
|
5
|
-
|
6
|
-
module CypressRails
|
7
|
-
def self.configure
|
8
|
-
yield(configuration)
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.configuration
|
12
|
-
Configuration.instance
|
13
|
-
end
|
14
|
-
|
15
|
-
class Configuration
|
16
|
-
include Singleton
|
17
|
-
|
18
|
-
attr_accessor :server_command, :log_path
|
19
|
-
|
20
|
-
def initialize
|
21
|
-
@server_command = ""
|
22
|
-
@log_path = "/dev/null"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
require "cypress_rails/server"
|
5
|
+
require "cypress_rails/runner"
|
6
|
+
|
7
|
+
RSpec.describe CypressRails::Runner do
|
8
|
+
let(:host) { "localhost" }
|
9
|
+
let(:log_path) { "/dev/null" }
|
10
|
+
let(:pipe) { IO.pipe }
|
11
|
+
let(:w) { pipe[1] }
|
12
|
+
let(:r) { pipe[0] }
|
13
|
+
|
14
|
+
context "when tests are passing" do
|
15
|
+
let(:command) { "rackup spec/support/dummy_passing/config.ru" }
|
16
|
+
|
17
|
+
it "runs cypress correctly" do
|
18
|
+
CypressRails::Server.new(host, command, log_path).start do |host, port|
|
19
|
+
CypressRails::Runner.new(
|
20
|
+
host: host,
|
21
|
+
port: port,
|
22
|
+
command: "cd spec/support/dummy_passing && npx cypress run",
|
23
|
+
output: w
|
24
|
+
).run
|
25
|
+
end
|
26
|
+
result = r.read
|
27
|
+
expect(result).to match(/Visiting the root address/)
|
28
|
+
expect(result).to match(/renders OK/)
|
29
|
+
expect(result).to match(/\(Tests Finished\)/)
|
30
|
+
r.close
|
31
|
+
end
|
32
|
+
|
33
|
+
it "returns status code 0" do
|
34
|
+
status = nil
|
35
|
+
CypressRails::Server.new(host, command, log_path).start do |host, port|
|
36
|
+
status = CypressRails::Runner.new(
|
37
|
+
host: host,
|
38
|
+
port: port,
|
39
|
+
command: "cd spec/support/dummy_passing && npx cypress run",
|
40
|
+
output: w
|
41
|
+
).run
|
42
|
+
end
|
43
|
+
r.read
|
44
|
+
r.close
|
45
|
+
expect(status).to eq 0
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "when tests are failing" do
|
50
|
+
let(:command) { "rackup spec/support/dummy_failing/config.ru" }
|
51
|
+
|
52
|
+
it "runs cypress correctly" do
|
53
|
+
CypressRails::Server.new(host, command, log_path).start do |host, port|
|
54
|
+
CypressRails::Runner.new(
|
55
|
+
host: host,
|
56
|
+
port: port,
|
57
|
+
command: "cd spec/support/dummy_failing && npx cypress run",
|
58
|
+
output: w
|
59
|
+
).run
|
60
|
+
end
|
61
|
+
result = r.read
|
62
|
+
expect(result).to match(/Visiting the root address/)
|
63
|
+
expect(result).to match(/renders OK/)
|
64
|
+
expect(result).to match(/\(Tests Finished\)/)
|
65
|
+
r.close
|
66
|
+
end
|
67
|
+
|
68
|
+
it "returns non-zero status code" do
|
69
|
+
status = nil
|
70
|
+
CypressRails::Server.new(host, command, log_path).start do |host, port|
|
71
|
+
status = CypressRails::Runner.new(
|
72
|
+
host: host,
|
73
|
+
port: port,
|
74
|
+
command: "cd spec/support/dummy_failing && npx cypress run",
|
75
|
+
output: w
|
76
|
+
).run
|
77
|
+
end
|
78
|
+
r.read
|
79
|
+
r.close
|
80
|
+
expect(status).not_to eq 0
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -2,33 +2,32 @@
|
|
2
2
|
|
3
3
|
require "spec_helper"
|
4
4
|
require "open-uri"
|
5
|
-
require "cypress_rails"
|
6
5
|
require "cypress_rails/server"
|
7
6
|
|
8
7
|
RSpec.describe CypressRails::Server do
|
9
|
-
|
10
|
-
|
8
|
+
let(:host) { "localhost" }
|
9
|
+
let(:command) { "rackup spec/support/dummy_passing/config.ru" }
|
10
|
+
let(:log_path) { "/dev/null" }
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
end
|
12
|
+
describe "#port" do
|
13
|
+
subject(:port) { described_class.new(host, command, log_path).port }
|
15
14
|
|
16
15
|
it { is_expected.to be_open_port }
|
17
16
|
end
|
18
17
|
|
19
18
|
describe "#start" do
|
20
|
-
subject(:server) { described_class.new(
|
19
|
+
subject(:server) { described_class.new(host, command, log_path) }
|
21
20
|
|
22
21
|
it "starts the server and blocks until it is ready" do
|
23
|
-
CypressRails.configure do |config|
|
24
|
-
config.server_command = "rackup spec/support/dummy/config.ru"
|
25
|
-
end
|
26
|
-
|
27
22
|
response = nil
|
28
23
|
server.start {
|
29
24
|
response = open("http://localhost:#{server.port}")
|
30
25
|
}
|
31
26
|
expect(response.status).to include "200"
|
32
27
|
end
|
28
|
+
|
29
|
+
it "yields the port number and host into the block" do
|
30
|
+
expect { |b| server.start(&b) }.to yield_with_args("localhost", server.port)
|
31
|
+
end
|
33
32
|
end
|
34
33
|
end
|