Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Refactor multi-domain communication lifecycle #20247

Merged
merged 27 commits into from Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
458ff7a
chore: refactor multi-domain communication lifecycle
chrisbreiding Feb 17, 2022
53125b9
unskip some tests, fix issues with uncaught errors
chrisbreiding Feb 17, 2022
edf94c3
Merge branch 'feature-multidomain' into md-refactor-comms-lifecycle
chrisbreiding Feb 17, 2022
73e6b6f
Merge branch 'feature-multidomain' into md-refactor-comms-lifecycle
chrisbreiding Feb 17, 2022
e37364b
handle non-object errors
chrisbreiding Feb 17, 2022
1d27118
Merge branch 'feature-multidomain' into md-refactor-comms-lifecycle
chrisbreiding Feb 17, 2022
f548f57
rename some files for consistency
chrisbreiding Feb 18, 2022
9815e9c
remote obselete autorun/pause logic from command queue
chrisbreiding Feb 18, 2022
339884c
bind with once
chrisbreiding Feb 18, 2022
16eaba9
add comment
chrisbreiding Feb 18, 2022
a702d99
simplify resolve call
chrisbreiding Feb 18, 2022
d407917
change name back
chrisbreiding Feb 18, 2022
9bc9fcb
use cy's builti-in doneEarly
chrisbreiding Feb 18, 2022
ad402cd
let -> const
chrisbreiding Feb 18, 2022
170826a
fix commands check logic
chrisbreiding Feb 18, 2022
7f8ab7e
revert error change
chrisbreiding Feb 18, 2022
3c81efa
only bind to uncaught:error once
chrisbreiding Feb 18, 2022
98b3d64
remove line that's not doing anything anyway due to typo
chrisbreiding Feb 18, 2022
516641e
Merge branch 'feature-multidomain' into md-refactor-comms-lifecycle
chrisbreiding Feb 22, 2022
6fd5f98
unskip and fix test
chrisbreiding Feb 22, 2022
f225830
fix subject and err handling
chrisbreiding Feb 22, 2022
6aaf730
remove types using done callback
chrisbreiding Feb 23, 2022
b923a42
fix pause test
chrisbreiding Feb 23, 2022
baa338b
fix issues with queue finish
chrisbreiding Feb 23, 2022
d6908a3
fix pause test in run mode
chrisbreiding Feb 23, 2022
27b0e21
Merge branch 'feature-multidomain' into md-refactor-comms-lifecycle
chrisbreiding Feb 23, 2022
fd53b47
fix log() test
chrisbreiding Feb 23, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -41,43 +41,61 @@ context('multi-domain actions', { experimentalSessionSupport: true, experimental
})
})

