Skip to content

Commit

Permalink
Merge branch 'develop' into retry-flake
Browse files Browse the repository at this point in the history
  • Loading branch information
flotwig committed Oct 27, 2022
2 parents 1ec4b6d + 9ceb95d commit 23b753e
Show file tree
Hide file tree
Showing 14 changed files with 127 additions and 26 deletions.
7 changes: 7 additions & 0 deletions npm/xpath/CHANGELOG.md
@@ -1,3 +1,10 @@
# [@cypress/xpath-v2.0.3](https://github.com/cypress-io/cypress/compare/@cypress/xpath-v2.0.2...@cypress/xpath-v2.0.3) (2022-10-26)


### Bug Fixes

* **xpath:** update xpath main path ([#24259](https://github.com/cypress-io/cypress/issues/24259)) ([edf99c4](https://github.com/cypress-io/cypress/commit/edf99c41d6031c7a72ad2258f4fd29231823790c))

# [@cypress/xpath-v2.0.2](https://github.com/cypress-io/cypress/compare/@cypress/xpath-v2.0.1...@cypress/xpath-v2.0.2) (2022-09-29)


Expand Down
2 changes: 1 addition & 1 deletion npm/xpath/package.json
Expand Up @@ -2,7 +2,7 @@
"name": "@cypress/xpath",
"version": "0.0.0-development",
"description": "Adds XPath command to Cypress.io test runner",
"main": "scripts",
"main": "src",
"scripts": {
"cy:run": "node ../../scripts/cypress.js run --e2e",
"cy:open": "node ../../scripts/cypress.js open --e2e --project ${PWD}"
Expand Down
22 changes: 3 additions & 19 deletions packages/app/src/runner/event-manager.ts
Expand Up @@ -11,6 +11,7 @@ import { automation, useRunnerUiStore } from '../store'
import { useScreenshotStore } from '../store/screenshot-store'
import { useStudioStore } from '../store/studio-store'
import { getAutIframeModel } from '.'
import { handlePausing } from './events/pausing'

export type CypressInCypressMochaEvent = Array<Array<string | Record<string, any>>>

Expand All @@ -33,7 +34,6 @@ interface AddGlobalListenerOptions {
randomString: string
}

const driverToReporterEvents = 'paused'.split(' ')
const driverToLocalAndReporterEvents = 'run:start run:end'.split(' ')
const driverToSocketEvents = 'backend:request automation:request mocha recorder:frame'.split(' ')
const driverTestEvents = 'test:before:run:async test:after:run'.split(' ')
Expand Down Expand Up @@ -225,18 +225,6 @@ export class EventManager {

this.reporterBus.on('runner:unpin:snapshot', this._unpinSnapshot.bind(this))

this.reporterBus.on('runner:resume', () => {
if (!Cypress) return

Cypress.emit('resume:all')
})

this.reporterBus.on('runner:next', () => {
if (!Cypress) return

Cypress.emit('resume:next')
})

this.reporterBus.on('runner:stop', () => {
if (!Cypress) return

Expand Down Expand Up @@ -538,12 +526,6 @@ export class EventManager {

Cypress.on('after:screenshot', handleAfterScreenshot)

driverToReporterEvents.forEach((event) => {
Cypress.on(event, (...args) => {
this.reporterBus.emit(event, ...args)
})
})

driverTestEvents.forEach((event) => {
Cypress.on(event, (test, cb) => {
this.reporterBus.emit(event, test, cb)
Expand Down Expand Up @@ -596,6 +578,8 @@ export class EventManager {
}
})

handlePausing(this.getCypress, this.reporterBus)

Cypress.on('test:before:run', (...args) => {
Cypress.primaryOriginCommunicator.toAllSpecBridges('test:before:run', ...args)
})
Expand Down
50 changes: 50 additions & 0 deletions packages/app/src/runner/events/pausing.ts
@@ -0,0 +1,50 @@
export const handlePausing = (getCypress, reporterBus) => {
const Cypress = getCypress()
// tracks whether the cy.pause() was called from the primary driver
// (value === null) or from a cross-origin spec bridge (value is the origin
// matching that spec bridge)
let sendEventsToOrigin = null

reporterBus.on('runner:next', () => {
const Cypress = getCypress()

if (!Cypress) return

// if paused from within a cy.origin() callback, send the event to the
// corresponding spec bridge
if (sendEventsToOrigin) {
Cypress.primaryOriginCommunicator.toSpecBridge(sendEventsToOrigin, 'resume:next')
} else {
Cypress.emit('resume:next')
}
})

reporterBus.on('runner:resume', () => {
const Cypress = getCypress()

if (!Cypress) return

// if paused from within a cy.origin() callback, send the event to the
// corresponding spec bridge
if (sendEventsToOrigin) {
Cypress.primaryOriginCommunicator.toSpecBridge(sendEventsToOrigin, 'resume:all')
} else {
Cypress.emit('resume:all')
}

// pause sequence is over - reset this for subsequent pauses
sendEventsToOrigin = null
})

// from the primary driver
Cypress.on('paused', (nextCommandName) => {
reporterBus.emit('paused', nextCommandName)
})

// from a cross-origin spec bridge
Cypress.primaryOriginCommunicator.on('paused', ({ nextCommandName, origin }) => {
sendEventsToOrigin = origin

reporterBus.emit('paused', nextCommandName)
})
}
1 change: 0 additions & 1 deletion packages/driver/cypress/e2e/commands/navigation.cy.js
Expand Up @@ -765,7 +765,6 @@ describe('src/cy/commands/navigation', () => {
})

cy.visit('fixtures/redirection-loop-a.html')
cy.get('div').should('contain', 'this should fail?')
})

if (!Cypress.config('experimentalSessionAndOrigin')) {
Expand Down
6 changes: 6 additions & 0 deletions packages/driver/cypress/e2e/commands/sessions/sessions.cy.js
Expand Up @@ -1754,4 +1754,10 @@ describe('cy.session', { retries: 0 }, () => {
})
})
})

it('should allow more than 20 sessions to be created per test', () => {
for (let index = 0; index < 21; index++) {
cy.session(`${index}`, () => {})
}
})
})
16 changes: 14 additions & 2 deletions packages/driver/cypress/e2e/e2e/origin/commands/misc.cy.ts
Expand Up @@ -37,10 +37,22 @@ context('cy.origin misc', { browser: '!webkit' }, () => {
})

it('.pause()', () => {
// ensures the 'paused' event makes it to the event-manager in the primary.
// if we get cross-origin cy-in-cy test working, we could potentially make
// this even more end-to-end: test out the reporter UI and click the
// resume buttons instead of sending the resume:all event
Cypress.primaryOriginCommunicator.once('paused', ({ nextCommandName, origin }) => {
expect(nextCommandName).to.equal('wrap')
expect(origin).to.equal('http://www.foobar.com:3500')

Cypress.primaryOriginCommunicator.toSpecBridge(origin, 'resume:all')
})

cy.origin('http://www.foobar.com:3500', () => {
const afterPaused = new Promise<void>((resolve) => {
cy.once('paused', () => {
Cypress.emit('resume:all')
// event is sent from the event listener in the primary above,
// ensuring that the pause sequence has come full circle
cy.once('resume:all', () => {
resolve()
})
})
Expand Down
12 changes: 12 additions & 0 deletions packages/driver/src/cross-origin/events/misc.ts
Expand Up @@ -35,4 +35,16 @@ export const handleMiscEvents = (Cypress: Cypress.Cypress, cy: $Cy) => {
Cypress.action('app:window:load', undefined, url)
Cypress.emit('internal:window:load', { type: 'same:origin', url })
})

Cypress.on('paused', (nextCommandName: string) => {
Cypress.specBridgeCommunicator.toPrimary('paused', { nextCommandName, origin: window.origin })
})

Cypress.specBridgeCommunicator.on('resume:next', () => {
Cypress.emit('resume:next')
})

Cypress.specBridgeCommunicator.on('resume:all', () => {
Cypress.emit('resume:all')
})
}
11 changes: 11 additions & 0 deletions packages/driver/src/cy/commands/navigation.ts
Expand Up @@ -315,6 +315,11 @@ const stabilityChanged = async (Cypress, state, config, stable) => {
const onPageLoadErr = (err) => {
state('onPageLoadErr', null)

// If the error thrown is a cypress error, return it instead of throwing a cross origin error.
if ($errUtils.isCypressErr(err)) {
return err
}

const { origin } = $Location.create(window.location.href)

try {
Expand All @@ -336,6 +341,11 @@ const stabilityChanged = async (Cypress, state, config, stable) => {
state('onPageLoadErr', onPageLoadErr)

const getRedirectionCount = (href) => {
// redirecting to about:blank should not count towards the redirection limit.
if (href === 'about:blank') {
return 0
}

// object updated at test:before:run:async
const count = state('redirectionCount')

Expand Down Expand Up @@ -363,6 +373,7 @@ const stabilityChanged = async (Cypress, state, config, stable) => {

if (count === limit) {
$errUtils.throwErrByPath('navigation.reached_redirection_limit', {
onFail: options._log,
args: {
href,
limit,
Expand Down
1 change: 1 addition & 0 deletions packages/driver/src/cy/commands/origin/index.ts
Expand Up @@ -64,6 +64,7 @@ export default (Commands, Cypress: Cypress.Cypress, cy: Cypress.cy, state: State
name: 'origin',
type: 'parent',
message: urlOrDomain,
timeout: 0,
// @ts-ignore TODO: revisit once log-grouping has more implementations
}, (_log) => {
log = _log
Expand Down
5 changes: 4 additions & 1 deletion packages/driver/src/cypress/cy.ts
Expand Up @@ -592,7 +592,10 @@ export class $Cy extends EventEmitter2 implements ITimeouts, IStability, IAssert
// this catches errors thrown by user-registered event handlers
// for `window:load`. this is used in the `catch` below so they
// aren't mistaken as cross-origin errors
err.isFromWindowLoadEvent = true
// If this is a cypress error, pass it on through.
if (!$errUtils.isCypressErr(err)) {
err.isFromWindowLoadEvent = true
}

throw err
} finally {
Expand Down
1 change: 1 addition & 0 deletions packages/driver/types/internal-types.d.ts
Expand Up @@ -58,6 +58,7 @@ declare namespace Cypress {
(action: 'clear:cookies', fn: () => void)
(action: 'cross:origin:cookies', fn: (cookies: AutomationCookie[]) => void)
(action: 'before:stability:release', fn: () => void)
(action: 'paused', fn: (nextCommandName: string) => void)
}

interface Backend {
Expand Down
4 changes: 2 additions & 2 deletions packages/server/lib/modes/run.ts
Expand Up @@ -164,8 +164,8 @@ const openProjectCreate = (projectRoot, socketId, args) => {

async function checkAccess (folderPath) {
return fs.access(folderPath, fs.constants.W_OK).catch((err) => {
if (['EACCES', 'EPERM'].includes(err.code)) {
// we cannot write due to folder permissions
if (['EACCES', 'EPERM', 'EROFS'].includes(err.code)) {
// we cannot write due to folder permissions, or read-only filesystem
return errors.warning('FOLDER_NOT_WRITABLE', folderPath)
}

Expand Down
15 changes: 15 additions & 0 deletions packages/server/test/unit/project_spec.js
Expand Up @@ -611,6 +611,21 @@ This option will not have an effect in Some-other-name. Tests that rely on web s
expect(err.code).to.eq('EPERM')
})
})

it('bubbles up Settings.read EROFS error', function () {
const err = new Error()

err.code = 'EROFS'

sinon.stub(settings, 'read').rejects(err)

return this.project.getProjectId()
.then((id) => {
throw new Error('expected to fail, but did not')
}).catch((err) => {
expect(err.code).to.eq('EROFS')
})
})
})
})

Expand Down

5 comments on commit 23b753e

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 23b753e Oct 27, 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/10.11.1/linux-x64/retry-flake-23b753eb3d04156a348996a4847d543fa1c59223/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 23b753e Oct 27, 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 arm64 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/10.11.1/linux-arm64/retry-flake-23b753eb3d04156a348996a4847d543fa1c59223/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 23b753e Oct 27, 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/10.11.1/win32-x64/retry-flake-23b753eb3d04156a348996a4847d543fa1c59223/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 23b753e Oct 27, 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/10.11.1/darwin-x64/retry-flake-23b753eb3d04156a348996a4847d543fa1c59223/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 23b753e Oct 27, 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 arm64 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/10.11.1/darwin-arm64/retry-flake-23b753eb3d04156a348996a4847d543fa1c59223/cypress.tgz

Please sign in to comment.