Skip to content

Commit 8dd954f

Browse files
committed
Supports Cypress v10 or later
1 parent 9b3ed03 commit 8dd954f

File tree

13 files changed

+111
-59
lines changed

13 files changed

+111
-59
lines changed

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Once installed, you'll want to run:
5050
$ rake cypress:init
5151
```
5252

53-
This will override a few configurations in your `cypress.json` configuration
53+
This will override a few configurations in your `cypress.config.js` configuration
5454
file.
5555

5656
## Usage
@@ -161,7 +161,7 @@ preferred environment variables project-wide using a tool like
161161
the Rails test server on
162162
* **CYPRESS_RAILS_BASE_PATH** (default: `"/"`) the base path for all Cypress's
163163
requests to the app (e.g. via `cy.visit()`). If you've customized your
164-
`baseUrl` setting (e.g. in `cypress.json`), you'll need to duplicate it with
164+
`baseUrl` setting (e.g. in `cypress.config.js`), you'll need to duplicate it with
165165
this environment variable
166166
* **CYPRESS_RAILS_TRANSACTIONAL_SERVER** (default: `true`) when true, will start
167167
a transaction on all database connections before launching the server. In

Diff for: example/cypress.config.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const { defineConfig } = require('cypress')
2+
3+
module.exports = defineConfig({
4+
// setupNodeEvents can be defined in either
5+
// the e2e or component configuration
6+
e2e: {
7+
setupNodeEvents(on, config) {
8+
on('before:browser:launch', (browser = {}, launchOptions) => {
9+
/* ... */
10+
})
11+
},
12+
},
13+
screenshotsFolder: "tmp/cypress_screenshots",
14+
videosFolder: "tmp/cypress_videos",
15+
trashAssetsBeforeRuns: false
16+
})

Diff for: example/cypress.json

-5
This file was deleted.
File renamed without changes.

Diff for: example/cypress/plugins/index.js

-21
This file was deleted.

Diff for: example/cypress/support/commands.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/// <reference types="cypress" />
2+
// ***********************************************
3+
// This example commands.ts shows you how to
4+
// create various custom commands and overwrite
5+
// existing commands.
6+
//
7+
// For more comprehensive examples of custom
8+
// commands please read more here:
9+
// https://on.cypress.io/custom-commands
10+
// ***********************************************
11+
//
12+
//
13+
// -- This is a parent command --
14+
// Cypress.Commands.add('login', (email, password) => { ... })
15+
//
16+
//
17+
// -- This is a child command --
18+
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
19+
//
20+
//
21+
// -- This is a dual command --
22+
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
23+
//
24+
//
25+
// -- This will overwrite an existing command --
26+
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
27+
//
28+
// declare global {
29+
// namespace Cypress {
30+
// interface Chainable {
31+
// login(email: string, password: string): Chainable<void>
32+
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
33+
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
34+
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
35+
// }
36+
// }
37+
// }

Diff for: example/cypress/support/index.js renamed to example/cypress/support/e2e.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// ***********************************************************
2-
// This example support/index.js is processed and
2+
// This example support/e2e.ts is processed and
33
// loaded automatically before your test files.
44
//
55
// This is a great place to put global configuration and
@@ -12,3 +12,9 @@
1212
// You can read more here:
1313
// https://on.cypress.io/configuration
1414
// ***********************************************************
15+
16+
// Import commands.js using ES2015 syntax:
17+
import './commands';
18+
19+
// Alternatively you can use CommonJS syntax:
20+
// require('./commands')

Diff for: example/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"version": "0.1.0",
1313
"devDependencies": {
14-
"cypress": "9.6.1",
14+
"cypress": "^12.13.0",
1515
"webpack-dev-server": "^3.8.0"
1616
}
1717
}

Diff for: example/yarn.lock

+22-17
Original file line numberDiff line numberDiff line change
@@ -2225,10 +2225,10 @@ commander@^2.20.0:
22252225
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33"
22262226
integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==
22272227

2228-
commander@^5.1.0:
2229-
version "5.1.0"
2230-
resolved "https://registry.yarnpkg.com/commander/-/commander-5.1.0.tgz#46abbd1652f8e059bddaef99bbdcb2ad9cf179ae"
2231-
integrity sha512-P0CysNDQ7rtVw4QIQtm+MRxV66vKFSvlsQvGYXZWR3qFU0jlMKHZZZgw8e+8DSah4UDKMqnknRDQz+xuQXQ/Zg==
2228+
commander@^6.2.1:
2229+
version "6.2.1"
2230+
resolved "https://registry.yarnpkg.com/commander/-/commander-6.2.1.tgz#0792eb682dfbc325999bb2b84fddddba110ac73c"
2231+
integrity sha512-U7VdrJFnJgo4xjrHpTzu0yrHPGImdsmD95ZlgYSEajAn2JKzDhDTPG9kBTefmObL2w/ngeZnilk+OV9CG3d7UA==
22322232

22332233
common-tags@^1.8.0:
22342234
version "1.8.2"
@@ -2654,10 +2654,10 @@ cyclist@^1.0.1:
26542654
resolved "https://registry.yarnpkg.com/cyclist/-/cyclist-1.0.1.tgz#596e9698fd0c80e12038c2b82d6eb1b35b6224d9"
26552655
integrity sha1-WW6WmP0MgOEgOMK4LW6xs1tiJNk=
26562656

2657-
cypress@9.6.1:
2658-
version "9.6.1"
2659-
resolved "https://registry.yarnpkg.com/cypress/-/cypress-9.6.1.tgz#a7d6b5a53325b3dc4960181f5800a5ade0f085eb"
2660-
integrity sha512-ECzmV7pJSkk+NuAhEw6C3D+RIRATkSb2VAHXDY6qGZbca/F9mv5pPsj2LO6Ty6oIFVBTrwCyL9agl28MtJMe2g==
2657+
cypress@^12.13.0:
2658+
version "12.13.0"
2659+
resolved "https://registry.yarnpkg.com/cypress/-/cypress-12.13.0.tgz#725b6617ea19e41e5c59cc509fc3e08097142b01"
2660+
integrity sha512-QJlSmdPk+53Zhy69woJMySZQJoWfEWun3X5OOenGsXjRPVfByVTHorxNehbzhZrEzH9RDUDqVcck0ahtlS+N/Q==
26612661
dependencies:
26622662
"@cypress/request" "^2.88.10"
26632663
"@cypress/xvfb" "^1.2.4"
@@ -2673,12 +2673,12 @@ [email protected]:
26732673
check-more-types "^2.24.0"
26742674
cli-cursor "^3.1.0"
26752675
cli-table3 "~0.6.1"
2676-
commander "^5.1.0"
2676+
commander "^6.2.1"
26772677
common-tags "^1.8.0"
26782678
dayjs "^1.10.4"
2679-
debug "^4.3.2"
2679+
debug "^4.3.4"
26802680
enquirer "^2.3.6"
2681-
eventemitter2 "^6.4.3"
2681+
eventemitter2 "6.4.7"
26822682
execa "4.1.0"
26832683
executable "^4.1.1"
26842684
extract-zip "2.0.1"
@@ -2691,7 +2691,7 @@ [email protected]:
26912691
listr2 "^3.8.3"
26922692
lodash "^4.17.21"
26932693
log-symbols "^4.0.0"
2694-
minimist "^1.2.6"
2694+
minimist "^1.2.8"
26952695
ospath "^1.2.2"
26962696
pretty-bytes "^5.6.0"
26972697
proxy-from-env "1.0.0"
@@ -2728,7 +2728,7 @@ debug@^3.1.0, debug@^3.1.1, debug@^3.2.7:
27282728
dependencies:
27292729
ms "^2.1.1"
27302730

2731-
debug@^4.1.0, debug@^4.1.1, debug@^4.3.2:
2731+
debug@^4.1.0, debug@^4.1.1, debug@^4.3.4:
27322732
version "4.3.4"
27332733
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865"
27342734
integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==
@@ -3124,10 +3124,10 @@ etag@~1.8.1:
31243124
resolved "https://registry.yarnpkg.com/etag/-/etag-1.8.1.tgz#41ae2eeb65efa62268aebfea83ac7d79299b0887"
31253125
integrity sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=
31263126

3127-
eventemitter2@^6.4.3:
3128-
version "6.4.5"
3129-
resolved "https://registry.yarnpkg.com/eventemitter2/-/eventemitter2-6.4.5.tgz#97380f758ae24ac15df8353e0cc27f8b95644655"
3130-
integrity sha512-bXE7Dyc1i6oQElDG0jMRZJrRAn9QR2xyyFGmBdZleNmyQX0FqGYmhZIrIrpPfm/w//LTo4tVQGOGQcGCb5q9uw==
3127+
3128+
version "6.4.7"
3129+
resolved "https://registry.yarnpkg.com/eventemitter2/-/eventemitter2-6.4.7.tgz#a7f6c4d7abf28a14c1ef3442f21cb306a054271d"
3130+
integrity sha512-tYUSVOGeQPKt/eC1ABfhHy5Xd96N3oIijJvN3O9+TsC28T5V9yX9oEfEK5faP0EFSNVOG97qtAS68GBrQB2hDg==
31313131

31323132
eventemitter3@^4.0.0:
31333133
version "4.0.7"
@@ -4898,6 +4898,11 @@ minimist@^1.1.0, minimist@^1.2.0, minimist@^1.2.5, minimist@^1.2.6:
48984898
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.6.tgz#8637a5b759ea0d6e98702cfb3a9283323c93af44"
48994899
integrity sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==
49004900

4901+
minimist@^1.2.8:
4902+
version "1.2.8"
4903+
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.8.tgz#c1a464e7693302e082a075cee0c057741ac4772c"
4904+
integrity sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==
4905+
49014906
minipass-collect@^1.0.2:
49024907
version "1.0.2"
49034908
resolved "https://registry.yarnpkg.com/minipass-collect/-/minipass-collect-1.0.2.tgz#22b813bf745dc6edba2576b940022ad6edc8c617"

Diff for: lib/cypress-rails/init.rb

+25-11
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,44 @@
11
module CypressRails
22
class Init
3-
DEFAULT_CONFIG = {
4-
"screenshotsFolder" => "tmp/cypress_screenshots",
5-
"videosFolder" => "tmp/cypress_videos",
6-
"trashAssetsBeforeRuns" => false
7-
}
3+
DEFAULT_CONFIG = <<~CYPRESS_CONFIG
4+
const { defineConfig } = require('cypress')
5+
6+
module.exports = defineConfig({
7+
// setupNodeEvents can be defined in either
8+
// the e2e or component configuration
9+
e2e: {
10+
setupNodeEvents(on, config) {
11+
on('before:browser:launch', (browser = {}, launchOptions) => {
12+
/* ... */
13+
})
14+
},
15+
},
16+
screenshotsFolder: "tmp/cypress_screenshots",
17+
videosFolder: "tmp/cypress_videos",
18+
trashAssetsBeforeRuns: false
19+
})
20+
21+
CYPRESS_CONFIG
822

923
def call(dir = Dir.pwd)
10-
config_path = File.join(dir, "cypress.json")
11-
json = JSON.pretty_generate(determine_new_config(config_path))
12-
File.write(config_path, json)
24+
config_path = File.join(dir, "cypress.config.js")
25+
config_content = determine_new_config(config_path)
26+
File.write(config_path, config_content)
1327
puts "Cypress config (re)initialized in #{config_path}"
1428
end
1529

1630
private
1731

1832
def determine_new_config(config_path)
1933
if File.exist?(config_path)
20-
merge_existing_with_defaults(config_path)
34+
merge_existing_with_defaults(config_path)
2135
else
2236
DEFAULT_CONFIG
2337
end
2438
end
2539

26-
def merge_existing_with_defaults(json_path)
27-
JSON.parse(File.read(json_path)).merge(DEFAULT_CONFIG).sort.to_h
40+
def merge_existing_with_defaults(config_path)
41+
File.read(config_path)
2842
end
2943
end
3044
end

Diff for: lib/cypress-rails/rake.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require "pathname"
22
CLI = Pathname.new(File.dirname(__FILE__)).join("../../exe/cypress-rails")
33

4-
desc "Initialize cypress.json"
4+
desc "Initialize cypress.config.js"
55
task :"cypress:init" do
66
system "#{CLI} init"
77
end

0 commit comments

Comments
 (0)