Skip to content

Commit

Permalink
chore: add browser state action for debug (#26763)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkasper-was-taken committed May 30, 2023
1 parent acc4d5f commit b5c8b15
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/data-context/src/actions/ProjectActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export interface ProjectApiShape {
resetBrowserTabsForNextTest(shouldKeepTabOpen: boolean): Promise<void>
resetServer(): void
runSpec(spec: Cypress.Spec): Promise<void>
routeToDebug(): Promise<void>
}

export interface FindSpecs<T> {
Expand Down Expand Up @@ -637,4 +638,9 @@ export class ProjectActions {
}
}
}

async debugCloudRun ({ runNumber }: { runNumber: number }) {
await this.ctx.relevantRuns.moveToRun(runNumber, this.ctx.git?.currentHashes || [])
await this.api.routeToDebug()
}
}
15 changes: 15 additions & 0 deletions packages/data-context/test/unit/actions/ProjectActions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,19 @@ describe('ProjectActions', () => {
})
})
})

describe('debugCloudRun', () => {
context('default', () => {
beforeEach(() => {
sinon.stub(ctx.relevantRuns, 'moveToRun')
})

it('should succeed', async () => {
await ctx.actions.project.debugCloudRun({ runNumber: 123 })

expect(ctx.relevantRuns.moveToRun).to.have.been.calledWith(123)
expect(ctx._apis.projectApi.routeToDebug).to.have.been.called
})
})
})
})
1 change: 1 addition & 0 deletions packages/data-context/test/unit/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export function createTestDataContext (mode: DataContextConfig['mode'] = 'run',
insertProjectToCache: sinon.stub().resolves(),
getProjectRootsFromCache: sinon.stub().resolves([]),
runSpec: sinon.stub(),
routeToDebug: sinon.stub(),
} as unknown as ProjectApiShape,
electronApi: {
isMainWindowFocused: sinon.stub().returns(false),
Expand Down
3 changes: 3 additions & 0 deletions packages/graphql/schemas/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1786,6 +1786,9 @@ type Mutation {
"""Set failed tests for the current run to be used by the runner"""
setTestsForRun(testsBySpec: [TestsBySpecInput!]!): Boolean

"""Set the route to debug and show the specified the CloudRun"""
showDebugForCloudRun(runNumber: Int!): Query

"""Show system notification via Electron"""
showSystemNotification(body: String!, title: String!): Boolean

Expand Down
13 changes: 13 additions & 0 deletions packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -847,5 +847,18 @@ export const mutation = mutationType({
return true
},
})

t.field('showDebugForCloudRun', {
type: Query,
description: 'Set the route to debug and show the specified the CloudRun',
args: {
runNumber: nonNull(intArg()),
},
resolve: async (_, args, ctx) => {
await ctx.actions.project.debugCloudRun({ runNumber: args.runNumber })

return {}
},
})
},
})
3 changes: 3 additions & 0 deletions packages/server/lib/makeDataContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ export function makeDataContext (options: MakeDataContextOptions): DataContext {
async runSpec (spec: Cypress.Spec): Promise<void> {
openProject.changeUrlToSpec(spec)
},
async routeToDebug (): Promise<void> {
openProject.changeUrlToDebug()
},
},
electronApi: {
openExternal (url: string) {
Expand Down
14 changes: 14 additions & 0 deletions packages/server/lib/open_project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,20 @@ export class OpenProject {
this.projectBase.server._socket.changeToUrl(newSpecUrl)
}

changeUrlToDebug () {
if (!this.projectBase) {
debug('No projectBase, cannot change url')

return
}

const newUrl = `#/debug/`

debug(`New url is ${newUrl}`)

this.projectBase.server._socket.changeToUrl(newUrl)
}

/**
* Sends the new telemetry context to the browser
* @param context - telemetry context string
Expand Down

0 comments on commit b5c8b15

Please sign in to comment.