From b5c8b157ddea0b9a361fbcd37aa8a807c509f3c1 Mon Sep 17 00:00:00 2001 From: David Kasper Date: Tue, 30 May 2023 17:12:09 -0500 Subject: [PATCH] chore: add browser state action for debug (#26763) --- .../data-context/src/actions/ProjectActions.ts | 6 ++++++ .../test/unit/actions/ProjectActions.spec.ts | 15 +++++++++++++++ packages/data-context/test/unit/helper.ts | 1 + packages/graphql/schemas/schema.graphql | 3 +++ .../src/schemaTypes/objectTypes/gql-Mutation.ts | 13 +++++++++++++ packages/server/lib/makeDataContext.ts | 3 +++ packages/server/lib/open_project.ts | 14 ++++++++++++++ 7 files changed, 55 insertions(+) diff --git a/packages/data-context/src/actions/ProjectActions.ts b/packages/data-context/src/actions/ProjectActions.ts index 254b14cad479..795c0a656d91 100644 --- a/packages/data-context/src/actions/ProjectActions.ts +++ b/packages/data-context/src/actions/ProjectActions.ts @@ -55,6 +55,7 @@ export interface ProjectApiShape { resetBrowserTabsForNextTest(shouldKeepTabOpen: boolean): Promise resetServer(): void runSpec(spec: Cypress.Spec): Promise + routeToDebug(): Promise } export interface FindSpecs { @@ -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() + } } diff --git a/packages/data-context/test/unit/actions/ProjectActions.spec.ts b/packages/data-context/test/unit/actions/ProjectActions.spec.ts index b814efe85adc..84e03f5093e1 100644 --- a/packages/data-context/test/unit/actions/ProjectActions.spec.ts +++ b/packages/data-context/test/unit/actions/ProjectActions.spec.ts @@ -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 + }) + }) + }) }) diff --git a/packages/data-context/test/unit/helper.ts b/packages/data-context/test/unit/helper.ts index bc7bf3288afb..17091f92143c 100644 --- a/packages/data-context/test/unit/helper.ts +++ b/packages/data-context/test/unit/helper.ts @@ -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), diff --git a/packages/graphql/schemas/schema.graphql b/packages/graphql/schemas/schema.graphql index 051f97132614..8bde10e33253 100644 --- a/packages/graphql/schemas/schema.graphql +++ b/packages/graphql/schemas/schema.graphql @@ -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 diff --git a/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts b/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts index c29d019bc02e..ed8c433237e7 100644 --- a/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts +++ b/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts @@ -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 {} + }, + }) }, }) diff --git a/packages/server/lib/makeDataContext.ts b/packages/server/lib/makeDataContext.ts index 74b7349df09c..31edae53b0f3 100644 --- a/packages/server/lib/makeDataContext.ts +++ b/packages/server/lib/makeDataContext.ts @@ -164,6 +164,9 @@ export function makeDataContext (options: MakeDataContextOptions): DataContext { async runSpec (spec: Cypress.Spec): Promise { openProject.changeUrlToSpec(spec) }, + async routeToDebug (): Promise { + openProject.changeUrlToDebug() + }, }, electronApi: { openExternal (url: string) { diff --git a/packages/server/lib/open_project.ts b/packages/server/lib/open_project.ts index 7706321fa97a..f6c70d14be8d 100644 --- a/packages/server/lib/open_project.ts +++ b/packages/server/lib/open_project.ts @@ -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