it('.submit()', (done) => {
it('.submit()', () => {
cy.get('a[data-cy="dom-link"]').click()

cy.switchToDomain('foobar.com', done, () => {
Cypress.once('form:submitted', () => done())
cy.switchToDomain('foobar.com', () => {
const afterFormSubmitted = new Promise<void>((resolve) => {
cy.once('form:submitted', resolve)
})

cy.get('#input-type-submit').submit()
cy.wrap(afterFormSubmitted)
})
})

it('.click()', (done) => {
it('.click()', () => {
cy.get('a[data-cy="dom-link"]').click()

cy.switchToDomain('foobar.com', done, () => {
cy.get('#button').then((btn) => {
btn.on('click', () => done())
}).click()
cy.switchToDomain('foobar.com', () => {
cy.get('#button').then(($btn) => {
const onClick = new Promise<void>((resolve) => {
$btn.on('click', () => resolve())
chrisbreiding marked this conversation as resolved.
Show resolved Hide resolved
})

cy.wrap($btn).click()
cy.wrap(onClick)
})
})
})

it('.dblclick()', (done) => {
it('.dblclick()', () => {
cy.get('a[data-cy="dom-link"]').click()

cy.switchToDomain('foobar.com', done, () => {
cy.get('#button').then((btn) => {
btn.on('dblclick', () => done())
}).dblclick()
cy.switchToDomain('foobar.com', () => {
cy.get('#button').then(($btn) => {
const afterDblClick = new Promise<void>((resolve) => {
$btn.on('dblclick', () => resolve())
chrisbreiding marked this conversation as resolved.
Show resolved Hide resolved
})

cy.wrap($btn).dblclick()
cy.wrap(afterDblClick)
})
})
})

it('.rightclick()', (done) => {
it('.rightclick()', () => {
cy.get('a[data-cy="dom-link"]').click()

cy.switchToDomain('foobar.com', done, () => {
cy.get('#button').then((btn) => {
btn.on('contextmenu', () => done())
}).rightclick()
cy.switchToDomain('foobar.com', () => {
cy.get('#button').then(($btn) => {
const afterContextmenu = new Promise<void>((resolve) => {
$btn.on('contextmenu', () => resolve())
chrisbreiding marked this conversation as resolved.
Show resolved Hide resolved
})

cy.wrap($btn).rightclick()
cy.wrap(afterContextmenu)
})
})
})

Expand Down Expand Up @@ -129,13 +147,18 @@ context('multi-domain actions', { experimentalSessionSupport: true, experimental
})
})

it('.trigger()', (done) => {
it('.trigger()', () => {
cy.get('a[data-cy="dom-link"]').click()

cy.switchToDomain('foobar.com', done, () => {
cy.get('#button').then((btn) => {
btn.on('click', () => done())
}).trigger('click')
cy.switchToDomain('foobar.com', () => {
cy.get('#button').then(($btn) => {
const afterClick = new Promise<void>((resolve) => {
$btn.on('click', () => resolve())
chrisbreiding marked this conversation as resolved.
Show resolved Hide resolved
})

cy.wrap($btn).trigger('click')
cy.wrap(afterClick)
})
})
})

Expand Down
Expand Up @@ -7,18 +7,35 @@ context('multi-domain misc', { experimentalSessionSupport: true, experimentalMul

it('verifies number of cy commands', () => {
// @ts-ignore
expect(Object.keys(cy.commandFns)).to.deep.equal(
[
'check', 'uncheck', 'click', 'dblclick', 'rightclick', 'focus', 'blur', 'hover', 'scrollIntoView', 'scrollTo', 'select',
'selectFile', 'submit', 'type', 'clear', 'trigger', 'as', 'ng', 'should', 'and', 'clock', 'tick', 'spread', 'each', 'then',
'invoke', 'its', 'getCookie', 'getCookies', 'setCookie', 'clearCookie', 'clearCookies', 'pause', 'debug', 'exec', 'readFile',
'writeFile', 'fixture', 'clearLocalStorage', 'url', 'hash', 'location', 'end', 'noop', 'log', 'wrap', 'reload', 'go', 'visit',
'focused', 'get', 'contains', 'shadow', 'root', 'within', 'request', 'session', 'screenshot', 'task', 'find', 'filter', 'not',
'children', 'eq', 'closest', 'first', 'last', 'next', 'nextAll', 'nextUntil', 'parent', 'parents', 'parentsUntil', 'prev',
'prevAll', 'prevUntil', 'siblings', 'wait', 'title', 'window', 'document', 'viewport', 'server', 'route', 'intercept', 'switchToDomain',
],
'The number of cy commands has changed. Please ensure any newly added commands are also tested in multi-domain.',
)
const actualCommands = Object.keys(cy.commandFns)
const expectedCommands = [
'check', 'uncheck', 'click', 'dblclick', 'rightclick', 'focus', 'blur', 'hover', 'scrollIntoView', 'scrollTo', 'select',
'selectFile', 'submit', 'type', 'clear', 'trigger', 'as', 'ng', 'should', 'and', 'clock', 'tick', 'spread', 'each', 'then',
'invoke', 'its', 'getCookie', 'getCookies', 'setCookie', 'clearCookie', 'clearCookies', 'pause', 'debug', 'exec', 'readFile',
'writeFile', 'fixture', 'clearLocalStorage', 'url', 'hash', 'location', 'end', 'noop', 'log', 'wrap', 'reload', 'go', 'visit',
'focused', 'get', 'contains', 'root', 'shadow', 'within', 'request', 'session', 'screenshot', 'task', 'find', 'filter', 'not',
'children', 'eq', 'closest', 'first', 'last', 'next', 'nextAll', 'nextUntil', 'parent', 'parents', 'parentsUntil', 'prev',
'prevAll', 'prevUntil', 'siblings', 'wait', 'title', 'window', 'document', 'viewport', 'server', 'route', 'intercept', 'switchToDomain',
]
const addedCommands = Cypress._.difference(actualCommands, expectedCommands)
const removedCommands = Cypress._.difference(expectedCommands, actualCommands)

if (addedCommands.length && removedCommands.length) {
throw new Error(`Commands have been added to and removed from Cypress.

The following command(s) were added: ${addedCommands.join(', ')}
The following command(s) were removed: ${removedCommands.join(', ')}

Update this test accordingly.`)
}

if (addedCommands.length) {
throw new Error(`The following command(s) have been added to Cypress: ${addedCommands.join(', ')}. Please add the command(s) to this test.`)
}

if (removedCommands.length) {
throw new Error(`The following command(s) have been removed from Cypress: ${removedCommands.join(', ')}. Please remove the command(s) from this test.`)
}
})

it('.end()', () => {
Expand Down Expand Up @@ -51,24 +68,30 @@ context('multi-domain misc', { experimentalSessionSupport: true, experimentalMul
})
})

it('.log()', (done) => {
cy.switchToDomain('foobar.com', done, () => {
Cypress.once('log:added', () => {
done()
it('.log()', () => {
cy.switchToDomain('foobar.com', () => {
const afterLogAdded = new Promise<void>((resolve) => {
cy.once('log:added', () => {
resolve()
})
chrisbreiding marked this conversation as resolved.
Show resolved Hide resolved
})

cy.log('test log in multi-domain')
cy.wrap(afterLogAdded)
})
})
chrisbreiding marked this conversation as resolved.
Show resolved Hide resolved

it('.pause()', (done) => {
cy.switchToDomain('foobar.com', done, () => {
Cypress.once('paused', () => {
Cypress.emit('resume:all')
done()
it('.pause()', () => {
cy.switchToDomain('foobar.com', () => {
const afterPaused = new Promise<void>((resolve) => {
cy.once('paused', () => {
Cypress.emit('resume:all')
resolve()
})
})

cy.pause()
cy.wrap(afterPaused)
})
})

Expand Down
@@ -1,5 +1,5 @@
// @ts-ignore / session support is needed for visiting about:blank between tests
context('screenshot specs', { experimentalSessionSupport: true, experimentalMultiDomain: true }, () => {
context('multi-domain screenshot', { experimentalSessionSupport: true, experimentalMultiDomain: true }, () => {
beforeEach(() => {
this.serverResult = {
path: '/path/to/screenshot',
Expand Down Expand Up @@ -68,7 +68,7 @@ context('screenshot specs', { experimentalSessionSupport: true, experimentalMult

cy.screenshot()
.then(() => {
expect(automationStub.args[0][1].titles).to.deep.equal(['screenshot specs', 'supports multiple titles'])
expect(automationStub.args[0][1].titles).to.deep.equal(['multi-domain screenshot', 'supports multiple titles'])
})
})
})
Expand Down

This file was deleted.