Skip to content

Commit

Permalink
chore: fix tests that visit the runner on windows and do some other c…
Browse files Browse the repository at this point in the history
…leanup (#20592)
  • Loading branch information
marktnoonan committed Mar 21, 2022
1 parent 110f8ae commit ae4bf3a
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 52 deletions.
6 changes: 3 additions & 3 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ mainBuildFilters: &mainBuildFilters
only:
- develop
- 10.0-release
- marktnoonan/backmerge-develop-3-8-22
- UNIFY-1294-specs-list-flake

# usually we don't build Mac app - it takes a long time
# but sometimes we want to really confirm we are doing the right thing
Expand All @@ -39,7 +39,7 @@ macWorkflowFilters: &mac-workflow-filters
or:
- equal: [ develop, << pipeline.git.branch >> ]
- equal: [ '10.0-release', << pipeline.git.branch >> ]
- equal: [ marktnoonan/backmerge-develop-3-8-22, << pipeline.git.branch >> ]
- equal: [ UNIFY-1294-specs-list-flake, << pipeline.git.branch >> ]
- matches:
pattern: "-release$"
value: << pipeline.git.branch >>
Expand All @@ -49,7 +49,7 @@ windowsWorkflowFilters: &windows-workflow-filters
or:
- equal: [ develop, << pipeline.git.branch >> ]
- equal: [ '10.0-release', << pipeline.git.branch >> ]
- equal: [ marktnoonan/backmerge-develop-3-8-22, << pipeline.git.branch >> ]
- equal: [ UNIFY-1294-specs-list-flake, << pipeline.git.branch >> ]
- matches:
pattern: "-release$"
value: << pipeline.git.branch >>
Expand Down
2 changes: 1 addition & 1 deletion packages/app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Route configuration that might typically appear in `router.ts` can be set in a `
```ts
<route>
{
name: 'SpecsRunner',
name: 'SpecRunner',
meta: {
header: false,
navBarExpandedAllowed: false
Expand Down
20 changes: 11 additions & 9 deletions packages/app/cypress/e2e/cypress-in-cypress-component.cy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import defaultMessages from '@packages/frontend-shared/src/locales/en-US.json'
import { getPathForPlatform } from '../../src/paths'
import { snapshotAUTPanel } from './support/snapshot-aut-panel'

describe('Cypress In Cypress', { viewportWidth: 1500 }, () => {
describe('Cypress In Cypress CT', { viewportWidth: 1500, defaultCommandTimeout: 10000 }, () => {
beforeEach(() => {
cy.scaffoldProject('cypress-in-cypress')
cy.findBrowsers()
Expand Down Expand Up @@ -56,6 +57,7 @@ describe('Cypress In Cypress', { viewportWidth: 1500 }, () => {
})

it('navigation between specs and other parts of the app works', () => {
cy.visitApp()
cy.contains('TestComponent.spec').click()
cy.get('[data-model-state="passed"]').should('contain', 'renders the test component')

Expand All @@ -79,11 +81,11 @@ describe('Cypress In Cypress', { viewportWidth: 1500 }, () => {
const { noSpecErrorTitle, noSpecErrorIntro, noSpecErrorExplainer } = defaultMessages.specPage
const badFilePath = 'src/DoesNotExist.spec.js'

cy.visit(`http://localhost:4455/__/#/specs/runner?file=${badFilePath}`)
cy.visitApp(`/specs/runner?file=${getPathForPlatform(badFilePath)}`)
cy.contains(noSpecErrorTitle).should('be.visible')
cy.contains(noSpecErrorIntro).should('be.visible')
cy.contains(noSpecErrorExplainer).should('be.visible')
cy.contains(badFilePath).should('be.visible')
cy.contains(getPathForPlatform(badFilePath)).should('be.visible')
cy.location()
.its('href')
.should('eq', 'http://localhost:4455/__/#/specs')
Expand All @@ -98,21 +100,21 @@ describe('Cypress In Cypress', { viewportWidth: 1500 }, () => {

const goodFilePath = 'src/TestComponent.spec.jsx'

// TODO: Figure out why test is flaky without wait
// see: https://cypress-io.atlassian.net/browse/UNIFY-1294
cy.wait(2000)
cy.visit(`http://localhost:4455/__/#/specs/runner?file=${goodFilePath}`)
cy.visitApp(`/specs/runner?file=${getPathForPlatform(goodFilePath)}`)

cy.contains('renders the test component').should('be.visible')

cy.withCtx((ctx) => {
ctx.actions.project.setSpecs([])
// rename relative path for any specs that happen to be found
const specs = ctx.project.specs.map((spec) => ({ ...spec, relative: `${spec.relative}-updated` }))

ctx.actions.project.setSpecs(specs)
ctx.emitter.toApp()
}).then(() => {
cy.contains(noSpecErrorTitle).should('be.visible')
cy.contains(noSpecErrorIntro).should('be.visible')
cy.contains(noSpecErrorExplainer).should('be.visible')
cy.contains(goodFilePath).should('be.visible')
cy.contains(getPathForPlatform(goodFilePath)).should('be.visible')
cy.location()
.its('href')
.should('eq', 'http://localhost:4455/__/#/specs')
Expand Down
20 changes: 11 additions & 9 deletions packages/app/cypress/e2e/cypress-in-cypress-e2e.cy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import defaultMessages from '@packages/frontend-shared/src/locales/en-US.json'
import { snapshotAUTPanel } from './support/snapshot-aut-panel'
import { getPathForPlatform } from '../../src/paths'

describe('Cypress In Cypress', { viewportWidth: 1500 }, () => {
describe('Cypress In Cypress E2E', { viewportWidth: 1500, defaultCommandTimeout: 10000 }, () => {
beforeEach(() => {
cy.scaffoldProject('cypress-in-cypress')
cy.findBrowsers()
Expand Down Expand Up @@ -99,11 +100,11 @@ describe('Cypress In Cypress', { viewportWidth: 1500 }, () => {
const { noSpecErrorTitle, noSpecErrorIntro, noSpecErrorExplainer } = defaultMessages.specPage
const badFilePath = 'cypress/e2e/does-not-exist.spec.js'

cy.visit(`http://localhost:4455/__/#/specs/runner?file=${badFilePath}`)
cy.visitApp(`/specs/runner?file=${getPathForPlatform(badFilePath)}`)
cy.contains(noSpecErrorTitle).should('be.visible')
cy.contains(noSpecErrorIntro).should('be.visible')
cy.contains(noSpecErrorExplainer).should('be.visible')
cy.contains(badFilePath).should('be.visible')
cy.contains(getPathForPlatform(badFilePath)).should('be.visible')
cy.location()
.its('href')
.should('eq', 'http://localhost:4455/__/#/specs')
Expand All @@ -120,21 +121,22 @@ describe('Cypress In Cypress', { viewportWidth: 1500 }, () => {

const goodFilePath = 'cypress/e2e/dom-content.spec.js'

// TODO: Figure out why test is flaky without wait
// see: https://cypress-io.atlassian.net/browse/UNIFY-1294
cy.wait(2000)
cy.visit(`http://localhost:4455/__/#/specs/runner?file=${goodFilePath}`)
cy.visit(`http://localhost:4455/__/#/specs/runner?file=${getPathForPlatform(goodFilePath)}`)

cy.contains('Dom Content').should('be.visible')

cy.withCtx((ctx) => {
ctx.actions.project.setSpecs([])
// rename relative path for any specs that happen to be found

const specs = ctx.project.specs.map((spec) => ({ ...spec, relative: `${spec.relative}-updated` }))

ctx.actions.project.setSpecs(specs)
ctx.emitter.toApp()
}).then(() => {
cy.contains(noSpecErrorTitle).should('be.visible')
cy.contains(noSpecErrorIntro).should('be.visible')
cy.contains(noSpecErrorExplainer).should('be.visible')
cy.contains(goodFilePath).should('be.visible')
cy.contains(getPathForPlatform(goodFilePath)).should('be.visible')
cy.location()
.its('href')
.should('eq', 'http://localhost:4455/__/#/specs')
Expand Down
7 changes: 1 addition & 6 deletions packages/app/cypress/e2e/specs.cy.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import defaultMessages from '@packages/frontend-shared/src/locales/en-US.json'

function getPathForPlatform (posixPath: string) {
if (Cypress.platform === 'win32') return posixPath.replaceAll('/', '\\')

return posixPath
}
import { getPathForPlatform } from '../../src/paths'

function getRunnerHref (specPath: string) {
specPath = getPathForPlatform(specPath)
Expand Down
6 changes: 3 additions & 3 deletions packages/app/src/pages/Specs/Runner.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<!--
Run Mode is a more minimal UI.
It does not render things like the SpecList,
Side and Top Nav, etc.
Side Nav, etc.
It also has no GraphQL dependency.
-->
<SpecRunnerContainerRunMode
Expand All @@ -14,7 +14,7 @@
<!--
Open Mode is the full Cypress runner UI -
including things like the SpecList,
Side and Top Nav, Selector Playground etc.
Side Nav, Selector Playground etc.
It is driven by GraphQL and urql.
-->
<SpecRunnerContainerOpenMode
Expand Down Expand Up @@ -59,7 +59,7 @@ const specs = window.__RUN_MODE_SPECS__
<route>
{
name: 'SpecsRunner',
name: 'SpecRunner',
meta: {
header: false,
navBarExpandedAllowed: false
Expand Down
35 changes: 21 additions & 14 deletions packages/app/src/runner/SpecRunnerContainerOpenMode.vue
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
<template>
<div v-if="specStore.activeSpec">
<SpecRunnerOpenMode
v-if="initialized"
:gql="props.gql"
/>
</div>
<SpecRunnerOpenMode
v-if="initialized && specStore.activeSpec"
:gql="props.gql"
/>
</template>

<script lang="ts" setup>
import { computed, watchEffect } from 'vue'
import { computed } from 'vue'
import type { SpecRunnerFragment } from '../generated/graphql'
import { useSpecStore } from '../store'
import SpecRunnerOpenMode from './SpecRunnerOpenMode.vue'
import { useUnifiedRunner } from './unifiedRunner'
import { useRouter } from 'vue-router'
import { useRouter, useRoute } from 'vue-router'
const props = defineProps<{
gql: SpecRunnerFragment
}>()
const specStore = useSpecStore()
const router = useRouter()
const route = useRoute()
const { initialized, watchSpec } = useUnifiedRunner()
Expand All @@ -30,13 +29,21 @@ const specs = computed(() => {
watchSpec(specs)
watchEffect(() => {
const specPath = router.currentRoute.value.query.file
specStore.$subscribe((mutation, state) => {
const file = route.query.file as string
if (specPath && !specStore.activeSpec) {
router.push({ name: 'Specs', params: {
unrunnable: router.currentRoute.value.query.file as string,
} })
const shouldRedirect = route.name === 'SpecRunner' && file && state.activeSpec === null
if (shouldRedirect) {
router.push({
name: 'Specs',
params: {
unrunnable: file,
},
})
}
}, {
immediate: true,
})
</script>
4 changes: 2 additions & 2 deletions packages/app/src/runner/unifiedRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function useUnifiedRunner () {
const route = useRoute()
const selectorPlaygroundStore = useSelectorPlaygroundStore()

watch(() => specs.value, () => {
watch(() => specs.value, (newVal) => {
const fileParam = route.query.file

if (!fileParam) {
Expand All @@ -36,7 +36,7 @@ export function useUnifiedRunner () {
return
}

const activeSpecInSpecsList = specs.value.find((x) => x.relative === fileParam)
const activeSpecInSpecsList = newVal.find((x) => x.relative === fileParam)

if (!activeSpecInSpecsList) {
// the specs list no longer contains the spec being shown
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/runner/useEventManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function useEventManager () {

function runSpec () {
if (!specStore.activeSpec) {
throw Error(`Cannot run spec when specStore.active spec is null!`)
throw Error(`Cannot run spec when specStore.active spec is null or undefined!`)
}

autStore.setScriptError(null)
Expand Down Expand Up @@ -54,7 +54,7 @@ export function useEventManager () {
}

const startSpecWatcher = () => {
return watch(() => specStore.activeSpec, (spec) => {
return watch(() => specStore.activeSpec, () => {
runSpec()
}, { immediate: true, flush: 'post' })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
>
<router-link
class="outline-none"
:to="{ name: 'SpecsRunner', query: { file: result.file.relative }, params: { shouldShowTroubleRenderingAlert: true } }
:to="{ name: 'SpecRunner', query: { file: result.file.relative }, params: { shouldShowTroubleRenderingAlert: true } }
"
>
<Button
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/store/specs-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import type { SpecFile } from '@packages/types/src'
import { defineStore } from 'pinia'

export interface SpecState {
activeSpec: SpecFile | null
activeSpec: SpecFile | null | undefined
}

export const useSpecStore = defineStore({
id: 'spec',

state (): SpecState {
return {
activeSpec: null,
activeSpec: undefined,
}
},

Expand Down

3 comments on commit ae4bf3a

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on ae4bf3a Mar 21, 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.0.0/linux-x64/10.0-release-ae4bf3a8bedd2dc8acc9897cab9a46411012deec/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on ae4bf3a Mar 21, 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.0.0/win32-x64/10.0-release-ae4bf3a8bedd2dc8acc9897cab9a46411012deec/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on ae4bf3a Mar 21, 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.0.0/darwin-x64/10.0-release-ae4bf3a8bedd2dc8acc9897cab9a46411012deec/cypress.tgz

Please sign in to comment.