@chromatic-com/vitest 0.0.8-c85de0f-20260520085428 → 0.0.9

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.ts CHANGED
@@ -45,7 +45,10 @@ interface ChromaticConfig {
45
45
  * Options that can be set per test, suite or module via `configure()`
46
46
  * - `assetDomains` is excluded as it can only be configured globally on the plugin
47
47
  */
48
- type ConfigureOptions = Omit<ChromaticConfig, 'assetDomains'>;
48
+ type ConfigureOptions = {
49
+ /** Custom title to be shown in Chromatic. Default is derived from test file name. */
50
+ title?: string;
51
+ } & Omit<ChromaticConfig, 'assetDomains'>;
49
52
 
50
53
  /**
51
54
  * Configure options for the current scope.
package/dist/plugin.js CHANGED
@@ -3871,6 +3871,7 @@ __name(viewportToString, "viewportToString");
3871
3871
  var sanitize = /* @__PURE__ */ __name((string) => {
3872
3872
  return string.toLowerCase().replace(/[ ’–—―′¿'`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, "-").replace(/[\r\n]/g, "-").replace(/-+/g, "-").replace(/^-+/, "").replace(/-+$/, "");
3873
3873
  }, "sanitize");
3874
+ var collapseNewlines = /* @__PURE__ */ __name((title) => title.replace(/[\r\n]+/g, " ").trim(), "collapseNewlines");
3874
3875
 
3875
3876
  // ../shared/src/write-archive/snapshot-files.ts
3876
3877
  var SNAPSHOT_FILE_EXT = "snapshot.json";
@@ -3891,47 +3892,58 @@ function snapshotFileName(snapshotId2, viewport) {
3891
3892
  __name(snapshotFileName, "snapshotFileName");
3892
3893
 
3893
3894
  // ../shared/src/write-archive/stories-files.ts
3895
+ import { storyNameFromExport, toId } from "storybook/internal/csf";
3894
3896
  var STORIES_FILE_EXT = "stories.json";
3897
+ var uniqueId = {
3898
+ value: 1
3899
+ };
3895
3900
  function storiesFileName(testTitle) {
3896
3901
  const fileName = [
3897
- sanitize(testTitle),
3902
+ sanitize(testTitle) + "-" + uniqueId.value++,
3898
3903
  STORIES_FILE_EXT
3899
3904
  ].join(".");
3900
3905
  const maxByteLength = MAX_FILE_NAME_BYTE_LENGTH - 25;
3901
3906
  return truncateFileName(fileName, maxByteLength);
3902
3907
  }
3903
3908
  __name(storiesFileName, "storiesFileName");
3904
- function createStories(title, domSnapshots, chromaticStorybookParams) {
3909
+ function createStories(storyTitle, domSnapshots, chromaticStorybookParams) {
3910
+ const title = collapseNewlines(storyTitle);
3905
3911
  return {
3906
3912
  title,
3907
- stories: Object.entries(domSnapshots).map(([name, { viewport }]) => ({
3908
- name,
3909
- // Viewport addon (Storybook 10+): `parameters.viewport.options` registers sizes; `globals.viewport`
3910
- // selects the active one. See https://storybook.js.org/docs/essentials/viewport#defining-the-viewport-for-a-story
3911
- // `defaultViewport` is not read by SB 10's types but our archive preview uses it as a fetch fallback.
3912
- globals: {
3913
- viewport: viewportToString(viewport)
3914
- },
3915
- parameters: {
3916
- server: {
3917
- id: snapshotId(title, name)
3918
- },
3919
- chromatic: {
3920
- ...chromaticStorybookParams,
3921
- modes: buildStoryModesConfig([
3922
- viewport
3923
- ])
3913
+ stories: Object.entries(domSnapshots).map(([snapshotName, { viewport }]) => {
3914
+ const name = collapseNewlines(snapshotName);
3915
+ return {
3916
+ name,
3917
+ // Viewport addon (Storybook 10+): `parameters.viewport.options` registers sizes; `globals.viewport`
3918
+ // selects the active one. See https://storybook.js.org/docs/essentials/viewport#defining-the-viewport-for-a-story
3919
+ // `defaultViewport` is not read by SB 10's types but our archive preview uses it as a fetch fallback.
3920
+ globals: {
3921
+ viewport: viewportToString(viewport)
3924
3922
  },
3925
- viewport: {
3926
- options: buildStoryViewportsConfig([
3927
- viewport
3928
- ]),
3929
- defaultViewport: viewportToString(findDefaultViewport([
3930
- viewport
3931
- ]))
3923
+ parameters: {
3924
+ // Work-around for cases where "あ" in story name would cause Storybook to fail to load the story due to an invalid story ID.
3925
+ // See https://github.com/chromaui/chromatic-e2e/issues/365
3926
+ __id: toId(title, storyNameFromExport(name)),
3927
+ server: {
3928
+ id: snapshotId(title, name)
3929
+ },
3930
+ chromatic: {
3931
+ ...chromaticStorybookParams,
3932
+ modes: buildStoryModesConfig([
3933
+ viewport
3934
+ ])
3935
+ },
3936
+ viewport: {
3937
+ options: buildStoryViewportsConfig([
3938
+ viewport
3939
+ ]),
3940
+ defaultViewport: viewportToString(findDefaultViewport([
3941
+ viewport
3942
+ ]))
3943
+ }
3932
3944
  }
3933
- }
3934
- }))
3945
+ };
3946
+ })
3935
3947
  };
3936
3948
  }
3937
3949
  __name(createStories, "createStories");
@@ -4182,32 +4194,29 @@ function createCommands(options) {
4182
4194
  assert(sessionSnapshots, `No snapshots found for test ${id}`);
4183
4195
  const snapshotBuffers = {};
4184
4196
  for (const [name, { snapshot, viewport, pseudoClassIds }] of sessionSnapshots) {
4185
- snapshotBuffers[name] = {
4197
+ const names = getSnapshotPrefix(entity).concat(name).join(" / ");
4198
+ snapshotBuffers[names] = {
4186
4199
  snapshot: Buffer.from(JSON.stringify(snapshot)),
4187
4200
  viewport,
4188
4201
  pseudoClassIds
4189
4202
  };
4190
4203
  }
4191
- await writeTestResult(
4192
- {
4193
- outputDir: resolve(context.project.vitest.config.root, options.outputDirectory),
4194
- pageUrl: context.page.url(),
4195
- titlePath: getNames(entity)
4196
- },
4197
- snapshotBuffers,
4198
- archive,
4199
- // Remove undefined options with stringify/parse
4200
- JSON.parse(JSON.stringify({
4201
- delay: testOptions.delay ?? options.delay,
4202
- diffIncludeAntiAliasing: testOptions.diffIncludeAntiAliasing ?? options.diffIncludeAntiAliasing,
4203
- diffThreshold: testOptions.diffThreshold ?? options.diffThreshold,
4204
- forcedColors: testOptions.forcedColors ?? options.forcedColors,
4205
- pauseAnimationAtEnd: testOptions.pauseAnimationAtEnd ?? options.pauseAnimationAtEnd,
4206
- prefersReducedMotion: testOptions.prefersReducedMotion ?? options.prefersReducedMotion,
4207
- cropToViewport: testOptions.cropToViewport ?? options.cropToViewport,
4208
- ignoreSelectors: testOptions.ignoreSelectors ?? options.ignoreSelectors
4209
- }))
4210
- );
4204
+ await writeTestResult({
4205
+ outputDir: resolve(context.project.vitest.config.root, options.outputDirectory),
4206
+ pageUrl: context.page.url(),
4207
+ titlePath: testOptions.title ? [
4208
+ testOptions.title
4209
+ ] : getTitle(entity)
4210
+ }, snapshotBuffers, archive, {
4211
+ delay: testOptions.delay ?? options.delay,
4212
+ diffIncludeAntiAliasing: testOptions.diffIncludeAntiAliasing ?? options.diffIncludeAntiAliasing,
4213
+ diffThreshold: testOptions.diffThreshold ?? options.diffThreshold,
4214
+ forcedColors: testOptions.forcedColors ?? options.forcedColors,
4215
+ pauseAnimationAtEnd: testOptions.pauseAnimationAtEnd ?? options.pauseAnimationAtEnd,
4216
+ prefersReducedMotion: testOptions.prefersReducedMotion ?? options.prefersReducedMotion,
4217
+ cropToViewport: testOptions.cropToViewport ?? options.cropToViewport,
4218
+ ignoreSelectors: testOptions.ignoreSelectors ?? options.ignoreSelectors
4219
+ });
4211
4220
  },
4212
4221
  /**
4213
4222
  * Clear test state without writing test results.
@@ -4249,7 +4258,18 @@ function createCommands(options) {
4249
4258
  __name(onTestCleanup, "onTestCleanup");
4250
4259
  }
4251
4260
  __name(createCommands, "createCommands");
4252
- function getNames(test) {
4261
+ function getTitle(test) {
4262
+ const names = [
4263
+ test.module.relativeModuleId
4264
+ ];
4265
+ const hasManyProjects = test.project.vitest.projects.filter((project) => project.config.browser.name === "chromium").length > 1;
4266
+ if (hasManyProjects && test.project.name) {
4267
+ names.unshift(test.project.name);
4268
+ }
4269
+ return names;
4270
+ }
4271
+ __name(getTitle, "getTitle");
4272
+ function getSnapshotPrefix(test) {
4253
4273
  const names = [
4254
4274
  test.name
4255
4275
  ];
@@ -4260,16 +4280,9 @@ function getNames(test) {
4260
4280
  names.unshift(current.name);
4261
4281
  }
4262
4282
  }
4263
- if (current.type === "module") {
4264
- names.unshift(current.relativeModuleId);
4265
- }
4266
- const hasManyProjects = test.project.vitest.projects.filter((project) => project.config.browser.name === "chromium").length > 1;
4267
- if (hasManyProjects && test.project.name) {
4268
- names.unshift(test.project.name);
4269
- }
4270
4283
  return names;
4271
4284
  }
4272
- __name(getNames, "getNames");
4285
+ __name(getSnapshotPrefix, "getSnapshotPrefix");
4273
4286
 
4274
4287
  // src/constants.ts
4275
4288
  var DEFAULT_OUTPUT_DIR = ".vitest/chromatic";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chromatic-com/vitest",
3
- "version": "0.0.8-c85de0f-20260520085428",
3
+ "version": "0.0.9",
4
4
  "description": "Chromatic Visual Regression Testing for Vitest",
5
5
  "repository": {
6
6
  "type": "git",