cypress-on-rails 1.14.0 → 1.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +3 -3
- data/CHANGELOG.md +6 -0
- data/README.md +62 -18
- data/lib/cypress_on_rails/command_executor.rb +9 -5
- data/lib/cypress_on_rails/configuration.rb +12 -2
- data/lib/cypress_on_rails/middleware.rb +8 -5
- data/lib/cypress_on_rails/vcr_middleware.rb +3 -3
- data/lib/cypress_on_rails/version.rb +1 -1
- data/lib/generators/cypress_on_rails/install_generator.rb +43 -20
- data/lib/generators/cypress_on_rails/templates/config/initializers/cypress_on_rails.rb.erb +2 -2
- data/lib/generators/cypress_on_rails/templates/spec/cypress/e2e/rails_examples/advance_factory_bot.cy.js +1 -1
- data/lib/generators/cypress_on_rails/templates/spec/cypress/e2e/rails_examples/other.cy.js +1 -1
- data/lib/generators/cypress_on_rails/templates/spec/cypress/e2e/rails_examples/using_factory_bot.cy.js +1 -1
- data/lib/generators/cypress_on_rails/templates/spec/cypress/e2e/rails_examples/using_fixtures.cy.js +1 -1
- data/lib/generators/cypress_on_rails/templates/spec/cypress/e2e/rails_examples/using_scenarios.cy.js +1 -1
- data/lib/generators/cypress_on_rails/templates/spec/cypress/e2e/rails_examples/using_vcr.cy.js +1 -1
- data/lib/generators/cypress_on_rails/templates/spec/cypress/support/on-rails.js +2 -2
- data/lib/generators/cypress_on_rails/templates/spec/playwright/e2e/rails_examples/using_scenarios.spec.js +12 -0
- data/lib/generators/cypress_on_rails/templates/spec/playwright/support/index.js.erb +21 -0
- data/lib/generators/cypress_on_rails/templates/spec/playwright/support/on-rails.js +37 -0
- data/lib/generators/cypress_on_rails/templates/spec/playwright.config.js +79 -0
- data/lib/generators/cypress_on_rails/update_generator.rb +14 -3
- data/plugin/support/index.js +2 -2
- data/spec/cypress_on_rails/command_executor_spec.rb +1 -1
- data/spec/cypress_on_rails/configuration_spec.rb +3 -3
- data/spec/cypress_on_rails/middleware_spec.rb +20 -20
- data/spec/cypress_on_rails/vcr_middleware_spec.rb +5 -5
- data/specs_e2e/playwright.config.js +79 -0
- data/specs_e2e/rails_3_2/test.sh +6 -1
- data/specs_e2e/rails_4_2/test.sh +11 -6
- data/specs_e2e/rails_5_2/test.sh +9 -4
- data/tmp/pids/.gitkeep +0 -0
- metadata +16 -10
- /data/lib/generators/cypress_on_rails/templates/spec/{cypress → e2e}/app_commands/activerecord_fixtures.rb +0 -0
- /data/lib/generators/cypress_on_rails/templates/spec/{cypress → e2e}/app_commands/clean.rb +0 -0
- /data/lib/generators/cypress_on_rails/templates/spec/{cypress → e2e}/app_commands/eval.rb +0 -0
- /data/lib/generators/cypress_on_rails/templates/spec/{cypress → e2e}/app_commands/factory_bot.rb +0 -0
- /data/lib/generators/cypress_on_rails/templates/spec/{cypress → e2e}/app_commands/log_fail.rb +0 -0
- /data/lib/generators/cypress_on_rails/templates/spec/{cypress → e2e}/app_commands/scenarios/basic.rb +0 -0
- /data/lib/generators/cypress_on_rails/templates/spec/{cypress/cypress_helper.rb.erb → e2e/e2e_helper.rb.erb} +0 -0
- /data/spec/cypress_on_rails/command_executor/{cypress_helper.rb → e2e_helper.rb} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc763de97980a2be63d8eac1ca850d9695c7e1778c8678d83cec0de7c8270b37
|
4
|
+
data.tar.gz: 9c830d9c70faebc8aac3891caa6ab3547cdf66fe9c89d3eda131248086ff55a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88104bb87f1ab6933c17495ff3cbe112a27fc8daa5ee97752eb25e72e46d1ca6e2b54b907857650d49455ca3cb30534e6a6e4d02a6d5f240ddc69ea9d9c5cdac
|
7
|
+
data.tar.gz: 61f547751df2b0500d15b3480732823916a6b3ce0a768cbed696764ec9ddb3853b0d4919e9f2a8249803830b70334f0914c8075d0eb97d84abf68c9835747d1a
|
data/.github/workflows/ruby.yml
CHANGED
@@ -16,7 +16,7 @@ jobs:
|
|
16
16
|
uses: ruby/setup-ruby@v1
|
17
17
|
with:
|
18
18
|
ruby-version: 2.3
|
19
|
-
bundler-cache: true
|
19
|
+
bundler-cache: true
|
20
20
|
- name: Run tests
|
21
21
|
run: bundle exec rake
|
22
22
|
- run: gem uninstall -v '>= 2' -ax bundler || true
|
@@ -54,10 +54,10 @@ jobs:
|
|
54
54
|
uses: ruby/setup-ruby@v1
|
55
55
|
with:
|
56
56
|
ruby-version: 2.6
|
57
|
-
bundler-cache: true
|
57
|
+
bundler-cache: true
|
58
58
|
- name: Run tests
|
59
59
|
run: bundle exec rake
|
60
60
|
- name: Run interaction tests
|
61
61
|
run: ./specs_e2e/rails_5_2/test.sh
|
62
62
|
env:
|
63
|
-
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
|
63
|
+
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## [1.15.0]
|
2
|
+
[Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.14.0...v1.15.0
|
3
|
+
|
4
|
+
### Changed
|
5
|
+
* Add support for any e2e testing framewrok starting with Playwright [PR 131](https://github.com/shakacode/cypress-on-rails/pull/131) by [KhaledEmaraDev]
|
6
|
+
|
1
7
|
## [1.14.0]
|
2
8
|
[Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.13.1...v1.14.0
|
3
9
|
|
data/README.md
CHANGED
@@ -14,20 +14,21 @@ Need help with cypress-on-rails? Contact [ShakaCode](mailto:justin@shakacode.com
|
|
14
14
|
|
15
15
|
----
|
16
16
|
|
17
|
-
# Playwright.dev support
|
18
|
-
We're working on full support for [Playwright.dev](https://playwright.dev/). See [issue #116](https://github.com/shakacode/cypress-on-rails/issues/116#issuecomment-1523946478) for details.
|
19
|
-
|
20
17
|
# Totally new to Cypress?
|
21
18
|
Suggest you first learn the basics of Cypress before attempting to integrate with Ruby on Rails
|
22
19
|
|
23
20
|
* [Good start Here](https://docs.cypress.io/examples/examples/tutorials.html#Best-Practices)
|
24
21
|
|
22
|
+
# Totally new to Playwright?
|
23
|
+
Suggest you first learn the basics of Playwright before attempting to integrate with Ruby on Rails
|
24
|
+
|
25
|
+
* [Good start Here](https://playwright.dev/docs/writing-tests)
|
26
|
+
|
25
27
|
## Overview
|
26
28
|
|
27
|
-
Gem for using [cypress.io](http://github.com/cypress-io/) in Rails and Ruby Rack applications
|
28
|
-
with the goal of controlling state as mentioned in [Cypress Best Practices](https://docs.cypress.io/guides/references/best-practices.html#Organizing-Tests-Logging-In-Controlling-State)
|
29
|
+
Gem for using [cypress.io](http://github.com/cypress-io/) or [playwright.dev](https://playwright.dev/) in Rails and Ruby Rack applications with the goal of controlling state as mentioned in [Cypress Best Practices](https://docs.cypress.io/guides/references/best-practices.html#Organizing-Tests-Logging-In-Controlling-State)
|
29
30
|
|
30
|
-
It allows you to run code in the application context when executing cypress tests.
|
31
|
+
It allows you to run code in the application context when executing cypress or playwright tests.
|
31
32
|
Do things like:
|
32
33
|
* use database_cleaner before each test
|
33
34
|
* seed the database with default data for each test
|
@@ -57,11 +58,18 @@ end
|
|
57
58
|
Generate the boilerplate code using:
|
58
59
|
|
59
60
|
```shell
|
61
|
+
# by default installs only cypress
|
60
62
|
bin/rails g cypress_on_rails:install
|
61
63
|
|
62
64
|
# if you have/want a different cypress folder (default is cypress)
|
63
65
|
bin/rails g cypress_on_rails:install --cypress_folder=spec/cypress
|
64
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
|
72
|
+
|
65
73
|
# if you target the Rails server with a path prefix to your URL
|
66
74
|
bin/rails g cypress_on_rails:install --api_prefix=/api
|
67
75
|
|
@@ -76,21 +84,22 @@ bin/rails g cypress_on_rails:update
|
|
76
84
|
```
|
77
85
|
|
78
86
|
The generator modifies/adds the following files/directory in your application:
|
79
|
-
* `config/environments/test.rb`
|
80
87
|
* `config/initializers/cypress_on_rails.rb` used to configure Cypress on Rails
|
81
88
|
* `spec/cypress/e2e/` contains your cypress tests
|
89
|
+
* `spec/playwright/e2e/` contains your playwright tests
|
82
90
|
* `spec/cypress/support/on-rails.js` contains Cypress on Rails support code
|
83
|
-
* `spec/
|
84
|
-
* `spec/
|
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
94
|
|
86
|
-
If you are not using `database_cleaner` look at `spec/
|
87
|
-
If you are not using `factory_bot` look at `spec/
|
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`.
|
88
97
|
|
89
98
|
Now you can create scenarios and commands that are plain Ruby files that get loaded through middleware, the ruby sky is your limit.
|
90
99
|
|
91
100
|
### Update your database.yml
|
92
101
|
|
93
|
-
When running `cypress test` on your local computer it's recommended to start your server in development mode so that changes you
|
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
|
94
103
|
make are picked up without having to restart the server.
|
95
104
|
It's recommended you update your `database.yml` to check if the `CYPRESS` environment variable is set and switch it to the test database
|
96
105
|
otherwise cypress will keep clearing your development database.
|
@@ -123,6 +132,10 @@ yarn cypress open
|
|
123
132
|
node_modules/.bin/cypress open
|
124
133
|
# or if you changed the cypress folder to spec/cypress
|
125
134
|
yarn cypress open --project ./spec
|
135
|
+
# or for playwright
|
136
|
+
yarn playwright test --ui
|
137
|
+
# or using npm
|
138
|
+
npx playwright test --ui
|
126
139
|
```
|
127
140
|
|
128
141
|
How to run cypress on CI
|
@@ -133,7 +146,7 @@ How to run cypress on CI
|
|
133
146
|
|
134
147
|
yarn run cypress run
|
135
148
|
# or for npm
|
136
|
-
|
149
|
+
npx cypress run
|
137
150
|
```
|
138
151
|
|
139
152
|
### Example of using factory bot
|
@@ -203,7 +216,7 @@ describe('My First Test', () => {
|
|
203
216
|
|
204
217
|
### Example of loading Rails test fixtures
|
205
218
|
```ruby
|
206
|
-
# spec/
|
219
|
+
# spec/e2e/app_commands/activerecord_fixtures.rb
|
207
220
|
require "active_record/fixtures"
|
208
221
|
|
209
222
|
fixtures_dir = ActiveRecord::Tasks::DatabaseTasks.fixtures_path
|
@@ -233,7 +246,7 @@ describe('My First Test', () => {
|
|
233
246
|
|
234
247
|
Scenarios are named `before` blocks that you can reference in your test.
|
235
248
|
|
236
|
-
You define a scenario in the `spec/
|
249
|
+
You define a scenario in the `spec/e2e/app_commands/scenarios` directory:
|
237
250
|
```ruby
|
238
251
|
# spec/cypress/app_commands/scenarios/basic.rb
|
239
252
|
Profile.create name: "Cypress Hill"
|
@@ -259,9 +272,9 @@ describe('My First Test', () => {
|
|
259
272
|
|
260
273
|
### Example of using app commands
|
261
274
|
|
262
|
-
Create a Ruby file in the `spec/
|
275
|
+
Create a Ruby file in the `spec/e2e/app_commands` directory:
|
263
276
|
```ruby
|
264
|
-
# spec/
|
277
|
+
# spec/e2e/app_commands/load_seed.rb
|
265
278
|
load "#{Rails.root}/db/seeds.rb"
|
266
279
|
```
|
267
280
|
|
@@ -279,6 +292,37 @@ describe('My First Test', () => {
|
|
279
292
|
})
|
280
293
|
```
|
281
294
|
|
295
|
+
### Example of using scenario with Playwright
|
296
|
+
|
297
|
+
Scenarios are named `before` blocks that you can reference in your test.
|
298
|
+
|
299
|
+
You define a scenario in the `spec/e2e/app_commands/scenarios` directory:
|
300
|
+
```ruby
|
301
|
+
# spec/e2e/app_commands/scenarios/basic.rb
|
302
|
+
Profile.create name: "Cypress Hill"
|
303
|
+
|
304
|
+
# or if you have factory_bot enabled in your cypress_helper
|
305
|
+
CypressOnRails::SmartFactoryWrapper.create(:profile, name: "Cypress Hill")
|
306
|
+
```
|
307
|
+
|
308
|
+
Then reference the scenario in your test:
|
309
|
+
```js
|
310
|
+
// spec/playwright/e2e/scenario_example.spec.js
|
311
|
+
import { test, expect } from "@playwright/test";
|
312
|
+
import { app, appScenario } from '../../support/on-rails';
|
313
|
+
|
314
|
+
test.describe("Rails using scenarios examples", () => {
|
315
|
+
test.beforeEach(async ({ page }) => {
|
316
|
+
await app('clean');
|
317
|
+
});
|
318
|
+
|
319
|
+
test("setup basic scenario", async ({ page }) => {
|
320
|
+
await appScenario('basic');
|
321
|
+
await page.goto("/");
|
322
|
+
});
|
323
|
+
});
|
324
|
+
```
|
325
|
+
|
282
326
|
## Experimental Features (matching npm package)
|
283
327
|
|
284
328
|
Please test and give feedback.
|
@@ -334,7 +378,7 @@ describe('My First Test', () => {
|
|
334
378
|
beforeEach(() => { cy.app('load_seed') })
|
335
379
|
|
336
380
|
it('visit root', () => {
|
337
|
-
cy.app('clean') // have a look at
|
381
|
+
cy.app('clean') // have a look at e2e/app_commands/clean.rb
|
338
382
|
|
339
383
|
cy.vcr_insert_cassette('cats', { record: "new_episodes" })
|
340
384
|
cy.visit('/using_vcr/index')
|
@@ -4,7 +4,7 @@ module CypressOnRails
|
|
4
4
|
# loads and evals the command files
|
5
5
|
class CommandExecutor
|
6
6
|
def self.perform(file,command_options = nil)
|
7
|
-
|
7
|
+
load_e2e_helper
|
8
8
|
file_data = File.read(file)
|
9
9
|
eval file_data, binding, file
|
10
10
|
rescue => e
|
@@ -13,12 +13,16 @@ module CypressOnRails
|
|
13
13
|
raise e
|
14
14
|
end
|
15
15
|
|
16
|
-
def self.
|
17
|
-
|
18
|
-
|
16
|
+
def self.load_e2e_helper
|
17
|
+
e2e_helper_file = "#{configuration.install_folder}/e2e_helper.rb"
|
18
|
+
cypress_helper_file = "#{configuration.cypress_folder}/cypress_helper.rb"
|
19
|
+
if File.exist?(e2e_helper_file)
|
20
|
+
Kernel.require e2e_helper_file
|
21
|
+
elsif File.exist?(cypress_helper_file)
|
19
22
|
Kernel.require cypress_helper_file
|
23
|
+
warn "cypress_helper.rb and cypress_folder are deprecated, please use the install generator to create e2e_helper.rb using install_folder"
|
20
24
|
else
|
21
|
-
logger.warn "could not find #{cypress_helper_file}
|
25
|
+
logger.warn "could not find #{e2e_helper_file} nor #{cypress_helper_file}"
|
22
26
|
end
|
23
27
|
end
|
24
28
|
|
@@ -2,12 +2,22 @@ require 'logger'
|
|
2
2
|
|
3
3
|
module CypressOnRails
|
4
4
|
class Configuration
|
5
|
-
attr_accessor :cypress_folder
|
6
5
|
attr_accessor :api_prefix
|
6
|
+
attr_accessor :install_folder
|
7
7
|
attr_accessor :use_middleware
|
8
8
|
attr_accessor :use_vcr_middleware
|
9
9
|
attr_accessor :logger
|
10
10
|
|
11
|
+
# Attributes for backwards compatibility
|
12
|
+
def cypress_folder
|
13
|
+
warn "cypress_folder is deprecated, please use install_folder"
|
14
|
+
install_folder
|
15
|
+
end
|
16
|
+
def cypress_folder=(v)
|
17
|
+
warn "cypress_folder= is deprecated, please use install_folder"
|
18
|
+
self.install_folder = v
|
19
|
+
end
|
20
|
+
|
11
21
|
def initialize
|
12
22
|
reset
|
13
23
|
end
|
@@ -16,8 +26,8 @@ module CypressOnRails
|
|
16
26
|
alias :use_vcr_middleware? :use_vcr_middleware
|
17
27
|
|
18
28
|
def reset
|
19
|
-
self.cypress_folder = 'spec/cypress'
|
20
29
|
self.api_prefix = ''
|
30
|
+
self.install_folder = 'spec/e2e'
|
21
31
|
self.use_middleware = true
|
22
32
|
self.use_vcr_middleware = false
|
23
33
|
self.logger = Logger.new(STDOUT)
|
@@ -4,7 +4,7 @@ require 'cypress_on_rails/middleware_config'
|
|
4
4
|
require 'cypress_on_rails/command_executor'
|
5
5
|
|
6
6
|
module CypressOnRails
|
7
|
-
# Middleware to handle
|
7
|
+
# Middleware to handle testing framework commands and eval
|
8
8
|
class Middleware
|
9
9
|
include MiddlewareConfig
|
10
10
|
|
@@ -16,7 +16,10 @@ module CypressOnRails
|
|
16
16
|
|
17
17
|
def call(env)
|
18
18
|
request = Rack::Request.new(env)
|
19
|
-
if request.path.start_with?("#{configuration.api_prefix}/
|
19
|
+
if request.path.start_with?("#{configuration.api_prefix}/__e2e__/command")
|
20
|
+
configuration.tagged_logged { handle_command(request) }
|
21
|
+
elsif request.path.start_with?("#{configuration.api_prefix}/__cypress__/command")
|
22
|
+
warn "/__cypress__/command is deprecated. Please use the install generator to use /__e2e__/command instead."
|
20
23
|
configuration.tagged_logged { handle_command(request) }
|
21
24
|
else
|
22
25
|
@app.call(env)
|
@@ -25,7 +28,7 @@ module CypressOnRails
|
|
25
28
|
|
26
29
|
private
|
27
30
|
|
28
|
-
Command = Struct.new(:name, :options, :
|
31
|
+
Command = Struct.new(:name, :options, :install_folder) do
|
29
32
|
# @return [Array<Cypress::Middleware::Command>]
|
30
33
|
def self.from_body(body, configuration)
|
31
34
|
if body.is_a?(Array)
|
@@ -34,12 +37,12 @@ module CypressOnRails
|
|
34
37
|
command_params = [body]
|
35
38
|
end
|
36
39
|
command_params.map do |params|
|
37
|
-
new(params.fetch('name'), params['options'], configuration.
|
40
|
+
new(params.fetch('name'), params['options'], configuration.install_folder)
|
38
41
|
end
|
39
42
|
end
|
40
43
|
|
41
44
|
def file_path
|
42
|
-
"#{
|
45
|
+
"#{install_folder}/app_commands/#{name}.rb"
|
43
46
|
end
|
44
47
|
end
|
45
48
|
|
@@ -15,9 +15,9 @@ module CypressOnRails
|
|
15
15
|
|
16
16
|
def call(env)
|
17
17
|
request = Rack::Request.new(env)
|
18
|
-
if request.path.start_with?('/
|
18
|
+
if request.path.start_with?('/__e2e__/vcr/insert')
|
19
19
|
configuration.tagged_logged { handle_insert(request) }
|
20
|
-
elsif request.path.start_with?('/
|
20
|
+
elsif request.path.start_with?('/__e2e__/vcr/eject')
|
21
21
|
configuration.tagged_logged { handle_eject }
|
22
22
|
else
|
23
23
|
do_first_call unless @first_call
|
@@ -57,7 +57,7 @@ module CypressOnRails
|
|
57
57
|
return @vcr if @vcr
|
58
58
|
require 'vcr'
|
59
59
|
VCR.configure do |config|
|
60
|
-
config.cassette_library_dir = "#{configuration.
|
60
|
+
config.cassette_library_dir = "#{configuration.install_folder}/fixtures/vcr_cassettes"
|
61
61
|
end
|
62
62
|
@vcr = VCR
|
63
63
|
end
|
@@ -1,45 +1,68 @@
|
|
1
1
|
module CypressOnRails
|
2
2
|
class InstallGenerator < Rails::Generators::Base
|
3
|
-
class_option :cypress_folder, type: :string, default: 'cypress'
|
4
3
|
class_option :api_prefix, type: :string, default: ''
|
4
|
+
class_option :install_folder, type: :string, default: 'e2e'
|
5
5
|
class_option :install_cypress, type: :boolean, default: true
|
6
|
-
class_option :
|
6
|
+
class_option :install_playwright, type: :boolean, default: false
|
7
|
+
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'
|
7
10
|
class_option :experimental, type: :boolean, default: false
|
8
11
|
source_root File.expand_path('../templates', __FILE__)
|
9
12
|
|
10
|
-
def
|
11
|
-
directories = options.
|
13
|
+
def install_framework
|
14
|
+
directories = options.install_folder.split('/')
|
12
15
|
directories.pop
|
13
16
|
install_dir = "#{Dir.pwd}/#{directories.join('/')}"
|
17
|
+
|
14
18
|
command = nil
|
19
|
+
packages = []
|
20
|
+
|
21
|
+
packages << 'cypress' if options.install_cypress
|
22
|
+
packages.push('playwright', '@playwright/test') if options.install_playwright
|
23
|
+
|
24
|
+
if options.install_with == 'yarn'
|
25
|
+
command = "yarn --cwd=#{install_dir} add #{packages.join(' ')} --dev"
|
26
|
+
elsif options.install_with == 'npm'
|
27
|
+
command = "cd #{install_dir}; npm install #{packages.join(' ')} --save-dev"
|
28
|
+
end
|
29
|
+
if command
|
30
|
+
say command
|
31
|
+
fail "failed to install #{packages.join(' ')}" unless system(command)
|
32
|
+
end
|
33
|
+
|
15
34
|
if options.install_cypress
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
fail 'failed to install cypress' unless system(command)
|
24
|
-
end
|
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"
|
38
|
+
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"
|
25
42
|
end
|
26
|
-
template "spec/cypress/support/index.js.erb", "#{options.cypress_folder}/support/index.js"
|
27
|
-
copy_file "spec/cypress/support/commands.js", "#{options.cypress_folder}/support/commands.js"
|
28
|
-
copy_file "spec/cypress.config.js", "#{options.cypress_folder}/../cypress.config.js"
|
29
43
|
end
|
30
44
|
|
31
45
|
def add_initial_files
|
32
46
|
template "config/initializers/cypress_on_rails.rb.erb", "config/initializers/cypress_on_rails.rb"
|
33
|
-
template "spec/
|
34
|
-
|
35
|
-
|
36
|
-
|
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"
|
52
|
+
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"
|
56
|
+
end
|
37
57
|
end
|
38
58
|
|
39
59
|
def update_files
|
40
60
|
append_to_file "#{options.cypress_folder}/support/index.js",
|
41
61
|
"\nimport './on-rails'",
|
42
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:'
|
43
66
|
end
|
44
67
|
end
|
45
68
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
if defined?(CypressOnRails)
|
2
2
|
CypressOnRails.configure do |c|
|
3
|
-
c.
|
3
|
+
c.api_prefix = "<%= options.api_prefix %>"
|
4
|
+
c.install_folder = File.expand_path("#{__dir__}/../../<%= options.install_folder %>")
|
4
5
|
# WARNING!! CypressOnRails can execute arbitrary ruby code
|
5
6
|
# please use with extra caution if enabling on hosted servers or starting your local server on 0.0.0.0
|
6
7
|
c.use_middleware = !Rails.env.production?
|
7
8
|
<% unless options.experimental %># <% end %> c.use_vcr_middleware = !Rails.env.production?
|
8
|
-
c.api_prefix = "<%= options.api_prefix %>"
|
9
9
|
c.logger = Rails.logger
|
10
10
|
end
|
11
11
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
describe('More Rails using factory bot examples', function() {
|
2
2
|
beforeEach(() => {
|
3
|
-
cy.app('clean') // have a look at
|
3
|
+
cy.app('clean') // have a look at e2e/app_commands/clean.rb
|
4
4
|
})
|
5
5
|
|
6
6
|
it('using response from factory bot', function() {
|
@@ -1,6 +1,6 @@
|
|
1
1
|
describe('Rails Other examples', function() {
|
2
2
|
it('cypress eval', function() {
|
3
|
-
cy.app('clean') // have a look at
|
3
|
+
cy.app('clean') // have a look at e2e/app_commands/clean.rb
|
4
4
|
cy.appEval("Post.create(title: 'Hello Eval')")
|
5
5
|
|
6
6
|
cy.visit('/')
|
data/lib/generators/cypress_on_rails/templates/spec/cypress/e2e/rails_examples/using_vcr.cy.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
describe('Rails Other examples', function() {
|
2
2
|
it('Inserting a cassette', function() {
|
3
|
-
cy.app('clean') // have a look at
|
3
|
+
cy.app('clean') // have a look at e2e/app_commands/clean.rb
|
4
4
|
|
5
5
|
cy.vcr_insert_cassette('cats', { record: "new_episodes" })
|
6
6
|
cy.visit('/using_vcr/index')
|
@@ -4,7 +4,7 @@ Cypress.Commands.add('appCommands', function (body) {
|
|
4
4
|
const log = Cypress.log({ name: "APP", message: body, autoEnd: false })
|
5
5
|
return cy.request({
|
6
6
|
method: 'POST',
|
7
|
-
url: "/
|
7
|
+
url: "/__e2e__/command",
|
8
8
|
body: JSON.stringify(body),
|
9
9
|
log: false,
|
10
10
|
failOnStatusCode: false
|
@@ -50,7 +50,7 @@ Cypress.Commands.add('appFixtures', function (options) {
|
|
50
50
|
Cypress.on('fail', (err, runnable) => {
|
51
51
|
// allow app to generate additional logging data
|
52
52
|
Cypress.$.ajax({
|
53
|
-
url: '/
|
53
|
+
url: '/__e2e__/command',
|
54
54
|
data: JSON.stringify({name: 'log_fail', options: {error_message: err.message, runnable_full_title: runnable.fullTitle() }}),
|
55
55
|
async: false,
|
56
56
|
method: 'POST'
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { test, expect } from "@playwright/test";
|
2
|
+
import { app, appScenario } from '../../support/on-rails';
|
3
|
+
|
4
|
+
test.describe("Rails using scenarios examples", () => {
|
5
|
+
test.beforeEach(async ({ page }) => {
|
6
|
+
await app('clean');
|
7
|
+
});
|
8
|
+
|
9
|
+
test("setup basic scenario", async ({ page }) => {
|
10
|
+
await appScenario('basic');
|
11
|
+
await page.goto("/"); });
|
12
|
+
});
|
@@ -0,0 +1,21 @@
|
|
1
|
+
// ***********************************************************
|
2
|
+
// This example support/index.js is processed and
|
3
|
+
// loaded automatically before your test files.
|
4
|
+
//
|
5
|
+
// This is a great place to put global configuration and
|
6
|
+
// behavior that modifies Cypress.
|
7
|
+
//
|
8
|
+
// You can change the location of this file or turn off
|
9
|
+
// automatically serving support files with the
|
10
|
+
// 'supportFile' configuration option.
|
11
|
+
//
|
12
|
+
// You can read more here:
|
13
|
+
// https://on.cypress.io/configuration
|
14
|
+
// ***********************************************************
|
15
|
+
|
16
|
+
// Import commands.js using ES2015 syntax:
|
17
|
+
import './on-rails'
|
18
|
+
<% unless options.experimental %>// <% end %>import 'cypress-on-rails/support/index'
|
19
|
+
|
20
|
+
// Alternatively you can use CommonJS syntax:
|
21
|
+
// require('./commands')
|
@@ -0,0 +1,37 @@
|
|
1
|
+
import { request, expect } from '@playwright/test'
|
2
|
+
import config from '../../playwright.config'
|
3
|
+
|
4
|
+
const contextPromise = request.newContext({ baseURL: config.use ? config.use.baseURL : 'http://localhost:5017' })
|
5
|
+
|
6
|
+
const appCommands = async (data) => {
|
7
|
+
const context = await contextPromise
|
8
|
+
const response = await context.post('/__e2e__/command', { data })
|
9
|
+
|
10
|
+
expect(response.ok()).toBeTruthy()
|
11
|
+
return response.body
|
12
|
+
}
|
13
|
+
|
14
|
+
const app = (name, options = {}) => appCommands({ name, options }).then((body) => body[0])
|
15
|
+
const appScenario = (name, options = {}) => app('scenarios/' + name, options)
|
16
|
+
const appEval = (code) => app('eval', code)
|
17
|
+
const appFactories = (options) => app('factory_bot', options)
|
18
|
+
|
19
|
+
const appVcrInsertCassette = async (cassette_name, options) => {
|
20
|
+
const context = await contextPromise;
|
21
|
+
if (!options) options = {};
|
22
|
+
|
23
|
+
Object.keys(options).forEach(key => options[key] === undefined ? delete options[key] : {});
|
24
|
+
const response = await context.post("/__e2e__/vcr/insert", {data: [cassette_name,options]});
|
25
|
+
expect(response.ok()).toBeTruthy();
|
26
|
+
return response.body;
|
27
|
+
}
|
28
|
+
|
29
|
+
const appVcrEjectCassette = async () => {
|
30
|
+
const context = await contextPromise;
|
31
|
+
|
32
|
+
const response = await context.post("/__e2e__/vcr/eject");
|
33
|
+
expect(response.ok()).toBeTruthy();
|
34
|
+
return response.body;
|
35
|
+
}
|
36
|
+
|
37
|
+
export { appCommands, app, appScenario, appEval, appFactories, appVcrInsertCassette, appVcrEjectCassette }
|
@@ -0,0 +1,79 @@
|
|
1
|
+
// @ts-check
|
2
|
+
const { defineConfig, devices } = require('@playwright/test');
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Read environment variables from file.
|
6
|
+
* https://github.com/motdotla/dotenv
|
7
|
+
*/
|
8
|
+
// require('dotenv').config();
|
9
|
+
|
10
|
+
/**
|
11
|
+
* @see https://playwright.dev/docs/test-configuration
|
12
|
+
*/
|
13
|
+
module.exports = defineConfig({
|
14
|
+
testDir: './playwright/e2e',
|
15
|
+
/* Run tests in files in parallel */
|
16
|
+
fullyParallel: true,
|
17
|
+
/* Fail the build on CI if you accidentally left test.only in the source code. */
|
18
|
+
forbidOnly: !!process.env.CI,
|
19
|
+
/* Retry on CI only */
|
20
|
+
retries: process.env.CI ? 2 : 0,
|
21
|
+
/* Opt out of parallel tests on CI. */
|
22
|
+
workers: process.env.CI ? 1 : undefined,
|
23
|
+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
|
24
|
+
reporter: 'html',
|
25
|
+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
|
26
|
+
use: {
|
27
|
+
/* Base URL to use in actions like `await page.goto('/')`. */
|
28
|
+
baseURL: 'http://127.0.0.1:5017',
|
29
|
+
|
30
|
+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
|
31
|
+
trace: 'on-first-retry',
|
32
|
+
},
|
33
|
+
|
34
|
+
/* Configure projects for major browsers */
|
35
|
+
projects: [
|
36
|
+
{
|
37
|
+
name: 'chromium',
|
38
|
+
use: { ...devices['Desktop Chrome'] },
|
39
|
+
},
|
40
|
+
|
41
|
+
{
|
42
|
+
name: 'firefox',
|
43
|
+
use: { ...devices['Desktop Firefox'] },
|
44
|
+
},
|
45
|
+
|
46
|
+
{
|
47
|
+
name: 'webkit',
|
48
|
+
use: { ...devices['Desktop Safari'] },
|
49
|
+
},
|
50
|
+
|
51
|
+
/* Test against mobile viewports. */
|
52
|
+
// {
|
53
|
+
// name: 'Mobile Chrome',
|
54
|
+
// use: { ...devices['Pixel 5'] },
|
55
|
+
// },
|
56
|
+
// {
|
57
|
+
// name: 'Mobile Safari',
|
58
|
+
// use: { ...devices['iPhone 12'] },
|
59
|
+
// },
|
60
|
+
|
61
|
+
/* Test against branded browsers. */
|
62
|
+
// {
|
63
|
+
// name: 'Microsoft Edge',
|
64
|
+
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
|
65
|
+
// },
|
66
|
+
// {
|
67
|
+
// name: 'Google Chrome',
|
68
|
+
// use: { ..devices['Desktop Chrome'], channel: 'chrome' },
|
69
|
+
// },
|
70
|
+
],
|
71
|
+
|
72
|
+
/* Run your local dev server before starting the tests */
|
73
|
+
// webServer: {
|
74
|
+
// command: 'npm run start',
|
75
|
+
// url: 'http://127.0.0.1:3000',
|
76
|
+
// reuseExistingServer: !process.env.CI,
|
77
|
+
// },
|
78
|
+
});
|
79
|
+
|
@@ -1,13 +1,24 @@
|
|
1
1
|
module CypressOnRails
|
2
2
|
class UpdateGenerator < Rails::Generators::Base
|
3
|
+
class_option :install_folder, type: :string, default: 'spec/e2e'
|
4
|
+
class_option :install_cypress, type: :boolean, default: true
|
5
|
+
class_option :install_playwright, type: :boolean, default: false
|
6
|
+
class_option :install_with, type: :string, default: 'yarn'
|
3
7
|
class_option :cypress_folder, type: :string, default: 'spec/cypress'
|
8
|
+
class_option :playwright_folder, type: :string, default: 'spec/playwright'
|
4
9
|
source_root File.expand_path('../templates', __FILE__)
|
5
10
|
|
6
11
|
def update_generated_files
|
7
12
|
template "config/initializers/cypress_on_rails.rb.erb", "config/initializers/cypress_on_rails.rb"
|
8
|
-
template "spec/
|
9
|
-
|
10
|
-
|
13
|
+
template "spec/e2e/e2e_helper.rb.erb", "#{options.install_folder}/e2e_helper.rb"
|
14
|
+
directory 'spec/e2e/app_commands', "#{options.install_folder}/app_commands"
|
15
|
+
|
16
|
+
if options.install_cypress
|
17
|
+
copy_file "spec/cypress/support/on-rails.js", "#{options.cypress_folder}/support/on-rails.js"
|
18
|
+
end
|
19
|
+
if options.install_playwright
|
20
|
+
copy_file "spec/playwright/support/on-rails.js", "#{options.playwright_folder}/support/on-rails.js"
|
21
|
+
end
|
11
22
|
end
|
12
23
|
end
|
13
24
|
end
|
data/plugin/support/index.js
CHANGED
@@ -5,7 +5,7 @@ Cypress.Commands.add("vcr_insert_cassette", (cassette_name, options) => {
|
|
5
5
|
const log = Cypress.log({ name: "VCR Insert", message: cassette_name, autoEnd: false })
|
6
6
|
return cy.request({
|
7
7
|
method: 'POST',
|
8
|
-
url: "/
|
8
|
+
url: "/__e2e__/vcr/insert",
|
9
9
|
body: JSON.stringify([cassette_name,options]),
|
10
10
|
log: false,
|
11
11
|
failOnStatusCode: false
|
@@ -23,7 +23,7 @@ Cypress.Commands.add("vcr_eject_cassette", () => {
|
|
23
23
|
const log = Cypress.log({ name: "VCR Eject", autoEnd: false })
|
24
24
|
return cy.request({
|
25
25
|
method: 'POST',
|
26
|
-
url: "/
|
26
|
+
url: "/__e2e__/vcr/eject",
|
27
27
|
log: false,
|
28
28
|
failOnStatusCode: false
|
29
29
|
}).then((response) => {
|
@@ -4,8 +4,8 @@ RSpec.describe CypressOnRails::Configuration do
|
|
4
4
|
it 'has defaults' do
|
5
5
|
CypressOnRails.configure { |config| config.reset }
|
6
6
|
|
7
|
-
expect(CypressOnRails.configuration.cypress_folder).to eq('spec/cypress')
|
8
7
|
expect(CypressOnRails.configuration.api_prefix).to eq('')
|
8
|
+
expect(CypressOnRails.configuration.install_folder).to eq('spec/e2e')
|
9
9
|
expect(CypressOnRails.configuration.use_middleware?).to eq(true)
|
10
10
|
expect(CypressOnRails.configuration.logger).to_not be_nil
|
11
11
|
end
|
@@ -13,13 +13,13 @@ RSpec.describe CypressOnRails::Configuration do
|
|
13
13
|
it 'can be configured' do
|
14
14
|
my_logger = Logger.new(STDOUT)
|
15
15
|
CypressOnRails.configure do |config|
|
16
|
-
config.cypress_folder = 'my/path'
|
17
16
|
config.api_prefix = '/api'
|
17
|
+
config.install_folder = 'my/path'
|
18
18
|
config.use_middleware = false
|
19
19
|
config.logger = my_logger
|
20
20
|
end
|
21
|
-
expect(CypressOnRails.configuration.cypress_folder).to eq('my/path')
|
22
21
|
expect(CypressOnRails.configuration.api_prefix).to eq('/api')
|
22
|
+
expect(CypressOnRails.configuration.install_folder).to eq('my/path')
|
23
23
|
expect(CypressOnRails.configuration.use_middleware?).to eq(false)
|
24
24
|
expect(CypressOnRails.configuration.logger).to eq(my_logger)
|
25
25
|
end
|
@@ -14,35 +14,35 @@ RSpec.describe CypressOnRails::Middleware do
|
|
14
14
|
StringIO.new(JSON.generate(json_value))
|
15
15
|
end
|
16
16
|
|
17
|
-
context '/
|
17
|
+
context '/__e2e__/command' do
|
18
18
|
before do
|
19
19
|
allow(command_executor).to receive(:perform).and_return({ id: 1, title: 'some result' })
|
20
20
|
allow(file).to receive(:exist?)
|
21
|
-
env['PATH_INFO'] = '/
|
21
|
+
env['PATH_INFO'] = '/__e2e__/command'
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'command file exist' do
|
25
25
|
allow(command_executor).to receive(:perform).and_return({ id: 1, title: 'some result' })
|
26
26
|
env['rack.input'] = rack_input(name: 'seed')
|
27
|
-
allow(file).to receive(:exist?).with('spec/
|
27
|
+
allow(file).to receive(:exist?).with('spec/e2e/app_commands/seed.rb').and_return(true)
|
28
28
|
|
29
29
|
aggregate_failures do
|
30
30
|
expect(response).to eq([201,
|
31
31
|
{"Content-Type"=>"application/json"},
|
32
32
|
["[{\"id\":1,\"title\":\"some result\"}]"]])
|
33
|
-
expect(command_executor).to have_received(:perform).with('spec/
|
33
|
+
expect(command_executor).to have_received(:perform).with('spec/e2e/app_commands/seed.rb', nil)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'command file exist with options' do
|
38
38
|
env['rack.input'] = rack_input(name: 'seed', options: ['my_options'])
|
39
|
-
allow(file).to receive(:exist?).with('spec/
|
39
|
+
allow(file).to receive(:exist?).with('spec/e2e/app_commands/seed.rb').and_return(true)
|
40
40
|
|
41
41
|
aggregate_failures do
|
42
42
|
expect(response).to eq([201,
|
43
43
|
{"Content-Type"=>"application/json"},
|
44
44
|
["[{\"id\":1,\"title\":\"some result\"}]"]])
|
45
|
-
expect(command_executor).to have_received(:perform).with('spec/
|
45
|
+
expect(command_executor).to have_received(:perform).with('spec/e2e/app_commands/seed.rb', ['my_options'])
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -50,52 +50,52 @@ RSpec.describe CypressOnRails::Middleware do
|
|
50
50
|
object = BasicObject.new
|
51
51
|
allow(command_executor).to receive(:perform).and_return(object)
|
52
52
|
env['rack.input'] = rack_input(name: 'seed')
|
53
|
-
allow(file).to receive(:exist?).with('spec/
|
53
|
+
allow(file).to receive(:exist?).with('spec/e2e/app_commands/seed.rb').and_return(true)
|
54
54
|
|
55
55
|
aggregate_failures do
|
56
56
|
expect(response).to eq([201,
|
57
57
|
{"Content-Type"=>"application/json"},
|
58
58
|
["{\"message\":\"Cannot convert to json\"}"]])
|
59
|
-
expect(command_executor).to have_received(:perform).with('spec/
|
59
|
+
expect(command_executor).to have_received(:perform).with('spec/e2e/app_commands/seed.rb', nil)
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
63
|
it 'command result does not respond to to_json' do
|
64
64
|
env['rack.input'] = rack_input(name: 'seed')
|
65
|
-
allow(file).to receive(:exist?).with('spec/
|
65
|
+
allow(file).to receive(:exist?).with('spec/e2e/app_commands/seed.rb').and_return(true)
|
66
66
|
|
67
67
|
aggregate_failures do
|
68
68
|
expect(response).to eq([201,
|
69
69
|
{"Content-Type"=>"application/json"},
|
70
70
|
["[{\"id\":1,\"title\":\"some result\"}]"]])
|
71
|
-
expect(command_executor).to have_received(:perform).with('spec/
|
71
|
+
expect(command_executor).to have_received(:perform).with('spec/e2e/app_commands/seed.rb', nil)
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
75
|
it 'running multiple commands' do
|
76
76
|
env['rack.input'] = rack_input([{name: 'load_user'},
|
77
77
|
{name: 'load_sample', options: {'all' => 'true'}}])
|
78
|
-
allow(file).to receive(:exist?).with('spec/
|
79
|
-
allow(file).to receive(:exist?).with('spec/
|
78
|
+
allow(file).to receive(:exist?).with('spec/e2e/app_commands/load_user.rb').and_return(true)
|
79
|
+
allow(file).to receive(:exist?).with('spec/e2e/app_commands/load_sample.rb').and_return(true)
|
80
80
|
|
81
81
|
aggregate_failures do
|
82
82
|
expect(response).to eq([201,
|
83
83
|
{"Content-Type"=>"application/json"},
|
84
84
|
["[{\"id\":1,\"title\":\"some result\"},{\"id\":1,\"title\":\"some result\"}]"]])
|
85
|
-
expect(command_executor).to have_received(:perform).with('spec/
|
86
|
-
expect(command_executor).to have_received(:perform).with('spec/
|
85
|
+
expect(command_executor).to have_received(:perform).with('spec/e2e/app_commands/load_user.rb', nil)
|
86
|
+
expect(command_executor).to have_received(:perform).with('spec/e2e/app_commands/load_sample.rb', {'all' => 'true'})
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
90
|
it 'running multiple commands but one missing' do
|
91
91
|
env['rack.input'] = rack_input([{name: 'load_user'}, {name: 'load_sample'}])
|
92
|
-
allow(file).to receive(:exist?).with('spec/
|
93
|
-
allow(file).to receive(:exist?).with('spec/
|
92
|
+
allow(file).to receive(:exist?).with('spec/e2e/app_commands/load_user.rb').and_return(true)
|
93
|
+
allow(file).to receive(:exist?).with('spec/e2e/app_commands/load_sample.rb').and_return(false)
|
94
94
|
|
95
95
|
aggregate_failures do
|
96
|
-
expect(response).to eq([404,
|
97
|
-
{"Content-Type"=>"application/json"},
|
98
|
-
["{\"message\":\"could not find command file: spec/
|
96
|
+
expect(response).to eq([404,
|
97
|
+
{"Content-Type"=>"application/json"},
|
98
|
+
["{\"message\":\"could not find command file: spec/e2e/app_commands/load_sample.rb\"}"]])
|
99
99
|
expect(command_executor).to_not have_received(:perform)
|
100
100
|
end
|
101
101
|
end
|
@@ -104,7 +104,7 @@ RSpec.describe CypressOnRails::Middleware do
|
|
104
104
|
context '"Other paths"' do
|
105
105
|
it 'runs app' do
|
106
106
|
aggregate_failures do
|
107
|
-
%w(/ /
|
107
|
+
%w(/ /__e2e__/login command /e2e_command /).each do |path|
|
108
108
|
env['PATH_INFO'] = path
|
109
109
|
|
110
110
|
response = subject.call(env)
|
@@ -16,9 +16,9 @@ module CypressOnRails
|
|
16
16
|
StringIO.new(JSON.generate(json_value))
|
17
17
|
end
|
18
18
|
|
19
|
-
describe '/
|
19
|
+
describe '/__e2e__/vcr/insert' do
|
20
20
|
before do
|
21
|
-
env['PATH_INFO'] = '/
|
21
|
+
env['PATH_INFO'] = '/__e2e__/vcr/insert'
|
22
22
|
end
|
23
23
|
|
24
24
|
it do
|
@@ -78,9 +78,9 @@ module CypressOnRails
|
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
|
-
describe '/
|
81
|
+
describe '/__e2e__/vcr/eject' do
|
82
82
|
before do
|
83
|
-
env['PATH_INFO'] = '/
|
83
|
+
env['PATH_INFO'] = '/__e2e__/vcr/eject'
|
84
84
|
end
|
85
85
|
|
86
86
|
it do
|
@@ -104,7 +104,7 @@ module CypressOnRails
|
|
104
104
|
|
105
105
|
it 'runs app' do
|
106
106
|
aggregate_failures do
|
107
|
-
%w(/ /
|
107
|
+
%w(/ /__e2e__/login command /e2e_command /).each do |path|
|
108
108
|
env['PATH_INFO'] = path
|
109
109
|
|
110
110
|
response = subject.call(env)
|
@@ -0,0 +1,79 @@
|
|
1
|
+
// @ts-check
|
2
|
+
const { defineConfig, devices } = require('@playwright/test');
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Read environment variables from file.
|
6
|
+
* https://github.com/motdotla/dotenv
|
7
|
+
*/
|
8
|
+
// require('dotenv').config();
|
9
|
+
|
10
|
+
/**
|
11
|
+
* @see https://playwright.dev/docs/test-configuration
|
12
|
+
*/
|
13
|
+
module.exports = defineConfig({
|
14
|
+
testDir: './playwright/e2e',
|
15
|
+
/* Run tests in files in parallel */
|
16
|
+
fullyParallel: true,
|
17
|
+
/* Fail the build on CI if you accidentally left test.only in the source code. */
|
18
|
+
forbidOnly: !!process.env.CI,
|
19
|
+
/* Retry on CI only */
|
20
|
+
retries: process.env.CI ? 2 : 0,
|
21
|
+
/* Opt out of parallel tests on CI. */
|
22
|
+
workers: process.env.CI ? 1 : undefined,
|
23
|
+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
|
24
|
+
reporter: 'html',
|
25
|
+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
|
26
|
+
use: {
|
27
|
+
/* Base URL to use in actions like `await page.goto('/')`. */
|
28
|
+
baseURL: 'http://127.0.0.1:5017',
|
29
|
+
|
30
|
+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
|
31
|
+
trace: 'on-first-retry',
|
32
|
+
},
|
33
|
+
|
34
|
+
/* Configure projects for major browsers */
|
35
|
+
projects: [
|
36
|
+
{
|
37
|
+
name: 'chromium',
|
38
|
+
use: { ...devices['Desktop Chrome'] },
|
39
|
+
},
|
40
|
+
|
41
|
+
{
|
42
|
+
name: 'firefox',
|
43
|
+
use: { ...devices['Desktop Firefox'] },
|
44
|
+
},
|
45
|
+
|
46
|
+
{
|
47
|
+
name: 'webkit',
|
48
|
+
use: { ...devices['Desktop Safari'] },
|
49
|
+
},
|
50
|
+
|
51
|
+
/* Test against mobile viewports. */
|
52
|
+
// {
|
53
|
+
// name: 'Mobile Chrome',
|
54
|
+
// use: { ...devices['Pixel 5'] },
|
55
|
+
// },
|
56
|
+
// {
|
57
|
+
// name: 'Mobile Safari',
|
58
|
+
// use: { ...devices['iPhone 12'] },
|
59
|
+
// },
|
60
|
+
|
61
|
+
/* Test against branded browsers. */
|
62
|
+
// {
|
63
|
+
// name: 'Microsoft Edge',
|
64
|
+
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
|
65
|
+
// },
|
66
|
+
// {
|
67
|
+
// name: 'Google Chrome',
|
68
|
+
// use: { ..devices['Desktop Chrome'], channel: 'chrome' },
|
69
|
+
// },
|
70
|
+
],
|
71
|
+
|
72
|
+
/* Run your local dev server before starting the tests */
|
73
|
+
// webServer: {
|
74
|
+
// command: 'npm run start',
|
75
|
+
// url: 'http://127.0.0.1:3000',
|
76
|
+
// reuseExistingServer: !process.env.CI,
|
77
|
+
// },
|
78
|
+
});
|
79
|
+
|
data/specs_e2e/rails_3_2/test.sh
CHANGED
@@ -14,7 +14,7 @@ bundle --version
|
|
14
14
|
bundle install --quiet --gemfile="$DIR/Gemfile" --retry 2 --path vendor/bundle
|
15
15
|
|
16
16
|
echo '-- cypress install'
|
17
|
-
bundle exec ./bin/rails g cypress_on_rails:install --
|
17
|
+
bundle exec ./bin/rails g cypress_on_rails:install --install_cypress --install_playwright --install_with=npm
|
18
18
|
rm -vf cypress/e2e/rails_examples/advance_factory_bot.cy.js
|
19
19
|
rm -vf cypress/e2e/rails_examples/using_vcr.cy.js
|
20
20
|
|
@@ -34,5 +34,10 @@ cp -fv ../cypress.config.js .
|
|
34
34
|
node_modules/.bin/cypress run --record
|
35
35
|
# fi
|
36
36
|
|
37
|
+
echo '-- playwright run'
|
38
|
+
cp -fv ../playwright.config.js .
|
39
|
+
npx playwright install-deps
|
40
|
+
npx playwright test playwright/e2e/
|
41
|
+
|
37
42
|
echo '-- stop rails server'
|
38
43
|
kill -9 `cat tmp/pids/server.pid`
|
data/specs_e2e/rails_4_2/test.sh
CHANGED
@@ -14,9 +14,8 @@ gem install bundler -v "~> 1.0" --conservative
|
|
14
14
|
bundle --version
|
15
15
|
bundle install --quiet --gemfile="$DIR/Gemfile" --retry 2 --path vendor/bundle
|
16
16
|
|
17
|
-
echo '-- cypress install'
|
18
|
-
|
19
|
-
bundle exec ./bin/rails g cypress_on_rails:install --cypress_folder=spec/cypress --experimental --skip
|
17
|
+
echo '-- cypress and playwright install'
|
18
|
+
bundle exec ./bin/rails g cypress_on_rails:install --install_folder=spec/e2e --cypress_folder=spec/cypress --playwright_folder=spec/playwright --install_cypress --install_playwright --experimental --install_with=npm --skip
|
20
19
|
rm -vf spec/cypress/e2e/rails_examples/advance_factory_bot.cy.js
|
21
20
|
|
22
21
|
echo '-- start rails server'
|
@@ -30,10 +29,16 @@ echo '-- cypress run'
|
|
30
29
|
cp -fv ../cypress.config.js spec/
|
31
30
|
# if [ -z $CYPRESS_RECORD_KEY ]
|
32
31
|
# then
|
33
|
-
#
|
32
|
+
# npx cypress run -P ./spec
|
34
33
|
# else
|
35
|
-
|
34
|
+
npx cypress run -P ./spec --record
|
36
35
|
# fi
|
37
36
|
|
37
|
+
echo '-- playwright run'
|
38
|
+
cp -fv ../playwright.config.js spec/
|
39
|
+
cd spec
|
40
|
+
npx playwright install-deps
|
41
|
+
npx playwright test spec/playwright/e2e/
|
42
|
+
|
38
43
|
echo '-- stop rails server'
|
39
|
-
kill -9 `cat tmp/pids/server.pid`
|
44
|
+
kill -9 `cat tmp/pids/server.pid` || true
|
data/specs_e2e/rails_5_2/test.sh
CHANGED
@@ -18,8 +18,8 @@ echo '-- migration'
|
|
18
18
|
bundle exec ./bin/rails db:drop || true
|
19
19
|
bundle exec ./bin/rails db:create db:migrate
|
20
20
|
|
21
|
-
echo '-- cypress install'
|
22
|
-
bundle exec ./bin/rails g cypress_on_rails:install --cypress_folder=test/cypress --skip
|
21
|
+
echo '-- cypress and playwright install'
|
22
|
+
bundle exec ./bin/rails g cypress_on_rails:install --install_folder=test/e2e --cypress_folder=test/cypress --playwright_folder=test/playwright --install_cypress --install_playwright --install_with=npm --skip
|
23
23
|
rm -vf test/cypress/e2e/rails_examples/using_vcr.cy.js
|
24
24
|
|
25
25
|
echo '-- start rails server'
|
@@ -34,10 +34,15 @@ cp -fv ../cypress.config.js test/
|
|
34
34
|
cd test
|
35
35
|
# if [ -z $CYPRESS_RECORD_KEY ]
|
36
36
|
# then
|
37
|
-
#
|
37
|
+
# npx cypress run
|
38
38
|
# else
|
39
|
-
|
39
|
+
npx cypress run --record
|
40
40
|
# fi
|
41
41
|
|
42
|
+
echo '-- playwright run'
|
43
|
+
cp -fv ../../playwright.config.js .
|
44
|
+
npx playwright install-deps
|
45
|
+
npx playwright test test/playwright/e2e/
|
46
|
+
|
42
47
|
echo '-- stop rails server'
|
43
48
|
kill -9 `cat ../tmp/pids/server.pid` || true
|
data/tmp/pids/.gitkeep
ADDED
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cypress-on-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.15.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- miceportal team
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-05
|
12
|
+
date: 2023-07-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
@@ -132,13 +132,6 @@ files:
|
|
132
132
|
- lib/generators/cypress_on_rails/install_generator.rb
|
133
133
|
- lib/generators/cypress_on_rails/templates/config/initializers/cypress_on_rails.rb.erb
|
134
134
|
- lib/generators/cypress_on_rails/templates/spec/cypress.config.js
|
135
|
-
- lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/activerecord_fixtures.rb
|
136
|
-
- lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/clean.rb
|
137
|
-
- lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/eval.rb
|
138
|
-
- lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/factory_bot.rb
|
139
|
-
- lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/log_fail.rb
|
140
|
-
- lib/generators/cypress_on_rails/templates/spec/cypress/app_commands/scenarios/basic.rb
|
141
|
-
- lib/generators/cypress_on_rails/templates/spec/cypress/cypress_helper.rb.erb
|
142
135
|
- lib/generators/cypress_on_rails/templates/spec/cypress/e2e/rails_examples/advance_factory_bot.cy.js
|
143
136
|
- lib/generators/cypress_on_rails/templates/spec/cypress/e2e/rails_examples/other.cy.js
|
144
137
|
- lib/generators/cypress_on_rails/templates/spec/cypress/e2e/rails_examples/using_factory_bot.cy.js
|
@@ -148,12 +141,23 @@ files:
|
|
148
141
|
- lib/generators/cypress_on_rails/templates/spec/cypress/support/commands.js
|
149
142
|
- lib/generators/cypress_on_rails/templates/spec/cypress/support/index.js.erb
|
150
143
|
- lib/generators/cypress_on_rails/templates/spec/cypress/support/on-rails.js
|
144
|
+
- lib/generators/cypress_on_rails/templates/spec/e2e/app_commands/activerecord_fixtures.rb
|
145
|
+
- lib/generators/cypress_on_rails/templates/spec/e2e/app_commands/clean.rb
|
146
|
+
- lib/generators/cypress_on_rails/templates/spec/e2e/app_commands/eval.rb
|
147
|
+
- lib/generators/cypress_on_rails/templates/spec/e2e/app_commands/factory_bot.rb
|
148
|
+
- lib/generators/cypress_on_rails/templates/spec/e2e/app_commands/log_fail.rb
|
149
|
+
- lib/generators/cypress_on_rails/templates/spec/e2e/app_commands/scenarios/basic.rb
|
150
|
+
- lib/generators/cypress_on_rails/templates/spec/e2e/e2e_helper.rb.erb
|
151
|
+
- lib/generators/cypress_on_rails/templates/spec/playwright.config.js
|
152
|
+
- lib/generators/cypress_on_rails/templates/spec/playwright/e2e/rails_examples/using_scenarios.spec.js
|
153
|
+
- lib/generators/cypress_on_rails/templates/spec/playwright/support/index.js.erb
|
154
|
+
- lib/generators/cypress_on_rails/templates/spec/playwright/support/on-rails.js
|
151
155
|
- lib/generators/cypress_on_rails/update_generator.rb
|
152
156
|
- plugin/.gitignore
|
153
157
|
- plugin/cypress/plugins/index.js
|
154
158
|
- plugin/package.json
|
155
159
|
- plugin/support/index.js
|
156
|
-
- spec/cypress_on_rails/command_executor/
|
160
|
+
- spec/cypress_on_rails/command_executor/e2e_helper.rb
|
157
161
|
- spec/cypress_on_rails/command_executor/test_command.rb
|
158
162
|
- spec/cypress_on_rails/command_executor/test_command_with_options.rb
|
159
163
|
- spec/cypress_on_rails/command_executor_spec.rb
|
@@ -165,6 +169,7 @@ files:
|
|
165
169
|
- spec/cypress_on_rails/vcr_middleware_spec.rb
|
166
170
|
- spec/spec_helper.rb
|
167
171
|
- specs_e2e/cypress.config.js
|
172
|
+
- specs_e2e/playwright.config.js
|
168
173
|
- specs_e2e/rails_3_2/.gitignore
|
169
174
|
- specs_e2e/rails_3_2/.ruby_version
|
170
175
|
- specs_e2e/rails_3_2/Gemfile
|
@@ -306,6 +311,7 @@ files:
|
|
306
311
|
- specs_e2e/rails_5_2/test/fixtures/posts.yml
|
307
312
|
- specs_e2e/rails_5_2/test/models/post_test.rb
|
308
313
|
- specs_e2e/rails_5_2/vendor/.keep
|
314
|
+
- tmp/pids/.gitkeep
|
309
315
|
homepage: http://github.com/shakacode/cypress-on-rails
|
310
316
|
licenses: []
|
311
317
|
metadata:
|
File without changes
|
File without changes
|
File without changes
|
/data/lib/generators/cypress_on_rails/templates/spec/{cypress → e2e}/app_commands/factory_bot.rb
RENAMED
File without changes
|
/data/lib/generators/cypress_on_rails/templates/spec/{cypress → e2e}/app_commands/log_fail.rb
RENAMED
File without changes
|
/data/lib/generators/cypress_on_rails/templates/spec/{cypress → e2e}/app_commands/scenarios/basic.rb
RENAMED
File without changes
|
File without changes
|
File without changes
|