vitest-plugin-vis 2.0.1 → 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.
@@ -1,5 +1,6 @@
1
1
  export declare const ctx: {
2
2
  getCurrentTest: () => import("vitest").RunnerTestCase<object> | undefined;
3
+ getCurrentSuite: () => import("vitest").SuiteCollector<object>;
3
4
  __test__reset(): void;
4
5
  };
5
6
  //# sourceMappingURL=ctx.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ctx.d.ts","sourceRoot":"","sources":["../../src/client/ctx.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,GAAG;;;CAKf,CAAA"}
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":"AACA,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,C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C,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 ? [ctx.getCurrentTest(), parseMeta(args[0])] : [args[0], parseMeta(args[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,2 +1,3 @@
1
1
  export declare const getCurrentTest: () => import("vitest").RunnerTestCase<object> | undefined;
2
+ export declare const getCurrentSuite: () => import("vitest").SuiteCollector<object>;
2
3
  //# sourceMappingURL=vitest_suite_proxy.d.ts.map
@@ -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"}
@@ -5,3 +5,4 @@ if (globalThis.__vitest_browser__) {
5
5
  });
6
6
  }
7
7
  export const getCurrentTest = () => vitestSuite?.getCurrentTest();
8
+ export const getCurrentSuite = () => vitestSuite?.getCurrentSuite();
@@ -21,7 +21,15 @@ export declare const visContext: {
21
21
  diffPath: string;
22
22
  timeout?: number | undefined | undefined;
23
23
  comparisonMethod?: any;
24
- diffOptions?: import("pixelmatch").PixelmatchOptions | undefined;
24
+ diffOptions?: {
25
+ threshold?: number | undefined;
26
+ includeAA?: boolean | undefined;
27
+ alpha?: number | undefined;
28
+ aaColor?: [number, number, number] | undefined;
29
+ diffColor?: [number, number, number] | undefined;
30
+ diffColorAlt?: [number, number, number] | undefined;
31
+ diffMask?: boolean | undefined;
32
+ } | undefined;
25
33
  failureThresholdType?: "pixel" | "percent" | undefined | undefined;
26
34
  failureThreshold?: number | undefined | undefined;
27
35
  };
@@ -1 +1 @@
1
- {"version":3,"file":"vis_context.d.ts","sourceRoot":"","sources":["../../src/server/vis_context.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU;;;;;;;sBAC69C,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CADz8C,CAAA"}
1
+ {"version":3,"file":"vis_context.d.ts","sourceRoot":"","sources":["../../src/server/vis_context.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU;;;;;;;sBAC69C,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CADz8C,CAAA"}
@@ -28,7 +28,15 @@ export declare function createVisContext(): {
28
28
  diffPath: string;
29
29
  timeout?: number | undefined | undefined;
30
30
  comparisonMethod?: any;
31
- diffOptions?: import("pixelmatch").PixelmatchOptions | undefined;
31
+ diffOptions?: {
32
+ threshold?: number | undefined;
33
+ includeAA?: boolean | undefined;
34
+ alpha?: number | undefined;
35
+ aaColor?: [number, number, number] | undefined;
36
+ diffColor?: [number, number, number] | undefined;
37
+ diffColorAlt?: [number, number, number] | undefined;
38
+ diffMask?: boolean | undefined;
39
+ } | undefined;
32
40
  failureThresholdType?: "pixel" | "percent" | undefined | undefined;
33
41
  failureThreshold?: number | undefined | undefined;
34
42
  };
@@ -1 +1 @@
1
- {"version":3,"file":"vis_context.logic.d.ts","sourceRoot":"","sources":["../../src/server/vis_context.logic.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAKpD,OAAO,KAAK,EAAE,4BAA4B,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAA;AAEpF,wBAAgB,gBAAgB;eAMnB,CAAC,SAAS,OAAO,GAAG,MAAM,YAAW,UAAU,CAAC,CAAC,CAAC;;;;IAY7D;;;;OAIG;wBACuB,4BAA4B;8BAa5B,MAAM,QAAQ,MAAM,YAAY;QAAE,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE;;;;;;;;;;;;;;;;;;;2BAkB1E,MAAM,UAAU,MAAM;+BAGlB,MAAM,UAAU,MAAM,kBAAkB,MAAM,GAAG,SAAS;8BAI3D;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE;YAAE,KAAK,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,kBAAkB,MAAM,GAAG,SAAS;2BASlF,MAAM,UAAU,MAAM;;;;;;;;;;EAe9C;AAyBD,wBAAgB,WAAW,CAAC,KAAK,EAAE,QAAQ,EAAE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1,4 @@
1
- import type { PixelmatchOptions } from 'pixelmatch';
1
+ import type pixelMatch from 'pixelmatch';
2
2
  import type { Options as SsimOptions } from 'ssim.js';
3
3
  export interface ImageSnapshotTimeoutOptions {
4
4
  /**
@@ -47,7 +47,7 @@ export type PixelComparisonOptions<M = 'pixel'> = {
47
47
  /**
48
48
  * Custom options passed to 'pixelmatch'
49
49
  */
50
- diffOptions?: PixelmatchOptions | undefined;
50
+ diffOptions?: Parameters<typeof pixelMatch>[5] | undefined;
51
51
  };
52
52
  export type ImageSnapshotCompareOptions<M extends ComparisonMethod = 'pixel'> = (M extends 'ssim' ? SsimComparisonOptions<M> : PixelComparisonOptions<M>) & FailureThresholdOptions;
53
53
  export type AutoSnapshotOptions = {
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/shared/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AACnD,OAAO,KAAK,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,SAAS,CAAA;AAErD,MAAM,WAAW,2BAA2B;IAC3C;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAC5B;AAED,MAAM,WAAW,sBAAsB;IACtC;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,CAAC,OAAO,EAAE;QAC/B,EAAE,EAAE,MAAM,CAAA;QAGV,KAAK,EAAE,MAAM,CAAA;KACb,KAAK,MAAM,CAAA;CACZ;AAED,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,MAAM,CAAA;AAE/C,MAAM,MAAM,uBAAuB,GAAG;IACrC;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,SAAS,CAAA;IACtD;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACrC,CAAA;AAED,MAAM,MAAM,qBAAqB,CAAC,CAAC,GAAG,MAAM,IA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D;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACrC,CAAA;AAED,MAAM,MAAM,qBAAqB,CAAC,CAAC,GAAG,MAAM,IAAI;IAC/C,gBAAgB,EAAE,CAAC,CAAA;IACnB;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,SAAS,CAAA;CAC9C,CAAA;AACD,MAAM,MAAM,sBAAsB,CAAC,CAAC,GAAG,OAAO,IAAI;IACjD,gBAAgB,CAAC,EAAE,CAAC,GAAG,SAAS,CAAA;IAChC;;OAEG;IACH,WAAW,CAAC,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAAA;CAC1D,CAAA;AAED,MAAM,MAAM,2BAA2B,CAAC,CAAC,SAAS,gBAAgB,GAAG,OAAO,IAAI,CAAC,CAAC,SAAS,MAAM,GAC9F,qBAAqB,CAAC,CAAC,CAAC,GACxB,sBAAsB,CAAC,CAAC,CAAC,CAAC,GAC5B,uBAAuB,CAAA;AAExB,MAAM,MAAM,mBAAmB,GAAG;IACjC;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACtC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitest-plugin-vis",
3
- "version": "2.0.1",
3
+ "version": "2.1.1",
4
4
  "description": "Vitest visual testing plugin",
5
5
  "keywords": [
6
6
  "image-snapshot",
@@ -61,12 +61,11 @@
61
61
  "!**/*.{spec,test,unit,accept,integrate,system,perf,stress}.*"
62
62
  ],
63
63
  "dependencies": {
64
- "@types/pixelmatch": "^5.2.6",
65
64
  "dedent": "^1.5.1",
66
65
  "is-ci": "^4.0.0",
67
66
  "mkdirp": "^3.0.1",
68
67
  "pathe": "^2.0.0",
69
- "pixelmatch": "^6.0.0",
68
+ "pixelmatch": "^7.1.0",
70
69
  "pngjs": "^7.0.0",
71
70
  "rimraf": "^6.0.1",
72
71
  "ssim.js": "^3.5.0",
@@ -77,10 +76,10 @@
77
76
  "@types/is-ci": "^3.0.4",
78
77
  "@types/pngjs": "^6.0.5",
79
78
  "@types/react": "^19.0.2",
80
- "@vitest/browser": "^3.0.5",
81
- "@vitest/coverage-istanbul": "^3.0.5",
82
- "@vitest/coverage-v8": "^3.0.5",
83
- "@vitest/expect": "^3.0.5",
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",
84
83
  "cross-env": "^7.0.3",
85
84
  "never-fail": "^1.1.4",
86
85
  "npm-run-all2": "^7.0.2",
@@ -89,8 +88,8 @@
89
88
  "react-dom": "^19.0.0",
90
89
  "typescript": "^5.7.2",
91
90
  "vite": "^6.0.9",
92
- "vitest": "^3.0.5",
93
- "vitest-browser-react": "^0.0.4",
91
+ "vitest": "^3.0.6",
92
+ "vitest-browser-react": "^0.1.0",
94
93
  "webdriverio": "latest"
95
94
  },
96
95
  "peerDependencies": {
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 ? [ctx.getCurrentTest(), parseMeta(args[0])] : [args[0], parseMeta(args[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> {
@@ -7,3 +7,4 @@ if ((globalThis as any).__vitest_browser__) {
7
7
  }
8
8
 
9
9
  export const getCurrentTest = () => vitestSuite?.getCurrentTest()
10
+ export const getCurrentSuite = () => vitestSuite?.getCurrentSuite()
@@ -1,4 +1,4 @@
1
- import type { PixelmatchOptions } from 'pixelmatch'
1
+ import type pixelMatch from 'pixelmatch'
2
2
  import type { Options as SsimOptions } from 'ssim.js'
3
3
 
4
4
  export interface ImageSnapshotTimeoutOptions {
@@ -54,7 +54,7 @@ export type PixelComparisonOptions<M = 'pixel'> = {
54
54
  /**
55
55
  * Custom options passed to 'pixelmatch'
56
56
  */
57
- diffOptions?: PixelmatchOptions | undefined
57
+ diffOptions?: Parameters<typeof pixelMatch>[5] | undefined
58
58
  }
59
59
 
60
60
  export type ImageSnapshotCompareOptions<M extends ComparisonMethod = 'pixel'> = (M extends 'ssim'