Skip to content

Commit 75a8026

Browse files
committed
add checkForStats and add tests for removing url parameters
1 parent 27ecd7c commit 75a8026

File tree

4 files changed

+47
-26
lines changed

4 files changed

+47
-26
lines changed

cli/types/cypress.d.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,7 @@ declare namespace Cypress {
297297
/**
298298
* The interface for user-defined properties in Window object under test.
299299
*/
300-
interface ApplicationWindow {
301-
state?: {
302-
studioSingleTestActive?: boolean
303-
[key: string]: any
304-
}
305-
} // tslint:disable-line
300+
interface ApplicationWindow {} // tslint:disable-line
306301

307302
/**
308303
* The configuration for Cypress.

packages/app/cypress/e2e/studio/studio-cloud.cy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe('Studio Cloud', () => {
4040
cy.wait('@indexHtml')
4141

4242
// Studio re-executes spec before waiting for commands - wait for the spec to finish executing.
43-
cy.waitForSpecToFinish()
43+
cy.waitForSpecToFinish(undefined, undefined, false)
4444

4545
// Verify the studio panel is still open
4646
cy.findByTestId('studio-panel')
@@ -224,7 +224,7 @@ describe('Studio Cloud', () => {
224224
cy.wait('@indexHtml')
225225

226226
// Studio re-executes spec before waiting for commands - wait for the spec to finish executing.
227-
cy.waitForSpecToFinish()
227+
cy.waitForSpecToFinish(undefined, undefined, false)
228228

229229
// Verify the studio panel is still open
230230
cy.findByTestId('studio-panel')

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

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { launchStudio, loadProjectAndRunSpec, assertClosingPanelWithoutChanges }
22

33
describe('Cypress Studio', () => {
44
function incrementCounter (initialCount: number) {
5-
cy.waitForSpecToFinish()
5+
cy.waitForSpecToFinish(undefined, undefined, false)
66

77
cy.getAutIframe().within(() => {
88
cy.get('p').contains(`Count is ${initialCount}`)
@@ -88,7 +88,7 @@ describe('studio functionality', () => {
8888
it('updates an existing test with assertions', () => {
8989
launchStudio()
9090

91-
cy.waitForSpecToFinish()
91+
cy.waitForSpecToFinish(undefined, undefined, false)
9292

9393
cy.getAutIframe().within(() => {
9494
cy.get('#increment').rightclick().then(() => {
@@ -403,7 +403,7 @@ describe('studio functionality', () => {
403403
it('shows assertions menu and submenu correctly', () => {
404404
launchStudio()
405405

406-
cy.waitForSpecToFinish()
406+
cy.waitForSpecToFinish(undefined, undefined, false)
407407

408408
cy.contains('No commands were issued in this test.').should('not.exist')
409409

@@ -442,7 +442,7 @@ describe('studio functionality', () => {
442442
win.location.href = win.location.href
443443
})
444444

445-
cy.waitForSpecToFinish()
445+
cy.waitForSpecToFinish(undefined, undefined, false)
446446

447447
// after reloading we should still be in studio mode but the commands should be removed
448448
// so the save button should be disabled
@@ -458,7 +458,7 @@ describe('studio functionality', () => {
458458

459459
cy.get('button[aria-label="Rerun all tests"]').click()
460460

461-
cy.waitForSpecToFinish()
461+
cy.waitForSpecToFinish(undefined, undefined, false)
462462
// after reloading we should still be in studio mode but the commands should be removed
463463
// the save button should be disabled since the commands were removed
464464
cy.findByTestId('studio-save-button').should('be.disabled')
@@ -524,7 +524,7 @@ describe('studio functionality', () => {
524524

525525
cy.findByTestId('studio-save-button').click()
526526

527-
cy.waitForSpecToFinish()
527+
cy.waitForSpecToFinish(undefined, undefined, false)
528528

529529
// only the commands in the editor are written to the test block - ideally we should also pick up the changes from the file system
530530
// TODO: https://github.com/cypress-io/cypress-services/issues/11085
@@ -651,7 +651,7 @@ describe('studio functionality', () => {
651651

652652
cy.findByTestId('record-button-recording').should('be.visible')
653653

654-
cy.waitForSpecToFinish()
654+
cy.waitForSpecToFinish(undefined, undefined, false)
655655

656656
cy.getAutIframe().within(() => {
657657
cy.get('#increment').realClick()
@@ -692,4 +692,34 @@ describe('studio functionality', () => {
692692

693693
cy.location().its('hash').should('contain', 'testId=r3').and('contain', 'studio=')
694694
})
695+
696+
it('removes the studio url parameters when closing studio existing test with the back button', () => {
697+
launchStudio()
698+
699+
cy.location().its('hash').should('contain', 'testId=r3').and('contain', 'studio=')
700+
701+
cy.get('[data-cy="studio-back-button"]').click()
702+
703+
cy.location().its('hash').and('not.contain', 'testId=').and('not.contain', 'studio=')
704+
})
705+
706+
it('removes the studio url parameters when closing studio existing test with the studio header button', () => {
707+
launchStudio()
708+
709+
cy.location().its('hash').should('contain', 'testId=r3').and('contain', 'studio=')
710+
711+
cy.findByTestId('studio-header-studio-button').click()
712+
713+
cy.location().its('hash').and('not.contain', 'testId=').and('not.contain', 'studio=')
714+
})
715+
716+
it('removes the studio url parameters when closing studio new test', () => {
717+
launchStudio({ specName: 'spec-w-visit.cy.js', createNewTest: true })
718+
719+
cy.location().its('hash').should('contain', 'suiteId=r2').and('contain', 'studio=')
720+
721+
cy.findByTestId('studio-header-studio-button').click()
722+
723+
cy.location().its('hash').and('not.contain', 'suiteId=').and('not.contain', 'studio=')
724+
})
695725
})

packages/app/cypress/e2e/support/execute-spec.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,19 @@ declare global {
1717
* 3. Waits (with a timeout of 30s) for the Rerun all tests button to be present. This ensures all tests have completed
1818
*
1919
*/
20-
waitForSpecToFinish(expectedResults?: ExpectedResults, timeout?: number): void
20+
waitForSpecToFinish(expectedResults?: ExpectedResults, timeout?: number, checkStats?: boolean): void
2121
verifyE2ESelected(): void
2222
verifyCtSelected(): void
2323
}
2424
}
2525
}
2626

27-
export const waitForSpecToFinish = (expectedResults, timeout?: number) => {
28-
// Check if we're in studio mode using URL hash parameters (same method as studio store)
29-
cy.window().then((win) => {
30-
const studioSingleTestActive = win.state?.studioSingleTestActive
31-
32-
if (!studioSingleTestActive) {
33-
cy.get('.passed > .num').should('exist')
34-
cy.get('.failed > .num').should('exist')
35-
}
36-
})
27+
export const waitForSpecToFinish = (expectedResults, timeout?: number, checkStats: boolean = true) => {
28+
// when we're in studio single test mode, we don't have the stats so we can skip this
29+
if (checkStats) {
30+
cy.get('.passed > .num').should('exist')
31+
cy.get('.failed > .num').should('exist')
32+
}
3733

3834
// Then ensure the tests are not running
3935
cy.contains('Your tests are loading...', { timeout: timeout || 30000 }).should('not.exist')

0 commit comments

Comments
 (0)