Skip to content

Commit

Permalink
updating specs
Browse files Browse the repository at this point in the history
  • Loading branch information
mschile committed Aug 25, 2023
1 parent 6b509b3 commit 6916937
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 22 deletions.
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
10 changes: 5 additions & 5 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', 'createdAtTimestamp', 'lastUpdatedAtTimestamp', '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 @@ -206,7 +206,7 @@ const defaults = function (state: StateFunc, config, obj) {
timeout: undefined,
wallClockStartedAt: new Date().toJSON(),
createdAtTimestamp: performance.now() + performance.timeOrigin,
lastUpdatedAtTimestamp: performance.now() + performance.timeOrigin,
updatedAtTimestamp: performance.now() + performance.timeOrigin,
renderProps () {
return {}
},
Expand Down Expand Up @@ -328,7 +328,7 @@ export class Log {
delete this.obj.id
}

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

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

Expand Down Expand Up @@ -594,8 +594,8 @@ class LogManager {
const attrs = log.toJSON()

const logAttrsEqual = _.isEqualWith(log._emittedAttrs, attrs, (_objValue, _othValue, key) => {
// if the key is 'lastUpdatedAtTimestamp' then we want to ignore it since it will always be different
if (key === 'lastUpdatedAtTimestamp') {
// 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

0 comments on commit 6916937

Please sign in to comment.