Skip to content

Commit b7002bf

Browse files
fix: test config overrides leak for .only execution (#18961)
1 parent de4fca3 commit b7002bf

File tree

9 files changed

+158
-1457
lines changed

9 files changed

+158
-1457
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"npm-release": "node scripts/npm-release.js",
4444
"prestart": "yarn ensure-deps",
4545
"start": "cypress open --dev --global",
46-
"stop-only": "npx stop-only --skip .cy,.publish,.projects,node_modules,dist,dist-test,fixtures,lib,bower_components,src,__snapshots__ --exclude e2e.ts,cypress-tests.ts",
46+
"stop-only": "npx stop-only --skip .cy,.publish,.projects,node_modules,dist,dist-test,fixtures,lib,bower_components,src,__snapshots__ --exclude e2e.ts,cypress-tests.ts,*only_spec.js",
4747
"stop-only-all": "yarn stop-only --folder packages",
4848
"pretest": "yarn ensure-deps",
4949
"test": "yarn lerna exec yarn test --scope cypress --scope \"'@packages/{config,electron,extension,https-proxy,launcher,net-stubbing,network,proxy,rewriter,runner,runner-shared,socket}'\"",

packages/config/lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ module.exports = {
5959
options,
6060

6161
validate: (cfg, onErr) => {
62-
debug('validating configuration')
62+
debug('validating configuration', cfg)
6363

6464
return _.each(cfg, (value, key) => {
6565
const validationFn = validationRules[key]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const shouldNotExecute = () => {
2+
throw new Error('Test Override validation should have failed & it block should not have executed.')
3+
}
4+
5+
it('first should not run', () => {
6+
shouldNotExecute()
7+
})
8+
9+
describe('second should not run', () => {
10+
it('test', () => {
11+
shouldNotExecute()
12+
})
13+
})
14+
15+
describe('correctly applies overrides ', { retries: 1 }, () => {
16+
// eslint-disable-next-line mocha/no-exclusive-tests
17+
describe.only('when valid configuration', () => {
18+
it('for describe.only', { baseUrl: null }, () => {
19+
const config = Cypress.config()
20+
21+
expect(config.testConfigList).to.be.undefined
22+
expect(config.unverifiedTestConfig).to.be.undefined
23+
expect(config.baseUrl).to.be.null
24+
expect(config.retries).to.eq(1)
25+
})
26+
})
27+
})
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const shouldNotExecute = () => {
2+
throw new Error('Test Override validation should have failed & it block should not have executed.')
3+
}
4+
5+
it('first should not run', () => {
6+
shouldNotExecute()
7+
})
8+
9+
describe('second should not run', () => {
10+
it('test', () => {
11+
shouldNotExecute()
12+
})
13+
})
14+
15+
describe('correctly applies overrides when valid configuration', { retries: 1 }, () => {
16+
// eslint-disable-next-line mocha/no-exclusive-tests
17+
it.only('for it.only', { baseUrl: null }, () => {
18+
const config = Cypress.config()
19+
20+
expect(config.testConfigList).to.be.undefined
21+
expect(config.unverifiedTestConfig).to.be.undefined
22+
expect(config.baseUrl).to.be.null
23+
expect(config.retries).to.eq(1)
24+
})
25+
})

packages/driver/src/cy/testConfigOverrides.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -109,27 +109,29 @@ function mutateConfiguration (testConfig: ResolvedTestConfigOverride, config, en
109109
// in order to resolve the test config upfront before test runs
110110
// note: must return as an object to meet the dashboard recording API
111111
export function getResolvedTestConfigOverride (test): ResolvedTestConfigOverride {
112-
let curParent = test.parent
113-
const testConfigList = [{
114-
overrides: test._testConfig,
115-
invocationDetails: test.invocationDetails,
116-
}]
117-
118-
while (curParent) {
119-
if (curParent._testConfig) {
120-
testConfigList.unshift({
121-
overrides: curParent._testConfig,
122-
invocationDetails: curParent.invocationDetails,
123-
})
112+
let curr = test
113+
let testConfigList: TestConfig[] = []
114+
115+
while (curr) {
116+
if (curr._testConfig) {
117+
if (curr._testConfig.testConfigList) {
118+
// configuration for mocha function has already been processed
119+
testConfigList = testConfigList.concat(curr._testConfig.testConfigList)
120+
} else {
121+
testConfigList.unshift({
122+
overrides: curr._testConfig,
123+
invocationDetails: curr.invocationDetails,
124+
})
125+
}
124126
}
125127

126-
curParent = curParent.parent
128+
curr = curr.parent
127129
}
128130

129131
const testConfig = {
130-
testConfigList: testConfigList.filter((opt) => opt.overrides !== undefined),
132+
testConfigList: testConfigList.filter(({ overrides }) => overrides !== undefined),
131133
// collect test overrides to send to the dashboard api when @packages/server is ran in record mode
132-
unverifiedTestConfig: _.reduce(testConfigList, (acc, opts) => _.extend(acc, opts.overrides), {}),
134+
unverifiedTestConfig: _.reduce(testConfigList, (acc, { overrides }) => _.extend(acc, overrides), {}),
133135
}
134136

135137
return testConfig

packages/driver/src/cypress/mocha.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ function overloadMochaFnForConfig (fnName, specWindow) {
107107
overrideMochaFn(replacementFn)
108108
}
109109

110-
const ui = (specWindow, _mocha, config) => {
110+
const ui = (specWindow, _mocha) => {
111111
// Override mocha.ui so that the pre-require event is emitted
112112
// with the iframe's `window` reference, rather than the parent's.
113113
_mocha.ui = function (name) {

packages/runner/__snapshots__/retries.mochaEvents.spec.js

Lines changed: 16 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,19 +1007,8 @@ exports['src/cypress/runner retries mochaEvents test retry with [only] #1'] = [
10071007
"test:before:run",
10081008
{
10091009
"_testConfig": {
1010-
"testConfigList": [
1011-
{
1012-
"overrides": {
1013-
"testConfigList": [],
1014-
"unverifiedTestConfig": {}
1015-
},
1016-
"invocationDetails": "{Object 9}"
1017-
}
1018-
],
1019-
"unverifiedTestConfig": {
1020-
"testConfigList": [],
1021-
"unverifiedTestConfig": {}
1022-
}
1010+
"testConfigList": [],
1011+
"unverifiedTestConfig": {}
10231012
},
10241013
"id": "r3",
10251014
"order": 1,
@@ -1057,19 +1046,8 @@ exports['src/cypress/runner retries mochaEvents test retry with [only] #1'] = [
10571046
"test",
10581047
{
10591048
"_testConfig": {
1060-
"testConfigList": [
1061-
{
1062-
"overrides": {
1063-
"testConfigList": [],
1064-
"unverifiedTestConfig": {}
1065-
},
1066-
"invocationDetails": "{Object 9}"
1067-
}
1068-
],
1069-
"unverifiedTestConfig": {
1070-
"testConfigList": [],
1071-
"unverifiedTestConfig": {}
1072-
}
1049+
"testConfigList": [],
1050+
"unverifiedTestConfig": {}
10731051
},
10741052
"id": "r3",
10751053
"order": 1,
@@ -1152,19 +1130,8 @@ exports['src/cypress/runner retries mochaEvents test retry with [only] #1'] = [
11521130
"retry",
11531131
{
11541132
"_testConfig": {
1155-
"testConfigList": [
1156-
{
1157-
"overrides": {
1158-
"testConfigList": [],
1159-
"unverifiedTestConfig": {}
1160-
},
1161-
"invocationDetails": "{Object 9}"
1162-
}
1163-
],
1164-
"unverifiedTestConfig": {
1165-
"testConfigList": [],
1166-
"unverifiedTestConfig": {}
1167-
}
1133+
"testConfigList": [],
1134+
"unverifiedTestConfig": {}
11681135
},
11691136
"id": "r3",
11701137
"order": 1,
@@ -1264,19 +1231,8 @@ exports['src/cypress/runner retries mochaEvents test retry with [only] #1'] = [
12641231
"test:after:run",
12651232
{
12661233
"_testConfig": {
1267-
"testConfigList": [
1268-
{
1269-
"overrides": {
1270-
"testConfigList": [],
1271-
"unverifiedTestConfig": {}
1272-
},
1273-
"invocationDetails": "{Object 9}"
1274-
}
1275-
],
1276-
"unverifiedTestConfig": {
1277-
"testConfigList": [],
1278-
"unverifiedTestConfig": {}
1279-
}
1234+
"testConfigList": [],
1235+
"unverifiedTestConfig": {}
12801236
},
12811237
"id": "r3",
12821238
"order": 1,
@@ -1353,19 +1309,8 @@ exports['src/cypress/runner retries mochaEvents test retry with [only] #1'] = [
13531309
"test:before:run",
13541310
{
13551311
"_testConfig": {
1356-
"testConfigList": [
1357-
{
1358-
"overrides": {
1359-
"testConfigList": [],
1360-
"unverifiedTestConfig": {}
1361-
},
1362-
"invocationDetails": "{Object 9}"
1363-
}
1364-
],
1365-
"unverifiedTestConfig": {
1366-
"testConfigList": [],
1367-
"unverifiedTestConfig": {}
1368-
}
1312+
"testConfigList": [],
1313+
"unverifiedTestConfig": {}
13691314
},
13701315
"id": "r3",
13711316
"title": "test 2",
@@ -1472,19 +1417,8 @@ exports['src/cypress/runner retries mochaEvents test retry with [only] #1'] = [
14721417
"pass",
14731418
{
14741419
"_testConfig": {
1475-
"testConfigList": [
1476-
{
1477-
"overrides": {
1478-
"testConfigList": [],
1479-
"unverifiedTestConfig": {}
1480-
},
1481-
"invocationDetails": "{Object 9}"
1482-
}
1483-
],
1484-
"unverifiedTestConfig": {
1485-
"testConfigList": [],
1486-
"unverifiedTestConfig": {}
1487-
}
1420+
"testConfigList": [],
1421+
"unverifiedTestConfig": {}
14881422
},
14891423
"id": "r3",
14901424
"title": "test 2",
@@ -1533,19 +1467,8 @@ exports['src/cypress/runner retries mochaEvents test retry with [only] #1'] = [
15331467
"test end",
15341468
{
15351469
"_testConfig": {
1536-
"testConfigList": [
1537-
{
1538-
"overrides": {
1539-
"testConfigList": [],
1540-
"unverifiedTestConfig": {}
1541-
},
1542-
"invocationDetails": "{Object 9}"
1543-
}
1544-
],
1545-
"unverifiedTestConfig": {
1546-
"testConfigList": [],
1547-
"unverifiedTestConfig": {}
1548-
}
1470+
"testConfigList": [],
1471+
"unverifiedTestConfig": {}
15491472
},
15501473
"id": "r3",
15511474
"title": "test 2",
@@ -1608,19 +1531,8 @@ exports['src/cypress/runner retries mochaEvents test retry with [only] #1'] = [
16081531
"test:after:run",
16091532
{
16101533
"_testConfig": {
1611-
"testConfigList": [
1612-
{
1613-
"overrides": {
1614-
"testConfigList": [],
1615-
"unverifiedTestConfig": {}
1616-
},
1617-
"invocationDetails": "{Object 9}"
1618-
}
1619-
],
1620-
"unverifiedTestConfig": {
1621-
"testConfigList": [],
1622-
"unverifiedTestConfig": {}
1623-
}
1534+
"testConfigList": [],
1535+
"unverifiedTestConfig": {}
16241536
},
16251537
"id": "r3",
16261538
"title": "test 2",

0 commit comments

Comments
 (0)