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

chore: adding wallClockUpdatedAt to log for protocol #26450

Merged
merged 5 commits into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/app/src/runner/event-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ export class EventManager {
this._interceptStudio(displayProps)

this.reporterBus.emit('reporter:log:add', displayProps)
Cypress.backend('protocol:command:log:added', displayProps, new Date().toJSON())
Cypress.backend('protocol:command:log:added', displayProps)
})

Cypress.on('log:changed', (log) => {
Expand All @@ -506,7 +506,7 @@ export class EventManager {
this._interceptStudio(displayProps)

this.reporterBus.emit('reporter:log:state:changed', displayProps)
Cypress.backend('protocol:command:log:changed', displayProps, new Date().toJSON())
Cypress.backend('protocol:command:log:changed', displayProps)
})

// TODO: MOVE BACK INTO useEventManager. Verify this works
Expand Down
16 changes: 14 additions & 2 deletions packages/driver/src/cypress/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type { StateFunc } from './state'
const groupsOrTableRe = /^(groups|table)$/
const parentOrChildRe = /parent|child|system/
const SNAPSHOT_PROPS = 'id snapshots $el url coords highlightAttr scrollBy viewportWidth viewportHeight'.split(' ')
const DISPLAY_PROPS = 'id alias aliasType callCount displayName end err event functionName groupLevel hookId instrument isStubbed group message method name numElements numResponses referencesAlias renderProps sessionInfo state testId timeout type url visible wallClockStartedAt testCurrentRetry'.split(' ')
const DISPLAY_PROPS = 'id alias aliasType callCount displayName end err event functionName groupLevel hookId instrument isStubbed group message method name numElements numResponses referencesAlias renderProps sessionInfo state testId timeout type url visible wallClockStartedAt testCurrentRetry wallClockUpdatedAt'.split(' ')
const BLACKLIST_PROPS = 'snapshots'.split(' ')

let counter = 0
Expand Down Expand Up @@ -317,6 +317,9 @@ export class Log {
delete this.obj.id
}

// if the log doesn't have a wallClockUpdatedAt, then set it to the wallClockStartedAt, otherwise set it to the current time
this.obj.wallClockUpdatedAt = !this.attributes.wallClockUpdatedAt ? this.attributes.wallClockStartedAt : new Date().toJSON()

_.extend(this.attributes, this.obj)

// if we have an consoleProps function
Expand Down Expand Up @@ -573,9 +576,18 @@ class LogManager {

const attrs = log.toJSON()

const logAttrsEqual = _.isEqualWith(log._emittedAttrs, attrs, (_objValue, _othValue, key) => {
// if the key is 'wallClockUpdatedAt' then we want to ignore it since its a date that will always be different
if (key === 'wallClockUpdatedAt') {
return true
}

return undefined
})

// only trigger this event if our last stored
// emitted attrs do not match the current toJSON
if (!_.isEqual(log._emittedAttrs, attrs)) {
if (!logAttrsEqual) {
log._emittedAttrs = attrs

return Cypress.action(event, attrs, log)
Expand Down
1 change: 1 addition & 0 deletions packages/driver/types/cypress/log.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,6 @@ declare namespace Cypress {
viewportWidth?: number
visible?: boolean
wallClockStartedAt?: string
wallClockUpdatedAt?: string
}
}
8 changes: 4 additions & 4 deletions packages/server/lib/cloud/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,20 @@ class ProtocolManagerImpl implements ProtocolManager {
this.protocol?.afterTest(test)
}

commandLogAdded (log: any, timestamp: string) {
commandLogAdded (log: any) {
if (!this.protocolEnabled()) {
return
}

this.protocol?.commandLogAdded(log, timestamp)
this.protocol?.commandLogAdded(log)
}

commandLogChanged (log: any, timestamp: string): void {
commandLogChanged (log: any): void {
if (!this.protocolEnabled()) {
return
}

this.protocol?.commandLogChanged(log, timestamp)
this.protocol?.commandLogChanged(log)
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/server/lib/socket-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,9 @@ export class SocketBase {
case 'protocol:test:after:run':
return this.protocolManager?.afterTest(args[0])
case 'protocol:command:log:added':
return this.protocolManager?.commandLogAdded(args[0], args[1])
return this.protocolManager?.commandLogAdded(args[0])
case 'protocol:command:log:changed':
return this.protocolManager?.commandLogChanged(args[0], args[1])
return this.protocolManager?.commandLogChanged(args[0])
default:
throw new Error(`You requested a backend event we cannot handle: ${eventName}`)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const AppCaptureProtocol = class {
beforeSpec (spec) {}
afterSpec (spec) {}
beforeTest (test) {}
commandLogAdded (log, timestamp) {}
commandLogChanged (log, timestamp) {}
commandLogAdded (log) {}
commandLogChanged (log) {}
}

module.exports = {
Expand Down
10 changes: 6 additions & 4 deletions packages/server/test/unit/cloud/protocol_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,15 @@ describe('lib/cloud/protocol', () => {
type: 'parent',
url: 'https://jsonplaceholder.cypress.io/comments/1',
wallClockStartedAt: '2023-03-30T21:58:08.456Z',
wallClockUpdatedAt: '2023-03-30T21:58:08.457Z',
testCurrentRetry: 0,
hasSnapshot: false,
hasConsoleProps: true,
}

protocolManager.commandLogAdded(log, '2023-03-30T21:58:08.457Z')
protocolManager.commandLogAdded(log)

expect(protocol.commandLogAdded).to.be.calledWith(log, '2023-03-30T21:58:08.457Z')
expect(protocol.commandLogAdded).to.be.calledWith(log)
})

it('should be able to change a command log', () => {
Expand All @@ -156,13 +157,14 @@ describe('lib/cloud/protocol', () => {
type: 'parent',
url: 'https://jsonplaceholder.cypress.io/comments/1',
wallClockStartedAt: '2023-03-30T21:58:08.456Z',
wallClockUpdatedAt: '2023-03-30T21:58:08.457Z',
testCurrentRetry: 0,
hasSnapshot: false,
hasConsoleProps: true,
}

protocolManager.commandLogChanged(log, '2023-03-30T21:58:08.457Z')
protocolManager.commandLogChanged(log)

expect(protocol.commandLogChanged).to.be.calledWith(log, '2023-03-30T21:58:08.457Z')
expect(protocol.commandLogChanged).to.be.calledWith(log)
})
})
8 changes: 4 additions & 4 deletions packages/types/src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export interface AppCaptureProtocolInterface {
afterSpec (): void
beforeTest(test: Record<string, any>): void
afterTest(test: Record<string, any>): void
commandLogAdded (log: any, timestamp: string): void
mschile marked this conversation as resolved.
Show resolved Hide resolved
commandLogChanged (log: any, timestamp: string): void
commandLogAdded (log: any): void
commandLogChanged (log: any): void
}

export interface ProtocolManager {
Expand All @@ -33,6 +33,6 @@ export interface ProtocolManager {
afterSpec (): void
beforeTest(test: Record<string, any>): void
afterTest(test: Record<string, any>): void
commandLogAdded (log: any, timestamp: string): void
commandLogChanged (log: any, timestamp: string): void
commandLogAdded (log: any): void
commandLogChanged (log: any): void
}