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

Add a "snapshot" utility #86

Open
kettanaito opened this issue Apr 28, 2021 · 1 comment · May be fixed by #90
Open

Add a "snapshot" utility #86

kettanaito opened this issue Apr 28, 2021 · 1 comment · May be fixed by #90
Labels
feature New feature or request

Comments

@kettanaito
Copy link
Member

Expected behavior

The snapshot utility would memorize the state of the database (its entities) at a call time, and allow to restore to that memorized state at any further point of time (i.e. before each test).

Usage

import { factory, primaryKey, snapshot } from '@mswjs/data'

const db = factory({
  user: {
    id: primaryKey(String),
    firstName: String
  }
})

db.user.create({ firstName: 'John' })
db.user.create({ firstName: 'Kate' })

// Takes a snapshot of the database
// in this point of time.
const restore = snapshot(db)

// Perform some other actions.
db.user.create({ firstName: 'Joe' })

// Restores the database to the taken snapshot.
// Will result in a database with 2 users:
// "John" and "Kate".
restore()

GitHub

@kettanaito
Copy link
Member Author

Restoring a database is effectively reset it to a given initial state. This may mean that #49 is a prerequisite for this task, as persistency also uses a restoration logic that hydrates a database instance from the sessionStorage.

@marcosvega91 marcosvega91 linked a pull request Apr 28, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant