Skip to content

Commit

Permalink
Merge pull request #18075 from cypress-io/feature-multidomain
Browse files Browse the repository at this point in the history
feat: Cross Origin Testing Support
  • Loading branch information
mjhenkes committed Apr 25, 2022
2 parents 0bb655e + f473d29 commit 676fc97
Show file tree
Hide file tree
Showing 239 changed files with 16,566 additions and 1,820 deletions.
3 changes: 2 additions & 1 deletion .vscode/launch.json
Expand Up @@ -5,7 +5,8 @@
"type": "node",
"request": "attach",
"name": "Attach by Process ID",
"processId": "${command:PickProcess}"
"processId": "${command:PickProcess}",
"continueOnAttach": true
},
{
"type": "node",
Expand Down
82 changes: 78 additions & 4 deletions circle.yml
Expand Up @@ -29,6 +29,7 @@ mainBuildFilters: &mainBuildFilters
only:
- develop
- 10.0-release
- feature-multidomain
- unify-1449-beta-slug-length

# usually we don't build Mac app - it takes a long time
Expand All @@ -38,6 +39,7 @@ macWorkflowFilters: &mac-workflow-filters
when:
or:
- equal: [ develop, << pipeline.git.branch >> ]
- equal: [ feature-multidomain, << pipeline.git.branch >> ]
- equal: [ unify-1449-beta-slug-length, << pipeline.git.branch >> ]
- matches:
pattern: "-release$"
Expand All @@ -48,6 +50,7 @@ windowsWorkflowFilters: &windows-workflow-filters
or:
- equal: [ master, << pipeline.git.branch >> ]
- equal: [ develop, << pipeline.git.branch >> ]
- equal: [ feature-multidomain, << pipeline.git.branch >> ]
- equal: [ unify-1449-beta-slug-length, << pipeline.git.branch >> ]
- matches:
pattern: "-release$"
Expand Down Expand Up @@ -403,6 +406,10 @@ commands:
description: chrome channel to install
type: string
default: ''
experimentalSessionAndOrigin:
description: experimental flag to apply
type: boolean
default: false
steps:
- restore_cached_workspace
- when:
Expand All @@ -420,8 +427,13 @@ commands:
if [[ -v MAIN_RECORD_KEY ]]; then
# internal PR
CYPRESS_RECORD_KEY=$MAIN_RECORD_KEY \
yarn cypress:run --record --parallel --group 5x-driver-<<parameters.browser>> --browser <<parameters.browser>>
if <<parameters.experimentalSessionAndOrigin>>; then
CYPRESS_RECORD_KEY=$MAIN_RECORD_KEY \
yarn cypress:run-experimentalSessionAndOrigin --record --parallel --group 5x-driver-<<parameters.browser>>-experimentalSessionAndOrigin --browser <<parameters.browser>>
else
CYPRESS_RECORD_KEY=$MAIN_RECORD_KEY \
yarn cypress:run --record --parallel --group 5x-driver-<<parameters.browser>> --browser <<parameters.browser>>
fi
else
# external PR
TESTFILES=$(circleci tests glob "cypress/integration/**/*spec.*" | circleci tests split --total=$CIRCLE_NODE_TOTAL)
Expand All @@ -430,7 +442,11 @@ commands:
if [[ -z "$TESTFILES" ]]; then
echo "Empty list of test files"
fi
yarn cypress:run --browser <<parameters.browser>> --spec $TESTFILES
if <<parameters.experimentalSessionAndOrigin>>; then
yarn cypress:run-experimentalSessionAndOrigin --browser <<parameters.browser>> --spec $TESTFILES
else
yarn cypress:run --browser <<parameters.browser>> --spec $TESTFILES
fi
fi
working_directory: packages/driver
- verify-mocha-results
Expand Down Expand Up @@ -1291,6 +1307,44 @@ jobs:
- run-driver-integration-tests:
browser: electron

driver-integration-tests-chrome-experimentalSessionAndOrigin:
<<: *defaults
resource_class: medium
parallelism: 5
steps:
- run-driver-integration-tests:
browser: chrome
install-chrome-channel: stable
experimentalSessionAndOrigin: true

driver-integration-tests-chrome-beta-experimentalSessionAndOrigin:
<<: *defaults
resource_class: medium
parallelism: 5
steps:
- run-driver-integration-tests:
browser: chrome:beta
install-chrome-channel: beta
experimentalSessionAndOrigin: true

driver-integration-tests-firefox-experimentalSessionAndOrigin:
<<: *defaults
resource_class: medium
parallelism: 5
steps:
- run-driver-integration-tests:
browser: firefox
experimentalSessionAndOrigin: true

driver-integration-tests-electron-experimentalSessionAndOrigin:
<<: *defaults
resource_class: medium
parallelism: 5
steps:
- run-driver-integration-tests:
browser: electron
experimentalSessionAndOrigin: true

desktop-gui-integration-tests-7x:
<<: *defaults
parallelism: 7
Expand Down Expand Up @@ -1604,7 +1658,7 @@ jobs:
- run:
name: Check current branch to persist artifacts
command: |
if [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "unify-1449-beta-slug-length" ]]; then
if [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "unify-1449-beta-slug-length" && "$CIRCLE_BRANCH" != "feature-multidomain" ]]; then
echo "Not uploading artifacts or posting install comment for this branch."
circleci-agent step halt
fi
Expand Down Expand Up @@ -2081,6 +2135,22 @@ linux-workflow: &linux-workflow
context: test-runner:cypress-record-key
requires:
- build
- driver-integration-tests-chrome-experimentalSessionAndOrigin:
context: test-runner:cypress-record-key
requires:
- build
- driver-integration-tests-chrome-beta-experimentalSessionAndOrigin:
context: test-runner:cypress-record-key
requires:
- build
- driver-integration-tests-firefox-experimentalSessionAndOrigin:
context: test-runner:cypress-record-key
requires:
- build
- driver-integration-tests-electron-experimentalSessionAndOrigin:
context: test-runner:cypress-record-key
requires:
- build
- runner-integration-tests-chrome:
context: [test-runner:cypress-record-key, test-runner:percy]
requires:
Expand Down Expand Up @@ -2177,6 +2247,10 @@ linux-workflow: &linux-workflow
- driver-integration-tests-chrome
- driver-integration-tests-chrome-beta
- driver-integration-tests-electron
- driver-integration-tests-firefox-experimentalSessionAndOrigin
- driver-integration-tests-chrome-experimentalSessionAndOrigin
- driver-integration-tests-chrome-beta-experimentalSessionAndOrigin
- driver-integration-tests-electron-experimentalSessionAndOrigin
- system-tests-non-root
- system-tests-firefox
- system-tests-electron
Expand Down
8 changes: 4 additions & 4 deletions cli/schema/cypress.schema.json
Expand Up @@ -253,15 +253,15 @@
"default": false,
"description": "Allows listening to the `before:run`, `after:run`, `before:spec`, and `after:spec` events in the plugins file during interactive mode."
},
"experimentalSourceRewriting": {
"experimentalSessionAndOrigin": {
"type": "boolean",
"default": false,
"description": "Enables AST-based JS/HTML rewriting. This may fix issues caused by the existing regex-based JS/HTML replacement algorithm."
"description": "Enables cross-origin and improved session support, including the `cy.origin` and `cy.session` commands. See https://on.cypress.io/origin and https://on.cypress.io/session."
},
"experimentalSessionSupport": {
"experimentalSourceRewriting": {
"type": "boolean",
"default": false,
"description": "Enable experimental session support. See https://on.cypress.io/session"
"description": "Enables AST-based JS/HTML rewriting. This may fix issues caused by the existing regex-based JS/HTML replacement algorithm."
},
"experimentalFetchPolyfill": {
"type": "boolean",
Expand Down
79 changes: 58 additions & 21 deletions cli/types/cypress.d.ts
Expand Up @@ -56,19 +56,6 @@ declare namespace Cypress {
password: string
}

interface RemoteState {
auth?: {
username: string
password: string
}
domainName: string
strategy: 'file' | 'http'
origin: string
fileServer: string
props: Record<string, any>
visiting: string
}

interface Backend {
/**
* Firefox only: Force Cypress to run garbage collection routines.
Expand Down Expand Up @@ -639,7 +626,7 @@ declare namespace Cypress {
* Trigger action
* @private
*/
action: (action: string, ...args: any[]) => void
action: (action: string, ...args: any[]) => any[] | void

/**
* Load files
Expand Down Expand Up @@ -1064,7 +1051,7 @@ declare namespace Cypress {
/**
* Save/Restore browser Cookies, LocalStorage, and SessionStorage data resulting from the supplied `setup` function.
*
* Only available if the `experimentalSessionSupport` config option is enabled.
* Only available if the `experimentalSessionAndOrigin` config option is enabled.
*
* @see https://on.cypress.io/session
*/
Expand Down Expand Up @@ -1426,6 +1413,29 @@ declare namespace Cypress {
*/
off: Actions

/**
* Enables running Cypress commands in a secondary origin.
* @see https://on.cypress.io/origin
* @example
* cy.origin('example.com', () => {
* cy.get('h1').should('equal', 'Example Domain')
* })
*/
origin<T extends any>(urlOrDomain: string, fn: () => void): Chainable<T>

/**
* Enables running Cypress commands in a secondary origin.
* @see https://on.cypress.io/origin
* @example
* cy.origin('example.com', { args: { key: 'value', foo: 'foo' } }, ({ key, foo }) => {
* expect(key).to.equal('value')
* expect(foo).to.equal('foo')
* })
*/
origin<T, S extends any>(urlOrDomain: string, options: {
args: T
}, fn: (args: T) => void): Chainable<S>

/**
* Get the parent DOM element of a set of DOM elements.
*
Expand Down Expand Up @@ -2822,15 +2832,15 @@ declare namespace Cypress {
*/
scrollBehavior: scrollBehaviorOptions
/**
* Enable experimental session support. See https://on.cypress.io/session
* Allows listening to the `before:run`, `after:run`, `before:spec`, and `after:spec` events in the plugins file during interactive mode.
* @default false
*/
experimentalSessionSupport: boolean
experimentalInteractiveRunEvents: boolean
/**
* Allows listening to the `before:run`, `after:run`, `before:spec`, and `after:spec` events in the plugins file during interactive mode.
* Enables cross-origin and improved session support, including the `cy.origin` and `cy.session` commands. See https://on.cypress.io/origin and https://on.cypress.io/session.
* @default false
*/
experimentalInteractiveRunEvents: boolean
experimentalSessionAndOrigin: boolean
/**
* Generate and save commands directly to your test suite by interacting with your app as an end user would.
* @default false
Expand Down Expand Up @@ -2962,7 +2972,6 @@ declare namespace Cypress {
projectName: string
projectRoot: string
proxyUrl: string
remote: RemoteState
report: boolean
reporterRoute: string
reporterUrl: string
Expand Down Expand Up @@ -5452,6 +5461,21 @@ declare namespace Cypress {
(action: 'task', tasks: Tasks): void
}

interface CodeFrame {
frame: string
language: string
line: number
column: number
absoluteFile: string
originalFile: string
relativeFile: string
}

interface CypressError extends Error {
docsUrl?: string
codeFrame?: CodeFrame
}

// for just a few events like "window:alert" it makes sense to allow passing cy.stub() or
// a user callback function. Others probably only need a callback function.

Expand Down Expand Up @@ -5557,7 +5581,7 @@ declare namespace Cypress {
* This event exists because it's extremely useful for debugging purposes.
* @see https://on.cypress.io/catalog-of-events#App-Events
*/
(action: 'fail', fn: (error: Error, mocha: Mocha.Runnable) => void): Cypress
(action: 'fail', fn: (error: CypressError, mocha: Mocha.Runnable) => void): Cypress
/**
* Fires whenever the viewport changes via a `cy.viewport()` or naturally when
* Cypress resets the viewport to the default between tests. Useful for debugging purposes.
Expand Down Expand Up @@ -5591,6 +5615,12 @@ declare namespace Cypress {
* @see https://on.cypress.io/catalog-of-events#App-Events
*/
(action: 'command:end', fn: (command: CommandQueue) => void): Cypress
/**
* Fires when a command is skipped, namely the `should` command.
* Useful for debugging and understanding how commands are handled.
* @see https://on.cypress.io/catalog-of-events#App-Events
*/
(action: 'skipped:command:end', fn: (command: CommandQueue) => void): Cypress
/**
* Fires whenever a command begins its retrying routines.
* This is called on the trailing edge after Cypress has internally
Expand Down Expand Up @@ -5681,10 +5711,13 @@ declare namespace Cypress {
}

interface EnqueuedCommand {
id: string
name: string
args: any[]
type: string
chainerId: string
injected: boolean
userInvocationStack?: string
fn(...args: any[]): any
}

Expand Down Expand Up @@ -5723,6 +5756,8 @@ declare namespace Cypress {
}

interface LogConfig extends Timeoutable {
/** Unique id for the log, in the form of '<origin>-<number>' */
id: string
/** The JQuery element for the command. This will highlight the command in the main window when debugging */
$el: JQuery
/** The scope of the log entry. If child, will appear nested below parents, prefixed with '-' */
Expand All @@ -5735,6 +5770,8 @@ declare namespace Cypress {
message: any
/** Set to false if you want to control the finishing of the command in the log yourself */
autoEnd: boolean
/** Set to true to immediately finish the log */
end: boolean
/** Return an object that will be printed in the dev tools console */
consoleProps(): ObjectLike
}
Expand Down
2 changes: 1 addition & 1 deletion cli/types/tests/actions.ts
Expand Up @@ -33,7 +33,7 @@ Cypress.on('url:changed', (url) => {
})

Cypress.on('fail', (error, mocha) => {
error // $ExpectType Error
error // $ExpectType CypressError
mocha // $ExpectType Runnable
})

Expand Down
19 changes: 18 additions & 1 deletion cli/types/tests/cypress-tests.ts
Expand Up @@ -904,7 +904,6 @@ namespace CypressTaskTests {
}

namespace CypressSessionsTests {
Cypress.config('experimentalSessionSupport') // $ExpectType boolean
cy.session('user')
cy.session('user', () => {})
cy.session({ name: 'bob' }, () => {})
Expand Down Expand Up @@ -939,3 +938,21 @@ namespace CypressKeyboardTests {
delay: 500 // $ExpectError
})
}

namespace CypressOriginTests {
cy.origin('example.com', () => {})
cy.origin('example.com', { args: {}}, (value: object) => {})
cy.origin('example.com', { args: { one: 1, key: 'value', bool: true } }, (value: { one: number, key: string, bool: boolean}) => {})
cy.origin('example.com', { args: [1, 'value', true ] }, (value: Array<(number | string | boolean)>) => {})
cy.origin('example.com', { args : 'value'}, (value: string) => {})
cy.origin('example.com', { args: 1 }, (value: number) => {})
cy.origin('example.com', { args: true }, (value: boolean) => {})

cy.origin() // $ExpectError
cy.origin('example.com') // $ExpectError
cy.origin(true) // $ExpectError
cy.origin('example.com', {}) // $ExpectError
cy.origin('example.com', {}, {}) // $ExpectError
cy.origin('example.com', { args: ['value'] }, (value: boolean[]) => {}) // $ExpectError
cy.origin('example.com', {}, (value: undefined) => {}) // $ExpectError
}

3 comments on commit 676fc97

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 676fc97 Apr 25, 2022

Choose a reason for hiding this comment

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

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

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/9.6.0/linux-x64/develop-676fc97f46f9798b5f17ee6d292924f8e1a0c82b/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 676fc97 Apr 25, 2022

Choose a reason for hiding this comment

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

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

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/9.6.0/darwin-x64/develop-676fc97f46f9798b5f17ee6d292924f8e1a0c82b/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 676fc97 Apr 25, 2022

Choose a reason for hiding this comment

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

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

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/9.6.0/win32-x64/develop-676fc97f46f9798b5f17ee6d292924f8e1a0c82b/cypress.tgz

Please sign in to comment.