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: updating log to use createdAtTimestamp and updatedAtTimestamp #27660

Merged
merged 3 commits into from
Aug 25, 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
6 changes: 4 additions & 2 deletions packages/driver/cypress/e2e/cypress/log.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,12 @@ describe('src/cypress/log', function () {
this.log = create(Cypress, this.cy, this.state, this.config)
})

it('uses performance api to mark timestamps', () => {
it('sets created at and updated at timestamps', () => {
const log = this.log()

expect(log.attributes.timestamp).to.be.a('number')
expect(log.attributes.createdAtTimestamp).to.be.a('number')
expect(log.attributes.updatedAtTimestamp).to.be.a('number')
expect(log.attributes.createdAtTimestamp).be.lessThan(log.attributes.updatedAtTimestamp)
})
})

Expand Down
15 changes: 8 additions & 7 deletions packages/driver/src/cypress/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ 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 PROTOCOL_PROPS = DISPLAY_PROPS.concat(['snapshots', 'timestamp', 'scrollBy', 'coords', 'highlightAttr'])
const PROTOCOL_PROPS = DISPLAY_PROPS.concat(['snapshots', 'createdAtTimestamp', 'updatedAtTimestamp', 'scrollBy', 'coords', 'highlightAttr'])
const BLACKLIST_PROPS = 'snapshots'.split(' ')

