Skip to content

Commit

Permalink
chore: Add e2e tests for global mode (#18719)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbreiding committed Nov 4, 2021
1 parent e2735de commit 0422ede
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 8 deletions.
15 changes: 13 additions & 2 deletions packages/data-context/src/DataContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ import type { App as ElectronApp } from 'electron'

const IS_DEV_ENV = process.env.CYPRESS_INTERNAL_ENV !== 'production'

export interface InternalDataContextOptions {
loadCachedProjects: boolean
}

export interface DataContextConfig extends DataContextShellConfig {
schema: GraphQLSchema
os: PlatformName
Expand All @@ -39,6 +43,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 {
Expand All @@ -58,12 +66,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) {
await this.actions.project.setActiveProject(this._config.launchArgs.projectRoot)

Expand Down
6 changes: 4 additions & 2 deletions packages/frontend-shared/cypress/e2e/e2ePluginSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<number> })

const fetchApi = ctx.util.fetch
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend-shared/cypress/e2e/support/e2eSupport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
16 changes: 15 additions & 1 deletion packages/launchpad/cypress/e2e/integration/open-mode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
5 changes: 5 additions & 0 deletions packages/server/lib/makeDataContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ 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

interface MakeDataContextOptions {
os: PlatformName
rootBus: EventEmitter
launchArgs: LaunchArgs
_internalOptions: InternalDataContextOptions
}

let legacyDataContext: DataContext | undefined
Expand All @@ -37,6 +39,9 @@ export function makeLegacyDataContext (launchArgs: LaunchArgs = {} as LaunchArgs
rootBus: new EventEmitter,
launchArgs,
os: os.platform() as PlatformName,
_internalOptions: {
loadCachedProjects: true,
},
})
}

Expand Down
5 changes: 3 additions & 2 deletions packages/server/lib/modes/internal-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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.
Expand Down

0 comments on commit 0422ede

Please sign in to comment.