Skip to content

Commit fec27a0

Browse files
authored
fix: test-recording instructions in Component Test mode (#21422)
1 parent a218f96 commit fec27a0

File tree

4 files changed

+51
-37
lines changed

4 files changed

+51
-37
lines changed

packages/app/cypress/e2e/runs.cy.ts

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
11
import defaultMessages from '@packages/frontend-shared/src/locales/en-US.json'
22
import type { SinonStub } from 'sinon'
33

4+
function scaffoldTestingTypeAndVisitRunsPage (testingType: 'e2e' | 'component') {
5+
cy.scaffoldProject('cypress-in-cypress')
6+
cy.openProject('cypress-in-cypress')
7+
cy.startAppServer(testingType)
8+
9+
cy.loginUser()
10+
11+
// make sure there are no runs found for the project ID
12+
cy.remoteGraphQLIntercept(async (obj) => {
13+
if (obj.result.data?.cloudProjectBySlug) {
14+
obj.result.data.cloudProjectBySlug.runs.nodes = []
15+
}
16+
17+
return obj.result
18+
})
19+
20+
cy.visitApp()
21+
22+
return cy.get('[href="#/runs"]').click()
23+
}
24+
425
describe('App: Runs', { viewportWidth: 1200 }, () => {
526
context('Runs Page', () => {
627
beforeEach(() => {
@@ -398,47 +419,40 @@ describe('App: Runs', { viewportWidth: 1200 }, () => {
398419
cy.findByText(defaultMessages.runs.connect.buttonProject).should('exist')
399420
})
400421

401-
it('displays how to record prompt when connected and no runs', () => {
402-
cy.scaffoldProject('component-tests')
403-
cy.openProject('component-tests')
404-
cy.startAppServer('component')
405-
406-
cy.loginUser()
407-
cy.remoteGraphQLIntercept(async (obj) => {
408-
if (obj.result.data?.cloudProjectBySlug?.runs?.nodes) {
409-
obj.result.data.cloudProjectBySlug.runs.nodes = []
410-
}
422+
it('displays how to record prompt when connected and no runs in Component Testing', () => {
423+
scaffoldTestingTypeAndVisitRunsPage('component')
424+
cy.contains(defaultMessages.runs.empty.title).should('be.visible')
425+
cy.contains(defaultMessages.runs.empty.description).should('be.visible')
426+
cy.contains('cypress run --component --record --key 2aaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa').should('be.visible')
427+
})
411428

412-
return obj.result
413-
})
429+
it('displays how to record prompt when connected and no runs in E2E', () => {
430+
scaffoldTestingTypeAndVisitRunsPage('e2e')
414431

415-
cy.visitApp()
416-
cy.get('[href="#/runs"]').click()
417-
cy.contains(defaultMessages.runs.empty.title)
418-
cy.contains(defaultMessages.runs.empty.description)
419-
cy.contains('--record --key 2aaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa')
432+
cy.contains(defaultMessages.runs.empty.title).should('be.visible')
433+
cy.contains(defaultMessages.runs.empty.description).should('be.visible')
434+
cy.contains('cypress run --record --key 2aaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa').should('be.visible')
420435
})
421436

422-
it('displays a copy button', () => {
423-
cy.scaffoldProject('component-tests')
424-
cy.openProject('component-tests')
425-
cy.startAppServer('component')
426-
437+
it('displays a copy button and copies correct command in Component Testing', () => {
438+
scaffoldTestingTypeAndVisitRunsPage('component')
427439
cy.withCtx(async (ctx, o) => {
428440
o.sinon.stub(ctx.electronApi, 'copyTextToClipboard')
429441
})
430442

431-
cy.loginUser()
432-
cy.remoteGraphQLIntercept(async (obj) => {
433-
if (obj.result.data?.cloudProjectBySlug?.runs?.nodes) {
434-
obj.result.data.cloudProjectBySlug.runs.nodes = []
435-
}
443+
cy.get('[data-cy="copy-button"]').click()
444+
cy.contains('Copied!')
445+
cy.withRetryableCtx((ctx) => {
446+
expect(ctx.electronApi.copyTextToClipboard as SinonStub).to.have.been.calledWith('cypress run --component --record --key 2aaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa')
447+
})
448+
})
436449

437-
return obj.result
450+
it('displays a copy button and copies correct command in E2E', () => {
451+
scaffoldTestingTypeAndVisitRunsPage('e2e')
452+
cy.withCtx(async (ctx, o) => {
453+
o.sinon.stub(ctx.electronApi, 'copyTextToClipboard')
438454
})
439455

440-
cy.visitApp()
441-
cy.get('[href="#/runs"]').click()
442456
cy.get('[data-cy="copy-button"]').click()
443457
cy.contains('Copied!')
444458
cy.withRetryableCtx((ctx) => {

packages/app/src/runs/RunsEmpty.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ fragment RunsEmpty on CurrentProject {
3333
title
3434
projectId
3535
configFile
36+
currentTestingType
3637
cloudProject {
3738
__typename
3839
... on CloudProject {
@@ -58,7 +59,9 @@ const firstRecordKey = computed(() => {
5859
: '<record-key>'
5960
})
6061
const recordCommand = computed(() => {
61-
return `cypress run --record --key ${firstRecordKey.value}`
62+
const componentFlagOrSpace = props.gql.currentTestingType === 'component' ? ' --component ' : ' '
63+
64+
return `cypress run${componentFlagOrSpace}--record --key ${firstRecordKey.value}`
6265
})
6366
</script>
6467

packages/frontend-shared/src/components/TerminalPrompt.cy.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ describe('<TerminalPrompt />', () => {
55
it('renders without overflow', { viewportWidth: 800, viewportHeight: 120 }, () => {
66
cy.mount(() => (
77
<div class="p-6">
8-
<TerminalPrompt projectFolderName="design-system" command="git add cypress.config.js"/>
8+
<TerminalPrompt command="git add cypress.config.js"/>
99
</div>
1010
))
1111

@@ -16,16 +16,14 @@ describe('<TerminalPrompt />', () => {
1616

1717
it('overflows nicely', { viewportWidth: 800, viewportHeight: 120 }, () => {
1818
const command = 'yarn workspace @packages/frontend-shared cypress:run --record --key 123as4d56asda987das'
19-
const projectFolderName = 'design-system'
2019

2120
cy.mount(() => (
2221
<div class="p-6">
23-
<TerminalPrompt projectFolderName={projectFolderName} command={command}/>
22+
<TerminalPrompt command={command}/>
2423
</div>
2524
))
2625

2726
cy.contains(command)
28-
cy.contains(projectFolderName)
2927
cy.contains('button', defaultMessages.clipboard.copy)
3028
.should('be.visible')
3129
.percySnapshot()

packages/frontend-shared/src/components/TerminalPrompt.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<code class="border rounded flex font-normal border-gray-100 px-16px text-gray-700 leading-40px relative items-center whitespace-nowrap overflow-hidden">
33
<i-cy-terminal_x16 class="flex-shrink-0 h-16px mr-8px w-16px icon-dark-gray-500 icon-light-gray-100" />
44
<span class="mr-8px text-purple-500">
5-
{{ projectFolderName }}<template v-if="projectFolderName">:~</template>$
5+
$
66
</span>
77
{{ command }}
88
<div class="font-sans opacity-gradient p-4px pl-32px top-0 right-0 bottom-0 absolute">
@@ -17,7 +17,6 @@
1717
import CopyButton from '../gql-components/CopyButton.vue'
1818
1919
defineProps<{
20-
projectFolderName?: string
2120
command: string
2221
}>()
2322
</script>

0 commit comments

Comments
 (0)