Skip to content

Commit c1bcb2f

Browse files
authored
Issue 1042 (#1057)
* server: remove unused file * server: WIP, start implementing accepting plugin returning promise and yielding config overrides [skip ci] * server: cleanup the env + environentVariables disaster. simplify and only use 'env' * server, desktop-gum: rename 'env' to 'cypressEnv' to avoid conflicts, fix failing tests * server: modify plugins error content to be clearer * runner, driver: more environmentVariables -> env cleanup * fixes #509 return the complete configuration object to Cypress.config() * fixes #1042 enable plugins to return a promise and modify config * desktop-gui: add 'plugin' override to configuration display * server: bug fix when plugin cause a project not to open * desktop-gui: fix for failing e2e test * server: make errors clearer when plugins crash * server: fix bug with PLUGINS_FUNCTION_ERROR not sending right arguments - fix failing tests - improve plugin error content * server: fix failing snapshots, preprocessor is invoked for support + spec files * server: fix tests, don't watch the support file initially - this was causing a problem where unhandled preprocessor errors were causing the entire process to hang. - this was happening because we weren’t properly running support files through a custom preprocessor initially * fixes failing tests
1 parent 6db7a83 commit c1bcb2f

38 files changed

+451
-268
lines changed

.eslintrc

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"plugin:cypress-dev/general"
44
],
55
"env": {
6+
"es6": true,
67
"node": true
78
}
89
}

