@chromatic-com/vitest 0.0.3 → 0.0.4-01dbbc2-20260506224818

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/dist/plugin.js CHANGED
@@ -3870,6 +3870,12 @@ function createStories(title, domSnapshots, chromaticStorybookParams) {
3870
3870
  title,
3871
3871
  stories: Object.entries(domSnapshots).map(([name, { viewport }]) => ({
3872
3872
  name,
3873
+ // Viewport addon (Storybook 10+): `parameters.viewport.options` registers sizes; `globals.viewport`
3874
+ // selects the active one. See https://storybook.js.org/docs/essentials/viewport#defining-the-viewport-for-a-story
3875
+ // `defaultViewport` is not read by SB 10's types but our archive preview uses it as a fetch fallback.
3876
+ globals: {
3877
+ viewport: viewportToString(viewport)
3878
+ },
3873
3879
  parameters: {
3874
3880
  server: {
3875
3881
  id: snapshotId(title, name)
@@ -3881,7 +3887,7 @@ function createStories(title, domSnapshots, chromaticStorybookParams) {
3881
3887
  ])
3882
3888
  },
3883
3889
  viewport: {
3884
- viewports: buildStoryViewportsConfig([
3890
+ options: buildStoryViewportsConfig([
3885
3891
  viewport
3886
3892
  ]),
3887
3893
  defaultViewport: viewportToString(findDefaultViewport([
@@ -3910,6 +3916,7 @@ function buildStoryViewportsConfig(viewports) {
3910
3916
  const viewportName = viewportToString(viewport);
3911
3917
  viewportsConfig[viewportName] = {
3912
3918
  name: viewportName,
3919
+ type: viewportAddonType(viewport),
3913
3920
  styles: {
3914
3921
  width: `${viewport.width}px`,
3915
3922
  height: `${viewport.height}px`
@@ -3920,6 +3927,17 @@ function buildStoryViewportsConfig(viewports) {
3920
3927
  }
3921
3928
  __name(buildStoryViewportsConfig, "buildStoryViewportsConfig");
3922
3929
  __name2(buildStoryViewportsConfig, "buildStoryViewportsConfig");
3930
+ function viewportAddonType(viewport) {
3931
+ if (viewport.width < 600) {
3932
+ return "mobile";
3933
+ }
3934
+ if (viewport.width < 1024) {
3935
+ return "tablet";
3936
+ }
3937
+ return "desktop";
3938
+ }
3939
+ __name(viewportAddonType, "viewportAddonType");
3940
+ __name2(viewportAddonType, "viewportAddonType");
3923
3941
  function findDefaultViewport(viewports) {
3924
3942
  const compareFn = /* @__PURE__ */ __name2((vp1, vp2) => {
3925
3943
  if (vp1.width < vp2.width) {
package/dist/setupFile.js CHANGED
@@ -124,42 +124,62 @@ beforeEach(async ({ task }) => {
124
124
  const hasMatchingTag = task.tags?.some((tag) => options.tags?.includes(tag));
125
125
  if (!hasMatchingTag) {
126
126
  task.meta.__chromatic_isRegistered = false;
127
- return;
127
+ return cleanup;
128
128
  }
129
129
  }
130
130
  task.meta.__chromatic_isRegistered = true;
131
131
  task.meta.__chromatic_isTakeSnapshotCalled = false;
132
132
  task.meta.__chromatic_autoSnapshot ??= !options.disableAutoSnapshot;
133
133
  await commands3.__chromatic_interceptFetch(task.id);
134
+ return /* @__PURE__ */ __name(async function beforeEachCleanup() {
135
+ const { __chromatic_isTakeSnapshotCalled: isTakeSnapshotCalled, __chromatic_pendingTakeSnapshots: pendingTakeSnapshots, __chromatic_isRegistered: isRegistered } = task.meta;
136
+ if (!isRegistered) {
137
+ return cleanup();
138
+ }
139
+ if (pendingTakeSnapshots?.length) {
140
+ throw new PendingSnapshotsError(pendingTakeSnapshots);
141
+ }
142
+ if (!isTakeSnapshotCalled) {
143
+ await commands3.__chromatic_stopWithoutSnapshots(task.id);
144
+ return cleanup();
145
+ }
146
+ await commands3.__chromatic_writeTestResult(task.id);
147
+ return cleanup();
148
+ }, "beforeEachCleanup");
149
+ function cleanup() {
150
+ task.meta.__chromatic_autoSnapshot = void 0;
151
+ task.meta.__chromatic_isTakeSnapshotCalled = void 0;
152
+ task.meta.__chromatic_isRegistered = void 0;
153
+ task.meta.__chromatic_pendingTakeSnapshots = void 0;
154
+ }
155
+ __name(cleanup, "cleanup");
134
156
  });
135
157
  afterEach(async ({ task }) => {
136
- const { __chromatic_autoSnapshot: autoSnapshot, __chromatic_isTakeSnapshotCalled: isTakeSnapshotCalled, __chromatic_pendingTakeSnapshots: pendingTakeSnapshots, __chromatic_isRegistered: isRegistered } = task.meta;
158
+ const { __chromatic_autoSnapshot: autoSnapshot, __chromatic_pendingTakeSnapshots: pendingTakeSnapshots, __chromatic_isRegistered: isRegistered } = task.meta;
137
159
  if (!isRegistered) {
138
- return cleanup();
160
+ return;
139
161
  }
140
162
  if (pendingTakeSnapshots?.length) {
141
- throw new AggregateError(pendingTakeSnapshots.map((call) => call.error), `${pendingTakeSnapshots.length} unawaited takeSnapshot() call(s)`);
163
+ throw new PendingSnapshotsError(pendingTakeSnapshots);
142
164
  }
143
- if (!autoSnapshot && !isTakeSnapshotCalled) {
144
- await commands3.__chromatic_stopWithoutSnapshots(task.id);
145
- return cleanup();
165
+ if (!autoSnapshot) {
166
+ return;
146
167
  }
147
168
  const options = await commands3.__chromatic_getOptions();
148
169
  if (options.resourceArchiveTimeout !== 0) {
149
170
  await waitForIdleNetwork(options.resourceArchiveTimeout);
150
171
  }
151
- if (autoSnapshot) {
152
- await takeSnapshot(void 0, {
153
- ignoreUnawaited: true
154
- });
172
+ await takeSnapshot(void 0, {
173
+ ignoreUnawaited: true
174
+ });
175
+ });
176
+ var PendingSnapshotsError = class PendingSnapshotsError2 extends AggregateError {
177
+ static {
178
+ __name(this, "PendingSnapshotsError");
155
179
  }
156
- await commands3.__chromatic_writeTestResult(task.id);
157
- return cleanup();
158
- function cleanup() {
159
- task.meta.__chromatic_autoSnapshot = void 0;
160
- task.meta.__chromatic_isTakeSnapshotCalled = void 0;
161
- task.meta.__chromatic_isRegistered = void 0;
162
- task.meta.__chromatic_pendingTakeSnapshots = void 0;
180
+ pendingCalls;
181
+ constructor(pendingCalls) {
182
+ super(pendingCalls.map((call) => call.error), `${pendingCalls.length} unawaited takeSnapshot() call(s)`), this.pendingCalls = pendingCalls;
183
+ this.name = "PendingSnapshotsError";
163
184
  }
164
- __name(cleanup, "cleanup");
165
- });
185
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chromatic-com/vitest",
3
- "version": "0.0.3",
3
+ "version": "0.0.4-01dbbc2-20260506224818",
4
4
  "description": "Chromatic Visual Regression Testing for Vitest",
5
5
  "repository": {
6
6
  "type": "git",