diff --git a/packages/data-context/src/DataContext.ts b/packages/data-context/src/DataContext.ts index b3c67e827572..9fb8edddfc27 100644 --- a/packages/data-context/src/DataContext.ts +++ b/packages/data-context/src/DataContext.ts @@ -22,6 +22,10 @@ import type { GraphQLSchema } from 'graphql' const IS_DEV_ENV = process.env.CYPRESS_INTERNAL_ENV !== 'production' +export interface InternalDataContextOptions { + loadCachedProjects: boolean +} + export interface DataContextConfig extends DataContextShellConfig { schema: GraphQLSchema os: PlatformName @@ -37,6 +41,10 @@ export interface DataContextConfig extends DataContextShellConfig { appApi: AppApiShape authApi: AuthApiShape projectApi: ProjectApiShape + /** + * Internal options used for testing purposes + */ + _internalOptions: InternalDataContextOptions } export class DataContext extends DataContextShell { @@ -52,12 +60,15 @@ export class DataContext extends DataContextShell { // Fetch the browsers when the app starts, so we have some by // the time we're continuing. this.actions.app.refreshBrowsers(), - // load projects from cache on start - this.actions.project.loadProjects(), // load the cached user & validate the token on start this.actions.auth.getUser(), ] + if (this._config._internalOptions.loadCachedProjects) { + // load projects from cache on start + toAwait.push(this.actions.project.loadProjects()) + } + if (this._config.launchArgs.projectRoot) { toAwait.push(this.actions.project.setActiveProject(this._config.launchArgs.projectRoot)) } diff --git a/packages/frontend-shared/cypress/e2e/e2ePluginSetup.ts b/packages/frontend-shared/cypress/e2e/e2ePluginSetup.ts index 68ba7d6ba826..5899af61b5e7 100644 --- a/packages/frontend-shared/cypress/e2e/e2ePluginSetup.ts +++ b/packages/frontend-shared/cypress/e2e/e2ePluginSetup.ts @@ -60,10 +60,10 @@ export async function e2ePluginSetup (projectRoot: string, on: Cypress.PluginEve return null }, - setupE2E (projectName: string) { + scaffoldProject (projectName: string) { Fixtures.scaffoldProject(projectName) - return null + return Fixtures.projectPath(projectName) }, async withCtx (obj: WithCtxObj) { // Ensure we spin up a completely isolated server/state for each test @@ -74,6 +74,8 @@ export async function e2ePluginSetup (projectRoot: string, on: Cypress.PluginEve testState = {}; ({ serverPortPromise, ctx } = runInternalServer({ projectRoot: null, + }, { + loadCachedProjects: false, }) as {ctx: DataContext, serverPortPromise: Promise }) const fetchApi = ctx.util.fetch diff --git a/packages/frontend-shared/cypress/e2e/support/e2eSupport.ts b/packages/frontend-shared/cypress/e2e/support/e2eSupport.ts index f0db8375db66..4ce6733e53f2 100644 --- a/packages/frontend-shared/cypress/e2e/support/e2eSupport.ts +++ b/packages/frontend-shared/cypress/e2e/support/e2eSupport.ts @@ -81,7 +81,7 @@ function setupE2E (projectName?: ProjectFixture) { } if (projectName) { - cy.task('setupE2E', projectName, { log: false }) + cy.task('scaffoldProject', projectName, { log: false }) } return cy.withCtx(async (ctx, o) => { diff --git a/packages/launchpad/cypress/e2e/integration/open-mode.spec.ts b/packages/launchpad/cypress/e2e/integration/open-mode.spec.ts index 204c76f3168f..31d8c362d381 100644 --- a/packages/launchpad/cypress/e2e/integration/open-mode.spec.ts +++ b/packages/launchpad/cypress/e2e/integration/open-mode.spec.ts @@ -6,10 +6,24 @@ describe('Launchpad: Open Mode', () => { cy.visitLaunchpad() }) - it('shows the open page when testingType is not specified', () => { + it('shows Add Project when no projects have been added', () => { cy.get('h1').should('contain', defaultMessages.globalPage.empty.title) }) + it('shows projects when projects have been added', () => { + cy.get('h1').should('contain', defaultMessages.globalPage.empty.title) + }) + + it('shows the projects page when a project is not specified', () => { + cy.task('scaffoldProject', 'todos').then((projectPath) => { + cy.withCtx(async (ctx, o) => { + ctx.actions.project.addProject({ path: o.projectPath as string, open: false }) + }, { projectPath }) + }) + + cy.contains(defaultMessages.globalPage.recentProjectsHeader) + }) + it('goes directly to e2e tests when launched with --e2e', () => { cy.setupE2E('todos') diff --git a/packages/server/lib/makeDataContext.ts b/packages/server/lib/makeDataContext.ts index b29dfa5e9399..fa30a83bffe5 100644 --- a/packages/server/lib/makeDataContext.ts +++ b/packages/server/lib/makeDataContext.ts @@ -12,6 +12,7 @@ import { openProject } from './open_project' import cache from './cache' import errors from './errors' import { graphqlSchema } from '@packages/graphql/src/schema' +import type { InternalDataContextOptions } from '@packages/data-context/src/DataContext' const { getBrowsers } = browserUtils @@ -19,6 +20,7 @@ interface MakeDataContextOptions { os: PlatformName rootBus: EventEmitter launchArgs: LaunchArgs + _internalOptions: InternalDataContextOptions } let legacyDataContext: DataContext | undefined @@ -36,6 +38,9 @@ export function makeLegacyDataContext (launchArgs: LaunchArgs = {} as LaunchArgs rootBus: new EventEmitter, launchArgs, os: os.platform() as PlatformName, + _internalOptions: { + loadCachedProjects: true, + }, }) } diff --git a/packages/server/lib/modes/internal-server.ts b/packages/server/lib/modes/internal-server.ts index 5dee56af5aee..64c3efb5404d 100644 --- a/packages/server/lib/modes/internal-server.ts +++ b/packages/server/lib/modes/internal-server.ts @@ -5,7 +5,7 @@ import { makeDataContext } from '../makeDataContext' import { makeGraphQLServer } from '../gui/makeGraphQLServer' import { assertValidPlatform } from '@packages/types/src/platform' -export function runInternalServer (options) { +export function runInternalServer (launchArgs, _internalOptions = { loadCachedProjects: true }) { const bus = new EventEmitter() const platform = os.platform() @@ -14,7 +14,8 @@ export function runInternalServer (options) { const ctx = makeDataContext({ os: platform, rootBus: bus, - launchArgs: options, + launchArgs, + _internalOptions, }) // Initializing the data context, loading browsers, etc.