Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add warned command state to use for recreated sessions #24592

Merged
merged 14 commits into from Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/driver/cypress/e2e/commands/sessions/sessions.cy.js
Expand Up @@ -217,6 +217,7 @@ describe('cy.session', { retries: 0 }, () => {
it('groups session logs correctly', () => {
expect(logs[0].get()).to.deep.contain({
name: 'session',
state: 'passed',
id: sessionGroupId,
sessionInfo: {
id: 'session-1',
Expand Down Expand Up @@ -298,6 +299,7 @@ describe('cy.session', { retries: 0 }, () => {
it('groups session logs correctly', () => {
expect(logs[0].get()).to.deep.contain({
name: 'session',
state: 'passed',
id: sessionGroupId,
sessionInfo: {
id: sessionId,
Expand Down Expand Up @@ -352,6 +354,7 @@ describe('cy.session', { retries: 0 }, () => {
expect(err.message).to.contain('This error occurred while validating the created session')
expect(logs[0].get()).to.deep.contain({
name: 'session',
state: 'failed',
id: sessionGroupId,
sessionInfo: {
id: `session-${Cypress.state('test').id}`,
Expand Down Expand Up @@ -432,6 +435,7 @@ describe('cy.session', { retries: 0 }, () => {
it('groups session logs correctly', () => {
expect(logs[0].get()).to.contain({
name: 'session',
state: 'passed',
id: sessionGroupId,
})

Expand Down Expand Up @@ -487,6 +491,7 @@ describe('cy.session', { retries: 0 }, () => {
it('groups session logs correctly', () => {
expect(logs[0].get()).to.contain({
name: 'session',
state: 'passed',
id: sessionGroupId,
})

Expand Down Expand Up @@ -561,6 +566,7 @@ describe('cy.session', { retries: 0 }, () => {
it('groups session logs correctly', () => {
expect(logs[0].get()).to.contain({
name: 'session',
state: 'warned',
id: sessionGroupId,
})

Expand Down Expand Up @@ -651,6 +657,7 @@ describe('cy.session', { retries: 0 }, () => {

expect(logs[0].get()).to.contain({
name: 'session',
state: 'failed',
id: sessionGroupId,
})

Expand Down Expand Up @@ -876,6 +883,7 @@ describe('cy.session', { retries: 0 }, () => {
it('groups session logs correctly', () => {
expect(logs[0].get()).to.deep.contain({
name: 'session',
state: 'passed',
id: sessionGroupId,
sessionInfo: {
id: 'session-1',
Expand Down Expand Up @@ -954,6 +962,7 @@ describe('cy.session', { retries: 0 }, () => {
it('groups session logs correctly', () => {
expect(logs[0].get()).to.deep.contain({
name: 'session',
state: 'passed',
id: sessionGroupId,
sessionInfo: {
id: sessionId,
Expand Down Expand Up @@ -1006,6 +1015,7 @@ describe('cy.session', { retries: 0 }, () => {
expect(err.message).to.contain('Your `cy.session` **validate** promise rejected with false')
expect(logs[0].get()).to.deep.contain({
name: 'session',
state: 'failed',
id: sessionGroupId,
sessionInfo: {
id: `session-${Cypress.state('test').id}`,
Expand Down Expand Up @@ -1083,6 +1093,7 @@ describe('cy.session', { retries: 0 }, () => {
it('groups session logs correctly', () => {
expect(logs[0].get()).to.contain({
name: 'session',
state: 'passed',
id: sessionGroupId,
})

Expand Down Expand Up @@ -1140,6 +1151,7 @@ describe('cy.session', { retries: 0 }, () => {
it('groups session logs correctly', () => {
expect(logs[0].get()).to.contain({
name: 'session',
state: 'passed',
id: sessionGroupId,
})

Expand Down Expand Up @@ -1216,6 +1228,7 @@ describe('cy.session', { retries: 0 }, () => {
it('groups session logs correctly', () => {
expect(logs[0].get()).to.contain({
name: 'session',
state: 'warned',
id: sessionGroupId,
})

Expand Down Expand Up @@ -1307,6 +1320,7 @@ describe('cy.session', { retries: 0 }, () => {

expect(logs[0].get()).to.contain({
name: 'session',
state: 'failed',
id: sessionGroupId,
})

Expand Down
13 changes: 8 additions & 5 deletions packages/driver/src/cy/commands/sessions/index.ts
Expand Up @@ -152,6 +152,7 @@ export default function (Commands, Cypress, cy) {

function setSessionLogStatus (status: string) {
_log.set({
state: statusMap.commandState(status),
sessionInfo: {
id: session.id,
isGlobalSession: session.cacheAcrossSpecs,
Expand Down Expand Up @@ -446,13 +447,13 @@ export default function (Commands, Cypress, cy) {
.then(() => validateSession(existingSession, step))
.then(async (isValidSession: boolean) => {
if (!isValidSession) {
throw new Error('not a valid session :(')
return 'failed'
emilyrohrbough marked this conversation as resolved.
Show resolved Hide resolved
}

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

setSessionLogStatus(statusMap.complete(step))
return statusMap.complete(step)
})
}

Expand All @@ -476,7 +477,7 @@ export default function (Commands, Cypress, cy) {
return createSessionWorkflow(existingSession, 'recreate')
}

setSessionLogStatus('restored')
return 'restored'
})
}

Expand Down Expand Up @@ -512,8 +513,10 @@ export default function (Commands, Cypress, cy) {
}

return restoreSessionWorkflow(session)
}).then(() => {
_log.set({ state: 'passed' })
}).then((status: 'passed' | 'warned' | 'failed') => {
setSessionLogStatus(status)

return null
})
})
},
Expand Down
14 changes: 14 additions & 0 deletions packages/driver/src/cy/commands/sessions/utils.ts
Expand Up @@ -204,6 +204,20 @@ function navigateAboutBlank (session: boolean = true) {
}

const statusMap = {
commandState: (status: string) => {
switch (status) {
case 'failed':
return 'failed'
case 'recreating':
case 'recreated':
return 'warned'
case 'created':
case 'restored':
return 'passed'
default:
return 'pending'
}
},
inProgress: (step) => {
switch (step) {
case 'create':
Expand Down
2 changes: 1 addition & 1 deletion packages/reporter/cypress/e2e/commands.cy.ts
Expand Up @@ -848,7 +848,7 @@ describe('commands', { viewportHeight: 1000 }, () => {
})

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

Expand Down
82 changes: 71 additions & 11 deletions packages/reporter/src/commands/command.cy.tsx
@@ -1,31 +1,91 @@
import React from 'react'
import Command from './command'
import CommandModel from './command-model'
import type { SessionStatus } from '../sessions/utils'
import type { TestState } from '@packages/types'

describe('commands', () => {
describe('test states', () => {
it('warned command', () => {
cy.mount(
<div>
<Command
key={status}
model={
new CommandModel({
name: 'session',
message: 'user1',
state: 'warned',
sessionInfo: {
id: 'user1',
isGlobalSession: false,
status: 'recreated',
},
number: 1,
type: 'parent',
hookId: '1',
testId: '1',
id: 1,
numElements: 1,
})
}
/>
</div>,
)

cy.percySnapshot()
})
})

describe('sessionPill', () => {
const statusList = [
'creating',
'created',
'restoring',
'restored',
'recreating',
'recreated',
'failed',
const statusList: Array<{
state: TestState
status: SessionStatus
}> = [
{
state: 'pending',
status: 'creating',
},
{
state: 'passed',
status: 'created',
},
{
state: 'pending',
status: 'restoring',
},
{
state: 'passed',
status: 'restored',
},
{
state: 'warned',
status: 'recreating',
},
{
state: 'warned',
status: 'recreated',
},
{
state: 'failed',
status: 'failed',
},
]

it('session status in command', () => {
cy.mount(
<div>
{statusList.map((status, index) => (
{statusList.map(({ state, status }, index) => (
<Command
key={status}
model={
new CommandModel({
name: 'session',
message: 'user1',
state: 'passed',
renderProps: {
state,
sessionInfo: {
id: 'user1',
isGlobalSession: false,
status,
},
number: index,
Expand Down
3 changes: 2 additions & 1 deletion packages/reporter/src/commands/command.tsx
Expand Up @@ -14,6 +14,7 @@ import Tag from '../lib/tag'
import { TimeoutID } from '../lib/types'
import runnablesStore, { RunnablesStore } from '../runnables/runnables-store'
import { Alias, AliasObject } from '../instruments/instrument-model'
import { determineTagType } from '../sessions/utils'

import CommandModel, { RenderProps } from './command-model'
import TestError from '../errors/test-error'
Expand Down Expand Up @@ -298,7 +299,7 @@ const CommandControls = observer(({ model, commandName, events }) => {
{isSessionCommand && (
<Tag
content={model.sessionInfo?.status}
type={`${model.sessionInfo?.status === 'failed' ? 'failed' : 'successful'}-status`}
type={determineTagType(model.state)}
/>
)}
{!model.visible && (
Expand Down
25 changes: 25 additions & 0 deletions packages/reporter/src/commands/commands.scss
Expand Up @@ -252,6 +252,30 @@
}
}

.command-state-warned {
color: $warn-text;

&:not(.command-type-system) {
border-left: $warn-border;
}

.command-number-column,
.command-method,
.command-message {
color: $warn-text;
}

.command-group {
border-color: $warn-text;
@include nested-command-dashes($warn-text);

.command-group-block {
border-color: $warn-text;
@include nested-command-dashes($warn-text);
}
}
}

.command-state-failed {
color: $err-header-text;

Expand Down Expand Up @@ -286,6 +310,7 @@
}

// Custom Styles for Specific Commands
// note: assert does not support warned state
emilyrohrbough marked this conversation as resolved.
Show resolved Hide resolved
.command-name-assert {
.command-method {
span {
Expand Down
1 change: 1 addition & 0 deletions packages/reporter/src/lib/tag.cy.tsx
Expand Up @@ -11,6 +11,7 @@ describe('Tag', () => {

const statuses = [
'successful-status',
'warned-status',
'failed-status',
]

Expand Down
7 changes: 6 additions & 1 deletion packages/reporter/src/lib/tag.scss
Expand Up @@ -37,9 +37,14 @@
color: $jade-300;
}

&.warned-status {
background-color: $gray-1000;
border: $gray-900 1px solid;
color: $warn-text;
}

&.failed-status {
background-color: $red-500;
font-weight: 500;
}

&.reporter-tag-has-count {
Expand Down
7 changes: 2 additions & 5 deletions packages/reporter/src/lib/variables.scss
Expand Up @@ -104,7 +104,6 @@ $fail: $red-400;
$pending: $indigo-400;
$pinned: $purple-400;
$retried: $orange-400;
$yellow-medium: $orange-800;

$link-text: $indigo-600;

Expand All @@ -118,10 +117,8 @@ $err-text: $red-400;

$reporter-section-background: #171926; // not a brand color

$warn-background: $red-1000;
$warn-header-background: $orange-1000;
$warn-header-text: $orange-700;
$warn-text: $orange-600;
$warn-border: 2px solid $orange-300;
$warn-text: $orange-300;

$header-height: 64px;
$reporter-contents-min-width: 170px;
Expand Down