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: refactor session tests #832

Merged
merged 3 commits into from
Oct 16, 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
5 changes: 4 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ module.exports = {
// but excluding the 'plugin:compat/recommended' rule
// we don't mind using the latest features in our tests
extends: extend.filter((s) => s !== 'plugin:compat/recommended'),
rules: rules.filter((s) => s !== 'no-console'),
rules: {
Copy link
Member Author

Choose a reason for hiding this comment

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

I couldn't run eslint until changing this

...rules,
'no-console': 'off',
},
},
],
root: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import {
FULL_SNAPSHOT_EVENT_TYPE,
} from '../../extensions/sessionrecording-utils'
import { largeString, threeMBAudioURI, threeMBImageURI } from './test_data/sessionrecording-utils-test-data'
import { eventWithTime } from '@rrweb/types'

describe(`SessionRecording utility functions`, () => {
describe(`filterLargeDataURLs`, () => {
it(`should not touch an object under 5mb`, () => {
var data = {
const data: eventWithTime = {
attributes: [
{
node: {
Expand All @@ -21,15 +22,15 @@ describe(`SessionRecording utility functions`, () => {
},
},
],
}
} as unknown as eventWithTime
expect(ensureMaxMessageSize(data)).toEqual({
event: data,
size: 3548406,
})
})

it(`should replace image data urls if the object is over 5mb`, () => {
var data = {
const data = {
attributes: [
{
node: {
Expand All @@ -50,7 +51,7 @@ describe(`SessionRecording utility functions`, () => {
},
},
],
}
} as unknown as eventWithTime

expect(ensureMaxMessageSize(data)).toEqual({
event: {
Expand Down Expand Up @@ -80,7 +81,7 @@ describe(`SessionRecording utility functions`, () => {
})

it(`should remove non-image data urls if the object is over 5mb`, () => {
var data = {
const data = {
attributes: [
{
node: {
Expand All @@ -97,7 +98,7 @@ describe(`SessionRecording utility functions`, () => {
},
},
],
}
} as unknown as eventWithTime

expect(ensureMaxMessageSize(data)).toEqual({
event: {
Expand Down Expand Up @@ -125,20 +126,20 @@ describe(`SessionRecording utility functions`, () => {

describe(`truncateLargeConsoleLogs`, () => {
it(`should handle null data objects`, () => {
expect(truncateLargeConsoleLogs(null)).toBe(null)
expect(truncateLargeConsoleLogs(null as unknown as eventWithTime)).toBe(null)
})

it(`should not touch non plugin objects`, () => {
expect(
truncateLargeConsoleLogs({
type: FULL_SNAPSHOT_EVENT_TYPE, // not plugin
type: FULL_SNAPSHOT_EVENT_TYPE,
data: {
plugin: CONSOLE_LOG_PLUGIN_NAME,
payload: {
payload: largeString,
},
},
})
} as unknown as eventWithTime)
).toEqual({
type: FULL_SNAPSHOT_EVENT_TYPE,
data: {
Expand All @@ -160,7 +161,7 @@ describe(`SessionRecording utility functions`, () => {
payload: largeString,
},
},
})
} as eventWithTime)
).toEqual({
type: PLUGIN_EVENT_TYPE,
data: {
Expand All @@ -182,7 +183,7 @@ describe(`SessionRecording utility functions`, () => {
payload: ['a', largeString],
},
},
})
} as eventWithTime)
).toEqual({
type: PLUGIN_EVENT_TYPE,
data: {
Expand All @@ -204,7 +205,7 @@ describe(`SessionRecording utility functions`, () => {
payload: Array(100).fill('a'),
},
},
})
} as eventWithTime)
).toEqual({
type: PLUGIN_EVENT_TYPE,
data: {
Expand All @@ -226,7 +227,7 @@ describe(`SessionRecording utility functions`, () => {
payload: [undefined, null],
},
},
})
} as eventWithTime)
).toEqual({
type: PLUGIN_EVENT_TYPE,
data: {
Expand Down
Loading
Loading