cypress-on-rails 1.16.0 → 1.17.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/CHANGELOG.md +11 -0
- data/README.md +25 -27
- data/cypress-on-rails.gemspec +1 -1
- data/lib/cypress_on_rails/middleware.rb +1 -0
- data/lib/cypress_on_rails/simple_rails_factory.rb +0 -2
- data/lib/cypress_on_rails/version.rb +1 -1
- data/lib/generators/cypress_on_rails/install_generator.rb +31 -29
- data/lib/generators/cypress_on_rails/templates/config/initializers/cypress_on_rails.rb.erb +1 -1
- data/lib/generators/cypress_on_rails/templates/spec/cypress/support/on-rails.js +6 -0
- data/specs_e2e/rails_3_2/test.sh +14 -7
- data/specs_e2e/rails_4_2/.gitignore +1 -0
- data/specs_e2e/rails_4_2/package.json +4 -2
- data/specs_e2e/rails_4_2/playwright-report/index.html +62 -0
- data/specs_e2e/rails_4_2/spec/fixtures/vcr_cassettes/cats.yml +63 -0
- data/specs_e2e/rails_4_2/test.sh +13 -7
- data/specs_e2e/rails_5_2/.gitignore +4 -0
- data/specs_e2e/rails_5_2/test.sh +16 -7
- metadata +8 -7
- data/lib/generators/cypress_on_rails/update_generator.rb +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c9e7d196e802c6bc10ed4a31fdfc868d92a4f059452e3315fa6c2b525f0ff17
|
4
|
+
data.tar.gz: 7378fe702963ed71a808dcdcf518c60519ef5c0149211b1e7e8692823dbb3796
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49c39f927764cab07fd2e1e7dd5c73773a60ce3c515666267fc8602e00b233c0d18f905653df742acb56c16ab594c7c463b13d66e71cde04be5ba785555c3150
|
7
|
+
data.tar.gz: 39701b20ce5fa8024fc9672dd49bbe6f66445d50f45764a22ad18068684595ebb5bd87f6b9a7d031b84df36cb5c705d1f808e056482f11c79247c4b9cd8ccbb4
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
## [1.17.0]
|
2
|
+
[Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.16.0...v1.17.0
|
3
|
+
|
4
|
+
### Changed
|
5
|
+
* Removed the update generator and reduced options for install generator [PR 149](https://github.com/shakacode/cypress-on-rails/pull/149)
|
6
|
+
|
7
|
+
### Fixed
|
8
|
+
* fix update index.js in install generator [PR 147](https://github.com/shakacode/cypress-on-rails/pull/147) by [Judahmeek]
|
9
|
+
* Support rails 7.1 by adding content-type header to generated on-rails.js file [PR 148](https://github.com/shakacode/cypress-on-rails/pull/148) by [anark]
|
10
|
+
* Rewind body before reading it [PR 150](https://github.com/shakacode/cypress-on-rails/pull/150)
|
11
|
+
|
1
12
|
## [1.16.0]
|
2
13
|
[Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.15.1...v1.16.0
|
3
14
|
|
data/README.md
CHANGED
@@ -61,46 +61,43 @@ Generate the boilerplate code using:
|
|
61
61
|
# by default installs only cypress
|
62
62
|
bin/rails g cypress_on_rails:install
|
63
63
|
|
64
|
-
# if you have/want a different cypress folder (default is
|
65
|
-
bin/rails g cypress_on_rails:install --
|
64
|
+
# if you have/want a different cypress folder (default is e2e)
|
65
|
+
bin/rails g cypress_on_rails:install --install_folder=spec/cypress
|
66
66
|
|
67
|
-
# to install
|
68
|
-
bin/rails g cypress_on_rails:install --
|
69
|
-
|
70
|
-
# to change where the Ruby files reside (default is e2e)
|
71
|
-
bin/rails g cypress_on_rails:install --install_folder=test/e2e
|
67
|
+
# to install playwright instead of cypress
|
68
|
+
bin/rails g cypress_on_rails:install --framework playwright
|
72
69
|
|
73
70
|
# if you target the Rails server with a path prefix to your URL
|
74
71
|
bin/rails g cypress_on_rails:install --api_prefix=/api
|
75
72
|
|
76
|
-
# if you want to install
|
77
|
-
bin/rails g cypress_on_rails:install --
|
73
|
+
# if you want to install with npm instead
|
74
|
+
bin/rails g cypress_on_rails:install --install_with=npm
|
78
75
|
|
79
76
|
# if you already have cypress installed globally
|
80
|
-
bin/rails g cypress_on_rails:install --
|
77
|
+
bin/rails g cypress_on_rails:install --install_with=skip
|
81
78
|
|
82
79
|
# to update the generated files run
|
83
|
-
bin/rails g cypress_on_rails:
|
80
|
+
bin/rails g cypress_on_rails:install --install_with=skip
|
84
81
|
```
|
85
82
|
|
86
83
|
The generator modifies/adds the following files/directory in your application:
|
87
84
|
* `config/initializers/cypress_on_rails.rb` used to configure Cypress on Rails
|
88
|
-
* `
|
89
|
-
* `
|
90
|
-
* `
|
91
|
-
* `
|
92
|
-
* `
|
93
|
-
* `
|
85
|
+
* `e2e/cypress/integration/` contains your cypress tests
|
86
|
+
* `e2e/cypress/support/on-rails.js` contains Cypress on Rails support code
|
87
|
+
* `e2e/cypress/e2e_helper.rb` contains helper code to require libraries like factory_bot
|
88
|
+
* `e2e/cypress/app_commands/` contains your scenario definitions
|
89
|
+
* `e2e/playwright/e2e/` contains your playwright tests
|
90
|
+
* `e2e/playwright/support/on-rails.js` contains Playwright on Rails support code
|
94
91
|
|
95
|
-
If you are not using `database_cleaner` look at `
|
96
|
-
If you are not using `factory_bot` look at `
|
92
|
+
If you are not using `database_cleaner` look at `e2e/cypress/app_commands/clean.rb`.
|
93
|
+
If you are not using `factory_bot` look at `e2e/cypress/app_commands/factory_bot.rb`.
|
97
94
|
|
98
95
|
Now you can create scenarios and commands that are plain Ruby files that get loaded through middleware, the ruby sky is your limit.
|
99
96
|
|
100
97
|
### Update your database.yml
|
101
98
|
|
102
|
-
When
|
103
|
-
make are picked up without having to restart
|
99
|
+
When writing and running tests on your local computer it's recommended to start your server in development mode so that changes you
|
100
|
+
make are picked up without having to restart your local server.
|
104
101
|
It's recommended you update your `database.yml` to check if the `CYPRESS` environment variable is set and switch it to the test database
|
105
102
|
otherwise cypress will keep clearing your development database.
|
106
103
|
|
@@ -127,11 +124,9 @@ Getting started on your local environment
|
|
127
124
|
CYPRESS=1 bin/rails server -p 5017
|
128
125
|
|
129
126
|
# in separate window start cypress
|
130
|
-
yarn cypress open
|
127
|
+
yarn cypress open --project ./e2e
|
131
128
|
# or for npm
|
132
|
-
|
133
|
-
# or if you changed the cypress folder to spec/cypress
|
134
|
-
yarn cypress open --project ./spec
|
129
|
+
npx cypress open --project ./e2e
|
135
130
|
# or for playwright
|
136
131
|
yarn playwright test --ui
|
137
132
|
# or using npm
|
@@ -144,9 +139,9 @@ How to run cypress on CI
|
|
144
139
|
# setup rails and start server in background
|
145
140
|
# ...
|
146
141
|
|
147
|
-
yarn run cypress run
|
142
|
+
yarn run cypress run --project ./e2e
|
148
143
|
# or for npm
|
149
|
-
npx cypress run
|
144
|
+
npx cypress run --project ./e2e
|
150
145
|
```
|
151
146
|
|
152
147
|
### Example of using factory bot
|
@@ -463,6 +458,9 @@ Cypress.Commands.add('appCommands', (body) => {
|
|
463
458
|
method: 'POST',
|
464
459
|
url: '/__cypress__/command',
|
465
460
|
body: JSON.stringify(body),
|
461
|
+
headers: {
|
462
|
+
'Content-Type': 'application/json; charset=utf-8',
|
463
|
+
},
|
466
464
|
log: true,
|
467
465
|
failOnStatusCode: true
|
468
466
|
})
|
data/cypress-on-rails.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.add_development_dependency 'rake'
|
20
20
|
s.add_development_dependency 'rspec'
|
21
21
|
s.add_development_dependency 'railties', '>= 3.2'
|
22
|
-
s.add_development_dependency 'factory_bot'
|
22
|
+
s.add_development_dependency 'factory_bot', '!= 6.4.5'
|
23
23
|
s.add_development_dependency 'vcr'
|
24
24
|
s.metadata = {
|
25
25
|
"bug_tracker_uri" => "https://github.com/shakacode/cypress-on-rails/issues",
|
@@ -51,6 +51,7 @@ module CypressOnRails
|
|
51
51
|
# Halt the middleware if an Rack Env was returned by `before_request`
|
52
52
|
return maybe_env unless maybe_env.nil?
|
53
53
|
|
54
|
+
req.body.rewind
|
54
55
|
body = JSON.parse(req.body.read)
|
55
56
|
logger.info "handle_command: #{body}"
|
56
57
|
commands = Command.from_body(body, configuration)
|
@@ -1,12 +1,9 @@
|
|
1
1
|
module CypressOnRails
|
2
2
|
class InstallGenerator < Rails::Generators::Base
|
3
3
|
class_option :api_prefix, type: :string, default: ''
|
4
|
+
class_option :framework, type: :string, default: 'cypress'
|
4
5
|
class_option :install_folder, type: :string, default: 'e2e'
|
5
|
-
class_option :install_cypress, type: :boolean, default: true
|
6
|
-
class_option :install_playwright, type: :boolean, default: false
|
7
6
|
class_option :install_with, type: :string, default: 'yarn'
|
8
|
-
class_option :cypress_folder, type: :string, default: 'cypress'
|
9
|
-
class_option :playwright_folder, type: :string, default: 'playwright'
|
10
7
|
class_option :experimental, type: :boolean, default: false
|
11
8
|
source_root File.expand_path('../templates', __FILE__)
|
12
9
|
|
@@ -17,10 +14,11 @@ module CypressOnRails
|
|
17
14
|
|
18
15
|
command = nil
|
19
16
|
packages = []
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
17
|
+
packages = if options.framework == 'cypress'
|
18
|
+
['cypress', 'cypress-on-rails']
|
19
|
+
elsif options.framework == 'playwright'
|
20
|
+
['playwright', '@playwright/test']
|
21
|
+
end
|
24
22
|
if options.install_with == 'yarn'
|
25
23
|
command = "yarn --cwd=#{install_dir} add #{packages.join(' ')} --dev"
|
26
24
|
elsif options.install_with == 'npm'
|
@@ -31,38 +29,42 @@ module CypressOnRails
|
|
31
29
|
fail "failed to install #{packages.join(' ')}" unless system(command)
|
32
30
|
end
|
33
31
|
|
34
|
-
if options.
|
35
|
-
template "spec/cypress/support/index.js.erb", "#{options.
|
36
|
-
copy_file "spec/cypress/support/commands.js", "#{options.
|
37
|
-
copy_file "spec/cypress.config.js", "#{options.
|
32
|
+
if options.framework == 'cypress'
|
33
|
+
template "spec/cypress/support/index.js.erb", "#{options.install_folder}/cypress/support/index.js"
|
34
|
+
copy_file "spec/cypress/support/commands.js", "#{options.install_folder}/cypress/support/commands.js"
|
35
|
+
copy_file "spec/cypress.config.js", "#{options.install_folder}/cypress.config.js"
|
38
36
|
end
|
39
|
-
if options.
|
40
|
-
template "spec/playwright/support/index.js.erb", "#{options.
|
41
|
-
copy_file "spec/playwright.config.js", "#{options.
|
37
|
+
if options.framework == 'playwright'
|
38
|
+
template "spec/playwright/support/index.js.erb", "#{options.install_folder}/playwright/support/index.js"
|
39
|
+
copy_file "spec/playwright.config.js", "#{options.install_folder}/playwright.config.js"
|
42
40
|
end
|
43
41
|
end
|
44
42
|
|
45
43
|
def add_initial_files
|
46
44
|
template "config/initializers/cypress_on_rails.rb.erb", "config/initializers/cypress_on_rails.rb"
|
47
|
-
template "spec/e2e/e2e_helper.rb.erb", "#{options.install_folder}/e2e_helper.rb"
|
48
|
-
directory 'spec/e2e/app_commands', "#{options.install_folder}/app_commands"
|
49
|
-
if options.
|
50
|
-
copy_file "spec/cypress/support/on-rails.js", "#{options.
|
51
|
-
directory 'spec/cypress/e2e/rails_examples', "#{options.
|
45
|
+
template "spec/e2e/e2e_helper.rb.erb", "#{options.install_folder}/#{options.framework}/e2e_helper.rb"
|
46
|
+
directory 'spec/e2e/app_commands', "#{options.install_folder}/#{options.framework}/app_commands"
|
47
|
+
if options.framework == 'cypress'
|
48
|
+
copy_file "spec/cypress/support/on-rails.js", "#{options.install_folder}/cypress/support/on-rails.js"
|
49
|
+
directory 'spec/cypress/e2e/rails_examples', "#{options.install_folder}/cypress/e2e/rails_examples"
|
52
50
|
end
|
53
|
-
if options.
|
54
|
-
copy_file "spec/playwright/support/on-rails.js", "#{options.
|
55
|
-
directory 'spec/playwright/e2e/rails_examples', "#{options.
|
51
|
+
if options.framework == 'playwright'
|
52
|
+
copy_file "spec/playwright/support/on-rails.js", "#{options.install_folder}/playwright/support/on-rails.js"
|
53
|
+
directory 'spec/playwright/e2e/rails_examples', "#{options.install_folder}/playwright/e2e/rails_examples"
|
56
54
|
end
|
57
55
|
end
|
58
56
|
|
59
57
|
def update_files
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
58
|
+
if options.framework == 'cypress'
|
59
|
+
append_to_file "#{options.install_folder}/cypress/support/index.js",
|
60
|
+
"\nimport './on-rails'",
|
61
|
+
after: 'import \'./commands\''
|
62
|
+
end
|
63
|
+
if options.framework == 'playwright'
|
64
|
+
append_to_file "#{options.install_folder}/playwright/support/index.js",
|
65
|
+
"\nimport './on-rails'",
|
66
|
+
after: '// Import commands.js using ES2015 syntax:'
|
67
|
+
end
|
66
68
|
end
|
67
69
|
end
|
68
70
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
if defined?(CypressOnRails)
|
2
2
|
CypressOnRails.configure do |c|
|
3
3
|
c.api_prefix = "<%= options.api_prefix %>"
|
4
|
-
c.install_folder = File.expand_path("#{__dir__}/../../<%= options.install_folder %>")
|
4
|
+
c.install_folder = File.expand_path("#{__dir__}/../../<%= options.install_folder %>/<%= options.framework %>")
|
5
5
|
# WARNING!! CypressOnRails can execute arbitrary ruby code
|
6
6
|
# please use with extra caution if enabling on hosted servers or starting your local server on 0.0.0.0
|
7
7
|
c.use_middleware = !Rails.env.production?
|
@@ -6,6 +6,9 @@ Cypress.Commands.add('appCommands', function (body) {
|
|
6
6
|
method: 'POST',
|
7
7
|
url: "/__e2e__/command",
|
8
8
|
body: JSON.stringify(body),
|
9
|
+
headers: {
|
10
|
+
'Content-Type': 'application/json',
|
11
|
+
},
|
9
12
|
log: false,
|
10
13
|
failOnStatusCode: false
|
11
14
|
}).then((response) => {
|
@@ -52,6 +55,9 @@ Cypress.on('fail', (err, runnable) => {
|
|
52
55
|
Cypress.$.ajax({
|
53
56
|
url: '/__e2e__/command',
|
54
57
|
data: JSON.stringify({name: 'log_fail', options: {error_message: err.message, runnable_full_title: runnable.fullTitle() }}),
|
58
|
+
headers: {
|
59
|
+
'Content-Type': 'application/json',
|
60
|
+
},
|
55
61
|
async: false,
|
56
62
|
method: 'POST'
|
57
63
|
});
|
data/specs_e2e/rails_3_2/test.sh
CHANGED
@@ -10,19 +10,20 @@ export BUNDLE_GEMFILE="$DIR/Gemfile"
|
|
10
10
|
cd $DIR
|
11
11
|
|
12
12
|
echo '-- bundle install'
|
13
|
-
|
14
|
-
bundle
|
13
|
+
gem install bundler -v '1.0.22'
|
14
|
+
bundle _1.0.22_ --version
|
15
|
+
bundle _1.0.22_ install --quiet --gemfile="$DIR/Gemfile" --path vendor/bundle
|
15
16
|
|
16
17
|
echo '-- cypress install'
|
17
|
-
bundle exec ./bin/rails g cypress_on_rails:install --
|
18
|
+
bundle exec ./bin/rails g cypress_on_rails:install --install_with=npm --install_folder="." --force
|
18
19
|
rm -vf cypress/e2e/rails_examples/advance_factory_bot.cy.js
|
19
20
|
rm -vf cypress/e2e/rails_examples/using_vcr.cy.js
|
20
21
|
|
21
22
|
echo '-- start rails server'
|
22
23
|
# make sure the server is not running
|
23
|
-
(kill -9 `cat
|
24
|
+
(kill -9 `cat ../server.pid` || true )
|
24
25
|
|
25
|
-
bundle exec ./bin/rails server -p 5017 -e test &
|
26
|
+
bundle exec ./bin/rails server -p 5017 -e test -P ../server.pid &
|
26
27
|
sleep 2 # give rails a chance to start up correctly
|
27
28
|
|
28
29
|
echo '-- cypress run'
|
@@ -31,13 +32,19 @@ cp -fv ../cypress.config.js .
|
|
31
32
|
# then
|
32
33
|
# node_modules/.bin/cypress run
|
33
34
|
# else
|
34
|
-
|
35
|
+
npx cypress run --record
|
35
36
|
# fi
|
36
37
|
|
38
|
+
echo '-- playwright install'
|
39
|
+
bundle exec ./bin/rails g cypress_on_rails:install --framework playwright --install_with=npm --install_folder="." --force
|
40
|
+
rm -vf playwright/e2e/rails_examples/advance_factory_bot.cy.js
|
41
|
+
rm -vf playwright/e2e/rails_examples/using_vcr.cy.js
|
42
|
+
|
37
43
|
echo '-- playwright run'
|
38
44
|
cp -fv ../playwright.config.js .
|
39
45
|
npx playwright install-deps
|
46
|
+
npx playwright install
|
40
47
|
npx playwright test playwright/e2e/
|
41
48
|
|
42
49
|
echo '-- stop rails server'
|
43
|
-
kill -9 `cat
|
50
|
+
kill -9 `cat ../server.pid` || true
|
@@ -4,7 +4,9 @@
|
|
4
4
|
"main": "index.js",
|
5
5
|
"license": "MIT",
|
6
6
|
"devDependencies": {
|
7
|
-
"
|
8
|
-
"cypress
|
7
|
+
"@playwright/test": "^1.40.1",
|
8
|
+
"cypress": "^10.11.0",
|
9
|
+
"cypress-on-rails": "file:../../plugin",
|
10
|
+
"playwright": "^1.40.1"
|
9
11
|
}
|
10
12
|
}
|