Skip to content

Commit 30c12f0

Browse files
authored
Merge branch 'develop' into astone123/cloud-rebrand
2 parents 6f5d954 + 8d85c80 commit 30c12f0

File tree

16 files changed

+227
-51
lines changed

16 files changed

+227
-51
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ describe('cy.session', { retries: 0 }, () => {
193193
it('groups session logs correctly', () => {
194194
expect(logs[0].get()).to.deep.contain({
195195
name: 'session',
196+
state: 'passed',
196197
id: sessionGroupId,
197198
sessionInfo: {
198199
id: 'session-1',
@@ -282,6 +283,7 @@ describe('cy.session', { retries: 0 }, () => {
282283
it('groups session logs correctly', () => {
283284
expect(logs[0].get()).to.deep.contain({
284285
name: 'session',
286+
state: 'passed',
285287
id: sessionGroupId,
286288
sessionInfo: {
287289
id: sessionId,
@@ -344,6 +346,7 @@ describe('cy.session', { retries: 0 }, () => {
344346
expect(err.message).to.contain('This error occurred while validating the created session')
345347
expect(logs[0].get()).to.deep.contain({
346348
name: 'session',
349+
state: 'failed',
347350
id: sessionGroupId,
348351
sessionInfo: {
349352
id: `session-${Cypress.state('test').id}`,
@@ -427,6 +430,7 @@ describe('cy.session', { retries: 0 }, () => {
427430
it('groups session logs correctly', () => {
428431
expect(logs[0].get()).to.contain({
429432
name: 'session',
433+
state: 'passed',
430434
id: sessionGroupId,
431435
})
432436

@@ -490,6 +494,7 @@ describe('cy.session', { retries: 0 }, () => {
490494
it('groups session logs correctly', () => {
491495
expect(logs[0].get()).to.contain({
492496
name: 'session',
497+
state: 'passed',
493498
id: sessionGroupId,
494499
})
495500

@@ -572,6 +577,7 @@ describe('cy.session', { retries: 0 }, () => {
572577
it('groups session logs correctly', () => {
573578
expect(logs[0].get()).to.contain({
574579
name: 'session',
580+
state: 'warned',
575581
id: sessionGroupId,
576582
})
577583

@@ -678,6 +684,7 @@ describe('cy.session', { retries: 0 }, () => {
678684

679685
expect(logs[0].get()).to.contain({
680686
name: 'session',
687+
state: 'failed',
681688
id: sessionGroupId,
682689
})
683690

@@ -914,6 +921,7 @@ describe('cy.session', { retries: 0 }, () => {
914921
it('groups session logs correctly', () => {
915922
expect(logs[0].get()).to.deep.contain({
916923
name: 'session',
924+
state: 'passed',
917925
id: sessionGroupId,
918926
sessionInfo: {
919927
id: 'session-1',
@@ -992,6 +1000,7 @@ describe('cy.session', { retries: 0 }, () => {
9921000
it('groups session logs correctly', () => {
9931001
expect(logs[0].get()).to.deep.contain({
9941002
name: 'session',
1003+
state: 'passed',
9951004
id: sessionGroupId,
9961005
sessionInfo: {
9971006
id: sessionId,
@@ -1044,6 +1053,7 @@ describe('cy.session', { retries: 0 }, () => {
10441053
expect(err.message).to.contain('Your `cy.session` **validate** promise rejected with false')
10451054
expect(logs[0].get()).to.deep.contain({
10461055
name: 'session',
1056+
state: 'failed',
10471057
id: sessionGroupId,
10481058
sessionInfo: {
10491059
id: `session-${Cypress.state('test').id}`,
@@ -1121,6 +1131,7 @@ describe('cy.session', { retries: 0 }, () => {
11211131
it('groups session logs correctly', () => {
11221132
expect(logs[0].get()).to.contain({
11231133
name: 'session',
1134+
state: 'passed',
11241135
id: sessionGroupId,
11251136
})
11261137

@@ -1178,6 +1189,7 @@ describe('cy.session', { retries: 0 }, () => {
11781189
it('groups session logs correctly', () => {
11791190
expect(logs[0].get()).to.contain({
11801191
name: 'session',
1192+
state: 'passed',
11811193
id: sessionGroupId,
11821194
})
11831195

@@ -1254,6 +1266,7 @@ describe('cy.session', { retries: 0 }, () => {
12541266
it('groups session logs correctly', () => {
12551267
expect(logs[0].get()).to.contain({
12561268
name: 'session',
1269+
state: 'warned',
12571270
id: sessionGroupId,
12581271
})
12591272

@@ -1345,6 +1358,7 @@ describe('cy.session', { retries: 0 }, () => {
13451358

13461359
expect(logs[0].get()).to.contain({
13471360
name: 'session',
1361+
state: 'failed',
13481362
id: sessionGroupId,
13491363
})
13501364

packages/driver/src/cy/commands/sessions/index.ts

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import SessionsManager from './manager'
88
import {
99
getConsoleProps,
1010
navigateAboutBlank,
11+
SESSION_STEPS,
1112
statusMap,
1213
} from './utils'
1314

@@ -39,8 +40,6 @@ export default function (Commands, Cypress, cy) {
3940
const sessionsManager = new SessionsManager(Cypress, cy)
4041
const sessions = sessionsManager.sessions
4142

42-
type SESSION_STEPS = 'create' | 'restore' | 'recreate' | 'validate'
43-
4443
Cypress.on('run:start', () => {
4544
// @ts-ignore
4645
Object.values(Cypress.state('activeSessions') || {}).forEach((sessionData: ServerSessionData) => {
@@ -149,6 +148,7 @@ export default function (Commands, Cypress, cy) {
149148

150149
function setSessionLogStatus (status: string) {
151150
_log.set({
151+
state: statusMap.commandState(status),
152152
sessionInfo: {
153153
id: session.id,
154154
isGlobalSession: session.cacheAcrossSpecs,
@@ -232,7 +232,7 @@ export default function (Commands, Cypress, cy) {
232232
return sessions.setSessionData(testSession)
233233
}
234234

235-
function validateSession (existingSession, step: SESSION_STEPS) {
235+
function validateSession (existingSession, step: keyof typeof SESSION_STEPS) {
236236
const isValidSession = true
237237

238238
if (!existingSession.validate) {
@@ -321,11 +321,7 @@ export default function (Commands, Cypress, cy) {
321321

322322
// skip all commands between this command which errored and _commandToRunAfterValidation
323323
for (let i = cy.queue.index; i < index; i++) {
324-
const cmd = commands[i]
325-
326-
if (!cmd.get('restore-within')) {
327-
commands[i].skip()
328-
}
324+
commands[i].skip()
329325
}
330326

331327
// restore within subject back to the original subject used when
@@ -369,7 +365,7 @@ export default function (Commands, Cypress, cy) {
369365
}
370366

371367
const failValidation = (err) => {
372-
if (step === 'restore') {
368+
if (step === SESSION_STEPS.restore) {
373369
enhanceErr(err)
374370

375371
// move to recreate session flow
@@ -442,13 +438,13 @@ export default function (Commands, Cypress, cy) {
442438
.then(() => validateSession(existingSession, step))
443439
.then(async (isValidSession: boolean) => {
444440
if (!isValidSession) {
445-
throw new Error('not a valid session :(')
441+
return 'failed'
446442
}
447443

448444
sessionsManager.registeredSessions.set(existingSession.id, true)
449445
await sessions.saveSessionData(existingSession)
450446

451-
setSessionLogStatus(statusMap.complete(step))
447+
return statusMap.complete(step)
452448
})
453449
}
454450

@@ -460,19 +456,19 @@ export default function (Commands, Cypress, cy) {
460456
*/
461457
const restoreSessionWorkflow = (existingSession: SessionData) => {
462458
return cy.then(async () => {
463-
setSessionLogStatus('restoring')
459+
setSessionLogStatus(statusMap.inProgress(SESSION_STEPS.restore))
464460
await navigateAboutBlank()
465461
await sessions.clearCurrentSessionData()
466462

467463
return restoreSession(existingSession)
468464
})
469-
.then(() => validateSession(existingSession, 'restore'))
465+
.then(() => validateSession(existingSession, SESSION_STEPS.restore))
470466
.then((isValidSession: boolean) => {
471467
if (!isValidSession) {
472-
return createSessionWorkflow(existingSession, 'recreate')
468+
return createSessionWorkflow(existingSession, SESSION_STEPS.recreate)
473469
}
474470

475-
setSessionLogStatus('restored')
471+
return statusMap.complete(SESSION_STEPS.restore)
476472
})
477473
}
478474

@@ -503,15 +499,15 @@ export default function (Commands, Cypress, cy) {
503499
_.extend(session, _.omit(serverStoredSession, 'setup', 'validate'))
504500
session.hydrated = true
505501
} else {
506-
return createSessionWorkflow(session, 'create')
502+
return createSessionWorkflow(session, SESSION_STEPS.create)
507503
}
508504
}
509505

510506
return restoreSessionWorkflow(session)
511-
}).then(() => {
507+
}).then((status: 'created' | 'restored' | 'recreated' | 'failed') => {
512508
return navigateAboutBlank()
513509
.then(() => {
514-
_log.set({ state: 'passed' })
510+
setSessionLogStatus(status)
515511
})
516512
})
517513
})

packages/driver/src/cy/commands/sessions/utils.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,28 @@ function navigateAboutBlank (session: boolean = true) {
208208
})
209209
}
210210

211+
const enum SESSION_STEPS {
212+
create = 'create',
213+
restore = 'restore',
214+
recreate = 'recreate',
215+
validate = 'validate',
216+
}
217+
211218
const statusMap = {
219+
commandState: (status: string) => {
220+
switch (status) {
221+
case 'failed':
222+
return 'failed'
223+
case 'recreating':
224+
case 'recreated':
225+
return 'warned'
226+
case 'created':
227+
case 'restored':
228+
return 'passed'
229+
default:
230+
return 'pending'
231+
}
232+
},
212233
inProgress: (step) => {
213234
switch (step) {
214235
case 'create':
@@ -255,5 +276,6 @@ export {
255276
getConsoleProps,
256277
getPostMessageLocalStorage,
257278
navigateAboutBlank,
279+
SESSION_STEPS,
258280
statusMap,
259281
}

packages/reporter/cypress/e2e/commands.cy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ describe('commands', { viewportHeight: 1000 }, () => {
848848
})
849849

850850
it('shows a tooltip', () => {
851-
cy.get('.command-name-within').click()
851+
cy.get('.command-name-within').click('top')
852852
cy.get('.cy-tooltip').should('have.text', 'Printed output to your console')
853853
})
854854

packages/reporter/src/commands/command.cy.tsx

Lines changed: 71 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,91 @@
11
import React from 'react'
22
import Command from './command'
33
import CommandModel from './command-model'
4+
import type { SessionStatus } from '../sessions/utils'
5+
import type { TestState } from '@packages/types'
46

57
describe('commands', () => {
8+
describe('test states', () => {
9+
it('warned command', () => {
10+
cy.mount(
11+
<div>
12+
<Command
13+
key={status}
14+
model={
15+
new CommandModel({
16+
name: 'session',
17+
message: 'user1',
18+
state: 'warned',
19+
sessionInfo: {
20+
id: 'user1',
21+
isGlobalSession: false,
22+
status: 'recreated',
23+
},
24+
number: 1,
25+
type: 'parent',
26+
hookId: '1',
27+
testId: '1',
28+
id: 1,
29+
numElements: 1,
30+
})
31+
}
32+
/>
33+
</div>,
34+
)
35+
36+
cy.percySnapshot()
37+
})
38+
})
39+
640
describe('sessionPill', () => {
7-
const statusList = [
8-
'creating',
9-
'created',
10-
'restoring',
11-
'restored',
12-
'recreating',
13-
'recreated',
14-
'failed',
41+
const statusList: Array<{
42+
state: TestState
43+
status: SessionStatus
44+
}> = [
45+
{
46+
state: 'pending',
47+
status: 'creating',
48+
},
49+
{
50+
state: 'passed',
51+
status: 'created',
52+
},
53+
{
54+
state: 'pending',
55+
status: 'restoring',
56+
},
57+
{
58+
state: 'passed',
59+
status: 'restored',
60+
},
61+
{
62+
state: 'warned',
63+
status: 'recreating',
64+
},
65+
{
66+
state: 'warned',
67+
status: 'recreated',
68+
},
69+
{
70+
state: 'failed',
71+
status: 'failed',
72+
},
1573
]
1674

1775
it('session status in command', () => {
1876
cy.mount(
1977
<div>
20-
{statusList.map((status, index) => (
78+
{statusList.map(({ state, status }, index) => (
2179
<Command
2280
key={status}
2381
model={
2482
new CommandModel({
2583
name: 'session',
2684
message: 'user1',
27-
state: 'passed',
28-
renderProps: {
85+
state,
86+
sessionInfo: {
87+
id: 'user1',
88+
isGlobalSession: false,
2989
status,
3090
},
3191
number: index,

packages/reporter/src/commands/command.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import Tag from '../lib/tag'
1414
import { TimeoutID } from '../lib/types'
1515
import runnablesStore, { RunnablesStore } from '../runnables/runnables-store'
1616
import { Alias, AliasObject } from '../instruments/instrument-model'
17+
import { determineTagType } from '../sessions/utils'
1718

1819
import CommandModel, { RenderProps } from './command-model'
1920
import TestError from '../errors/test-error'
@@ -298,7 +299,7 @@ const CommandControls = observer(({ model, commandName, events }) => {
298299
{isSessionCommand && (
299300
<Tag
300301
content={model.sessionInfo?.status}
301-
type={`${model.sessionInfo?.status === 'failed' ? 'failed' : 'successful'}-status`}
302+
type={determineTagType(model.state)}
302303
/>
303304
)}
304305
{!model.visible && (

0 commit comments

Comments
 (0)