cypress-on-rails 1.16.0 → 1.17.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
  SHA256:
3
- metadata.gz: 2dc7073afd439183f15dbe8e33fd275ec4ec4121c2640e026ed5d7f80bc2736c
4
- data.tar.gz: 2361d555bab1bae7072d8909275669a139b9c2ee255f5f8195660189208591fa
3
+ metadata.gz: 9c9e7d196e802c6bc10ed4a31fdfc868d92a4f059452e3315fa6c2b525f0ff17
4
+ data.tar.gz: 7378fe702963ed71a808dcdcf518c60519ef5c0149211b1e7e8692823dbb3796
5
5
  SHA512:
6
- metadata.gz: 717a48f1352f07b052683ba0699d2806191aed7ebc249e6c0f319af8f2e47d3eb0062787fa6d847ce326afe66325c59859806c9f93f3f95a8276e6aec85d580f
7
- data.tar.gz: abee0f60bec8a8eca395b6a621c33c0caa731452f5e253d27b80c967cd7138a992cb29c68fa41bafcddc85a3f02e6767f6a3f5bcf77ffbaad543264c31d5630a
6
+ metadata.gz: 49c39f927764cab07fd2e1e7dd5c73773a60ce3c515666267fc8602e00b233c0d18f905653df742acb56c16ab594c7c463b13d66e71cde04be5ba785555c3150
7
+ data.tar.gz: 39701b20ce5fa8024fc9672dd49bbe6f66445d50f45764a22ad18068684595ebb5bd87f6b9a7d031b84df36cb5c705d1f808e056482f11c79247c4b9cd8ccbb4
data/.gitignore CHANGED
@@ -9,4 +9,5 @@ vendor/bundle
9
9
  .vscode
10
10
  node_modules
11
11
  package-lock.json
12
- yarn.lock
12
+ yarn.lock
13
+ specs_e2e/server.pid
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 cypress)
65
- bin/rails g cypress_on_rails:install --cypress_folder=spec/cypress
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 both cypress and playwright
68
- bin/rails g cypress_on_rails:install --install_cypress --install_playwright --playwright_folder=playwright
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 cypress with npm
77
- bin/rails g cypress_on_rails:install --install_cypress_with=npm
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 --no-install-cypress
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:update
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
- * `spec/cypress/e2e/` contains your cypress tests
89
- * `spec/playwright/e2e/` contains your playwright tests
90
- * `spec/cypress/support/on-rails.js` contains Cypress on Rails support code
91
- * `spec/playwright/support/on-rails.js` contains Playwright on Rails support code
92
- * `spec/e2e/app_commands/scenarios/` contains your Cypress on Rails scenario definitions
93
- * `spec/e2e/cypress_helper.rb` contains helper code for Cypress on Rails app commands
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 `spec/e2e/app_commands/clean.rb`.
96
- If you are not using `factory_bot` look at `spec/e2e/app_commands/factory_bot.rb`.
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 running `cypress test` or `playwright test` on your local computer it's recommended to start your server in development mode so that changes you
103
- make are picked up without having to restart the server.
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
- node_modules/.bin/cypress open
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
  })
@@ -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,5 +1,3 @@
1
- require 'active_support/core_ext/string'
2
-
3
1
  module CypressOnRails
4
2
  module SimpleRailsFactory
5
3
  def self.create(type, *params)
@@ -1,3 +1,3 @@
1
1
  module CypressOnRails
2
- VERSION = '1.16.0'.freeze
2
+ VERSION = '1.17.0'.freeze
3
3
  end
@@ -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
- packages << 'cypress' if options.install_cypress
22
- packages.push('playwright', '@playwright/test') if options.install_playwright
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.install_cypress
35
- template "spec/cypress/support/index.js.erb", "#{options.cypress_folder}/support/index.js"
36
- copy_file "spec/cypress/support/commands.js", "#{options.cypress_folder}/support/commands.js"
37
- copy_file "spec/cypress.config.js", "#{options.cypress_folder}/../cypress.config.js"
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.install_playwright
40
- template "spec/playwright/support/index.js.erb", "#{options.playwright_folder}/support/index.js"
41
- copy_file "spec/playwright.config.js", "#{options.playwright_folder}/../playwright.config.js"
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.install_cypress
50
- copy_file "spec/cypress/support/on-rails.js", "#{options.cypress_folder}/support/on-rails.js"
51
- directory 'spec/cypress/e2e/rails_examples', "#{options.cypress_folder}/e2e/rails_examples"
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.install_playwright
54
- copy_file "spec/playwright/support/on-rails.js", "#{options.playwright_folder}/support/on-rails.js"
55
- directory 'spec/playwright/e2e/rails_examples', "#{options.playwright_folder}/e2e/rails_examples"
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
- append_to_file "#{options.cypress_folder}/support/index.js",
61
- "\nimport './on-rails'",
62
- after: 'import \'./commands\''
63
- append_to_file "#{options.playwright_folder}/support/index.js",
64
- "\nimport './on-rails'",
65
- after: '// Import commands.js using ES2015 syntax:'
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
  });
@@ -10,19 +10,20 @@ export BUNDLE_GEMFILE="$DIR/Gemfile"
10
10
  cd $DIR
11
11
 
12
12
  echo '-- bundle install'
13
- bundle --version
14
- bundle install --quiet --gemfile="$DIR/Gemfile" --retry 2 --path vendor/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 --install_cypress --install_playwright --install_with=npm
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 tmp/pids/server.pid` || true )
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
- node_modules/.bin/cypress run --record
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 tmp/pids/server.pid`
50
+ kill -9 `cat ../server.pid` || true
@@ -4,6 +4,7 @@ spec/cypress.config.js
4
4
  spec/package.json
5
5
  spec/yarn.lock
6
6
  spec/cypress
7
+ spec/app_commands
7
8
  config/initializers/cypress_on_rails.rb
8
9
  vendor/bundle
9
10
  tmp/pids
@@ -4,7 +4,9 @@
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "devDependencies": {
7
- "cypress": "^10.0.2",
8
- "cypress-on-rails": "file:../../plugin"
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
  }