Skip to content

Commit 0074acd

Browse files
chore: (cy.prompt) refactor getTestsState to take a runnable id (#31965)
* chore: (cy.prompt) refactor getTestsState to take a runnable id * fix tests * minor tweak
1 parent ba6b391 commit 0074acd

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

packages/driver/cypress/e2e/commands/navigation.cy.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -950,11 +950,13 @@ describe('src/cy/commands/navigation', () => {
950950
})
951951

952952
describe('when origins don\'t match', () => {
953+
let mockGetTestsState
954+
953955
beforeEach(() => {
954956
Cypress.emit('test:before:run', { id: 'r2' })
955957

956958
cy.stub(Cypress.runner, 'getEmissions').returns([])
957-
cy.stub(Cypress.runner, 'getTestsState').returns([])
959+
mockGetTestsState = cy.stub(Cypress.runner, 'getTestsState').returns([])
958960
cy.stub(Cypress.runner, 'getStartTime').returns('12345')
959961
cy.stub(Cypress.Log, 'countLogsByTests').withArgs([]).returns(1)
960962
cy.stub(Cypress.runner, 'countByTestState')
@@ -993,7 +995,9 @@ describe('src/cy/commands/navigation', () => {
993995
.withArgs('preserve:run:state')
994996
.callsFake(fn)
995997

996-
cy.visit('http://localhost:4200')
998+
cy.visit('http://localhost:4200').then(() => {
999+
expect(mockGetTestsState).to.be.calledWith('r2')
1000+
})
9971001
})
9981002

9991003
it('replaces window.location when origins don\'t match', (done) => {
@@ -1024,7 +1028,9 @@ describe('src/cy/commands/navigation', () => {
10241028
.withArgs('preserve:run:state')
10251029
.resolves()
10261030

1027-
cy.visit('http://localhost:4200')
1031+
cy.visit('http://localhost:4200').then(() => {
1032+
expect(mockGetTestsState).to.be.calledWith('r2')
1033+
})
10281034
})
10291035
})
10301036

packages/driver/src/cy/commands/navigation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,7 @@ export default (Commands, Cypress, cy, state, config) => {
10741074
// state for like scrollTop
10751075
let runState: RunState = {
10761076
currentId: id,
1077-
tests: Cypress.runner.getTestsState(),
1077+
tests: Cypress.runner.getTestsState(id),
10781078
startTime: Cypress.runner.getStartTime(),
10791079
emissions: Cypress.runner.getEmissions(),
10801080
}

packages/driver/src/cypress/runner.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,8 +1901,8 @@ export default {
19011901
return _emissions
19021902
},
19031903

1904-
getTestsState () {
1905-
const id = _test != null ? _test.id : undefined
1904+
getTestsState (testId?: string) {
1905+
const id = testId ?? (_test != null ? _test.id : undefined)
19061906
const tests = {}
19071907

19081908
// bail if we dont have a current test

0 commit comments

Comments
 (0)