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.
- package/esm/client/ctx.d.ts +1 -2
- package/esm/client/ctx.d.ts.map +1 -1
- package/esm/client/ctx.js +1 -1
- package/esm/client/vitest_suite_proxy.d.ts +2 -0
- package/esm/client/vitest_suite_proxy.d.ts.map +1 -0
- package/esm/client/vitest_suite_proxy.js +7 -0
- package/package.json +1 -1
- package/readme.md +87 -79
- package/src/client/ctx.ts +1 -1
- package/src/client/vitest_suite_proxy.ts +9 -0
package/esm/client/ctx.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { getCurrentTest } from 'vitest/suite';
|
|
2
1
|
export declare const ctx: {
|
|
3
|
-
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
|
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":"
|
|
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
|
@@ -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"}
|
package/package.json
CHANGED
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
-
|
|
102
|
-
|
|
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
|
-
|
|
120
|
-
|
|
127
|
+
// Apply options to all tests in the current suite (file)
|
|
128
|
+
setAutoSnapshotOptions(suite, /* options */)
|
|
121
129
|
})
|
|
122
130
|
|
|
123
131
|
beforeEach(({ task }) => {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
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
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
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