Fix e2e visual regression tests by always showing Updates badge in CI

- ensure that window.__IS_VISUAL_REGRESSION_TESTING is true when CI=1
This commit is contained in:
Cole Lawrence 2022-08-02 09:11:19 -04:00
parent 963b03ab6e
commit ea3e7434c6
3 changed files with 24 additions and 3 deletions

View file

@ -25,6 +25,8 @@ const testDir = playgroundDir('src/tests')
export async function start(options: { export async function start(options: {
/** enable live reload and watching stuff */ /** enable live reload and watching stuff */
dev: boolean dev: boolean
/** make some UI elements predictable by setting the __IS_VISUAL_REGRESSION_TESTING value on window */
isVisualRegressionTesting: boolean
serve?: { serve?: {
findAvailablePort: boolean findAvailablePort: boolean
openBrowser: boolean openBrowser: boolean
@ -169,7 +171,9 @@ export async function start(options: {
}, },
define: { define: {
...definedGlobals, ...definedGlobals,
'window.__IS_VISUAL_REGRESSION_TESTING': 'true', 'window.__IS_VISUAL_REGRESSION_TESTING': JSON.stringify(
options.isVisualRegressionTesting,
),
}, },
banner: liveReload?.esbuildBanner, banner: liveReload?.esbuildBanner,
watch: liveReload?.esbuildWatch && { watch: liveReload?.esbuildWatch && {

View file

@ -21,6 +21,7 @@ function onUpdatedBuildScript(rebuild) {
module module
.start({ .start({
dev: !isCI && dev, dev: !isCI && dev,
isVisualRegressionTesting: isCI,
serve: serve && { serve: serve && {
findAvailablePort: !isCI, findAvailablePort: !isCI,
// If not in CI, try to spawn a browser // If not in CI, try to spawn a browser

View file

@ -1,6 +1,6 @@
import {usePrism, useVal} from '@theatre/react' import {usePrism, useVal} from '@theatre/react'
import getStudio from '@theatre/studio/getStudio' import getStudio from '@theatre/studio/getStudio'
import React, {useRef} from 'react' import React, {useMemo, useRef} from 'react'
import styled from 'styled-components' import styled from 'styled-components'
import type {$IntentionalAny} from '@theatre/dataverse/dist/types' import type {$IntentionalAny} from '@theatre/dataverse/dist/types'
import useTooltip from '@theatre/studio/uiComponents/Popover/useTooltip' import useTooltip from '@theatre/studio/uiComponents/Popover/useTooltip'
@ -65,6 +65,8 @@ const GroupDivider = styled.div`
opacity: 0.4; opacity: 0.4;
` `
let showedVisualTestingWarning = false
const GlobalToolbar: React.FC = () => { const GlobalToolbar: React.FC = () => {
const conflicts = usePrism(() => { const conflicts = usePrism(() => {
const ephemeralStateOfAllProjects = val( const ephemeralStateOfAllProjects = val(
@ -123,6 +125,20 @@ const GlobalToolbar: React.FC = () => {
) )
const moreMenuTriggerRef = useRef<HTMLButtonElement>(null) const moreMenuTriggerRef = useRef<HTMLButtonElement>(null)
const showUpdatesBadge = useMemo(() => {
if (hasUpdates || window.__IS_VISUAL_REGRESSION_TESTING) {
if (!showedVisualTestingWarning) {
showedVisualTestingWarning = true
console.warn(
"Visual regression testing enabled, so we're showing the updates badge unconditionally",
)
}
return true
}
return hasUpdates
}, [hasUpdates])
return ( return (
<Container> <Container>
<SubContainer> <SubContainer>
@ -158,7 +174,7 @@ const GlobalToolbar: React.FC = () => {
}} }}
> >
<Ellipsis /> <Ellipsis />
{hasUpdates && <HasUpdatesBadge />} {showUpdatesBadge && <HasUpdatesBadge />}
</ToolbarIconButton> </ToolbarIconButton>
<PinButton <PinButton
ref={triggerButtonRef as $IntentionalAny} ref={triggerButtonRef as $IntentionalAny}