let counter = 0
Expand Down Expand Up @@ -205,7 +205,8 @@ const defaults = function (state: StateFunc, config, obj) {
message: undefined,
timeout: undefined,
wallClockStartedAt: new Date().toJSON(),
timestamp: performance.now() - performance.timeOrigin,
createdAtTimestamp: performance.now() + performance.timeOrigin,
updatedAtTimestamp: performance.now() + performance.timeOrigin,
renderProps () {
return {}
},
Expand Down Expand Up @@ -327,7 +328,7 @@ export class Log {
delete this.obj.id
}

this.obj.timestamp = performance.now() + performance.timeOrigin
this.obj.updatedAtTimestamp = performance.now() + performance.timeOrigin

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

Expand Down Expand Up @@ -371,8 +372,8 @@ export class Log {
}

snapshot (name?, options: any = {}) {
// bail early and don't snapshot if we're in headless mode or we're not storing tests
// and the protocol is not enabled
// bail early and don't snapshot if we're in headless mode
// or we're not storing tests and the protocol is not enabled
if ((!this.config('isInteractive') || (this.config('numTestsKeptInMemory') === 0)) && !this.config('protocolEnabled')) {
return this
}
Expand Down Expand Up @@ -593,8 +594,8 @@ class LogManager {
const attrs = log.toJSON()

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

Expand Down
6 changes: 4 additions & 2 deletions packages/server/test/unit/cloud/protocol_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ describe('lib/cloud/protocol', () => {
state: 'pending',
testId: 'r4',
timeout: 0,
timestamp: 1689619127850.2854,
createdAtTimestamp: 1689619127850.2854,
updatedAtTimestamp: 1689619127851.2854,
type: 'parent',
url: 'https://jsonplaceholder.cypress.io/comments/1',
wallClockStartedAt: '2023-03-30T21:58:08.456Z',
Expand Down Expand Up @@ -214,7 +215,8 @@ describe('lib/cloud/protocol', () => {
state: 'pending',
testId: 'r4',
timeout: 0,
timestamp: 1689619127850.2854,
createdAtTimestamp: 1689619127850.2854,
updatedAtTimestamp: 1689619127851.2854,
type: 'parent',
url: 'https://jsonplaceholder.cypress.io/comments/1',
wallClockStartedAt: '2023-03-30T21:58:08.456Z',
Expand Down
36 changes: 24 additions & 12 deletions system-tests/__snapshots__/protocol_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,8 @@ exports['protocol events'] = `
"url": "",
"wallClockStartedAt": "2015-03-18T00:00:00.000Z",
"testCurrentRetry": 0,
"timestamp": 100
"createdAtTimestamp": 100,
"updatedAtTimestamp": 100
},
{
"id": "log-http://localhost:3131-2",
Expand All @@ -362,7 +363,8 @@ exports['protocol events'] = `
"url": "http://localhost:3131/index.html",
"wallClockStartedAt": "2015-03-18T00:00:00.000Z",
"testCurrentRetry": 0,
"timestamp": 100
"createdAtTimestamp": 100,
"updatedAtTimestamp": 100
},
{
"id": "log-http://localhost:3131-3",
Expand All @@ -379,7 +381,8 @@ exports['protocol events'] = `
"url": "http://localhost:3131/index.html",
"wallClockStartedAt": "2015-03-18T00:00:00.000Z",
"testCurrentRetry": 0,
"timestamp": 100
"createdAtTimestamp": 100,
"updatedAtTimestamp": 100
},
{
"id": "log-http://localhost:3131-4",
Expand All @@ -398,7 +401,8 @@ exports['protocol events'] = `
"visible": true,
"wallClockStartedAt": "2015-03-18T00:00:00.000Z",
"testCurrentRetry": 0,
"timestamp": 100,
"createdAtTimestamp": 100,
"updatedAtTimestamp": 100,
"highlightAttr": "data-cypress-el"
},
{
Expand All @@ -416,7 +420,8 @@ exports['protocol events'] = `
"url": "http://localhost:3131/index.html",
"wallClockStartedAt": "2015-03-18T00:00:00.000Z",
"testCurrentRetry": 0,
"timestamp": 100
"createdAtTimestamp": 100,
"updatedAtTimestamp": 100
},
{
"id": "log-http://foobar.com-6",
Expand All @@ -435,7 +440,8 @@ exports['protocol events'] = `
"url": "",
"wallClockStartedAt": "2015-03-18T00:00:00.000Z",
"testCurrentRetry": 0,
"timestamp": 100
"createdAtTimestamp": 100,
"updatedAtTimestamp": 100
}
],
"commandLogChanged": [
Expand All @@ -459,7 +465,8 @@ exports['protocol events'] = `
"timestamp": 100
}
],
"timestamp": 100
"createdAtTimestamp": 100,
"updatedAtTimestamp": 100
},
{
"id": "log-http://localhost:3131-2",
Expand All @@ -481,7 +488,8 @@ exports['protocol events'] = `
"timestamp": 100
}
],
"timestamp": 100
"createdAtTimestamp": 100,
"updatedAtTimestamp": 100
},
{
"id": "log-http://localhost:3131-3",
Expand Down Expand Up @@ -510,7 +518,8 @@ exports['protocol events'] = `
]
}
],
"timestamp": 100,
"createdAtTimestamp": 100,
"updatedAtTimestamp": 100,
"highlightAttr": "data-cypress-el"
},
{
Expand Down Expand Up @@ -550,7 +559,8 @@ exports['protocol events'] = `
]
}
],
"timestamp": 100,
"createdAtTimestamp": 100,
"updatedAtTimestamp": 100,
"coords": {
"top": 22,
"left": 8,
Expand Down Expand Up @@ -579,7 +589,8 @@ exports['protocol events'] = `
"wallClockStartedAt": "2015-03-18T00:00:00.000Z",
"testCurrentRetry": 0,
"snapshots": [],
"timestamp": 100
"createdAtTimestamp": 100,
"updatedAtTimestamp": 100
},
{
"id": "log-http://localhost:3131-5",
Expand All @@ -601,7 +612,8 @@ exports['protocol events'] = `
"timestamp": 100
}
],
"timestamp": 100
"createdAtTimestamp": 100,
"updatedAtTimestamp": 100
}
],
"viewportChanged": [
Expand Down
2 changes: 1 addition & 1 deletion system-tests/test/protocol_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const {

// source: https://www.myintervals.com/blog/2009/05/20/iso-8601-date-validation-that-doesnt-suck/
const isoDateRegex = /"([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?"/g
const numberRegex = /"(wallClockDuration|fnDuration|afterFnDuration|lifecycle|duration|timestamp)": (0|[1-9]\d*)(\.\d+)?/g
const numberRegex = /"(wallClockDuration|fnDuration|afterFnDuration|lifecycle|duration|timestamp|createdAtTimestamp|updatedAtTimestamp)": (0|[1-9]\d*)(\.\d+)?/g
const pathRegex = /"(name|absoluteFile)": "\/[^"]+"/g

const normalizeEvents = (resultsJson) => {
Expand Down