vitest-plugin-vis 2.1.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/client/ctx.d.ts +1 -0
- package/esm/client/ctx.d.ts.map +1 -1
- package/esm/client/ctx.js +3 -1
- package/esm/client/snapshot_options.d.ts.map +1 -1
- package/esm/client/snapshot_options.js +4 -1
- package/esm/client/vitest_suite_proxy.d.ts +1 -0
- package/esm/client/vitest_suite_proxy.d.ts.map +1 -1
- package/esm/client/vitest_suite_proxy.js +1 -0
- package/package.json +6 -6
- package/readme.md +12 -0
- package/src/client/ctx.ts +3 -1
- package/src/client/snapshot_options.ts +4 -1
- package/src/client/vitest_suite_proxy.ts +1 -0
package/esm/client/ctx.d.ts
CHANGED
package/esm/client/ctx.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ctx.d.ts","sourceRoot":"","sources":["../../src/client/ctx.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,GAAG
|
|
1
|
+
{"version":3,"file":"ctx.d.ts","sourceRoot":"","sources":["../../src/client/ctx.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,GAAG;;;;CAOf,CAAA"}
|
package/esm/client/ctx.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { getCurrentTest } from "./vitest_suite_proxy.js";
|
|
1
|
+
import { getCurrentSuite, getCurrentTest } from "./vitest_suite_proxy.js";
|
|
2
2
|
export const ctx = {
|
|
3
3
|
getCurrentTest,
|
|
4
|
+
getCurrentSuite,
|
|
4
5
|
__test__reset() {
|
|
5
6
|
ctx.getCurrentTest = getCurrentTest;
|
|
7
|
+
ctx.getCurrentSuite = getCurrentSuite;
|
|
6
8
|
},
|
|
7
9
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snapshot_options.d.ts","sourceRoot":"","sources":["../../src/client/snapshot_options.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"snapshot_options.d.ts","sourceRoot":"","sources":["../../src/client/snapshot_options.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAE/E,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,2CAA2C,CAAA;AAE5F,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,gBAAgB,IAAI,2BAA2B,CAAC,CAAC,CAAC,GACpF,mBAAmB,GAAG;IACrB,MAAM,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;IAC5B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACtB,CAAA;AAEF,KAAK,KAAK,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAAC,KAAK,CAAC,EAAE,KAAK,GAAG,SAAS,CAAA;CAAE,CAAA;AAErE,MAAM,MAAM,QAAQ,GACjB;IACA,IAAI,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;KAAE,GAAG,SAAS,CAAA;IAChD,KAAK,CAAC,EAAE,KAAK,GAAG,SAAS,CAAA;IACzB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CACxB,GACD,SAAS,CAAA;AAEZ;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,gBAAgB,EAChE,IAAI,EAAE,QAAQ,EACd,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,OAAO,GAC7B,IAAI,CAAA;AACP,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,gBAAgB,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,OAAO,GAAG,IAAI,CAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getCurrentTest } from 'vitest/suite';
|
|
1
2
|
import { NAME } from "../shared/constants.js";
|
|
2
3
|
import { ctx } from "./ctx.js";
|
|
3
4
|
export function setAutoSnapshotOptions(...args) {
|
|
@@ -9,7 +10,9 @@ export function setAutoSnapshotOptions(...args) {
|
|
|
9
10
|
};
|
|
10
11
|
}
|
|
11
12
|
function parseArgs(args) {
|
|
12
|
-
return args.length === 1
|
|
13
|
+
return args.length === 1
|
|
14
|
+
? [ctx.getCurrentTest() ?? ctx.getCurrentSuite().tasks?.[0]?.file, parseMeta(args[0])]
|
|
15
|
+
: [args[0], parseMeta(args[1])];
|
|
13
16
|
}
|
|
14
17
|
function parseMeta(meta) {
|
|
15
18
|
return typeof meta === 'boolean' ? { enable: meta } : { enable: true, ...meta };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vitest_suite_proxy.d.ts","sourceRoot":"","sources":["../../src/client/vitest_suite_proxy.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,cAAc,2DAAsC,CAAA"}
|
|
1
|
+
{"version":3,"file":"vitest_suite_proxy.d.ts","sourceRoot":"","sources":["../../src/client/vitest_suite_proxy.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,cAAc,2DAAsC,CAAA;AACjE,eAAO,MAAM,eAAe,+CAAuC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest-plugin-vis",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "Vitest visual testing plugin",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"image-snapshot",
|
|
@@ -76,10 +76,10 @@
|
|
|
76
76
|
"@types/is-ci": "^3.0.4",
|
|
77
77
|
"@types/pngjs": "^6.0.5",
|
|
78
78
|
"@types/react": "^19.0.2",
|
|
79
|
-
"@vitest/browser": "^3.0.
|
|
80
|
-
"@vitest/coverage-istanbul": "^3.0.
|
|
81
|
-
"@vitest/coverage-v8": "^3.0.
|
|
82
|
-
"@vitest/expect": "^3.0.
|
|
79
|
+
"@vitest/browser": "^3.0.6",
|
|
80
|
+
"@vitest/coverage-istanbul": "^3.0.6",
|
|
81
|
+
"@vitest/coverage-v8": "^3.0.6",
|
|
82
|
+
"@vitest/expect": "^3.0.6",
|
|
83
83
|
"cross-env": "^7.0.3",
|
|
84
84
|
"never-fail": "^1.1.4",
|
|
85
85
|
"npm-run-all2": "^7.0.2",
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
"react-dom": "^19.0.0",
|
|
89
89
|
"typescript": "^5.7.2",
|
|
90
90
|
"vite": "^6.0.9",
|
|
91
|
-
"vitest": "^3.0.
|
|
91
|
+
"vitest": "^3.0.6",
|
|
92
92
|
"vitest-browser-react": "^0.1.0",
|
|
93
93
|
"webdriverio": "latest"
|
|
94
94
|
},
|
package/readme.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# Vitest Visual Testing Plugin
|
|
2
2
|
|
|
3
|
+
[![NPM version][npm_image]][npm_url]
|
|
4
|
+
[![NPM downloads][downloads_image]][npm_url]
|
|
5
|
+
|
|
3
6
|
Vitest visual testing plugin allowing you to capture and compare image snapshots automatically and manually.
|
|
4
7
|
|
|
5
8
|
It requires [Vitest Browser Mode][vitest-browser-mode] to work.
|
|
@@ -127,6 +130,10 @@ vis.presets.manual()
|
|
|
127
130
|
|
|
128
131
|
// or capture image snapshot for all rendering tests
|
|
129
132
|
// for multiple themes (light and dark in this example)
|
|
133
|
+
//
|
|
134
|
+
// Note that this changes the theme in the `afterEach` hook.
|
|
135
|
+
// If you want to capture manual snapshots in different themes,
|
|
136
|
+
// configure Vitest to run the tests in different themes.
|
|
130
137
|
vis.presets.theme({
|
|
131
138
|
async light() { document.body.classList.remove('dark') },
|
|
132
139
|
async dark() { document.body.classList.add('dark') },
|
|
@@ -167,6 +174,8 @@ import { beforeEach, it } from 'vitest'
|
|
|
167
174
|
beforeAll((suite) => {
|
|
168
175
|
// Apply options to all tests in the current suite (file)
|
|
169
176
|
setAutoSnapshotOptions(suite, /* options */)
|
|
177
|
+
// or
|
|
178
|
+
setAutoSnapshotOptions(/* options */)
|
|
170
179
|
})
|
|
171
180
|
|
|
172
181
|
beforeEach(({ task }) => {
|
|
@@ -340,8 +349,11 @@ This is because through our own usage, we do not found a good use case for them.
|
|
|
340
349
|
|
|
341
350
|
If you have a good use case for these features, please open an issue or PR.
|
|
342
351
|
|
|
352
|
+
[downloads_image]: https://img.shields.io/npm/dm/vitest-plugin-vis.svg?style=flat
|
|
343
353
|
[firefox]: https://www.mozilla.org/en-US/firefox/
|
|
344
354
|
[jest-image-snapshot]: https://github.com/americanexpress/jest-image-snapshot
|
|
355
|
+
[npm_image]: https://img.shields.io/npm/v/vitest-plugin-vis.svg?style=flat
|
|
356
|
+
[npm_url]: https://npmjs.org/package/vitest-plugin-vis
|
|
345
357
|
[storybook-addon-vis]: https://github.com/repobuddy/storybook-addon-vis
|
|
346
358
|
[vitest-browser-mode]: https://vitest.dev/guide/browser/
|
|
347
359
|
[vitest-plugin-vis]: https://www.npmjs.com/package/vitest-plugin-vis
|
package/src/client/ctx.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { getCurrentTest } from './vitest_suite_proxy.ts'
|
|
1
|
+
import { getCurrentSuite, getCurrentTest } from './vitest_suite_proxy.ts'
|
|
2
2
|
|
|
3
3
|
export const ctx = {
|
|
4
4
|
getCurrentTest,
|
|
5
|
+
getCurrentSuite,
|
|
5
6
|
__test__reset() {
|
|
6
7
|
ctx.getCurrentTest = getCurrentTest
|
|
8
|
+
ctx.getCurrentSuite = getCurrentSuite
|
|
7
9
|
},
|
|
8
10
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getCurrentTest } from 'vitest/suite'
|
|
1
2
|
import { NAME } from '../shared/constants.ts'
|
|
2
3
|
import type { AutoSnapshotOptions, ComparisonMethod } from '../shared/types.ts'
|
|
3
4
|
import { ctx } from './ctx.ts'
|
|
@@ -53,7 +54,9 @@ export function setAutoSnapshotOptions<M extends ComparisonMethod>(
|
|
|
53
54
|
function parseArgs<M extends ComparisonMethod>(
|
|
54
55
|
args: [task: MetaTask, meta: SnapshotMeta<M> | boolean] | [meta: boolean | SnapshotMeta<M>],
|
|
55
56
|
): [MetaTask | undefined, SnapshotMeta<M>] {
|
|
56
|
-
return args.length === 1
|
|
57
|
+
return args.length === 1
|
|
58
|
+
? [ctx.getCurrentTest() ?? (ctx.getCurrentSuite().tasks?.[0] as any)?.file, parseMeta(args[0])]
|
|
59
|
+
: [args[0], parseMeta(args[1])]
|
|
57
60
|
}
|
|
58
61
|
|
|
59
62
|
function parseMeta<M extends ComparisonMethod>(meta: boolean | SnapshotMeta<M>): SnapshotMeta<M> {
|