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

fix: only adjust autoscrolling in interactive mode #23053

Merged
merged 17 commits into from Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
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
12 changes: 11 additions & 1 deletion packages/reporter/cypress/e2e/runnables.cy.ts
Expand Up @@ -26,8 +26,9 @@ describe('runnables', () => {

runner = new EventEmitter()

render = (renderProps: Partial<BaseReporterProps> = {}) => {
render = (renderProps: Partial<BaseReporterProps> = {}, cypressMode = 'open') => {
marktnoonan marked this conversation as resolved.
Show resolved Hide resolved
cy.visit('/').then((win: Cypress.AUTWindow) => {
win.__CYPRESS_MODE__ = cypressMode
win.render({
runner,
studioEnabled: renderProps.studioEnabled || false,
Expand Down Expand Up @@ -201,5 +202,14 @@ describe('runnables', () => {
expect(runner.emit).to.be.calledWith('open:file:unified')
})
})

it('adds a scroll listener in open mode', () => {
cy.get('[data-cy-scroll-listen]').should('have.attr', 'data-cy-scroll-listen', 'true')
})

it('does not add a scroll listener in run mode', () => {
render({}, 'run')
cy.get('[data-cy-scroll-listen]').should('have.attr', 'data-cy-scroll-listen', 'false')
})
})
})
2 changes: 1 addition & 1 deletion packages/reporter/src/lib/scroller.ts
Expand Up @@ -15,7 +15,7 @@

import { TimeoutID } from './types'

type UserScrollCallback = () => void
export type UserScrollCallback = () => void

const PADDING = 100

Expand Down
1 change: 1 addition & 0 deletions packages/reporter/src/main.tsx
Expand Up @@ -144,6 +144,7 @@ declare global {
Cypress: any
state: AppState
render: ((props: Partial<BaseReporterProps>) => void)
__CYPRESS_MODE__: 'run' | 'open'
}
}

Expand Down
32 changes: 26 additions & 6 deletions packages/reporter/src/runnables/runnables.tsx
Expand Up @@ -9,7 +9,7 @@ import Runnable from './runnable-and-suite'
import RunnableHeader from './runnable-header'
import { RunnablesStore, RunnableArray } from './runnables-store'
import statsStore, { StatsStore } from '../header/stats-store'
import { Scroller } from '../lib/scroller'
import { Scroller, UserScrollCallback } from '../lib/scroller'
import type { AppState } from '../lib/app-state'
import OpenFileInIDE from '../lib/open-file-in-ide'

Expand Down Expand Up @@ -176,11 +176,31 @@ class Runnables extends Component<RunnablesProps> {
componentDidMount () {
const { scroller, appState } = this.props

scroller.setContainer(this.refs.container as Element, action('user:scroll:detected', () => {
if (appState && appState.isRunning) {
appState.temporarilySetAutoScrolling(false)
}
}))
let maybeHandleScroll: UserScrollCallback | undefined = undefined

const containerEl = this.refs.container as HTMLElement

if (window.__CYPRESS_MODE__ === 'open') {
// in open mode, listen for scroll events so that users can pause the command log auto-scroll
// by manually scrolling the command log
containerEl.setAttribute('data-cy-scroll-listen', 'true')
maybeHandleScroll = action('user:scroll:detected', () => {
marktnoonan marked this conversation as resolved.
Show resolved Hide resolved
if (appState && appState.isRunning) {
appState.temporarilySetAutoScrolling(false)
}
})
} else {
// in run mode, still add the data attribute so the tests have an explicit test locator,
// but do not do any scroll handling. No user is scrolling in run mode and it can
// cause problems in video recordings by incorrectly turning off autoscrolling,
// see issue https://github.com/cypress-io/cypress/issues/16098
containerEl.setAttribute('data-cy-scroll-listen', 'false')
}

// we need to always call scroller.setContainer, but the callback can be undefined
// so we pass maybeHandleScroll. If we don't, Cypress blows up with an error like
// `A container must be set on the scroller with scroller.setContainer(container)`
scroller.setContainer(this.refs.container as Element, maybeHandleScroll)
}
}

Expand Down