-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(replay): Use vitest
instead of jest
#11899
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
Changes from all commits
0c2c609
a33ce01
091bf94
ac4de92
c0d4cfa
83162b6
ceca10e
cde0779
1864c67
2b2ea3d
6ec58f6
a42012e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,10 +51,12 @@ | |
"build:tarball": "ts-node ../../scripts/prepack.ts --bundles && npm pack ./build/npm", | ||
"circularDepCheck": "madge --circular src/index.ts", | ||
"clean": "rimraf build sentry-replay-*.tgz", | ||
"fix": "eslint . --format stylish --fix", | ||
"fix": "run-s fix:biome fix:eslint", | ||
"fix:eslint": "eslint . --format stylish --fix", | ||
"fix:biome": "biome check --apply .", | ||
"lint": "eslint . --format stylish", | ||
"test": "jest", | ||
"test:watch": "jest --watch", | ||
"test": "vitest", | ||
"test:watch": "vitest --watch", | ||
"yalc:publish": "ts-node ../../scripts/prepack.ts --bundles && yalc publish ./build/npm --push --sig" | ||
}, | ||
"repository": { | ||
|
@@ -73,6 +75,7 @@ | |
"@sentry-internal/rrweb": "2.15.0", | ||
"@sentry-internal/rrweb-snapshot": "2.15.0", | ||
"fflate": "^0.8.1", | ||
"jest-matcher-utils": "^29.0.0", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Our custom matchers use a util fn from this lib to pretty print diffs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess we can possibly refactor this later to avoid this dependency, but all good for now! |
||
"jsdom-worker": "^0.2.1" | ||
}, | ||
"dependencies": { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,42 @@ | ||
import { vi } from 'vitest'; | ||
|
||
import { EventType } from '@sentry-internal/rrweb'; | ||
|
||
import { saveSession } from '../../src/session/saveSession'; | ||
import type { RecordingEvent } from '../../src/types'; | ||
import { addEvent } from '../../src/util/addEvent'; | ||
import { resetSdkMock } from '../mocks/resetSdkMock'; | ||
import { useFakeTimers } from '../utils/use-fake-timers'; | ||
|
||
useFakeTimers(); | ||
|
||
vi.mock('../../src/session/saveSession', () => { | ||
return { | ||
saveSession: vi.fn(), | ||
}; | ||
}); | ||
|
||
describe('Integration | autoSaveSession', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
test.each([ | ||
['with stickySession=true', true, 1], | ||
['with stickySession=false', false, 0], | ||
])('%s', async (_: string, stickySession: boolean, addSummand: number) => { | ||
const saveSessionSpy = jest.fn(); | ||
|
||
jest.mock('../../src/session/saveSession', () => { | ||
return { | ||
saveSession: saveSessionSpy, | ||
}; | ||
}); | ||
|
||
Comment on lines
-19
to
-26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This gets hoisted and yells at you for using vars outside of scope |
||
const { replay } = await resetSdkMock({ | ||
replayOptions: { | ||
stickySession, | ||
}, | ||
}); | ||
|
||
// Initially called up to three times: once for start, then once for replay.updateSessionActivity & once for segmentId increase | ||
expect(saveSessionSpy).toHaveBeenCalledTimes(addSummand * 3); | ||
expect(saveSession).toHaveBeenCalledTimes(addSummand * 3); | ||
|
||
replay['_updateSessionActivity'](); | ||
|
||
expect(saveSessionSpy).toHaveBeenCalledTimes(addSummand * 4); | ||
expect(saveSession).toHaveBeenCalledTimes(addSummand * 4); | ||
|
||
// In order for runFlush to actually do something, we need to add an event | ||
const event = { | ||
|
@@ -48,8 +49,8 @@ describe('Integration | autoSaveSession', () => { | |
|
||
addEvent(replay, event); | ||
|
||
await replay['_runFlush'](); | ||
await Promise.all([replay['_runFlush'](), vi.runAllTimersAsync()]); | ||
|
||
expect(saveSessionSpy).toHaveBeenCalledTimes(addSummand * 5); | ||
expect(saveSession).toHaveBeenCalledTimes(addSummand * 5); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this, kept running into lint errors because I only want to
yarn fix
this package.