Skip to content

Commit

Permalink
Merge branch 'develop' into ryanm/fix/v8-improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanthemanuel committed Dec 1, 2022
2 parents 39d02d6 + 3f0d150 commit ce8c74a
Show file tree
Hide file tree
Showing 46 changed files with 1,267 additions and 731 deletions.
6 changes: 6 additions & 0 deletions .eslintrc.js
Expand Up @@ -34,6 +34,12 @@ module.exports = {
'plugin:@cypress/dev/tests',
],
parser: '@typescript-eslint/parser',
ignorePatterns: [
// cli types are checked by dtslint
'cli/types/**',
// these fixtures are supposed to fail linting
'npm/eslint-plugin-dev/test/fixtures/**',
],
overrides: [
{
files: [
Expand Down
63 changes: 62 additions & 1 deletion cli/types/cypress.d.ts
Expand Up @@ -142,6 +142,39 @@ declare namespace Cypress {
clear: (keys?: string[]) => void
}

// TODO: raise minimum required TypeScript version to 3.7
// and make this recursive
// https://github.com/cypress-io/cypress/issues/24875
type Storable =
| string
| number
| boolean
| null
| StorableObject
| StorableArray

interface StorableObject {
[key: string]: Storable
}

interface StorableArray extends Array<Storable> { }

type StorableRecord = Record<string, Storable>

interface OriginStorage {
origin: string
value: StorableRecord
}

interface Storages {
localStorage: OriginStorage[]
sessionStorage: OriginStorage[]
}

interface StorageByOrigin {
[key: string]: StorableRecord
}

type IsBrowserMatcher = BrowserName | Partial<Browser> | Array<BrowserName | Partial<Browser>>

interface ViewportPosition extends WindowPosition {
Expand Down Expand Up @@ -792,7 +825,35 @@ declare namespace Cypress {
clearCookies(options?: CookieOptions): Chainable<null>

/**
* Clear data in local storage.
* Get local storage for all origins.
*
* @see https://on.cypress.io/getalllocalstorage
*/
getAllLocalStorage(options?: Partial<Loggable>): Chainable<StorageByOrigin>

/**
* Clear local storage for all origins.
*
* @see https://on.cypress.io/clearalllocalstorage
*/
clearAllLocalStorage(options?: Partial<Loggable>): Chainable<null>

/**
* Get session storage for all origins.
*
* @see https://on.cypress.io/getallsessionstorage
*/
getAllSessionStorage(options?: Partial<Loggable>): Chainable<StorageByOrigin>

/**
* Clear session storage for all origins.
*
* @see https://on.cypress.io/clearallsessionstorage
*/
clearAllSessionStorage(options?: Partial<Loggable>): Chainable<null>

/**
* Clear data in local storage for the current origin.
* Cypress automatically runs this command before each test to prevent state from being
* shared across tests. You shouldn't need to use this command unless you're using it
* to clear localStorage inside a single test. Yields `localStorage` object.
Expand Down
26 changes: 26 additions & 0 deletions cli/types/tests/cypress-tests.ts
Expand Up @@ -1062,3 +1062,29 @@ namespace CypressClearCookiesTests {
cy.clearCookies({ timeout: '10' }) // $ExpectError
cy.clearCookies({ domain: false }) // $ExpectError
}

namespace CypressLocalStorageTests {
cy.getAllLocalStorage().then((result) => {
result // $ExpectType StorageByOrigin
})
cy.getAllLocalStorage({ log: false })
cy.getAllLocalStorage({ log: 'true' }) // $ExpectError

cy.clearAllLocalStorage().then((result) => {
result // $ExpectType null
})
cy.clearAllLocalStorage({ log: false })
cy.clearAllLocalStorage({ log: 'true' }) // $ExpectError

cy.getAllSessionStorage().then((result) => {
result // $ExpectType StorageByOrigin
})
cy.getAllSessionStorage({ log: false })
cy.getAllSessionStorage({ log: 'true' }) // $ExpectError

cy.clearAllSessionStorage().then((result) => {
result // $ExpectType null
})
cy.clearAllSessionStorage({ log: false })
cy.clearAllSessionStorage({ log: 'true' }) // $ExpectError
}
16 changes: 11 additions & 5 deletions packages/app/cypress/e2e/run-all-specs.cy.ts
Expand Up @@ -6,9 +6,15 @@ describe('run-all-specs', () => {
spec2: { relative: 'cypress/e2e/folder-a/spec-b.cy.js', name: 'runs folder-a/spec-b' },
spec3: { relative: 'cypress/e2e/folder-b/spec-a.cy.js', name: 'runs folder-b/spec-a' },
spec4: { relative: 'cypress/e2e/folder-b/spec-b.cy.js', name: 'runs folder-b/spec-b' },
spec5: { relative: 'folder-c/spec-a.cy.js', name: 'runs folder-c/spec-a' },
spec6: { relative: 'folder-c/spec-b.cy.js', name: 'runs folder-c/spec-b' },
}

const clickRunAllSpecs = (directory: string) => {
if (directory === 'all') {
return cy.findByTestId('run-all-specs-for-all').click()
}

const command = cy.get('[data-cy=spec-item-directory]').contains(directory)

return command.realHover().then(() => {
Expand All @@ -30,7 +36,7 @@ describe('run-all-specs', () => {
// Verify "Run All Specs" with sub-directory
const subDirectorySpecs = [ALL_SPECS.spec1, ALL_SPECS.spec2]

cy.get('[data-cy=sidebar-link-specs-page]').click()
cy.findByTestId('sidebar-link-specs-page').click()

clickRunAllSpecs('folder-a')

Expand Down Expand Up @@ -87,16 +93,16 @@ describe('run-all-specs', () => {
// Verify "Run All Specs" live-reload
cy.get('[data-cy=sidebar-link-specs-page]').click()
cy.findByLabelText('Search specs').clear()
cy.get('[data-cy=spec-list-file]').should('have.length', 4)
cy.get('[data-cy=spec-list-file]').should('have.length', 6)

clickRunAllSpecs('cypress/e2e')
clickRunAllSpecs('all')

cy.withCtx((ctx, { specs, runAllSpecsKey }) => {
expect(ctx.actions.project.launchProject).to.have.been.calledWith('e2e', undefined, runAllSpecsKey)
expect(ctx.project.runAllSpecs).to.include.members(specs.map((spec) => spec.relative))
}, { specs: Object.values(ALL_SPECS), runAllSpecsKey: RUN_ALL_SPECS_KEY })

cy.waitForSpecToFinish({ passCount: 4 })
cy.waitForSpecToFinish({ passCount: 6 })

for (const spec of Object.values(ALL_SPECS)) {
cy.get('.runnable-title').contains(spec.name)
Expand All @@ -111,6 +117,6 @@ describe('run-all-specs', () => {
await ctx.actions.file.writeFileInProject(spec.relative, newContent)
}, { spec: ALL_SPECS.spec1 })

cy.waitForSpecToFinish({ passCount: 3, failCount: 1 })
cy.waitForSpecToFinish({ passCount: 5, failCount: 1 })
})
})
69 changes: 0 additions & 69 deletions packages/app/src/composables/useRunAllSpecs.ts

This file was deleted.

9 changes: 3 additions & 6 deletions packages/app/src/pages/Specs/Runner.vue
Expand Up @@ -31,6 +31,7 @@ import SpecRunnerContainerOpenMode from '../../runner/SpecRunnerContainerOpenMod
import SpecRunnerContainerRunMode from '../../runner/SpecRunnerContainerRunMode.vue'
import { useEventManager } from '../../runner/useEventManager'
import { useSpecStore } from '../../store'
import { isRunMode } from '@packages/frontend-shared/src/utils/isRunMode'
gql`
query SpecPageContainer {
Expand Down Expand Up @@ -59,18 +60,14 @@ subscription Runner_ConfigChange {
}
`
const isRunMode = window.__CYPRESS_MODE__ === 'run'
// subscriptions are used to trigger live updates without
// reloading the page.
// this is only useful in open mode - in run mode, we don't
// use GraphQL, so we pause the
// subscriptions so they never execute.
const shouldPauseSubscriptions = isRunMode && window.top === window
useSubscription({
query: SpecPageContainer_SpecsChangeDocument,
pause: shouldPauseSubscriptions,
pause: isRunMode,
})
// in run mode, we are not using GraphQL or urql
Expand All @@ -80,7 +77,7 @@ useSubscription({
// requests, which is what we want.
const query = useQuery({
query: SpecPageContainerDocument,
pause: shouldPauseSubscriptions,
pause: isRunMode,
})
let initialLoad = true
Expand Down
Expand Up @@ -8,12 +8,12 @@
</template>

<script lang="ts" setup>
import { isRunMode } from '@packages/frontend-shared/src/utils/isRunMode'
import { computed } from 'vue'
import { useScreenshotStore } from '../../store'
import { runnerConstants } from '../runner-constants'
const screenshotStore = useScreenshotStore()
const isRunMode = window.__CYPRESS_MODE__ === 'run'
const style = computed(() => {
if (screenshotStore.isScreenshotting) {
Expand Down
3 changes: 2 additions & 1 deletion packages/app/src/runner/useRunnerStyle.ts
@@ -1,3 +1,4 @@
import { isRunMode } from '@packages/frontend-shared/src/utils/isRunMode'
import { useWindowSize } from '@vueuse/core'
import { computed, ref, watchEffect } from 'vue'
import { usePreferences } from '../composables/usePreferences'
Expand Down Expand Up @@ -97,7 +98,7 @@ export const useRunnerStyle = () => {
return {
viewportStyle,
windowWidth: computed(() => {
if (window.__CYPRESS_MODE__ === 'run') {
if (isRunMode) {
return windowWidth.value
}

Expand Down
16 changes: 14 additions & 2 deletions packages/app/src/specs/InlineRunAllSpecs.cy.tsx
Expand Up @@ -13,15 +13,27 @@ describe('<InlineRunAllSpecs/>', () => {
})

it('renders component correctly', () => {
cy.findByTestId('tooltip').children().should('have.length', 1)
cy.findByTestId('run-all-specs-for-cypress/e2e').children().should('have.length', 1)
cy.findByTestId('play-button').should('be.visible')
})

it('provides expected tooltip content', () => {
cy.findByTestId('tooltip-content').should('not.exist')
cy.findByTestId('tooltip').realHover().then(() => {
cy.findByTestId('run-all-specs-for-cypress/e2e').realHover().then(() => {
cy.findByTestId('tooltip-content').should('contain.text', 'Run 40 specs')
})
})
})

it('disables button when no specs are available', () => {
cy.mount(() => {
return (
<div class="flex justify-center">
<InlineRunAllSpecs specNumber={0} directory='cypress/e2e' />
</div>
)
})

cy.findByTestId('run-all-specs-button').should('be.disabled')
})
})
19 changes: 12 additions & 7 deletions packages/app/src/specs/InlineRunAllSpecs.vue
@@ -1,16 +1,20 @@
<template>
<Tooltip
placement="right"
class="h-full truncate"
data-cy="tooltip"
:data-cy="`run-all-specs-for-${directory}`"
>
<button @click.stop="emits('runAllSpecs')">
<button
class="flex h-full w-full items-center justify-center"
data-cy="run-all-specs-button"
:disabled="specNumber === 0"
@click.stop="emits('runAllSpecs')"
>
<IconActionPlaySmall
size="16"
stroke-color="gray-700"
:stroke-color="grayscale ? 'gray-200' : 'gray-700'"
fill-color="transparent"
hocus-stroke-color="indigo-500"
hocus-fill-color="indigo-100"
:hocus-stroke-color="grayscale ? undefined : 'indigo-500'"
:hocus-fill-color="grayscale ? undefined : 'indigo-100'"
class="inline-flex align-text-bottom"
data-cy="play-button"
/>
Expand All @@ -22,7 +26,7 @@
class="font-normal text-sm inline-flex"
data-cy="tooltip-content"
>
{{ t('specPage.runAllSpecs', specNumber) }}
{{ t('specPage.runSelectedSpecs', specNumber) }}
</span>
</template>
</Tooltip>
Expand All @@ -38,6 +42,7 @@ const { t } = useI18n()
defineProps<{
specNumber: number
directory: string
grayscale?: boolean
}>()
const emits = defineEmits<{
Expand Down

4 comments on commit ce8c74a

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on ce8c74a Dec 1, 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/11.3.0/linux-x64/ryanm/fix/v8-improvements-ce8c74a2bb005b443a988c6f4e53a42b9ff45d9b/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on ce8c74a Dec 1, 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/11.3.0/linux-arm64/ryanm/fix/v8-improvements-ce8c74a2bb005b443a988c6f4e53a42b9ff45d9b/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on ce8c74a Dec 1, 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/11.3.0/darwin-x64/ryanm/fix/v8-improvements-ce8c74a2bb005b443a988c6f4e53a42b9ff45d9b/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on ce8c74a Dec 1, 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/11.3.0/darwin-arm64/ryanm/fix/v8-improvements-ce8c74a2bb005b443a988c6f4e53a42b9ff45d9b/cypress.tgz

Please sign in to comment.