Skip to content

Commit

Permalink
chore: update FF tests to 115 as serialization now works with errors …
Browse files Browse the repository at this point in the history
…and click events do not get fired on buttons being typed into
  • Loading branch information
AtofStryker committed Sep 2, 2023
1 parent 9d16713 commit 313ea25
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .circleci/workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ commands:
- run:
name: Types check 🧩 (maybe)
working_directory: /tmp/<<parameters.repo>>
command: yarn types
command: yarn types --ignore-engines
- run:
working_directory: /tmp/<<parameters.repo>>
command: <<parameters.server-start-command>>
Expand Down
59 changes: 44 additions & 15 deletions packages/driver/cypress/e2e/commands/actions/type_events.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -594,29 +594,48 @@ describe('src/cy/commands/actions/type - #type events', () => {
]

targets.forEach((target) => {
// NOTE: newer versions of firefox do NOT trigger a click event on buttons when typed into
const shouldEvaluateClickForEl = target !== 'button-tag' || Cypress.browser.name !== 'firefox'

// TODO fix this test in Webkit /~https://github.com/cypress-io/cypress/issues/26438
it(target, { browser: '!webkit' }, () => {
cy.get(`#target-${target}`).focus().type('{enter}')

cy.get('li').should('have.length', 4)
cy.get('li').eq(0).should('have.text', 'keydown')
cy.get('li').eq(1).should('have.text', 'keypress')
cy.get('li').eq(2).should('have.text', 'click')
cy.get('li').eq(3).should('have.text', 'keyup')
if (shouldEvaluateClickForEl) {
cy.get('li').should('have.length', 4)
cy.get('li').eq(0).should('have.text', 'keydown')
cy.get('li').eq(1).should('have.text', 'keypress')
cy.get('li').eq(2).should('have.text', 'click')
cy.get('li').eq(3).should('have.text', 'keyup')
} else {
cy.get('li').should('have.length', 3)
cy.get('li').eq(0).should('have.text', 'keydown')
cy.get('li').eq(1).should('have.text', 'keypress')
cy.get('li').eq(2).should('have.text', 'keyup')
}
})
})

describe('keydown triggered on another element', () => {
targets.forEach((target) => {
// NOTE: newer versions of firefox do NOT trigger a click event on buttons when typed into
const shouldEvaluateClickForEl = target !== 'button-tag' || Cypress.browser.name !== 'firefox'

// TODO fix this test in Webkit /~https://github.com/cypress-io/cypress/issues/26438
it(target, { browser: '!webkit' }, () => {
cy.get('#focus-options').select(target)
cy.get('#input-text').focus().type('{enter}')

cy.get('li').should('have.length', 3)
cy.get('li').eq(0).should('have.text', 'keypress')
cy.get('li').eq(1).should('have.text', 'click')
cy.get('li').eq(2).should('have.text', 'keyup')
if (shouldEvaluateClickForEl) {
cy.get('li').should('have.length', 3)
cy.get('li').eq(0).should('have.text', 'keypress')
cy.get('li').eq(1).should('have.text', 'click')
cy.get('li').eq(2).should('have.text', 'keyup')
} else {
cy.get('li').should('have.length', 2)
cy.get('li').eq(0).should('have.text', 'keypress')
cy.get('li').eq(1).should('have.text', 'keyup')
}
})
})
})
Expand Down Expand Up @@ -658,11 +677,11 @@ describe('src/cy/commands/actions/type - #type events', () => {
it('propagates through shadow roots', () => {
cy.visit('fixtures/shadow-dom-button.html')

cy.get('cy-test-element').invoke('on', 'click', cy.spy().as('clickSpy'))
cy.get('cy-test-element').invoke('on', 'keyup', cy.spy().as('keyUpSpy'))

cy.get('cy-test-element').shadow().find('button').focus().type('{enter}')

cy.get('@clickSpy').should('have.been.called')
cy.get('@keyUpSpy').should('have.been.called')
})
})
})
Expand All @@ -682,6 +701,9 @@ describe('src/cy/commands/actions/type - #type events', () => {

describe(`triggers with single space`, () => {
targets.forEach((target) => {
// NOTE: newer versions of firefox do NOT trigger a click event on buttons when typed into
const shouldEvaluateClickForEl = target !== '#target-button-tag' || Cypress.browser.name !== 'firefox'

it(target, () => {
const events = []

Expand All @@ -694,14 +716,16 @@ describe('src/cy/commands/actions/type - #type events', () => {
'keydown',
'keypress',
'keyup',
'click',
...(shouldEvaluateClickForEl ? ['click'] : []),
])
})

cy.get('li').eq(0).should('have.text', 'keydown')
cy.get('li').eq(1).should('have.text', 'keypress')
cy.get('li').eq(2).should('have.text', 'keyup')
cy.get('li').eq(3).should('have.text', 'click')
if (shouldEvaluateClickForEl) {
cy.get('li').eq(3).should('have.text', 'click')
}
})
})
})
Expand Down Expand Up @@ -737,6 +761,9 @@ describe('src/cy/commands/actions/type - #type events', () => {

describe('triggers after other characters', () => {
targets.forEach((target) => {
// NOTE: newer versions of firefox do NOT trigger a click event on buttons when typed into
const shouldEvaluateClickForEl = target !== '#target-button-tag' || Cypress.browser.name !== 'firefox'

it(target, () => {
const events = []

Expand All @@ -758,11 +785,13 @@ describe('src/cy/commands/actions/type - #type events', () => {
'keydown',
'keypress',
'keyup',
'click',
...(shouldEvaluateClickForEl ? ['click'] : []),
])
})

cy.get('li').eq(12).should('have.text', 'click')
if (shouldEvaluateClickForEl) {
cy.get('li').eq(12).should('have.text', 'click')
}
})
})
})
Expand Down
17 changes: 3 additions & 14 deletions packages/driver/cypress/e2e/e2e/origin/config_env.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,21 +233,10 @@
})

