@argos-ci/vitest 0.4.7 → 0.5.0

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.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import "@argos-ci/core";
2
1
  import { ScreenshotMetadata } from "@argos-ci/util";
2
+ import "@argos-ci/core";
3
3
  import { ArgosAttachment } from "@argos-ci/playwright";
4
4
  import { StabilizationPluginOptions, ViewportOption } from "@argos-ci/browser";
5
5
  //#region src/metadata.d.ts
@@ -142,8 +142,8 @@ type SerializableSnapshotOptions = Omit<VitestSnapshotOptions, "serialize" | "na
142
142
  //#region src/index.d.ts
143
143
  declare module "vitest/browser" {
144
144
  interface BrowserCommands {
145
- argosScreenshot: (name: string, options?: VitestScreenshotOptions, test?: TestMetadata) => Promise<ArgosAttachment[]>;
146
- argosSnapshot: (name: string, content: string, options?: SerializableSnapshotOptions, test?: TestMetadata) => Promise<ArgosAttachment[]>;
145
+ argosScreenshot: (name: string, options?: VitestScreenshotOptions, test?: TestMetadata, captureIndex?: number | null) => Promise<ArgosAttachment[]>;
146
+ argosSnapshot: (name: string, content: string, options?: SerializableSnapshotOptions, test?: TestMetadata, captureIndex?: number | null) => Promise<ArgosAttachment[]>;
147
147
  }
148
148
  }
149
149
  /**
package/dist/index.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import { getTestRunKey, nextCaptureIndex } from "@argos-ci/util";
1
2
  //#region src/test-context.ts
2
3
  /**
3
4
  * Get the current Vitest test task, or `undefined` when not inside a test.
@@ -137,6 +138,23 @@ async function getTestMetadata() {
137
138
  if (!task) return null;
138
139
  return buildTestMetadata(task);
139
140
  }
141
+ /**
142
+ * Take the next capture index for the current Vitest test, or `null` outside a
143
+ * test. Screenshots and snapshots share the counter, so a test that mixes both
144
+ * still numbers them in the order it produced them.
145
+ *
146
+ * Runs on the test side, where the test context is available; the number then
147
+ * crosses the RPC boundary to the Node command.
148
+ */
149
+ async function takeCaptureIndex() {
150
+ const task = await getCurrentTest();
151
+ if (!task) return null;
152
+ return nextCaptureIndex(getTestRunKey({
153
+ id: task.id,
154
+ retry: task.result?.retryCount ?? void 0,
155
+ repeat: task.result?.repeatCount ?? void 0
156
+ }));
157
+ }
140
158
  //#endregion
141
159
  //#region ../../node_modules/.pnpm/tinyrainbow@3.1.1/node_modules/tinyrainbow/dist/index.js
