Skip to content

Commit

Permalink
chore: refactor session tests (#832)
Browse files Browse the repository at this point in the history
* fix lint config

* obey eslint

* obey linter
  • Loading branch information
pauldambra authored Oct 16, 2023
1 parent 8157df9 commit 4af8c2d
Show file tree
Hide file tree
Showing 8 changed files with 307 additions and 279 deletions.
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: {
...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

0 comments on commit 4af8c2d

Please sign in to comment.