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

feat: add snapshot utility #90

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
test: add performance test for snapshot
  • Loading branch information
marcosvega91 committed Apr 28, 2021
commit 66de0310ace51aede1630d884499d007db344172
43 changes: 43 additions & 0 deletions test/performance/snapshot.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { datatype, random, name } from 'faker'
import { factory, primaryKey, snapshot } from '@mswjs/data'
import { measurePerformance, repeat } from '../testUtils'

test('snapshot a database with 1000 records in under 350ms', async () => {
const db = factory({
user: {
id: primaryKey(datatype.uuid),
firstName: name.firstName,
lastName: name.lastName,
age: datatype.number,
role: random.word,
},
})
repeat(db.user.create, 1000)

const snapshotPerformance = await measurePerformance('snapshot', () => {
snapshot(db)
})

expect(snapshotPerformance.duration).toBeLessThanOrEqual(350)
})

it('restore a database with 1000 records in under 350ms', async () => {
const db = factory({
user: {
id: primaryKey(datatype.uuid),
firstName: name.firstName,
lastName: name.lastName,
age: datatype.number,
role: random.word,
},
})
repeat(db.user.create, 1000)

const restore = snapshot(db)

const restorePerformance = await measurePerformance('restore', () => {
restore()
})

expect(restorePerformance.duration).toBeLessThanOrEqual(350)
})