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

test(replay): Normalize time offset in DOM snapshots #7219

Merged
merged 3 commits into from
Feb 17, 2023

Conversation

Lms24
Copy link
Member

@Lms24 Lms24 commented Feb 17, 2023

I just noticed that the last integration test I added in #7212 is flaky because of time offsets which can change in some CI runs. This PR normalizes the time offset to [timeOffset] in DOM snapshots to make sure this doesn't happen.

@Lms24 Lms24 added Type: Tests Package: replay Issues related to the Sentry Replay SDK labels Feb 17, 2023
@Lms24 Lms24 requested review from mydea and AbhiPrasad February 17, 2023 12:15
@Lms24 Lms24 self-assigned this Feb 17, 2023
*/
export function normalize(obj: unknown): string {
const rawString = JSON.stringify(obj, null, 2);
const normalizedString = rawString.replace(/"file:\/\/.+(\/.*\.html)"/g, '"$1"');
const normalizedString = rawString
.replace(/"file:\/\/.+(\/.*\.html)"/, '"$1"')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m: should both of these regexes have a /gm (or at least /g, not 100% sure tbh) suffix? I

Copy link
Member Author

@Lms24 Lms24 Feb 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, plus another regex fix (I didn't take negative offsets into account)

Copy link
Member

@AbhiPrasad AbhiPrasad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to also update snapshots?

const normalizedString = rawString.replace(/"file:\/\/.+(\/.*\.html)"/g, '"$1"');
const normalizedString = rawString
.replace(/"file:\/\/.+(\/.*\.html)"/, '"$1"')
.replace(/"timeOffset":\s*\d+/, '"timeOffset": 0');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m: I would prefer it if we made the redaction explicit here.

Suggested change
.replace(/"timeOffset":\s*\d+/, '"timeOffset": 0');
.replace(/"timeOffset":\s*\d+/, '"timeOffset": [timeOffset]');

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the redaction we now need to update snapshots :D

@Lms24 Lms24 merged commit aa1d4e5 into develop Feb 17, 2023
@Lms24 Lms24 deleted the lms/replay-pw-norm-timeoffset branch February 17, 2023 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: replay Issues related to the Sentry Replay SDK Type: Tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants