theintern / intern

A next-generation code testing stack for JavaScript.
https://theintern.io/
Other
4.36k stars 309 forks source link

Add support for snapshot testing #1142

Open jason0x43 opened 4 years ago

jason0x43 commented 4 years ago

Intern should have built-in support for snapshot testing for serializable data values. The goal would be for Intern to record values (any JSON-serializable value, like React render trees) to files and provide a way to easily update them.

The simplest API would probably be to create or use an existing chai plugin, something like chai-karma-snapshot or mocha-chai-snapshot. This would give us an API like:

assert.matchesSnapshot(value);
expect(value).to.matchSnapshot();

Intern should have two functions accessible via the CLI: a way to update snapshots, and a way to prune them (delete any that are no longer relevant). On the config side, these could live under a snapshots property:

{
  "snapshots": {
    "update": true
  }
}

From the command line, using the current option format in Intern master, the above config could be temporarily enabled with --snapshots-update.