Skip to content

Commit

Permalink
Merge branch 'tgriesser/fix/UNIFY-1408' of github.com:cypress-io/cypr…
Browse files Browse the repository at this point in the history
…ess into tgriesser/fix/UNIFY-1408

* 'tgriesser/fix/UNIFY-1408' of github.com:cypress-io/cypress:
  chore: compare `cy.screenshot` images in percy (#21598)
  • Loading branch information
tgriesser committed May 26, 2022
2 parents b70f346 + 91f58c1 commit 2c5fbcb
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 5 deletions.
10 changes: 10 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,16 @@ commands:
PERCY_ENABLE=${PERCY_TOKEN:-0} \
PERCY_PARALLEL_TOTAL=-1 \
$cmd yarn workspace @packages/<<parameters.package>> cypress:run:<<parameters.type>> --browser <<parameters.browser>> --record --parallel --group <<parameters.package>>-<<parameters.type>>
- run:
command: |
if [[ <<parameters.package>> == 'app' && <<parameters.percy>> == 'true' && -d "packages/app/cypress/screenshots/runner/screenshot/screenshot.cy.tsx/percy" ]]; then
PERCY_PARALLEL_NONCE=$CIRCLE_SHA1 \
PERCY_ENABLE=${PERCY_TOKEN:-0} \
PERCY_PARALLEL_TOTAL=-1 \
yarn percy upload packages/app/cypress/screenshots/runner/screenshot/screenshot.cy.tsx/percy
else
echo "skipping percy screenshots uploading"
fi
- store_test_results:
path: /tmp/cypress
- store_artifacts:
Expand Down
18 changes: 18 additions & 0 deletions packages/app/src/pages/Specs/Runner.vue
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,24 @@ iframe.aut-iframe {
background: white;
}
.is-screenshotting #main-pane {
overflow: auto !important;
}
.is-screenshotting.screenshot-scrolling #main-pane {
overflow: visible !important;
}
#resizable-panels-root {
overflow-x: auto;
overflow-y: hidden;
}
.is-screenshotting #resizable-panels-root {
overflow-x: visible;
overflow-y: visible;
}
iframe.spec-iframe {
border: none;
height: 0;
Expand Down
6 changes: 4 additions & 2 deletions packages/app/src/runner/ResizablePanels.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<template>
<div
class="flex overflow-y-hidden"
id="resizable-panels-root"
class="flex"
:class="{
'select-none': panel1IsDragging || panel2IsDragging,
'overflow-x-auto': !isFirefox
'overflow-x-hidden': isFirefox
}"
@mouseup="handleMouseup"
@mousemove="handleMousemove"
Expand Down Expand Up @@ -209,4 +210,5 @@ watchEffect(() => {
// TODO: UNIFY-1704 - avoid special case for FF
const isFirefox = window.__CYPRESS_BROWSER__?.family === 'firefox'
</script>
2 changes: 1 addition & 1 deletion packages/app/src/runner/SpecRunnerOpenMode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/>
<ResizablePanels
v-else
:style="{width: `calc(100vw - ${collapsedNavBarWidth}px)`}"
:style="{width: `calc(100vw - ${screenshotStore.isScreenshotting ? 0 : collapsedNavBarWidth}px)`}"
:offset-left="collapsedNavBarWidth"
:max-total-width="windowWidth - collapsedNavBarWidth"
:initial-panel1-width="specsListWidthPreferences"
Expand Down
18 changes: 18 additions & 0 deletions packages/app/src/runner/screenshot/screenshot.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ const Layout: FunctionalComponent = () => {

const captureTypes = ['fullPage', 'viewport', 'runner'] as const

function removeGlobalStyles () {
// To help with consistency over time when diffing the images produce in this test
// this function removes global app styles after mounting,
// so that only the CSS injected by the component will be applied.

cy.get('style').each((item) => {
if (item[0].dataset.cy !== 'injected-style-tag') {
item.remove()
}
})

return cy.get('style').should('have.length', 1)
}

describe('screenshot', () => {
captureTypes.forEach((capture) => {
it(`takes a standard screenshot with viewport: ${capture}`, () => {
Expand All @@ -45,6 +59,7 @@ describe('screenshot', () => {
styles,
})

removeGlobalStyles()
cy.screenshot(`percy/component_testing_takes_a_screenshot_viewport_${capture}`, { capture })
})
})
Expand All @@ -55,6 +70,7 @@ describe('screenshot', () => {
styles,
})

removeGlobalStyles()
cy.screenshot('percy/component_testing_screenshot_custom_viewport_screenshot')
})

Expand All @@ -64,6 +80,7 @@ describe('screenshot', () => {
styles,
})

removeGlobalStyles()
cy.screenshot('percy/component_testing_screenshot_long_viewport')
})

Expand Down Expand Up @@ -134,6 +151,7 @@ describe('screenshot', () => {
}

mount(() => <Comp />, { style }).then(() => {
removeGlobalStyles()
cy.screenshot(`percy/large_component_hardcoded_size_viewport_${viewport[0]}_${viewport[1]}`, { capture: 'viewport' })
cy.screenshot(`percy/large_component_hardcoded_size_fullPage_${viewport[0]}_${viewport[1]}`, { capture: 'fullPage' })
})
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/specs/InlineSpecListTree.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div
v-bind="containerProps"
class="pt-8px specs-list-container overflow-y-auto overflow-x-hidden"
class="pt-8px specs-list-container overflow-hidden"
>
<ul
v-bind="wrapperProps"
Expand Down Expand Up @@ -157,7 +157,7 @@ a::before {
}
/** h-[calc] was getting dropped so moved to styles. Virtual list requires defined height. */
/** Header is 64px, padding-bottom is 8px **/
/** Header is 64px, padding-top is 8px **/
.specs-list-container {
height: calc(100vh - 64px - 8px);
}
Expand Down
6 changes: 6 additions & 0 deletions packages/driver/src/cy/commands/screenshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ const scrollOverrides = (win, doc) => {
// hide scrollbars
doc.documentElement.style.overflow = 'hidden'

// this body class is used to set some other overflow-related CSS
// around the resizable panels in the Runner
document.querySelector('body')?.classList.add('screenshot-scrolling')

// in the case that an element might change size on scroll
// we trigger a scroll event to ensure that all elements are
// at their final size before we calculate the total height
Expand All @@ -112,6 +116,8 @@ const scrollOverrides = (win, doc) => {
doc.body.style.overflowY = originalBodyOverflowY
}

document.querySelector('body')?.classList.remove('screenshot-scrolling')

return win.scrollTo(originalX, originalY)
}
}
Expand Down

0 comments on commit 2c5fbcb

Please sign in to comment.