chai-karma-snapshot
Advanced tools
Comparing version 0.4.0 to 0.4.1
{ | ||
"name": "chai-karma-snapshot", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"main": "lib/index.js", | ||
@@ -5,0 +5,0 @@ "typings": "lib/index.d.ts", |
@@ -9,10 +9,15 @@ # Chai Plugin for Snapshot Testing with Karma | ||
Snapshots are stored in a [Markdown](https://en.wikipedia.org/wiki/Markdown) format to improve readability. | ||
Snapshot can be stored in different formats. Right now there are two formats supported: `md` and `indented-md`. | ||
### Markdown Format | ||
This format is preferred when you specify language for code blocks in an assertion plugin. With this format, code | ||
editors will automatically highlight syntax of code blocks. | ||
````md | ||
## `Root Suite` | ||
# `src/html.js` | ||
## `Sub Suite` | ||
## `Sub Suite` | ||
#### `HTML Snapshot` | ||
#### `HTML Snapshot` | ||
@@ -26,2 +31,16 @@ ```html | ||
### Indented Markdown Format | ||
```md | ||
# `src/html.js` | ||
## `Sub Suite` | ||
#### `HTML Snapshot` | ||
<div> | ||
<span /> | ||
</div> | ||
``` | ||
## Snapshot File Path | ||
@@ -32,2 +51,4 @@ | ||
Snapshot file path can be changed by providing a custom `pathResolver` in snapshot config. | ||
## Usage Example | ||
@@ -65,7 +86,3 @@ | ||
webpack: { | ||
plugins: [ | ||
new webpack.SourceMapDevToolPlugin({ | ||
test: /\.js$/, | ||
}), | ||
], | ||
devtool: "inline-source-map", | ||
performance: { | ||
@@ -136,1 +153,32 @@ hints: false | ||
``` | ||
## Config | ||
```js | ||
function resolve(basePath, suiteName) { | ||
return path.join(basePath, "__snapshots__", suiteName); | ||
} | ||
config.set({ | ||
... | ||
snapshot: { | ||
update: true, // Run snapshot tests in UPDATE mode (default: false) | ||
prune: true, // Prune snapshots for removed tests (default: true) | ||
format: "indented-md", // Snapshot format (default: md) | ||
checkSourceFile: true, // Checks existince of the source file associated with tests (default: false) | ||
pathResolver: resolve, // Custom path resolver | ||
} | ||
}); | ||
``` | ||
## Custom Snapshot Format | ||
Snapshot config option `format` also works with custom serialization formats. Custom snapshot serializer should have | ||
interface: | ||
```ts | ||
interface SnapshotSerializer { | ||
serialize: (name: string, suite: SnapshotSuite) => string, | ||
deserialize: (content: string) => { name: string, suite: SnapshotSuite }, | ||
} | ||
``` |
5628
180