diff --git a/packages/driver/cypress/e2e/commands/navigation.cy.js b/packages/driver/cypress/e2e/commands/navigation.cy.js index 433e8826004..05ccbe3fc03 100644 --- a/packages/driver/cypress/e2e/commands/navigation.cy.js +++ b/packages/driver/cypress/e2e/commands/navigation.cy.js @@ -950,11 +950,13 @@ describe('src/cy/commands/navigation', () => { }) describe('when origins don\'t match', () => { + let mockGetTestsState + beforeEach(() => { Cypress.emit('test:before:run', { id: 'r2' }) cy.stub(Cypress.runner, 'getEmissions').returns([]) - cy.stub(Cypress.runner, 'getTestsState').returns([]) + mockGetTestsState = cy.stub(Cypress.runner, 'getTestsState').returns([]) cy.stub(Cypress.runner, 'getStartTime').returns('12345') cy.stub(Cypress.Log, 'countLogsByTests').withArgs([]).returns(1) cy.stub(Cypress.runner, 'countByTestState') @@ -993,7 +995,9 @@ describe('src/cy/commands/navigation', () => { .withArgs('preserve:run:state') .callsFake(fn) - cy.visit('http://localhost:4200') + cy.visit('http://localhost:4200').then(() => { + expect(mockGetTestsState).to.be.calledWith('r2') + }) }) it('replaces window.location when origins don\'t match', (done) => { @@ -1024,7 +1028,9 @@ describe('src/cy/commands/navigation', () => { .withArgs('preserve:run:state') .resolves() - cy.visit('http://localhost:4200') + cy.visit('http://localhost:4200').then(() => { + expect(mockGetTestsState).to.be.calledWith('r2') + }) }) }) diff --git a/packages/driver/src/cy/commands/navigation.ts b/packages/driver/src/cy/commands/navigation.ts index 496d672409c..d8eae62f040 100644 --- a/packages/driver/src/cy/commands/navigation.ts +++ b/packages/driver/src/cy/commands/navigation.ts @@ -1074,7 +1074,7 @@ export default (Commands, Cypress, cy, state, config) => { // state for like scrollTop let runState: RunState = { currentId: id, - tests: Cypress.runner.getTestsState(), + tests: Cypress.runner.getTestsState(id), startTime: Cypress.runner.getStartTime(), emissions: Cypress.runner.getEmissions(), } diff --git a/packages/driver/src/cypress/runner.ts b/packages/driver/src/cypress/runner.ts index 8e14610ac4d..7348f073354 100644 --- a/packages/driver/src/cypress/runner.ts +++ b/packages/driver/src/cypress/runner.ts @@ -1901,8 +1901,8 @@ export default { return _emissions }, - getTestsState () { - const id = _test != null ? _test.id : undefined + getTestsState (testId?: string) { + const id = testId ?? (_test != null ? _test.id : undefined) const tests = {} // bail if we dont have a current test