Skip to content

Commit

Permalink
Merge branch 'unified-desktop-gui' of https://github.com/cypress-io/c…
Browse files Browse the repository at this point in the history
…ypress into scaffold-integration-in-app
  • Loading branch information
ZachJW34 committed Nov 12, 2021
2 parents 0cf3451 + d65a6df commit bd9de7b
Show file tree
Hide file tree
Showing 41 changed files with 107 additions and 378 deletions.
4 changes: 1 addition & 3 deletions packages/data-context/__snapshots__/data-context.spec.ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,15 @@ exports['@packages/data-context initializeData initializes 1'] = {
"app": {
"currentTestingType": null,
"refreshingBrowsers": {},
"navItem": "settings",
"browsers": [
{
"path": "/dev/chrome"
}
],
"projects": [],
"currentProject": null,
"isInGlobalMode": false,
"isAuthBrowserOpened": false
},
"isAuthBrowserOpened": false,
"wizard": {
"chosenTestingType": null,
"chosenBundler": null,
Expand Down
14 changes: 6 additions & 8 deletions packages/data-context/src/DataContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import debugLib from 'debug'
import { CoreDataShape, makeCoreData } from './data/coreDataShape'
import { DataActions } from './DataActions'
import {
AppDataSource,
GitDataSource,
FileDataSource,
ProjectDataSource,
Expand Down Expand Up @@ -80,6 +79,10 @@ export class DataContext {
return this._config.electronApi
}

get isGlobalMode () {
return !this.currentProject
}

async initializeData () {
const toAwait: Promise<any>[] = [
// Fetch the browsers when the app starts, so we have some by
Expand All @@ -97,7 +100,7 @@ export class DataContext {
if (this._config.launchArgs.projectRoot) {
await this.actions.project.setActiveProject(this._config.launchArgs.projectRoot)

if (this.coreData.app.currentProject?.preferences) {
if (this.coreData.currentProject?.preferences) {
toAwait.push(this.actions.project.launchProjectWithoutElectron())
}
}
Expand Down Expand Up @@ -177,11 +180,6 @@ export class DataContext {
return new DataActions(this)
}

@cached
get app () {
return new AppDataSource(this)
}

get appData () {
return this.coreData.app
}
Expand All @@ -206,7 +204,7 @@ export class DataContext {
}

get currentProject () {
return this.coreData.app.currentProject
return this.coreData.currentProject
}

@cached
Expand Down
4 changes: 2 additions & 2 deletions packages/data-context/src/actions/AppActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ export class AppActions {

this.ctx.coreData.app.browsers = browsers

if (this.ctx.coreData.app.currentProject) {
this.ctx.coreData.app.currentProject.browsers = browsers
if (this.ctx.coreData.currentProject) {
this.ctx.coreData.currentProject.browsers = browsers
}

// If we don't have a chosen browser, assign to the first one in the list
Expand Down
4 changes: 2 additions & 2 deletions packages/data-context/src/actions/AuthActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ export class AuthActions {

async login () {
this.setAuthenticatedUser(await this.authApi.logIn(({ browserOpened }) => {
this.ctx.appData.isAuthBrowserOpened = browserOpened
this.ctx.coreData.isAuthBrowserOpened = browserOpened
}))
}

async logout () {
try {
this.ctx.appData.isAuthBrowserOpened = false
this.ctx.coreData.isAuthBrowserOpened = false
await this.authApi.logOut()
} catch {
//
Expand Down
9 changes: 4 additions & 5 deletions packages/data-context/src/actions/ProjectActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@ export class ProjectActions {
}

async clearActiveProject () {
this.ctx.appData.currentProject = null
this.ctx.coreData.currentProject = null
await this.api.closeActiveProject()

// TODO(tim): Improve general state management w/ immutability (immer) & updater fn
this.ctx.coreData.app.isInGlobalMode = true
this.ctx.coreData.app.currentProject = null
this.ctx.coreData.currentProject = null
this.ctx.coreData.app.currentTestingType = null
}

Expand Down Expand Up @@ -79,9 +78,9 @@ export class ProjectActions {
}

private setCurrentProjectProperties (currentProjectProperties: Partial<ActiveProjectShape>) {
this.ctx.coreData.app.currentProject = {
this.ctx.coreData.currentProject = {
browsers: this.ctx.coreData.app.browsers,
...this.ctx.coreData.app.currentProject,
...this.ctx.coreData.currentProject,
...currentProjectProperties,
} as ActiveProjectShape
}
Expand Down
2 changes: 0 additions & 2 deletions packages/data-context/src/actions/WizardActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ export class WizardActions {
//
}

setSelectedNavItem (navItem: NexusGenEnums['NavItem']) {}

setTestingType (type: 'component' | 'e2e') {
this.ctx.coreData.wizard.chosenTestingType = type

Expand Down
14 changes: 5 additions & 9 deletions packages/data-context/src/data/coreDataShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,8 @@ export interface ActiveProjectShape extends ProjectShape {
}

export interface AppDataShape {
navItem: NexusGenEnums['NavItem']
browsers: ReadonlyArray<FoundBrowser> | null
projects: ProjectShape[]
currentProject: ActiveProjectShape | null
isInGlobalMode: boolean
isAuthBrowserOpened: boolean
currentTestingType: Maybe<TestingTypeEnum>
refreshingBrowsers: Promise<FoundBrowser[]> | null
}
Expand Down Expand Up @@ -75,9 +71,11 @@ export interface CoreDataShape {
baseError: BaseErrorDataShape | null
dev: DevStateShape
app: AppDataShape
currentProject: ActiveProjectShape | null
wizard: WizardDataShape
user: AuthenticatedUserShape | null
electron: ElectronShape
isAuthBrowserOpened: boolean
}

/**
Expand All @@ -90,15 +88,13 @@ export function makeCoreData (): CoreDataShape {
refreshState: null,
},
app: {
refreshingBrowsers: null,
currentTestingType: null,
navItem: 'settings',
refreshingBrowsers: null,
browsers: null,
projects: [],
currentProject: null,
isInGlobalMode: false,
isAuthBrowserOpened: false,
},
isAuthBrowserOpened: false,
currentProject: null,
wizard: {
chosenTestingType: null,
chosenBundler: null,
Expand Down
16 changes: 0 additions & 16 deletions packages/data-context/src/sources/AppDataSource.ts

This file was deleted.

12 changes: 6 additions & 6 deletions packages/data-context/src/sources/ConfigDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ export class ConfigDataSource {
constructor (private ctx: DataContext) {}

async getConfigForProject (projectRoot: string): Promise<FullConfig> {
if (!this.ctx.coreData.app.currentProject) {
if (!this.ctx.coreData.currentProject) {
throw new Error(`Cannot access config without currentProject`)
}

if (!this.ctx.coreData.app.currentProject.config) {
this.ctx.coreData.app.currentProject.config = Promise.resolve().then(async () => {
if (!this.ctx.coreData.currentProject.config) {
this.ctx.coreData.currentProject.config = Promise.resolve().then(async () => {
const configFile = await this.ctx.config.getDefaultConfigBasename(projectRoot)

return this.ctx._apis.projectApi.getConfig(projectRoot, { configFile })
})
}

return this.ctx.coreData.app.currentProject.config
return this.ctx.coreData.currentProject.config
}

async getDefaultConfigBasename (projectRoot: string) {
Expand Down Expand Up @@ -53,10 +53,10 @@ export class ConfigDataSource {
}

async cleanupCachedConfigForActiveProject () {
if (!this.ctx.coreData.app.currentProject?.config) {
if (!this.ctx.coreData.currentProject?.config) {
return
}

this.ctx.coreData.app.currentProject.config = null
this.ctx.coreData.currentProject.config = null
}
}
1 change: 0 additions & 1 deletion packages/data-context/src/sources/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable padding-line-between-statements */
// created by autobarrel, do not modify directly

export * from './AppDataSource'
export * from './BrowserDataSource'
export * from './CloudDataSource'
export * from './ConfigDataSource'
Expand Down
2 changes: 1 addition & 1 deletion packages/data-context/test/unit/data-context.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const makeDataContext = (options) => {
getProjectRootsFromCache: () => ([]),
getProjectPreferencesFromCache: () => {
return {
[options.coreData.app.currentProject.title]: {
[options.coreData.currentProject.title]: {
browserPath: chromeTestPath,
testingType: 'component',
},
Expand Down
3 changes: 3 additions & 0 deletions packages/frontend-shared/cypress/e2e/support/e2eSupport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ beforeEach(() => {
// function setup

function setupE2E (projectName?: ProjectFixture) {
const _log = Cypress.log({ name: 'setupE2E', message: projectName ?? '' })

if (projectName && !e2eProjectDirs.includes(projectName)) {
throw new Error(`Unknown project ${projectName}`)
}
Expand All @@ -94,6 +96,7 @@ function setupE2E (projectName?: ProjectFixture) {
ctx.appServerPort,
]
}, { projectName, log: false }).then(([gqlPort, serverPort]) => {
_log.end()
Cypress.env('e2e_gqlPort', gqlPort)
Cypress.env('e2e_serverPort', serverPort)
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import { cloneDeep } from 'lodash'
import type { CloudUser } from '../generated/test-cloud-graphql-types.gen'
import type { WizardStep, NavItem, CurrentProject, Browser, WizardBundler, WizardFrontendFramework, TestingTypeEnum, GlobalProject } from '../generated/test-graphql-types.gen'
import type { WizardStep, CurrentProject, Browser, WizardBundler, WizardFrontendFramework, TestingTypeEnum, GlobalProject } from '../generated/test-graphql-types.gen'
import { resetTestNodeIdx } from './clientTestUtils'
import { stubBrowsers } from './stubgql-Browser'
import * as cloudTypes from './stubgql-CloudTypes'
import { stubNavigationMenu } from './stubgql-NavigationMenu'
import { createTestCurrentProject, createTestGlobalProject, stubGlobalProject } from './stubgql-Project'
import { allBundlers } from './stubgql-Wizard'

export interface ClientTestContext {
currentProject: CurrentProject | null
projects: GlobalProject[]
app: {
navItem: NavItem
currentBrowser: Browser | null
browsers: Browser[] | null
isInGlobalMode: boolean
isAuthBrowserOpened: boolean
}
isAuthBrowserOpened: boolean
wizard: {
step: WizardStep
canNavigateForward: boolean
Expand All @@ -33,7 +29,6 @@ export interface ClientTestContext {
}
user: Partial<CloudUser> | null
cloudTypes: typeof cloudTypes
navigationMenu: typeof stubNavigationMenu
__mockPartial: any
}

Expand All @@ -50,12 +45,10 @@ export function makeClientTestContext (): ClientTestContext {
currentProject: testProject,
projects: [stubGlobalProject, createTestGlobalProject('another-test-project')],
app: {
navItem: 'settings',
browsers: stubBrowsers,
currentBrowser: stubBrowsers[0],
isInGlobalMode: false,
isAuthBrowserOpened: false,
},
isAuthBrowserOpened: false,
wizard: {
step: 'configFiles',
canNavigateForward: false,
Expand All @@ -71,7 +64,6 @@ export function makeClientTestContext (): ClientTestContext {
},
user: null,
cloudTypes,
navigationMenu: cloneDeep(stubNavigationMenu),
__mockPartial: {},
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import { makeCacheExchange } from '@packages/frontend-shared/src/graphql/urqlCli
import { clientTestSchema } from './clientTestSchema'
import type { ClientTestContext } from './clientTestContext'
import { defaultTypeResolver, FieldNode, GraphQLFieldResolver, GraphQLResolveInfo, GraphQLTypeResolver, isNonNullType } from 'graphql'
import { stubApp } from './stubgql-App'
import { stubWizard } from './stubgql-Wizard'
import type { CodegenTypeMap } from '../generated/test-graphql-types.gen'
import type { MaybeResolver } from './clientTestUtils'
import { stubNavigationItem, stubNavigationMenu } from './stubgql-NavigationMenu'
import { stubMutation } from './stubgql-Mutation'
import { pathToArray } from 'graphql/jsutils/Path'
import dedent from 'dedent'
Expand All @@ -21,14 +19,11 @@ import { CloudOrganizationStubs, CloudProjectStubs, CloudRecordKeyStubs, CloudRu
type MaybeResolveMap = {[K in keyof CodegenTypeMap]: MaybeResolver<CodegenTypeMap[K]>}

const GQLStubRegistry: Partial<MaybeResolveMap> = {
App: stubApp,
Wizard: stubWizard,
NavigationMenu: stubNavigationMenu,
ProjectLike: stubProject,
GlobalProject: stubGlobalProject,
CurrentProject: stubProject,
Mutation: stubMutation,
NavigationItem: stubNavigationItem,
Query: stubQuery,
CloudOrganization: CloudOrganizationStubs.cyOrg,
CloudProject: CloudProjectStubs.componentProject,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import type { App } from '../generated/test-graphql-types.gen'
import type { MaybeResolver } from './clientTestUtils'

export const longBrowsersList = [
{
name: 'electron',
Expand Down Expand Up @@ -123,13 +120,3 @@ export const longBrowsersList = [
majorVersion: '69',
},
] as const

export const stubApp: MaybeResolver<App> = {
__typename: 'App',
isInGlobalMode (source, args, ctx) {
return Boolean(ctx.currentProject)
},
isAuthBrowserOpened (source, args, ctx) {
return ctx.app.isAuthBrowserOpened
},
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Browser } from '../generated/test-graphql-types.gen'

import { testNodeId } from './clientTestUtils'
import { longBrowsersList } from './stubgql-App'
import { longBrowsersList } from './longBrowsersList'

export const stubBrowsers = longBrowsersList.map((browser, i): Browser => {
return {
Expand Down

This file was deleted.

Loading

0 comments on commit bd9de7b

Please sign in to comment.