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: [Multi-domain]: Support multiple multi-domain commands in a single test #20354

Merged
merged 7 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ describe('multi-domain', { experimentalSessionSupport: true, experimentalMultiDo
cy.switchToDomain('0000:0000:0000:0000:0000:0000:0000:0001', () => undefined)
})

// TODO: this was hanging in CI
it.skip('succeeds on a unicode domain', () => {
it('succeeds on a unicode domain', () => {
cy.switchToDomain('はじめよう.みんな', () => undefined)
})
})
Expand Down
8 changes: 6 additions & 2 deletions packages/driver/src/multi-domain/communicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ const debug = debugFn('cypress:driver:multi-domain')

const CROSS_DOMAIN_PREFIX = 'cross:domain:'

declare global {
interface Window { specBridgeDomain: string }
}

const preprocessErrorForPostMessage = (value) => {
const { isDom } = $dom

Expand Down Expand Up @@ -192,14 +196,14 @@ export class SpecBridgeDomainCommunicator extends EventEmitter {
* @param {any} data - any meta data to be sent with the event.
*/
toPrimary (event: string, data?: any, options = { syncConfig: false }) {
debug('<= to Primary ', event, data, location.hostname)
debug('<= to Primary ', event, data, window.specBridgeDomain)
if (options.syncConfig) this.syncConfigEnvToPrimary()

this.handleSubjectAndErr(data, (data: any) => {
this.windowReference.top.postMessage({
event: `${CROSS_DOMAIN_PREFIX}${event}`,
data,
domain: location.hostname,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The host name is converted into punycode, which will not match the domain specified in the command. To circumvent this and avoid adding a dependency to convert punycode to unicode I have attached the unicode domain name to the window via the server.

domain: window.specBridgeDomain,
}, '*')
})
}
Expand Down
1 change: 1 addition & 0 deletions packages/server/lib/html/multi-domain-iframe.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<body>
<script type="text/javascript">
document.domain = '{{domain}}';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the browser converts document.domain to punycode by default, how helpful, but doesn't provide any API's to convert it back to unicode. So I attach the domain to window below.

window.specBridgeDomain = '{{domain}}';
</script>
<script src="/__cypress/runner/cypress_multi_domain_runner.js"></script>
</body>
Expand Down