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

chore: automatically infer cypress major version from package.json #30911

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/data-context/src/data/ProjectLifecycleManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { EventRegistrar } from './EventRegistrar'
import { getServerPluginHandlers, resetPluginHandlers } from '../util/pluginHandlers'
import { detectLanguage } from '@packages/scaffold-config'
import { validateNeedToRestartOnChange } from '@packages/config'
import { MAJOR_VERSION_FOR_CONTENT } from '@packages/types'
import { GET_MAJOR_VERSION_FOR_CONTENT } from '@packages/types'
import { telemetry } from '@packages/telemetry'

export interface SetupFullConfigOptions {
Expand Down Expand Up @@ -332,7 +332,7 @@ export class ProjectLifecycleManager {

const preferences = await this.ctx._apis.localSettingsApi.getPreferences()

const hasWelcomeBeenDismissed = Boolean(preferences.majorVersionWelcomeDismissed?.[MAJOR_VERSION_FOR_CONTENT])
const hasWelcomeBeenDismissed = Boolean(preferences.majorVersionWelcomeDismissed?.[GET_MAJOR_VERSION_FOR_CONTENT()])

// only continue if the browser was successfully set - we must have an activeBrowser once this function resolves
// but if the user needs to dismiss a landing page, don't continue, the active browser will be opened
Expand Down
4 changes: 2 additions & 2 deletions packages/data-context/test/unit/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { getOperationName } from '@urql/core'
import { CloudQuery } from '@packages/graphql/test/stubCloudTypes'
import { remoteSchema } from '@packages/graphql/src/stitching/remoteSchema'
import type { OpenModeOptions, RunModeOptions } from '@packages/types'
import { MAJOR_VERSION_FOR_CONTENT } from '@packages/types'
import { GET_MAJOR_VERSION_FOR_CONTENT } from '@packages/types'
import { RelevantRunInfo } from '../../src/gen/graphcache-config.gen'

type SystemTestProject = typeof fixtureDirs[number]
Expand Down Expand Up @@ -48,7 +48,7 @@ export function createTestDataContext (mode: DataContextConfig['mode'] = 'run',
appApi: {} as AppApiShape,
localSettingsApi: {
getPreferences: sinon.stub().resolves({
majorVersionWelcomeDismissed: { [MAJOR_VERSION_FOR_CONTENT]: 123456 },
majorVersionWelcomeDismissed: { [GET_MAJOR_VERSION_FOR_CONTENT()]: 123456 },
notifyWhenRunCompletes: ['failed'],
}),
getAvailableEditors: sinon.stub(),
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend-shared/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { fixtureDirs, ProjectFixtureDir } from '@tooling/system-tests'
import type { DataContext } from '@packages/data-context'
import type { AuthenticatedUserShape } from '@packages/data-context/src/data'
import type { DocumentNode, ExecutionResult } from 'graphql'
import type { Browser, FoundBrowser, OpenModeOptions } from '@packages/types'
import { GET_MAJOR_VERSION_FOR_CONTENT, type Browser, type FoundBrowser, type OpenModeOptions } from '@packages/types'

import type { SinonStub } from 'sinon'
import type sinon from 'sinon'
Expand Down Expand Up @@ -402,7 +402,7 @@ function visitLaunchpad (options: { showWelcome?: boolean } = { showWelcome: fal
// avoid re-stubbing already stubbed prompts in case we call getPreferences multiple times
if ((ctx._apis.localSettingsApi.getPreferences as any).wrappedMethod === undefined) {
o.sinon.stub(ctx._apis.localSettingsApi, 'getPreferences').resolves({ majorVersionWelcomeDismissed: {
[14]: Date.now(),
[GET_MAJOR_VERSION_FOR_CONTENT()]: Date.now(),
} })
}
}).then(() => {
Expand Down
6 changes: 3 additions & 3 deletions packages/launchpad/cypress/e2e/open-mode.cy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { SinonStub } from 'sinon'
import defaultMessages from '@packages/frontend-shared/src/locales/en-US.json'
import { MAJOR_VERSION_FOR_CONTENT } from '@packages/types'
import { GET_MAJOR_VERSION_FOR_CONTENT } from '@packages/types'

describe('Launchpad: Open Mode', () => {
describe('global mode', () => {
Expand Down Expand Up @@ -228,10 +228,10 @@ describe('Launchpad: Open Mode', () => {
cy.withCtx((ctx, o) => {
o.sinon.stub(ctx._apis.projectApi, 'launchProject').resolves()
o.sinon.stub(ctx._apis.localSettingsApi, 'getPreferences').resolves({ majorVersionWelcomeDismissed: {
[o.MAJOR_VERSION_FOR_CONTENT]: Date.now(),
[o.GET_MAJOR_VERSION_FOR_CONTENT()]: Date.now(),
} })
}, {
MAJOR_VERSION_FOR_CONTENT,
GET_MAJOR_VERSION_FOR_CONTENT: GET_MAJOR_VERSION_FOR_CONTENT(),
})

cy.scaffoldProject('launchpad')
Expand Down
6 changes: 3 additions & 3 deletions packages/launchpad/cypress/e2e/project-setup.cy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MAJOR_VERSION_FOR_CONTENT } from '@packages/types'
import { GET_MAJOR_VERSION_FOR_CONTENT } from '@packages/types'
import { getPathForPlatform } from './support/getPathForPlatform'

function verifyScaffoldedFiles (testingType: string) {
Expand Down Expand Up @@ -38,13 +38,13 @@ describe('Launchpad: Setup Project', () => {
cy.withCtx(async (ctx, o) => {
o.sinon.stub(ctx.project, 'projectId').resolves(null)
o.sinon.stub(ctx._apis.localSettingsApi, 'getPreferences').resolves({ majorVersionWelcomeDismissed: {
[o.MAJOR_VERSION_FOR_CONTENT]: Date.now(),
[o.GET_MAJOR_VERSION_FOR_CONTENT()]: Date.now(),
} })

// Delete the fixtures folder so it scaffold correctly the example
await ctx.actions.file.removeFileInProject('cypress/fixtures')
}, {
MAJOR_VERSION_FOR_CONTENT,
GET_MAJOR_VERSION_FOR_CONTENT: GET_MAJOR_VERSION_FOR_CONTENT(),
})
}

Expand Down
6 changes: 3 additions & 3 deletions packages/launchpad/src/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ import OpenBrowser from './setup/OpenBrowser.vue'
import LoginConnectModals from '@cy/gql-components/LoginConnectModals.vue'
import CloudViewerAndProject from '@cy/gql-components/CloudViewerAndProject.vue'
import { usePromptManager } from '@cy/gql-components/composables/usePromptManager'
import { MAJOR_VERSION_FOR_CONTENT } from '@packages/types'
import { GET_MAJOR_VERSION_FOR_CONTENT } from '@packages/types'

const { setMajorVersionWelcomeDismissed } = usePromptManager()
const { t } = useI18n()
Expand Down Expand Up @@ -234,7 +234,7 @@ watch(
)

function handleClearLandingPage () {
setMajorVersionWelcomeDismissed(MAJOR_VERSION_FOR_CONTENT)
setMajorVersionWelcomeDismissed(GET_MAJOR_VERSION_FOR_CONTENT())
const shouldLaunchBrowser = query.data?.value?.localSettings?.preferences?.shouldLaunchBrowserFromOpenBrowser

const currentTestingType = currentProject.value?.currentTestingType
Expand All @@ -246,7 +246,7 @@ function handleClearLandingPage () {

const shouldShowWelcome = computed(() => {
if (query.data.value) {
const hasThisVersionBeenSeen = query.data.value?.localSettings?.preferences?.majorVersionWelcomeDismissed?.[MAJOR_VERSION_FOR_CONTENT]
const hasThisVersionBeenSeen = query.data.value?.localSettings?.preferences?.majorVersionWelcomeDismissed?.[GET_MAJOR_VERSION_FOR_CONTENT()]
const wasBrowserSetInCLI = query.data?.value?.localSettings.preferences?.wasBrowserSetInCLI
const currentTestingType = currentProject.value?.currentTestingType

Expand Down
10 changes: 10 additions & 0 deletions packages/launchpad/src/migration/MajorVersionWelcome.cy.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defaultMessages } from '@cy/i18n'
import MajorVersionWelcome from './MajorVersionWelcome.vue'
import interval from 'human-interval'
import { GET_MAJOR_VERSION_FOR_CONTENT } from '@packages/types'

const text = defaultMessages.majorVersionWelcome

Expand Down Expand Up @@ -52,4 +53,13 @@ describe('<MajorVersionWelcome />', { viewportWidth: 1280, viewportHeight: 1400

cy.percySnapshot('content overflows inside box')
})

// Test is designed to fail as a signal when the next major version of Cypress is bumped in the package.json
// to signal to the team that we need to create a splash page
it('makes sure there is an entry for the current major release in the monorepo package.json version', () => {
cy.mount(<MajorVersionWelcome />)
const currentMajorVersion = GET_MAJOR_VERSION_FOR_CONTENT()

cy.get('a').should('contain.text', `${currentMajorVersion}.0.0`)
})
})
1 change: 1 addition & 0 deletions packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"devDependencies": {
"@types/node": "20.16.0",
"devtools-protocol": "0.0.1346313",
"semver": "^7.6.3",
"typescript": "~5.4.5"
},
"files": [
Expand Down
5 changes: 4 additions & 1 deletion packages/types/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import semverMajor from 'semver/functions/major'
import { version } from '../../../package.json'

import type { SpecFile } from './spec'

export const PLUGINS_STATE = ['uninitialized', 'initializing', 'initialized', 'error'] as const
Expand Down Expand Up @@ -25,7 +28,7 @@ export const PACKAGE_MANAGERS = ['npm', 'yarn', 'pnpm'] as const

// Note: ONLY change this in code that will be merged into a release branch
// for a new major version of Cypress
export const MAJOR_VERSION_FOR_CONTENT = '14'
export const GET_MAJOR_VERSION_FOR_CONTENT = () => semverMajor(version).toString()

export const RUN_ALL_SPECS_KEY = '__all' as const

Expand Down
Loading