vitest-plugin-vis 1.0.0 → 1.0.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,6 +1,5 @@
1
- import { getCurrentTest } from 'vitest/suite';
2
1
  export declare const ctx: {
3
- getCurrentTest: typeof getCurrentTest;
2
+ getCurrentTest: () => import("vitest").RunnerTestCase<object> | import("vitest").RunnerCustomCase<object> | undefined;
4
3
  __test__reset(): void;
5
4
  };
6
5
  //# sourceMappingURL=ctx.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ctx.d.ts","sourceRoot":"","sources":["../../src/client/ctx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAE7C,eAAO,MAAM,GAAG;;;CAKf,CAAA"}
1
+ {"version":3,"file":"ctx.d.ts","sourceRoot":"","sources":["../../src/client/ctx.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,GAAG;;;CAKf,CAAA"}
package/esm/client/ctx.js CHANGED
@@ -1,4 +1,4 @@
1
- import { getCurrentTest } from 'vitest/suite';
1
+ import { getCurrentTest } from "./vitest_suite_proxy.js";
2
2
  export const ctx = {
3
3
  getCurrentTest,
4
4
  __test__reset() {
@@ -0,0 +1,2 @@
1
+ export declare const getCurrentTest: () => import("vitest").RunnerTestCase<object> | import("vitest").RunnerCustomCase<object> | undefined;
2
+ //# sourceMappingURL=vitest_suite_proxy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vitest_suite_proxy.d.ts","sourceRoot":"","sources":["../../src/client/vitest_suite_proxy.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,cAAc,uGAAsC,CAAA"}
@@ -0,0 +1,7 @@
1
+ let vitestSuite;
2
+ if (globalThis.__vitest_browser__) {
3
+ import('vitest/suite').then((m) => {
4
+ vitestSuite = m;
5
+ });
6
+ }
7
+ export const getCurrentTest = () => vitestSuite?.getCurrentTest();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitest-plugin-vis",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Vitest visual testing plugin",
5
5
  "keywords": [
6
6
  "image-snapshot",
package/readme.md CHANGED
@@ -27,15 +27,15 @@ import { defineConfig } from 'vitest/config'
27
27
  import { vis } from 'vitest-plugin-vis/config'
28
28
 
29
29
  export default defineConfig({
30
- plugins: [vis()],
31
- test: {
32
- browser: {
33
- // typical browser config
34
- enabled: true,
35
- provider: 'playwright',
36
- name: 'chromium'
37
- }
38
- }
30
+ plugins: [vis()],
31
+ test: {
32
+ browser: {
33
+ // typical browser config
34
+ enabled: true,
35
+ provider: 'playwright',
36
+ name: 'chromium'
37
+ }
38
+ }
39
39
  })
40
40
  ```
41
41
 
@@ -56,21 +56,21 @@ import { defineConfig } from 'vitest/config'
56
56
  import { vis } from 'vitest-plugin-vis/config'
57
57
 
58
58
  export default defineConfig({
59
- plugins: [
60
- vis({
61
- preset: 'auto', // preset is disabled by default when you provide a custom config
62
- snapshotRootDir: '__vis__',
63
- customizeSnapshotSubpath: (subpath) => subpath,
64
- customizeSnapshotId: (id, index) => `${id}-${index}`,
65
- diffOptions: undefined, // pixelmatch options
66
- failureThresholdType: 'pixel',
67
- failureThreshold: 0,
68
- timeout: 5000 // 30000 on CI
69
- })
70
- ],
71
- test:{
72
- browser:{/* ... */}
73
- }
59
+ plugins: [
60
+ vis({
61
+ preset: 'auto',
62
+ snapshotRootDir: '__vis__',
63
+ customizeSnapshotSubpath: (subpath) => subpath,
64
+ customizeSnapshotId: (id, index) => `${id}-${index}`,
65
+ diffOptions: undefined, // pixelmatch options
66
+ failureThresholdType: 'pixel',
67
+ failureThreshold: 0,
68
+ timeout: 5000 // 30000 on CI
69
+ })
70
+ ],
71
+ test:{
72
+ browser:{/* ... */}
73
+ }
74
74
  })
75
75
  ```
76
76
 
@@ -84,22 +84,30 @@ import { defineConfig } from 'vitest/config'
84
84
  import { vis } from 'vitest-plugin-vis/config'
85
85
 
86
86
  export default defineConfig({
87
- plugins: [
88
- // preset is disabled by default when you provide a custom config
89
- vis({}) // or vis({ preset: 'none' })
90
- ],
91
- test:{
92
- browser:{/* ... */},
93
- setupFiles: ['vitest.setup.ts']
94
- }
87
+ plugins: [
88
+ // preset is disabled by default when you provide a custom config
89
+ vis({}) // or vis({ preset: 'none' })
90
+ ],
91
+ test:{
92
+ browser:{/* ... */},
93
+ setupFiles: ['vitest.setup.ts']
94
+ }
95
95
  })
96
96
 
97
97
  // vitest.setup.ts
98
98
  import { vis } from 'vitest-plugin-vis/setup'
99
99
 
100
+ // if you set `preset: none` in `vitest.config.ts`,
101
+ // you can enable `auto` or `manual` setup here
102
+ vis.presets.auto()
103
+ vis.presets.manual()
104
+
105
+
106
+ // or capture image snapshot for all stories with `snapshot` tag,
107
+ // for multiple themes (light and dark in this example)
100
108
  vis.presets.theme({
101
- light() { document.body.classList.remove('dark') },
102
- dark() { document.body.classList.add('dark') },
109
+ light() { document.body.classList.remove('dark') },
110
+ dark() { document.body.classList.add('dark') },
103
111
  })
104
112
  ```
105
113
 
@@ -116,32 +124,32 @@ import { setAutoSnapshotOptions } from 'vitest-plugin-vis'
116
124
  import { beforeEach, it } from 'vitest'
117
125
 
118
126
  beforeAll((suite) => {
119
- // Apply options to all tests in the current suite (file)
120
- setAutoSnapshotOptions(suite, /* options */)
127
+ // Apply options to all tests in the current suite (file)
128
+ setAutoSnapshotOptions(suite, /* options */)
121
129
  })
122
130
 
123
131
  beforeEach(({ task }) => {
124
- // Apply options to all tests in the current scope
125
- setAutoSnapshotOptions(task, /* options */)
126
- // or
127
- setAutoSnapshotOptions(/* options */)
132
+ // Apply options to all tests in the current scope
133
+ setAutoSnapshotOptions(task, /* options */)
134
+ // or
135
+ setAutoSnapshotOptions(/* options */)
128
136
  })
129
137
 
130
138
 
131
139
  it('disable snapshot per test', async ({ task }) => {
132
- // Apply options to this test only
133
- setAutoSnapshotOptions(task, /* options */)
134
- // or
135
- setAutoSnapshotOptions(/* options */)
140
+ // Apply options to this test only
141
+ setAutoSnapshotOptions(task, /* options */)
142
+ // or
143
+ setAutoSnapshotOptions(/* options */)
136
144
  })
137
145
 
138
146
  describe('nested scope', () => {
139
- beforeEach(({ task }) => {
140
- // Apply options to all tests in the current scope
141
- setAutoSnapshotOptions(task, /* options */)
142
- // or
143
- setAutoSnapshotOptions(/* options */)
144
- })
147
+ beforeEach(({ task }) => {
148
+ // Apply options to all tests in the current scope
149
+ setAutoSnapshotOptions(task, /* options */)
150
+ // or
151
+ setAutoSnapshotOptions(/* options */)
152
+ })
145
153
  })
146
154
  ```
147
155
 
@@ -154,12 +162,12 @@ You can also set the preset to `manual` and compare snapshots manually:
154
162
  import { defineConfig } from 'vitest/config'
155
163
 
156
164
  export default defineConfig({
157
- plugins: [
158
- vis({ preset: 'manual' })
159
- ],
160
- test:{
161
- browser:{/* ... */}
162
- }
165
+ plugins: [
166
+ vis({ preset: 'manual' })
167
+ ],
168
+ test:{
169
+ browser:{/* ... */}
170
+ }
163
171
  })
164
172
 
165
173
  // some.test.ts
@@ -168,11 +176,11 @@ import { page } from '@vitest/browser/context'
168
176
  import { expect, it } from 'vitest'
169
177
 
170
178
  it('manual snapshot', async () => {
171
- page.render(<div data-testid="subject">hello world</div>)
172
- await expect(document.body).toMatchImageSnapshot(/* options */)
173
- // or
174
- const subject = page.getByTestId('subject')
175
- await expect(subject).toMatchImageSnapshot(/* options */)
179
+ page.render(<div data-testid="subject">hello world</div>)
180
+ await expect(document.body).toMatchImageSnapshot(/* options */)
181
+ // or
182
+ const subject = page.getByTestId('subject')
183
+ await expect(subject).toMatchImageSnapshot(/* options */)
176
184
  })
177
185
  ```
178
186
 
@@ -185,17 +193,17 @@ import { page } from '@vitest/browser/context'
185
193
  import { expect, it } from 'vitest'
186
194
 
187
195
  it('manual snapshot with options', async () => {
188
- page.render(<div data-testid="subject">hello world</div>)
189
- const subject = page.getByTestId('subject')
190
- await expect(subject).toMatchImageSnapshot({
191
- customizeSnapshotId: (id, index) => `${id}-${index}`,
192
- failureThreshold: 0.01,
193
- failureThresholdType: 'percent',
194
- diffOptions: {
195
- threshold: 0.1
196
- },
197
- timeout: 15000
198
- })
196
+ page.render(<div data-testid="subject">hello world</div>)
197
+ const subject = page.getByTestId('subject')
198
+ await expect(subject).toMatchImageSnapshot({
199
+ customizeSnapshotId: (id, index) => `${id}-custom-${index}`,
200
+ failureThreshold: 0.01,
201
+ failureThresholdType: 'percent',
202
+ diffOptions: {
203
+ threshold: 0.1
204
+ },
205
+ timeout: 15000
206
+ })
199
207
  })
200
208
  ```
201
209
 
@@ -208,13 +216,13 @@ import { page } from '@vitest/browser/context'
208
216
  import { expect, it } from 'vitest'
209
217
 
210
218
  it('Has Snapshot', async () => {
211
- const hasSnapshot = await page.hasImageSnapshot(/* options */)
212
- if (!hasSnapshot) {
213
- // do something
214
- }
215
- else {
216
- // do something else
217
- }
219
+ const hasSnapshot = await page.hasImageSnapshot(/* options */)
220
+ if (!hasSnapshot) {
221
+ // do something
222
+ }
223
+ else {
224
+ // do something else
225
+ }
218
226
  })
219
227
  ```
220
228
 
package/src/client/ctx.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { getCurrentTest } from 'vitest/suite'
1
+ import { getCurrentTest } from './vitest_suite_proxy.ts'
2
2
 
3
3
  export const ctx = {
4
4
  getCurrentTest,
@@ -0,0 +1,9 @@
1
+ let vitestSuite: Awaited<typeof import('vitest/suite')>
2
+
3
+ if ((globalThis as any).__vitest_browser__) {
4
+ import('vitest/suite').then((m) => {
5
+ vitestSuite = m
6
+ })
7
+ }
8
+
9
+ export const getCurrentTest = () => vitestSuite?.getCurrentTest()