vitest-plugin-vis 1.6.2 → 1.6.4

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,4 @@
1
- import type { AutoSnapshotOptions } from '../config/types.ts';
2
- import type { ComparisonMethod } from '../shared/types.ts';
1
+ import type { AutoSnapshotOptions, ComparisonMethod } from '../shared/types.ts';
3
2
  import type { ToMatchImageSnapshotOptions } from './expect/to_match_image_snapshot.types.ts';
4
3
  export type SnapshotMeta<M extends ComparisonMethod> = ToMatchImageSnapshotOptions<M> & AutoSnapshotOptions & {
5
4
  enable?: boolean | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"snapshot_options.d.ts","sourceRoot":"","sources":["../../src/client/snapshot_options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAE7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAE1D,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;CAC5B,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;CAC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AY,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,4 +1,4 @@
1
- import type { ComparisonMethod, ImageSnapshotCompareOptions, ImageSnapshotIdOptions, ImageSnapshotTimeoutOptions } from '../shared/types.ts';
1
+ import type { AutoSnapshotOptions, ComparisonMethod, ImageSnapshotCompareOptions, ImageSnapshotIdOptions, ImageSnapshotTimeoutOptions } from '../shared/types.ts';
2
2
  export type { ComparisonMethod };
3
3
  export type VisOptions<M extends ComparisonMethod = 'pixel'> = ImageSnapshotTimeoutOptions & ImageSnapshotIdOptions & ImageSnapshotCompareOptions<M> & AutoSnapshotOptions & {
4
4
  /**
@@ -41,13 +41,4 @@ export type VisOptions<M extends ComparisonMethod = 'pixel'> = ImageSnapshotTime
41
41
  */
42
42
  customizeSnapshotSubpath?: (subPath: string) => string;
43
43
  };
44
- export type AutoSnapshotOptions = {
45
- /**
46
- * Specify the data-testid of the subject element. Default is `subject`.
47
- *
48
- * If the test does not have an element with the specified data-testid,
49
- * the `body` element will be used.
50
- */
51
- subjectDataTestId?: string | undefined;
52
- };
53
44
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/config/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,gBAAgB,EAChB,2BAA2B,EAC3B,sBAAsB,EACtB,2BAA2B,EAC3B,MAAM,oBAAoB,CAAA;AAE3B,YAAY,EAAE,gBAAgB,EAAE,CAAA;AAEhC,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,gBAAgB,GAAG,OAAO,IAAI,2BAA2B,GACzF,sBAAsB,GACtB,2BAA2B,CAAC,CAAC,CAAC,GAC9B,mBAAmB,GAAG;IACrB;;OAEG;IACH,MAAM,CAAC,EAAE,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;IAC/C;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACpC;;;;;;;;;;;;;;;;;;;OAmBG;IACH,wBAAwB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAA;CACtD,CAAA;AAEF,MAAM,MAAM,mBAAmB,GAAG;IACjC;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACtC,CAAA"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/config/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,mBAAmB,EACnB,gBAAgB,EAChB,2BAA2B,EAC3B,sBAAsB,EACtB,2BAA2B,EAC3B,MAAM,oBAAoB,CAAA;AAE3B,YAAY,EAAE,gBAAgB,EAAE,CAAA;AAEhC,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,gBAAgB,GAAG,OAAO,IAAI,2BAA2B,GACzF,sBAAsB,GACtB,2BAA2B,CAAC,CAAC,CAAC,GAC9B,mBAAmB,GAAG;IACrB;;OAEG;IACH,MAAM,CAAC,EAAE,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;IAC/C;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACpC;;;;;;;;;;;;;;;;;;;OAmBG;IACH,wBAAwB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAA;CACtD,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"create_vis.d.ts","sourceRoot":"","sources":["../../src/setup/create_vis.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAA;AAEjF,wBAAgB,SAAS,CAAC,QAAQ,EAAE,oBAAoB;;QAOrD;;WAEG;;QAIH;;;;WAIG;;QAKH;;;;;;;;;;;;;;WAcG;sBACW,MAAM,CAAC,MAAM,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;;;;;;;8BAoBlC,MAAM,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;;EAsClE"}
1
+ {"version":3,"file":"create_vis.d.ts","sourceRoot":"","sources":["../../src/setup/create_vis.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAA;AAEjF,wBAAgB,SAAS,CAAC,QAAQ,EAAE,oBAAoB;;QAOrD;;WAEG;;QAIH;;;;WAIG;;QAKH;;;;;;;;;;;;;;WAcG;sBACW,MAAM,CAAC,MAAM,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;;;;;;;8BAqBlC,MAAM,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;;EAwClE"}
@@ -1,5 +1,5 @@
1
1
  import dedent from 'dedent';
2
- import { afterEach, beforeAll, expect } from 'vitest';
2
+ import { afterEach, beforeAll } from 'vitest';
3
3
  import { toTaskId } from "../client.js";
4
4
  import { ctx } from "../client/ctx.js";
5
5
  import { shouldTakeSnapshot } from "../client/should_take_snapshot.js";
@@ -59,7 +59,7 @@ export function createVis(commands) {
59
59
  const meta = getAutoSnapshotOptions(test);
60
60
  if (!shouldTakeSnapshot(meta))
61
61
  return;
62
- await expect(getSubject(meta?.subjectDataTestId ?? subjectDataTestId)).toMatchImageSnapshot(meta);
62
+ await test.context.expect(getSubject(meta?.subjectDataTestId ?? subjectDataTestId)).toMatchImageSnapshot(meta);
63
63
  },
64
64
  matchPerTheme(themes) {
65
65
  return async function matchImageSnapshot() {
@@ -73,7 +73,9 @@ export function createVis(commands) {
73
73
  for (const themeId in themes) {
74
74
  try {
75
75
  await new Promise((a) => setTimeout(() => a(themes[themeId]()), 10));
76
- await expect(getSubject(meta?.subjectDataTestId ?? subjectDataTestId)).toMatchImageSnapshot({
76
+ await test.context
77
+ .expect(getSubject(meta?.subjectDataTestId ?? subjectDataTestId))
78
+ .toMatchImageSnapshot({
77
79
  ...meta,
78
80
  customizeSnapshotId: (id) => `${id}-${themeId}`,
79
81
  });
@@ -47,4 +47,13 @@ export type PixelComparisonOptions<M = 'pixel'> = {
47
47
  diffOptions?: PixelmatchOptions | undefined;
48
48
  };
49
49
  export type ImageSnapshotCompareOptions<M extends ComparisonMethod = 'pixel'> = (M extends 'ssim' ? SsimComparisonOptions<M> : PixelComparisonOptions<M>) & FailureThresholdOptions;
50
+ export type AutoSnapshotOptions = {
51
+ /**
52
+ * Specify the data-testid of the subject element. Default is `subject`.
53
+ *
54
+ * If the test does not have an element with the specified data-testid,
55
+ * the `body` element will be used.
56
+ */
57
+ subjectDataTestId?: string | undefined;
58
+ };
50
59
  //# sourceMappingURL=types.d.ts.map
@@ -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,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,CAAA;CAC3D;AAED,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,MAAM,CAAA;AAE/C,MAAM,MAAM,uBAAuB,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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,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,iBAAiB,GAAG,SAAS,CAAA;CAC3C,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": "1.6.2",
3
+ "version": "1.6.4",
4
4
  "description": "Vitest visual testing plugin",
5
5
  "keywords": [
6
6
  "image-snapshot",
@@ -1,6 +1,5 @@
1
- import type { AutoSnapshotOptions } from '../config/types.ts'
2
1
  import { NAME } from '../shared/constants.ts'
3
- import type { ComparisonMethod } from '../shared/types.ts'
2
+ import type { AutoSnapshotOptions, ComparisonMethod } from '../shared/types.ts'
4
3
  import { ctx } from './ctx.ts'
5
4
  import type { ToMatchImageSnapshotOptions } from './expect/to_match_image_snapshot.types.ts'
6
5
 
@@ -1,4 +1,5 @@
1
1
  import type {
2
+ AutoSnapshotOptions,
2
3
  ComparisonMethod,
3
4
  ImageSnapshotCompareOptions,
4
5
  ImageSnapshotIdOptions,
@@ -51,13 +52,3 @@ export type VisOptions<M extends ComparisonMethod = 'pixel'> = ImageSnapshotTime
51
52
  */
52
53
  customizeSnapshotSubpath?: (subPath: string) => string
53
54
  }
54
-
55
- export type AutoSnapshotOptions = {
56
- /**
57
- * Specify the data-testid of the subject element. Default is `subject`.
58
- *
59
- * If the test does not have an element with the specified data-testid,
60
- * the `body` element will be used.
61
- */
62
- subjectDataTestId?: string | undefined
63
- }
@@ -1,5 +1,5 @@
1
1
  import dedent from 'dedent'
2
- import { afterEach, beforeAll, expect } from 'vitest'
2
+ import { afterEach, beforeAll } from 'vitest'
3
3
  import { toTaskId } from '../client.ts'
4
4
  import { ctx } from '../client/ctx.ts'
5
5
  import { shouldTakeSnapshot } from '../client/should_take_snapshot.ts'
@@ -56,12 +56,13 @@ export function createVis(commands: SetupVisSuiteCommand) {
56
56
  afterEach: {
57
57
  async matchImageSnapshot() {
58
58
  const test = ctx.getCurrentTest()
59
+
59
60
  if ((test?.result?.errors?.length ?? 0) > 0) return
60
61
 
61
62
  const meta = getAutoSnapshotOptions(test)
62
63
  if (!shouldTakeSnapshot(meta)) return
63
64
 
64
- await expect(getSubject(meta?.subjectDataTestId ?? subjectDataTestId)).toMatchImageSnapshot(meta)
65
+ await test!.context.expect(getSubject(meta?.subjectDataTestId ?? subjectDataTestId)).toMatchImageSnapshot(meta)
65
66
  },
66
67
  matchPerTheme(themes: Record<string, () => Promise<void> | void>) {
67
68
  return async function matchImageSnapshot() {
@@ -74,10 +75,12 @@ export function createVis(commands: SetupVisSuiteCommand) {
74
75
  for (const themeId in themes) {
75
76
  try {
76
77
  await new Promise((a) => setTimeout(() => a(themes[themeId]!()), 10))
77
- await expect(getSubject(meta?.subjectDataTestId ?? subjectDataTestId)).toMatchImageSnapshot({
78
- ...meta,
79
- customizeSnapshotId: (id) => `${id}-${themeId}`,
80
- })
78
+ await test!.context
79
+ .expect(getSubject(meta?.subjectDataTestId ?? subjectDataTestId))
80
+ .toMatchImageSnapshot({
81
+ ...meta,
82
+ customizeSnapshotId: (id) => `${id}-${themeId}`,
83
+ })
81
84
  } catch (error) {
82
85
  errors.push([themeId, error])
83
86
  }
@@ -56,3 +56,13 @@ export type ImageSnapshotCompareOptions<M extends ComparisonMethod = 'pixel'> =
56
56
  ? SsimComparisonOptions<M>
57
57
  : PixelComparisonOptions<M>) &
58
58
  FailureThresholdOptions
59
+
60
+ export type AutoSnapshotOptions = {
61
+ /**
62
+ * Specify the data-testid of the subject element. Default is `subject`.
63
+ *
64
+ * If the test does not have an element with the specified data-testid,
65
+ * the `body` element will be used.
66
+ */
67
+ subjectDataTestId?: string | undefined
68
+ }