Skip to content

Commit 70ef58b

Browse files
kucebbrian-mann
authored andcommittedNov 7, 2019
merge all console events in one table (#5606)
* merge all events in one table, cleanup keyboard events * fix tests * reorder table columns, address feedback * set Typed col to user passed input
1 parent 8e309e9 commit 70ef58b

File tree

6 files changed

+491
-443
lines changed

6 files changed

+491
-443
lines changed
 

‎packages/driver/src/cy/commands/actions/click.js

+29-69
Original file line numberDiff line numberDiff line change
@@ -5,58 +5,29 @@ const $dom = require('../../../dom')
55
const $utils = require('../../../cypress/utils')
66
const $actionability = require('../../actionability')
77

8-
const formatMoveEventsTable = (events) => {
9-
return {
10-
name: `Mouse Move Events${events ? '' : ' (skipped)'}`,
11-
data: _.map(events, (obj) => {
12-
const key = _.keys(obj)[0]
13-
const val = obj[_.keys(obj)[0]]
14-
15-
if (val.skipped) {
16-
const reason = val.skipped
17-
18-
// no modifiers can be present
19-
// on move events
20-
return {
21-
'Event Name': key,
22-
'Target Element': reason,
23-
'Prevented Default?': null,
24-
'Stopped Propagation?': null,
25-
}
26-
}
27-
28-
// no modifiers can be present
29-
// on move events
30-
return {
31-
'Event Name': key,
32-
'Target Element': val.el,
33-
'Prevented Default?': val.preventedDefault,
34-
'Stopped Propagation?': val.stoppedPropagation,
35-
}
36-
}),
37-
}
38-
}
39-
408
const formatMouseEvents = (events) => {
419
return _.map(events, (val, key) => {
10+
// get event type either from the keyname, or from the sole object key name
11+
const eventName = (typeof key === 'string') ? key : val.type
12+
4213
if (val.skipped) {
4314
const reason = val.skipped
4415

4516
return {
46-
'Event Name': key,
17+
'Event Type': eventName,
4718
'Target Element': reason,
48-
'Prevented Default?': null,
49-
'Stopped Propagation?': null,
50-
'Modifiers': null,
19+
'Prevented Default': null,
20+
'Stopped Propagation': null,
21+
'Active Modifiers': null,
5122
}
5223
}
5324

5425
return {
55-
'Event Name': key,
26+
'Event Type': eventName,
5627
'Target Element': val.el,
57-
'Prevented Default?': val.preventedDefault,
58-
'Stopped Propagation?': val.stoppedPropagation,
59-
'Modifiers': val.modifiers ? val.modifiers : null,
28+
'Prevented Default': val.preventedDefault || null,
29+
'Stopped Propagation': val.stoppedPropagation || null,
30+
'Active Modifiers': val.modifiers || null,
6031
}
6132
})
6233
}
@@ -243,12 +214,12 @@ module.exports = (Commands, Cypress, cy, state, config) => {
243214
onTable (domEvents) {
244215
return {
245216
1: () => {
246-
return formatMoveEventsTable(domEvents.moveEvents.events)
247-
},
248-
2: () => {
249217
return {
250-
name: 'Mouse Click Events',
251-
data: formatMouseEvents(domEvents.clickEvents),
218+
name: 'Mouse Events',
219+
data: _.concat(
220+
formatMouseEvents(domEvents.moveEvents.events),
221+
formatMouseEvents(domEvents.clickEvents),
222+
),
252223
}
253224
},
254225
}
@@ -275,25 +246,18 @@ module.exports = (Commands, Cypress, cy, state, config) => {
275246
onTable (domEvents) {
276247
return {
277248
1: () => {
278-
return formatMoveEventsTable(domEvents.moveEvents.events)
279-
},
280-
2: () => {
281249
return {
282-
name: 'Mouse Click Events',
250+
name: 'Mouse Events',
283251
data: _.concat(
252+
formatMouseEvents(domEvents.moveEvents.events),
284253
formatMouseEvents(domEvents.clickEvents[0]),
285-
formatMouseEvents(domEvents.clickEvents[1])
254+
formatMouseEvents(domEvents.clickEvents[1]),
255+
formatMouseEvents({
256+
dblclick: domEvents.dblclick,
257+
})
286258
),
287259
}
288260
},
289-
3: () => {
290-
return {
291-
name: 'Mouse Double Click Event',
292-
data: formatMouseEvents({
293-
dblclick: domEvents.dblclick,
294-
}),
295-
}
296-
},
297261
}
298262
},
299263
})
@@ -316,20 +280,16 @@ module.exports = (Commands, Cypress, cy, state, config) => {
316280
onTable (domEvents) {
317281
return {
318282
1: () => {
319-
return formatMoveEventsTable(domEvents.moveEvents.events)
320-
},
321-
2: () => {
322283
return {
323-
name: 'Mouse Click Events',
324-
data: formatMouseEvents(domEvents.clickEvents, formatMouseEvents),
325-
}
326-
},
327-
3: () => {
328-
return {
329-
name: 'Mouse Right Click Event',
330-
data: formatMouseEvents(domEvents.contextmenuEvent),
284+
name: 'Mouse Events',
285+
data: _.concat(
286+
formatMouseEvents(domEvents.moveEvents.events),
287+
formatMouseEvents(domEvents.clickEvents),
288+
formatMouseEvents(domEvents.contextmenuEvent)
289+
),
331290
}
332291
},
292+
333293
}
334294
},
335295
})

‎packages/driver/src/cy/commands/actions/type.js

+23-22
Original file line numberDiff line numberDiff line change
@@ -36,33 +36,39 @@ module.exports = function (Commands, Cypress, cy, state, config) {
3636

3737
const table = {}
3838

39-
const getRow = (id, key, which) => {
39+
const getRow = (id, key, event) => {
4040
if (table[id]) {
4141
return table[id]
4242
}
4343

44-
const obj = table[id] = {}
4544
const modifiers = $Keyboard.modifiersToString(keyboard.getActiveModifiers(state))
4645

47-
if (modifiers) {
48-
obj.modifiers = modifiers
46+
const formatEventDetails = (obj) => {
47+
return `{ ${(Object.keys(obj)
48+
.filter((v) => Boolean(obj[v]))
49+
.map((v) => `${v}: ${obj[v]}`))
50+
.join(', ')
51+
} }`
4952
}
50-
51-
if (key) {
52-
obj.typed = key
53-
54-
if (which) {
55-
obj.which = which
56-
}
53+
const obj = table[id] = {
54+
'Typed': key || null,
55+
'Target Element': event.target,
56+
'Events Fired': '',
57+
'Details': formatEventDetails({ code: event.code, which: event.which }),
58+
'Prevented Default': null,
59+
'Active Modifiers': modifiers || null,
5760
}
5861

5962
return obj
6063
}
6164

62-
updateTable = function (id, key, column, which, value) {
63-
const row = getRow(id, key, which)
65+
updateTable = function (id, key, event, value) {
66+
const row = getRow(id, key, event)
6467

65-
row[column] = value || 'preventedDefault'
68+
row['Events Fired'] += row['Events Fired'] ? `, ${event.type}` : event.type
69+
if (!value) {
70+
row['Prevented Default'] = true
71+
}
6672
}
6773

6874
// transform table object into object with zero based index as keys
@@ -84,13 +90,12 @@ module.exports = function (Commands, Cypress, cy, state, config) {
8490
'Applied To': $dom.getElements(options.$el),
8591
'Options': deltaOptions,
8692
'table': {
87-
// mouse events tables will take up slots 1 and 2 if they're present
93+
// mouse events tables will take up slot 1 if they're present
8894
// this preserves the order of the tables
89-
3: () => {
95+
2: () => {
9096
return {
9197
name: 'Keyboard Events',
9298
data: getTableData(),
93-
columns: ['typed', 'which', 'keydown', 'keypress', 'textInput', 'input', 'keyup', 'change', 'modifiers'],
9499
}
95100
},
96101
},
@@ -271,11 +276,7 @@ module.exports = function (Commands, Cypress, cy, state, config) {
271276
return cy.timeout(totalKeys * options.delay, true, 'type')
272277
},
273278

274-
onEvent (...args) {
275-
if (updateTable) {
276-
return updateTable(...args)
277-
}
278-
},
279+
onEvent: updateTable || _.noop,
279280

280281
// fires only when the 'value'
281282
// of input/text/contenteditable

‎packages/driver/src/cy/keyboard.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ interface KeyDetails {
5252
shiftKeyCode?: number
5353
simulatedDefault?: SimulatedDefault
5454
simulatedDefaultOnly?: boolean
55+
originalSequence?: string
5556
events: {
5657
[key in KeyEventType]?: boolean;
5758
}
@@ -153,16 +154,16 @@ const getFormattedKeyString = (details: KeyDetails) => {
153154
let foundKeyString = _.findKey(keyboardMappings, { key: details.key })
154155

155156
if (foundKeyString) {
156-
return `{${foundKeyString}}`
157+
return `{${details.originalSequence}}`
157158
}
158159

159160
foundKeyString = keyToModifierMap[details.key]
160161

161162
if (foundKeyString) {
162-
return `<${foundKeyString}>`
163+
return `{${details.originalSequence}}`
163164
}
164165

165-
return details.key
166+
return details.originalSequence
166167
}
167168

168169
const countNumIndividualKeyStrokes = (keys: KeyDetails[]) => {
@@ -206,6 +207,8 @@ const getKeyDetails = (onKeyNotFound) => {
206207
details.text = details.key
207208
}
208209

210+
details.originalSequence = key
211+
209212
return details
210213
}
211214

@@ -747,6 +750,8 @@ export class Keyboard {
747750
.then(() => {
748751
if (options.release !== false) {
749752
return Promise.map(modifierKeys, (key) => {
753+
options.id = _.uniqueId('char')
754+
750755
return this.simulatedKeyup(getActiveEl(doc), key, options)
751756
})
752757
}
@@ -898,7 +903,7 @@ export class Keyboard {
898903
const formattedKeyString = getFormattedKeyString(keyDetails)
899904

900905
debug('format string', formattedKeyString)
901-
options.onEvent(options.id, formattedKeyString, eventType, which, dispatched)
906+
options.onEvent(options.id, formattedKeyString, event, dispatched)
902907

903908
return dispatched
904909
}

‎packages/driver/src/cy/mouse.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -247,16 +247,16 @@ const create = (state, keyboard, focused) => {
247247

248248
pointerout()
249249
pointerleave()
250-
events.push({ pointerover: pointerover() })
250+
events.push({ type: 'pointerover', ...pointerover() })
251251
pointerenter()
252252
mouseout()
253253
mouseleave()
254-
events.push({ mouseover: mouseover() })
254+
events.push({ type: 'mouseover', ...mouseover() })
255255
mouseenter()
256256
state('mouseLastHoveredEl', $elements.isAttachedEl(el) ? el : null)
257257
state('mouseCoords', { x, y })
258-
events.push({ pointermove: pointermove() })
259-
events.push({ mousemove: mousemove() })
258+
events.push({ type: 'pointermove', ...pointermove() })
259+
events.push({ type: 'mousemove', ...mousemove() })
260260

261261
return events
262262
},

‎packages/driver/test/cypress/integration/commands/actions/click_spec.js

+401-319
Large diffs are not rendered by default.

‎packages/driver/test/cypress/integration/commands/actions/type_spec.js

+25-25
Original file line numberDiff line numberDiff line change
@@ -4310,39 +4310,40 @@ describe('src/cy/commands/actions/type', () => {
43104310
// https://github.com/cypress-io/cypress/issues/5424
43114311
it('has a table of keys', () => {
43124312
cy.get(':text:first').type('{cmd}{option}foo{enter}b{leftarrow}{del}{enter}')
4313-
.then(function () {
4314-
const table = this.lastLog.invoke('consoleProps').table[3]()
4313+
.then(function ($input) {
4314+
const table = this.lastLog.invoke('consoleProps').table[2]()
43154315

43164316
// eslint-disable-next-line
43174317
console.table(table.data, table.columns)
4318-
expect(table.columns).to.deep.eq([
4319-
'typed', 'which', 'keydown', 'keypress', 'textInput', 'input', 'keyup', 'change', 'modifiers',
4320-
])
43214318

43224319
expect(table.name).to.eq('Keyboard Events')
43234320
const expectedTable = {
4324-
1: { typed: '<meta>', which: 91, keydown: true, modifiers: 'meta' },
4325-
2: { typed: '<alt>', which: 18, keydown: true, modifiers: 'alt, meta' },
4326-
3: { typed: 'f', which: 70, keydown: true, keyup: true, modifiers: 'alt, meta' },
4327-
4: { typed: 'o', which: 79, keydown: true, keyup: true, modifiers: 'alt, meta' },
4328-
5: { typed: 'o', which: 79, keydown: true, keyup: true, modifiers: 'alt, meta' },
4329-
6: { typed: '{enter}', which: 13, keydown: true, keyup: true, modifiers: 'alt, meta' },
4330-
7: { typed: 'b', which: 66, keydown: true, keyup: true, modifiers: 'alt, meta' },
4331-
8: { typed: '{leftArrow}', which: 37, keydown: true, keyup: true, modifiers: 'alt, meta' },
4332-
9: { typed: '{del}', which: 46, keydown: true, keyup: true, modifiers: 'alt, meta' },
4333-
10: { typed: '{enter}', which: 13, keydown: true, keyup: true, modifiers: 'alt, meta' },
4321+
1: { 'Details': '{ code: MetaLeft, which: 91 }', Typed: '{cmd}', 'Events Fired': 'keydown', 'Active Modifiers': 'meta', 'Prevented Default': null, 'Target Element': $input[0] },
4322+
2: { 'Details': '{ code: AltLeft, which: 18 }', Typed: '{option}', 'Events Fired': 'keydown', 'Active Modifiers': 'alt, meta', 'Prevented Default': null, 'Target Element': $input[0] },
4323+
3: { 'Details': '{ code: KeyF, which: 70 }', Typed: 'f', 'Events Fired': 'keydown, keyup', 'Active Modifiers': 'alt, meta', 'Prevented Default': null, 'Target Element': $input[0] },
4324+
4: { 'Details': '{ code: KeyO, which: 79 }', Typed: 'o', 'Events Fired': 'keydown, keyup', 'Active Modifiers': 'alt, meta', 'Prevented Default': null, 'Target Element': $input[0] },
4325+
5: { 'Details': '{ code: KeyO, which: 79 }', Typed: 'o', 'Events Fired': 'keydown, keyup', 'Active Modifiers': 'alt, meta', 'Prevented Default': null, 'Target Element': $input[0] },
4326+
6: { 'Details': '{ code: Enter, which: 13 }', Typed: '{enter}', 'Events Fired': 'keydown, keyup', 'Active Modifiers': 'alt, meta', 'Prevented Default': null, 'Target Element': $input[0] },
4327+
7: { 'Details': '{ code: KeyB, which: 66 }', Typed: 'b', 'Events Fired': 'keydown, keyup', 'Active Modifiers': 'alt, meta', 'Prevented Default': null, 'Target Element': $input[0] },
4328+
8: { 'Details': '{ code: ArrowLeft, which: 37 }', Typed: '{leftarrow}', 'Events Fired': 'keydown, keyup', 'Active Modifiers': 'alt, meta', 'Prevented Default': null, 'Target Element': $input[0] },
4329+
9: { 'Details': '{ code: Delete, which: 46 }', Typed: '{del}', 'Events Fired': 'keydown, keyup', 'Active Modifiers': 'alt, meta', 'Prevented Default': null, 'Target Element': $input[0] },
4330+
10: { 'Details': '{ code: Enter, which: 13 }', Typed: '{enter}', 'Events Fired': 'keydown, keyup', 'Active Modifiers': 'alt, meta', 'Prevented Default': null, 'Target Element': $input[0] },
4331+
11: { 'Details': '{ code: MetaLeft, which: 91 }', Typed: '{cmd}', 'Events Fired': 'keyup', 'Active Modifiers': 'alt', 'Prevented Default': null, 'Target Element': $input[0] },
4332+
12: { 'Details': '{ code: AltLeft, which: 18 }', Typed: '{option}', 'Events Fired': 'keyup', 'Active Modifiers': null, 'Prevented Default': null, 'Target Element': $input[0] },
43344333
}
43354334

4335+
// uncomment for debugging
4336+
// _.each(table.data, (v, i) => expect(v).containSubset(expectedTable[i]))
43364337
expect(table.data).to.deep.eq(expectedTable)
43374338
})
43384339
})
43394340

43404341
it('has no modifiers when there are none activated', () => {
4341-
cy.get(':text:first').type('f').then(function () {
4342-
const table = this.lastLog.invoke('consoleProps').table[3]()
4342+
cy.get(':text:first').type('f').then(function ($el) {
4343+
const table = this.lastLog.invoke('consoleProps').table[2]()
43434344

43444345
expect(table.data).to.deep.eq({
4345-
1: { typed: 'f', which: 70, keydown: true, keypress: true, textInput: true, input: true, keyup: true },
4346+
1: { Typed: 'f', 'Events Fired': 'keydown, keypress, textInput, input, keyup', 'Active Modifiers': null, Details: '{ code: KeyF, which: 70 }', 'Prevented Default': null, 'Target Element': $el[0] },
43464347
})
43474348
})
43484349
})
@@ -4352,14 +4353,14 @@ describe('src/cy/commands/actions/type', () => {
43524353
return false
43534354
})
43544355

4355-
cy.get(':text:first').type('f').then(function () {
4356-
const table = this.lastLog.invoke('consoleProps').table[3]()
4356+
cy.get(':text:first').type('f').then(function ($el) {
4357+
const table = this.lastLog.invoke('consoleProps').table[2]()
43574358

43584359
// eslint-disable-next-line
43594360
console.table(table.data, table.columns)
43604361

43614362
expect(table.data).to.deep.eq({
4362-
1: { typed: 'f', which: 70, keydown: 'preventedDefault', keyup: true },
4363+
1: { Typed: 'f', 'Events Fired': 'keydown, keyup', 'Active Modifiers': null, Details: '{ code: KeyF, which: 70 }', 'Prevented Default': true, 'Target Element': $el[0] },
43634364
})
43644365
})
43654366
})
@@ -5284,10 +5285,9 @@ https://on.cypress.io/type`)
52845285

52855286
$(commandLogEl).find('.command-wrapper').click()
52865287

5287-
expect(spyTableName.firstCall).calledWith('Mouse Move Events')
5288-
expect(spyTableName.secondCall).calledWith('Mouse Click Events')
5289-
expect(spyTableName.thirdCall).calledWith('Keyboard Events')
5290-
expect(spyTableData).calledThrice
5288+
expect(spyTableName.firstCall).calledWith('Mouse Events')
5289+
expect(spyTableName.secondCall).calledWith('Keyboard Events')
5290+
expect(spyTableData).calledTwice
52915291
})
52925292
})
52935293
})

4 commit comments

Comments
 (4)

cypress-bot[bot] commented on Nov 7, 2019

@cypress-bot[bot]
Contributor

Circle has built the linux x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.6.1/linux-x64/circle-develop-70ef58bede981567732697c8b79fe7642ab164cf-186030/cypress.zip
npm install https://cdn.cypress.io/beta/npm/3.6.1/circle-develop-70ef58bede981567732697c8b79fe7642ab164cf-186018/cypress.tgz

cypress-bot[bot] commented on Nov 7, 2019

@cypress-bot[bot]
Contributor

AppVeyor has built the win32 x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.6.1/win32-x64/appveyor-develop-70ef58bede981567732697c8b79fe7642ab164cf-28674100/cypress.zip
npm install https://cdn.cypress.io/beta/binary/3.6.1/win32-x64/appveyor-develop-70ef58bede981567732697c8b79fe7642ab164cf-28674100/cypress.zip

cypress-bot[bot] commented on Nov 7, 2019

@cypress-bot[bot]
Contributor

AppVeyor has built the win32 ia32 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.6.1/win32-ia32/appveyor-develop-70ef58bede981567732697c8b79fe7642ab164cf-28674100/cypress.zip
npm install https://cdn.cypress.io/beta/binary/3.6.1/win32-ia32/appveyor-develop-70ef58bede981567732697c8b79fe7642ab164cf-28674100/cypress.zip

cypress-bot[bot] commented on Nov 7, 2019

@cypress-bot[bot]
Contributor

Circle has built the darwin x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.6.1/darwin-x64/circle-develop-70ef58bede981567732697c8b79fe7642ab164cf-186095/cypress.zip
npm install https://cdn.cypress.io/beta/npm/3.6.1/circle-develop-70ef58bede981567732697c8b79fe7642ab164cf-186031/cypress.tgz
Please sign in to comment.