context('structuredClone()', () => {
it('(firefox) uses native structuredClone in firefox and does NOT serialize Error objects in config', {
browser: 'firefox',
}, function () {
Cypress[fnName](USED_KEYS.error, new Error('error'))

cy.origin('http://www.foobar.com:3500', { args: { fnName, USED_KEYS } }, ({ fnName, USED_KEYS }) => {
const isUndefined = Cypress[fnName](USED_KEYS.error)

expect(isUndefined).to.be.undefined
})
})

// NOTE: chrome 98 and above uses a native structuredClone() method, but that method CAN clone Error objects
it('(chromium) uses ponyfilled or native structuredClone that can serialize Error objects in config', {
browser: { family: 'chromium' },
// NOTE: firefox 114 can now serialize/clone error objects
it('uses ponyfilled or native structuredClone that can serialize Error objects in config', {
browser: '!webkit',
}, () => {
Cypress[fnName](USED_KEYS.error, new Error('error'))

Expand Down
2 changes: 1 addition & 1 deletion packages/driver/cypress/e2e/e2e/origin/validation.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ describe('cy.origin', { browser: '!webkit' }, () => {
if (Cypress.browser.family === 'chromium') {
expect(err.message).to.include('HTMLDivElement object could not be cloned')
} else if (Cypress.browser.family === 'firefox') {
expect(err.message).to.include('The object could not be cloned')
expect(err.message).to.include('object could not be cloned')
}

done()
Expand Down
8 changes: 4 additions & 4 deletions packages/driver/src/util/serialization/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ To determine if a given value is serializable, the value is passed as an argumen

[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) preprocessing is a bit complicated, because the error object itself may be considered serializable depending on the browser's implementation of the structured clone algorithm.

At the time of this writing, the structured clone algorithm does NOT support cloning of errors in Firefox, but is supported in Chromium and `core-js`. However, there are caveats to this support. Take the following snippet:
At the time of this writing, the structured clone algorithm does support cloning of errors in Firefox 99, but is supported in newer versions of Firefox (such as 115) and is supported in Chromium and `core-js`. However, there are caveats to this support. Take the following snippet:

```js
// firefox
// older firefox version 99
var myError = new Error('error-message')
var myErrorCopy = structuredClone(myError) // throws DOMException: The object could not be cloned
var myErrorCopy = structuredClone(myError) // throws DOMException: object could not be cloned

// chrome/edge/electron
// chrome/edge/electron/firefox115+
var myError = new Error('error-message')
myError.foo = 'bar'
var myErrorCopy = structuredClone(myError)
Expand Down
2 changes: 1 addition & 1 deletion system-tests/test-binary/module_api_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import systemTests from '../lib/system-tests'
describe('module API', () => {
systemTests.it('can run module API Mocha spec', {
timeout: 240000,
dockerImage: 'ypress/base-internal:18.15.0',
dockerImage: 'cypress/base-internal:18.15.0',
withBinary: true,
project: 'module-api',
browser: 'electron',
Expand Down

0 comments on commit 313ea25

Please sign in to comment.