142
160
  var b = {
@@ -1142,9 +1160,13 @@ async function argosScreenshot(nameOrOptions, maybeOptions) {
1142
1160
  const name = typeof nameOrOptions === "string" ? nameOrOptions : void 0;
1143
1161
  const options = typeof nameOrOptions === "string" ? maybeOptions : nameOrOptions;
1144
1162
  if (!await checkIsVitestEnv()) return [];
1145
- const [resolvedName, test] = await Promise.all([resolveAutoName(name, { reservedLength: SCREENSHOT_NAME_RESERVED }), getTestMetadata()]);
1163
+ const [resolvedName, test, captureIndex] = await Promise.all([
1164
+ resolveAutoName(name, { reservedLength: SCREENSHOT_NAME_RESERVED }),
1165
+ getTestMetadata(),
1166
+ takeCaptureIndex()
1167
+ ]);
1146
1168
  const { server } = await import("vitest/browser");
1147
- return server.commands.argosScreenshot(resolvedName, options ?? {}, test);
1169
+ return server.commands.argosScreenshot(resolvedName, options ?? {}, test, captureIndex);
1148
1170
  }
1149
1171
  /**
1150
1172
  * Take an Argos snapshot of any serializable value, mimicking
@@ -1181,15 +1203,19 @@ async function argosSnapshot(content, options = {}) {
1181
1203
  if (!await checkIsVitestEnv()) return [];
1182
1204
  const rawExtension = options.extension ?? ".txt";
1183
1205
  const extension = rawExtension.startsWith(".") ? rawExtension : `.${rawExtension}`;
1184
- const [resolvedName, test] = await Promise.all([resolveAutoName(options.name, { reservedLength: 9 + extension.length + 11 }), getTestMetadata()]);
1206
+ const [resolvedName, test, captureIndex] = await Promise.all([
1207
+ resolveAutoName(options.name, { reservedLength: 9 + extension.length + 11 }),
1208
+ getTestMetadata(),
1209
+ takeCaptureIndex()
1210
+ ]);
1185
1211
  const serialized = serializeSnapshot(content, options);
1186
1212
  const { serialize: _serialize, name: _name, ...serializableOptions } = options;
1187
1213
  if (checkIsBrowserEnv()) {
1188
1214
  const { server } = await import("vitest/browser");
1189
- return server.commands.argosSnapshot(resolvedName, serialized, serializableOptions, test);
1215
+ return server.commands.argosSnapshot(resolvedName, serialized, serializableOptions, test, captureIndex);
1190
1216
  }
1191
- const { writeSnapshotFile } = await import("./snapshot-file-D8dL3z_T.mjs");
1192
- return writeSnapshotFile(resolvedName, serialized, serializableOptions, test);
1217
+ const { writeSnapshotFile } = await import("./snapshot-file-CZE4r9Wl.mjs");
1218
+ return writeSnapshotFile(resolvedName, serialized, serializableOptions, test, captureIndex);
1193
1219
  }
1194
1220
  /**
1195
1221
  * Check if we are running in a Vitest environment.
package/dist/plugin.d.mts CHANGED
@@ -174,7 +174,7 @@ type TestMetadata = ScreenshotMetadata["test"];
174
174
  * Arguments of the `argosScreenshot` browser command.
175
175
  * Only serializable values cross the browser/node RPC boundary.
176
176
  */
177
- type ArgosScreenshotCommandArgs = [name: string, options?: VitestScreenshotOptions, test?: TestMetadata];
177
+ type ArgosScreenshotCommandArgs = [name: string, options?: VitestScreenshotOptions, test?: TestMetadata, captureIndex?: number | null];
178
178
  /**
179
179
  * Create the `argosScreenshot` browser command used to capture Argos
180
180
  * screenshots from Vitest browser tests.
@@ -191,7 +191,7 @@ declare const createArgosScreenshotCommand: (pluginOptions?: ArgosVitestPluginOp
191
191
  * Only serializable values cross the browser/node RPC boundary — the value is
192
192
  * already serialized to a string on the browser side.
193
193
  */
194
- type ArgosSnapshotCommandArgs = [name: string, content: string, options?: SerializableSnapshotOptions, test?: TestMetadata];
194
+ type ArgosSnapshotCommandArgs = [name: string, content: string, options?: SerializableSnapshotOptions, test?: TestMetadata, captureIndex?: number | null];
195
195
  /**
196
196
  * Create the `argosSnapshot` browser command used to write serialized snapshots
197
197
  * from Vitest browser tests. The serialized string is produced on the browser
package/dist/plugin.mjs CHANGED
@@ -188,7 +188,7 @@ async function getVitestVersion() {
188
188
  * and are merged with the serializable per-call options (per-call wins).
189
189
  */
190
190
  const createArgosScreenshotCommand = (pluginOptions = {}) => {
191
- return async (ctx, name, options, test) => {
191
+ return async (ctx, name, options, test, captureIndex) => {
192
192
  if (!name) throw new Error("The `name` argument is required.");
193
193
  const merged = {
194
194
  ...pluginOptions,
@@ -208,7 +208,8 @@ const createArgosScreenshotCommand = (pluginOptions = {}) => {
208
208
  },
209
209
  playwrightLibraries: ["vitest"],
210
210
  viewport,
211
- test
211
+ test,
212
+ captureIndex
212
213
  });
213
214
  };
214
215
  const attachments = [];
@@ -276,7 +277,7 @@ function normalizeExtension(extension) {
276
277
  * This is the shared Node-side primitive used by both the browser command (which
277
278
  * receives the already-serialized string over RPC) and the Node code path.
278
279
  */
279
- async function writeSnapshotFile(name, content, options = {}, test) {
280
+ async function writeSnapshotFile(name, content, options = {}, test, captureIndex) {
280
281
  if (!name) throw new Error("The `name` argument is required.");
281
282
  const root = options.root ?? "./snapshots";
282
283
  const extension = normalizeExtension(options.extension ?? DEFAULT_EXTENSION);
@@ -298,7 +299,8 @@ async function writeSnapshotFile(name, content, options = {}, test) {
298
299
  version: sdkVersion
299
300
  },
300
301
  ...tags ? { tags } : {},
301
- ...resolvedTest ? { test: resolvedTest } : {}
302
+ ...resolvedTest ? { test: resolvedTest } : {},
303
+ ...captureIndex != null ? { capture: { index: captureIndex } } : {}
302
304
  };
303
305
  await createDirectory(dirname(snapshotPath));
304
306
  await Promise.all([writeFile(snapshotPath, content, "utf-8"), writeMetadata(snapshotPath, metadata)]);
@@ -320,12 +322,12 @@ async function writeSnapshotFile(name, content, options = {}, test) {
320
322
  * side and this command writes it (and its metadata) to disk on the Node side.
321
323
  */
322
324
  const createArgosSnapshotCommand = (pluginOptions = {}) => {
323
- return async (_ctx, name, content, options, test) => {
325
+ return async (_ctx, name, content, options, test, captureIndex) => {
324
326
  if (!name) throw new Error("The `name` argument is required.");
325
327
  return writeSnapshotFile(name, content, {
326
328
  root: pluginOptions.root,
327
329
  ...options
328
- }, test);
330
+ }, test, captureIndex);
329
331
  };
330
332
  };
331
333
  //#endregion
@@ -1,8 +1,8 @@
1
1
  import { createRequire } from "node:module";
2
+ import { createDirectory, getGitRepositoryPath, getMetadataPath, getScreenshotName, readVersionFromPackage, writeMetadata } from "@argos-ci/util";
2
3
  import { writeFile } from "node:fs/promises";
3
4
  import { dirname, relative, resolve } from "node:path";
4
5
  import { getSnapshotMimeType } from "@argos-ci/core";
5
- import { createDirectory, getGitRepositoryPath, getMetadataPath, getScreenshotName, readVersionFromPackage, writeMetadata } from "@argos-ci/util";
6
6
  //#region src/version.ts
7
7
  const require = createRequire(import.meta.url);
8
8
  /**
@@ -60,7 +60,7 @@ function normalizeExtension(extension) {
60
60
  * This is the shared Node-side primitive used by both the browser command (which
61
61
  * receives the already-serialized string over RPC) and the Node code path.
62
62
  */
63
- async function writeSnapshotFile(name, content, options = {}, test) {
63
+ async function writeSnapshotFile(name, content, options = {}, test, captureIndex) {
64
64
  if (!name) throw new Error("The `name` argument is required.");
65
65
  const root = options.root ?? "./snapshots";
66
66
  const extension = normalizeExtension(options.extension ?? DEFAULT_EXTENSION);
@@ -82,7 +82,8 @@ async function writeSnapshotFile(name, content, options = {}, test) {
82
82
  version: sdkVersion
83
83
  },
84
84
  ...tags ? { tags } : {},
85
- ...resolvedTest ? { test: resolvedTest } : {}
85
+ ...resolvedTest ? { test: resolvedTest } : {},
86
+ ...captureIndex != null ? { capture: { index: captureIndex } } : {}
86
87
  };
87
88
  await createDirectory(dirname(snapshotPath));
88
89
  await Promise.all([writeFile(snapshotPath, content, "utf-8"), writeMetadata(snapshotPath, metadata)]);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@argos-ci/vitest",
3
3
  "description": "Vitest SDK for visual testing with Argos.",
4
- "version": "0.4.7",
4
+ "version": "0.5.0",
5
5
  "author": "Smooth Code",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -52,9 +52,9 @@
52
52
  },
53
53
  "dependencies": {
54
54
  "@argos-ci/browser": "6.4.5",
55
- "@argos-ci/core": "6.8.2",
56
- "@argos-ci/playwright": "7.4.7",
57
- "@argos-ci/util": "4.1.0"
55
+ "@argos-ci/core": "6.8.3",
56
+ "@argos-ci/playwright": "7.5.0",
57
+ "@argos-ci/util": "4.2.0"
58
58
  },
59
59
  "peerDependencies": {
60
60
  "@vitest/browser": ">=4",
@@ -81,5 +81,5 @@
81
81
  "check-format": "prettier --check --ignore-unknown --ignore-path=./.gitignore --ignore-path=../../.gitignore --ignore-path=../../.prettierignore .",
82
82
  "lint": "eslint ."
83
83
  },
84
- "gitHead": "30a374b2c0f2b67b7a90fd4d22e395b70c191e0c"
84
+ "gitHead": "b2a9a9d84dc14e148a68295f56cfdfec03f887f1"
85
85
  }