@@ -59,7 +59,9 @@ describe('cy.session', { retries: 0 }, () => {
59
59
. then ( async ( ) => {
60
60
cy . spy ( Cypress , 'action' ) . log ( false )
61
61
62
- await Cypress . action ( 'runner:test:before:after:run:async' , { } , Cypress . state ( 'runnable' ) , { nextTestHasTestIsolationOn : true } )
62
+ await Cypress . action ( 'runner:test:before:after:run:async' , { } , Cypress . state ( 'runnable' ) , {
63
+ nextTestHasTestIsolationOn : true ,
64
+ } )
63
65
64
66
expect ( Cypress . action ) . to . be . calledWith ( 'cy:url:changed' , '' )
65
67
expect ( Cypress . action ) . to . be . calledWith ( 'cy:visit:blank' , { testIsolation : true } )
@@ -73,7 +75,9 @@ describe('cy.session', { retries: 0 }, () => {
73
75
. then ( async ( ) => {
74
76
cy . spy ( Cypress , 'action' ) . log ( false )
75
77
76
- await Cypress . action ( 'runner:test:before:after:run:async' , { } , Cypress . state ( 'runnable' ) , { nextTestHasTestIsolationOn : undefined } )
78
+ await Cypress . action ( 'runner:test:before:after:run:async' , { } , Cypress . state ( 'runnable' ) , {
79
+ nextTestHasTestIsolationOn : undefined ,
80
+ } )
77
81
78
82
expect ( Cypress . action ) . to . be . calledWith ( 'cy:url:changed' , '' )
79
83
expect ( Cypress . action ) . to . be . calledWith ( 'cy:visit:blank' , { testIsolation : true } )
@@ -87,7 +91,9 @@ describe('cy.session', { retries: 0 }, () => {
87
91
. then ( async ( ) => {
88
92
cy . spy ( Cypress , 'action' ) . log ( false )
89
93
90
- await Cypress . action ( 'runner:test:before:after:run:async' , { } , Cypress . state ( 'runnable' ) , { nextTestHasTestIsolationOn : false } )
94
+ await Cypress . action ( 'runner:test:before:after:run:async' , { } , Cypress . state ( 'runnable' ) , {
95
+ nextTestHasTestIsolationOn : false ,
96
+ } )
91
97
92
98
expect ( Cypress . action ) . not . to . be . calledWith ( 'cy:url:changed' , '' )
93
99
expect ( Cypress . action ) . not . to . be . calledWith ( 'cy:visit:blank' , { testIsolation : true } )
@@ -99,31 +105,52 @@ describe('cy.session', { retries: 0 }, () => {
99
105
it ( 'clears the browser cookie after each run' , ( ) => {
100
106
cy . window ( )
101
107
. then ( ( win ) => {
102
- // @ts -expect-error TODO: cookie doesn't exist on win, usually cookie is set on document
103
- win . cookie = 'key=value; SameSite=Strict; Secure; Path=/fixtures'
108
+ // Check that the only cookie present is the Cypress initial cookie
109
+ expect ( win . document . cookie ) . to . satisfy ( ( cookie ) => {
110
+ return ! cookie || cookie === '__cypress.initial=true'
111
+ } )
112
+
113
+ win . document . cookie = 'key=value; SameSite=Strict; Secure; Path=/fixtures'
104
114
} )
105
115
. then ( async ( ) => {
106
116
cy . spy ( Cypress , 'action' ) . log ( false )
107
117
108
- await Cypress . action ( 'runner:test:before:after:run:async' , { } , Cypress . state ( 'runnable' ) , { nextTestHasTestIsolationOn : true } )
118
+ await Cypress . action ( 'runner:test:before:after:run:async' , { } , Cypress . state ( 'runnable' ) , {
119
+ nextTestHasTestIsolationOn : true ,
120
+ } )
109
121
} )
110
122
111
- cy . window ( ) . its ( 'cookie' ) . should ( 'be.undefined' )
123
+ cy . window ( ) . then ( ( win ) => {
124
+ // Check that the only cookie present is the Cypress initial cookie
125
+ expect ( win . document . cookie ) . to . satisfy ( ( cookie ) => {
126
+ return ! cookie || cookie === '__cypress.initial=true'
127
+ } )
128
+ } )
112
129
} )
113
130
114
131
it ( 'does not clear the browser cookie after each run if the next test has test isolation off' , ( ) => {
115
132
cy . window ( )
116
133
. then ( ( win ) => {
117
- // @ts -expect-error TODO: cookie doesn't exist on win, usually cookie is set on document
118
- win . cookie = 'key=value; SameSite=Strict; Secure; Path=/fixtures'
134
+ // Check that the only cookie present is the Cypress initial cookie
135
+ expect ( win . document . cookie ) . to . satisfy ( ( cookie ) => {
136
+ return ! cookie || cookie === '__cypress.initial=true'
137
+ } )
138
+
139
+ win . document . cookie = 'key=value'
140
+ expect ( win . document . cookie ) . to . include ( 'key=value' )
119
141
} )
120
142
. then ( async ( ) => {
121
143
cy . spy ( Cypress , 'action' ) . log ( false )
122
144
123
- await Cypress . action ( 'runner:test:before:after:run:async' , { } , Cypress . state ( 'runnable' ) , { nextTestHasTestIsolationOn : false } )
145
+ await Cypress . action ( 'runner:test:before:after:run:async' , { } , Cypress . state ( 'runnable' ) , {
146
+ nextTestHasTestIsolationOn : false ,
147
+ } )
124
148
} )
125
149
126
- cy . window ( ) . its ( 'cookie' ) . should ( 'eq' , 'key=value; SameSite=Strict; Secure; Path=/fixtures' )
150
+ cy . window ( )
151
+ . then ( ( win ) => {
152
+ expect ( win . document . cookie ) . to . include ( 'key=value' )
153
+ } )
127
154
} )
128
155
} )
129
156
@@ -896,8 +923,7 @@ describe('cy.session', { retries: 0 }, () => {
896
923
it ( 'does not clear the browser context before each run' , ( ) => {
897
924
cy . window ( )
898
925
. then ( ( win ) => {
899
- // @ts -expect-error TODO: cookie doesn't exist on win, usually cookie is set on document
900
- win . cookie = 'key=value; SameSite=Strict; Secure; Path=/fixtures'
926
+ win . document . cookie = 'key=value; SameSite=Strict; Secure; Path=/fixtures'
901
927
win . localStorage . setItem ( 'animal' , 'bear' )
902
928
win . sessionStorage . setItem ( 'food' , 'burgers' )
903
929
} )
@@ -913,9 +939,11 @@ describe('cy.session', { retries: 0 }, () => {
913
939
expect ( Cypress . action ) . not . to . be . calledWith ( 'cy:visit:blank' )
914
940
} )
915
941
916
- cy . window ( ) . its ( 'cookie' ) . should ( 'equal' , 'key=value; SameSite=Strict; Secure; Path=/fixtures' )
917
- cy . window ( ) . its ( 'localStorage' ) . should ( 'have.length' , 1 ) . should ( 'deep.contain' , { animal : 'bear' } )
918
- cy . window ( ) . its ( 'sessionStorage' ) . should ( 'have.length' , 1 ) . should ( 'deep.contain' , { food : 'burgers' } )
942
+ cy . window ( ) . then ( ( win ) => {
943
+ expect ( win . document . cookie ) . to . contain ( 'key=value' )
944
+ expect ( win . localStorage ) . to . have . length ( 1 ) . and . to . deep . contain ( { animal : 'bear' } )
945
+ expect ( win . sessionStorage ) . to . have . length ( 1 ) . and . to . deep . contain ( { food : 'burgers' } )
946
+ } )
919
947
} )
920
948
} )
921
949
0 commit comments