@chromatic-com/vitest 0.0.3 → 0.0.4-0533fac-20260505080350

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/index.js CHANGED
@@ -21,8 +21,18 @@ async function resolveHooks() {
21
21
  }
22
22
  __name(resolveHooks, "resolveHooks");
23
23
 
24
+ // src/browser/isChromium.ts
25
+ import { server } from "vitest/browser";
26
+ function isChromium() {
27
+ return server.browser === "chromium";
28
+ }
29
+ __name(isChromium, "isChromium");
30
+
24
31
  // src/browser/public/takeSnapshot.ts
25
32
  async function takeSnapshot(name, options) {
33
+ if (!isChromium()) {
34
+ return;
35
+ }
26
36
  const test = getCurrentTest();
27
37
  if (!test) {
28
38
  throw new TypeError("takeSnapshot() must be called within a test()");
@@ -101,6 +111,9 @@ __name(toDataURL, "toDataURL");
101
111
  // src/browser/public/autoSnapshot.ts
102
112
  import { beforeAll } from "vitest";
103
113
  function disableAutoSnapshot() {
114
+ if (!isChromium()) {
115
+ return;
116
+ }
104
117
  const test = getCurrentTest();
105
118
  if (test) {
106
119
  test.meta.__chromatic_autoSnapshot = false;
@@ -123,6 +136,9 @@ __name(disableAutoSnapshot, "disableAutoSnapshot");
123
136
  // src/browser/public/waitForIdleNetwork.ts
124
137
  import { commands as commands2 } from "vitest/browser";
125
138
  async function waitForIdleNetwork(timeout) {
139
+ if (!isChromium()) {
140
+ return;
141
+ }
126
142
  const test = getCurrentTest();
127
143
  if (!test) {
128
144
  throw new TypeError("waitForIdleNetwork() must be called within a test()");
package/dist/plugin.js CHANGED
@@ -4230,7 +4230,7 @@ function getNames(test) {
4230
4230
  if (current.type === "module") {
4231
4231
  names.unshift(current.relativeModuleId);
4232
4232
  }
4233
- const hasManyProjects = test.project.vitest.projects.length > 1;
4233
+ const hasManyProjects = test.project.vitest.projects.filter((project) => project.config.browser.name === "chromium").length > 1;
4234
4234
  if (hasManyProjects && test.project.name) {
4235
4235
  names.unshift(test.project.name);
4236
4236
  }
@@ -4272,8 +4272,9 @@ function chromaticPlugin(userOptions = {}) {
4272
4272
  },
4273
4273
  configureVitest(context) {
4274
4274
  const project = context.project;
4275
+ const browser = project.config.browser;
4275
4276
  const sequence = context.vitest.config.sequence;
4276
- if (!project.config.browser.enabled) {
4277
+ if (!browser.enabled || browser.name !== "chromium") {
4277
4278
  return;
4278
4279
  }
4279
4280
  if (sequence.hooks === "stack") {
package/dist/setupFile.js CHANGED
@@ -25,8 +25,18 @@ async function resolveHooks() {
25
25
  }
26
26
  __name(resolveHooks, "resolveHooks");
27
27
 
28
+ // src/browser/isChromium.ts
29
+ import { server } from "vitest/browser";
30
+ function isChromium() {
31
+ return server.browser === "chromium";
32
+ }
33
+ __name(isChromium, "isChromium");
34
+
28
35
  // src/browser/public/takeSnapshot.ts
29
36
  async function takeSnapshot(name, options) {
37
+ if (!isChromium()) {
38
+ return;
39
+ }
30
40
  const test = getCurrentTest();
31
41
  if (!test) {
32
42
  throw new TypeError("takeSnapshot() must be called within a test()");
@@ -105,6 +115,9 @@ __name(toDataURL, "toDataURL");
105
115
  // src/browser/public/waitForIdleNetwork.ts
106
116
  import { commands as commands2 } from "vitest/browser";
107
117
  async function waitForIdleNetwork(timeout) {
118
+ if (!isChromium()) {
119
+ return;
120
+ }
108
121
  const test = getCurrentTest();
109
122
  if (!test) {
110
123
  throw new TypeError("waitForIdleNetwork() must be called within a test()");
@@ -124,42 +137,62 @@ beforeEach(async ({ task }) => {
124
137
  const hasMatchingTag = task.tags?.some((tag) => options.tags?.includes(tag));
125
138
  if (!hasMatchingTag) {
126
139
  task.meta.__chromatic_isRegistered = false;
127
- return;
140
+ return cleanup;
128
141
  }
129
142
  }
130
143
  task.meta.__chromatic_isRegistered = true;
131
144
  task.meta.__chromatic_isTakeSnapshotCalled = false;
132
145
  task.meta.__chromatic_autoSnapshot ??= !options.disableAutoSnapshot;
133
146
  await commands3.__chromatic_interceptFetch(task.id);
147
+ return /* @__PURE__ */ __name(async function beforeEachCleanup() {
148
+ const { __chromatic_isTakeSnapshotCalled: isTakeSnapshotCalled, __chromatic_pendingTakeSnapshots: pendingTakeSnapshots, __chromatic_isRegistered: isRegistered } = task.meta;
149
+ if (!isRegistered) {
150
+ return cleanup();
151
+ }
152
+ if (pendingTakeSnapshots?.length) {
153
+ throw new PendingSnapshotsError(pendingTakeSnapshots);
154
+ }
155
+ if (!isTakeSnapshotCalled) {
156
+ await commands3.__chromatic_stopWithoutSnapshots(task.id);
157
+ return cleanup();
158
+ }
159
+ await commands3.__chromatic_writeTestResult(task.id);
160
+ return cleanup();
161
+ }, "beforeEachCleanup");
162
+ function cleanup() {
163
+ task.meta.__chromatic_autoSnapshot = void 0;
164
+ task.meta.__chromatic_isTakeSnapshotCalled = void 0;
165
+ task.meta.__chromatic_isRegistered = void 0;
166
+ task.meta.__chromatic_pendingTakeSnapshots = void 0;
167
+ }
168
+ __name(cleanup, "cleanup");
134
169
  });
135
170
  afterEach(async ({ task }) => {
136
- const { __chromatic_autoSnapshot: autoSnapshot, __chromatic_isTakeSnapshotCalled: isTakeSnapshotCalled, __chromatic_pendingTakeSnapshots: pendingTakeSnapshots, __chromatic_isRegistered: isRegistered } = task.meta;
171
+ const { __chromatic_autoSnapshot: autoSnapshot, __chromatic_pendingTakeSnapshots: pendingTakeSnapshots, __chromatic_isRegistered: isRegistered } = task.meta;
137
172
  if (!isRegistered) {
138
- return cleanup();
173
+ return;
139
174
  }
140
175
  if (pendingTakeSnapshots?.length) {
141
- throw new AggregateError(pendingTakeSnapshots.map((call) => call.error), `${pendingTakeSnapshots.length} unawaited takeSnapshot() call(s)`);
176
+ throw new PendingSnapshotsError(pendingTakeSnapshots);
142
177
  }
143
- if (!autoSnapshot && !isTakeSnapshotCalled) {
144
- await commands3.__chromatic_stopWithoutSnapshots(task.id);
145
- return cleanup();
178
+ if (!autoSnapshot) {
179
+ return;
146
180
  }
147
181
  const options = await commands3.__chromatic_getOptions();
148
182
  if (options.resourceArchiveTimeout !== 0) {
149
183
  await waitForIdleNetwork(options.resourceArchiveTimeout);
150
184
  }
151
- if (autoSnapshot) {
152
- await takeSnapshot(void 0, {
153
- ignoreUnawaited: true
154
- });
185
+ await takeSnapshot(void 0, {
186
+ ignoreUnawaited: true
187
+ });
188
+ });
189
+ var PendingSnapshotsError = class PendingSnapshotsError2 extends AggregateError {
190
+ static {
191
+ __name(this, "PendingSnapshotsError");
155
192
  }
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;
193
+ pendingCalls;
194
+ constructor(pendingCalls) {
195
+ super(pendingCalls.map((call) => call.error), `${pendingCalls.length} unawaited takeSnapshot() call(s)`), this.pendingCalls = pendingCalls;
196
+ this.name = "PendingSnapshotsError";
163
197
  }
164
- __name(cleanup, "cleanup");
165
- });
198
+ };
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-0533fac-20260505080350",
4
4
  "description": "Chromatic Visual Regression Testing for Vitest",
5
5
  "repository": {
6
6
  "type": "git",