packages/desktop-gui/cypress/fixtures/config.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
"clientUrlDisplay": "http://localhost:2020",
2828
"commandTimeout": 4000,
2929
"cypressHostUrl": "http://localhost:2020",
30-
"env": "development",
31-
"environmentVariables": {
32-
30+
"cypressEnv": "development",
31+
"env": {
32+
3333
},
3434
"execTimeout": 60000,
3535
"fileServerFolder": "/Users/jennifer/Dev/Projects/cypress-example-kitchensink",
@@ -40,7 +40,7 @@
4040
"isHeadless": false,
4141
"isNewProject": false,
4242
"javascripts": [
43-
43+
4444
],
4545
"morgan": true,
4646
"namespace": "__cypress",
@@ -108,7 +108,7 @@
108108
"from": "default",
109109
"value": 4000
110110
},
111-
"environmentVariables": {
111+
"env": {
112112
"fileServerFolder": {
113113
"from": "default",
114114
"value": ""

packages/desktop-gui/cypress/integration/settings_spec.coffee

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ describe "Settings", ->
6565
cy.contains("Your project's configuration is displayed")
6666

6767
it "displays legend in table", ->
68-
cy.get("table>tbody>tr").should("have.length", 5)
68+
cy.get("table>tbody>tr").should("have.length", 6)
6969

7070
it "wraps config line in proper classes", ->
7171
cy

packages/desktop-gui/src/app/app.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class App extends Component {
2020
appApi.listenForMenuClicks()
2121

2222
ipc.getOptions().then((options = {}) => {
23-
appStore.set(_.pick(options, 'env', 'os', 'projectPath', 'version'))
23+
appStore.set(_.pick(options, 'cypressEnv', 'os', 'projectPath', 'version'))
2424
viewStore.showApp()
2525
})
2626

packages/desktop-gui/src/lib/app-store.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { action, computed, observable } from 'mobx'
22
import localData from '../lib/local-data'
33

44
class AppStore {
5-
@observable env
5+
@observable cypressEnv
66
@observable os
77
@observable projectPath = null
88
@observable newVersion
@@ -15,7 +15,7 @@ class AppStore {
1515
}
1616

1717
@computed get isDev () {
18-
return this.env === 'development'
18+
return this.cypressEnv === 'development'
1919
}
2020

2121
@computed get isGlobalMode () {
@@ -27,7 +27,7 @@ class AppStore {
2727
}
2828

2929
@action set (props) {
30-
if (props.env != null) this.env = props.env
30+
if (props.cypressEnv != null) this.cypressEnv = props.cypressEnv
3131
if (props.os != null) this.os = props.os
3232
if (props.projectPath != null) this.projectPath = props.projectPath
3333
if (props.version != null) this.version = this.newVersion = props.version

packages/desktop-gui/src/settings/configuration.jsx

+4
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ const Configuration = observer(({ project }) => (
102102
<td><span className='cli'>CLI</span></td>
103103
<td>set from CLI arguments</td>
104104
</tr>
105+
<tr className='config-keys'>
106+
<td><span className='plugin'>plugin</span></td>
107+
<td>set from plugin file</td>
108+
</tr>
105109
</tbody>
106110
</table>
107111
<pre className='config-vars'>

packages/desktop-gui/src/settings/settings.scss

+7-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
padding: 10px;
5454
font-family: $font-mono;
5555

56-
.envFile:hover, .env:hover, .config:hover, .cli:hover, .default:hover {
56+
.envFile:hover, .env:hover, .config:hover, .cli:hover, .plugin:hover, .default:hover {
5757
border-bottom: 1px dotted #777;
5858
}
5959

@@ -83,7 +83,7 @@
8383
}
8484
}
8585

86-
.envFile, .env, .config, .cli, .default {
86+
.envFile, .env, .config, .cli, .plugin, .default {
8787
font-family: $font-mono;
8888

8989
padding: 2px;
@@ -109,6 +109,11 @@
109109
color: #A21313;
110110
}
111111

112+
.plugin {
113+
background-color: #f0e7fc;
114+
color: #134aa2;
115+
}
116+
112117
}
113118

114119
.settings-wrapper {

packages/driver/src/cypress.coffee

+3-3
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,13 @@ class $Cypress
119119
longStackTraces: config.isInteractive
120120
})
121121

122-
{environmentVariables, remote} = config
122+
{env, remote} = config
123123

124-
config = _.omit(config, "environmentVariables", "remote")
124+
config = _.omit(config, "env", "remote", "resolved", "scaffoldedFiles", "javascripts", "state")
125125

126126
@state = $SetterGetter.create({})
127127
@config = $SetterGetter.create(config)
128-
@env = $SetterGetter.create(environmentVariables)
128+
@env = $SetterGetter.create(env)
129129

130130
@Cookies = $Cookies.create(config.namespace, d)
131131

packages/driver/src/cypress/error_messages.coffee

-3
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,6 @@ module.exports = {
204204
invalid_argument: "#{cmd('each')} must be passed a callback function."
205205
non_array: "#{cmd('each')} can only operate on an array like subject. Your subject was: '{{subject}}'"
206206

207-
env:
208-
variables_missing: "Cypress.environmentVariables is not defined. Open an issue if you see this message."
209-
210207
exec:
211208
failed: """#{cmd('exec', '\'{{cmd}}\'')} failed with the following error:
212209

packages/driver/test/unit/cypress_spec.coffee

+3-3
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ describe "src/cypress", ->
7878
describe "#env", ->
7979
beforeEach ->
8080
@Cypress.setConfig({
81-
environmentVariables: {foo: "bar"}
81+
env: {foo: "bar"}
8282
})
8383

8484
it "acts as getter", ->
@@ -108,9 +108,9 @@ describe "src/cypress", ->
108108
it "instantiates Cookies", ->
109109
expect(@Cypress.Cookies).to.be.an("object")
110110

111-
it "passes config.environmentVariables", ->
111+
it "passes config.env", ->
112112
@Cypress.setConfig({
113-
environmentVariables: {foo: "bar"}
113+
env: {foo: "bar"}
114114
})
115115

116116
expect(@Cypress.env()).to.deep.eq({foo: "bar"})

packages/runner/src/app/app.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ App.propTypes = {
121121
majorVersion: PropTypes.string.isRequired,
122122
version: PropTypes.string.isRequired,
123123
})).isRequired,
124-
env: PropTypes.string.isRequired,
124+
cypressEnv: PropTypes.string.isRequired,
125125
integrationFolder: PropTypes.string.isRequired,
126126
numTestsKeptInMemory: PropTypes.number.isRequired,
127127
projectName: PropTypes.string.isRequired,

packages/runner/src/app/app.spec.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import App from './app'
1313
const createProps = () => ({
1414
config: {
1515
browsers: [],
16-
env: 'tst',
16+
cypressEnv: 'tst',
1717
integrationFolder: '',
1818
numTestsKeptInMemory: 1,
1919
projectName: '',

packages/runner/src/app/container.spec.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import Container, { automationElementId } from './container'
1414
const createProps = () => ({
1515
config: {
1616
browsers: [],
17-
env: 'test',
17+
cypressEnv: 'test',
1818
integrationFolder: '',
1919
numTestsKeptInMemory: 1,
2020
projectName: '',

packages/runner/src/lib/event-manager.js

+2-26
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const eventManager = {
6262
})
6363

6464
_.each(socketRerunEvents, (event) => {
65-
channel.on(event, this._reRun.bind(this))
65+
channel.on(event, this._reRun.bind(this))
6666
})
6767

6868
reporterBus.on('runner:console:error', (testId) => {
@@ -165,31 +165,7 @@ const eventManager = {
165165
},
166166

167167
setup (config, specPath) {
168-
Cypress = $Cypress.create(
169-
_.pick(config,
170-
'isTextTerminal',
171-
'numTestsKeptInMemory',
172-
'waitForAnimations',
173-
'animationDistanceThreshold',
174-
'defaultCommandTimeout',
175-
'pageLoadTimeout',
176-
'requestTimeout',
177-
'responseTimeout',
178-
'environmentVariables',
179-
'xhrUrl',
180-
'baseUrl',
181-
'viewportWidth',
182-
'viewportHeight',
183-
'execTimeout',
184-
'screenshotOnHeadlessFailure',
185-
'namespace',
186-
'remote',
187-
'version',
188-
'fixturesFolder',
189-
'platform',
190-
'arch'
191-
)
192-
)
168+
Cypress = $Cypress.create(config)
193169

194170
// expose Cypress globally
195171
window.Cypress = Cypress

packages/server/__snapshots__/plugins_spec.coffee

+39-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Started video recording: /foo/bar/.projects/plugins-async-error/cypress/videos/a
33

44
(Tests Starting)
55

6-
Error: The following error was thrown by a plugin. We've stopped running your tests because this likely interrupts behavior critical to them.
6+
Error: The following error was thrown by a plugin. We've stopped running your tests because a plugin crashed.
77
88
Error: Async error from plugins file
99
at stack trace line
@@ -50,15 +50,16 @@ Started video recording: /foo/bar/.projects/working-preprocessor/cypress/videos/
5050
(Tests Starting)
5151
5252
53+
✓ is another spec
5354
✓ is another spec
5455
55-
1 passing
56+
2 passing
5657
5758
5859
(Tests Finished)
5960
60-
- Tests: 1
61-
- Passes: 1
61+
- Tests: 2
62+
- Passes: 2
6263
- Failures: 0
6364
- Pending: 0
6465
- Duration: 10 seconds
@@ -73,6 +74,40 @@ Started video recording: /foo/bar/.projects/working-preprocessor/cypress/videos/
7374
- Finished processing: /foo/bar/.projects/working-preprocessor/cypress/videos/abc123.mp4 (0 seconds)
7475
7576
77+
(All Done)
78+
79+
`
80+
81+
exports['e2e plugins can modify config from plugins 1'] = `
82+
Started video recording: /foo/bar/.projects/plugin-config/cypress/videos/abc123.mp4
83+
84+
(Tests Starting)
85+
86+
87+
✓ overrides config
88+
✓ overrides env
89+
90+
2 passing
91+
92+
93+
(Tests Finished)
94+
95+
- Tests: 2
96+
- Passes: 2
97+
- Failures: 0
98+
- Pending: 0
99+
- Duration: 10 seconds
100+
- Screenshots: 0
101+
- Video Recorded: true
102+
- Cypress Version: 1.2.3
103+
104+
105+
(Video)
106+
107+
- Started processing: Compressing to 20 CRF
108+
- Finished processing: /foo/bar/.projects/plugin-config/cypress/videos/abc123.mp4 (0 seconds)
109+
110+
76111
(All Done)
77112
78113
`

0 commit comments

Comments
 (0)