@chromatic-com/vitest 0.0.8 → 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,7 +4194,8 @@ 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
@@ -4191,7 +4204,9 @@ function createCommands(options) {
4191
4204
  await writeTestResult({
4192
4205
  outputDir: resolve(context.project.vitest.config.root, options.outputDirectory),
4193
4206
  pageUrl: context.page.url(),
4194
- titlePath: getNames(entity)
4207
+ titlePath: testOptions.title ? [
4208
+ testOptions.title
4209
+ ] : getTitle(entity)
4195
4210
  }, snapshotBuffers, archive, {
4196
4211
  delay: testOptions.delay ?? options.delay,
4197
4212
  diffIncludeAntiAliasing: testOptions.diffIncludeAntiAliasing ?? options.diffIncludeAntiAliasing,
@@ -4243,7 +4258,18 @@ function createCommands(options) {
4243
4258
  __name(onTestCleanup, "onTestCleanup");
4244
4259
  }
4245
4260
  __name(createCommands, "createCommands");
4246
- 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) {
4247
4273
  const names = [
4248
4274
  test.name
4249
4275
  ];
@@ -4254,16 +4280,9 @@ function getNames(test) {
4254
4280
  names.unshift(current.name);
4255
4281
  }
4256
4282
  }
4257
- if (current.type === "module") {
4258
- names.unshift(current.relativeModuleId);
4259
- }
4260
- const hasManyProjects = test.project.vitest.projects.filter((project) => project.config.browser.name === "chromium").length > 1;
4261
- if (hasManyProjects && test.project.name) {
4262
- names.unshift(test.project.name);
4263
- }
4264
4283
  return names;
4265
4284
  }
4266
- __name(getNames, "getNames");
4285
+ __name(getSnapshotPrefix, "getSnapshotPrefix");
4267
4286
 
4268
4287
  // src/constants.ts
4269
4288
  var DEFAULT_OUTPUT_DIR = ".vitest/chromatic";
package/dist/setupFile.js CHANGED
@@ -143,6 +143,7 @@ beforeEach(async ({ task }) => {
143
143
  task.meta.__chromatic_isRegistered = true;
144
144
  task.meta.__chromatic_isTakeSnapshotCalled = false;
145
145
  task.meta.__chromatic_options ||= {};
146
+ task.meta.__chromatic_options.disableAutoSnapshot ??= options.disableAutoSnapshot;
146
147
  await commands3.__chromatic_interceptFetch(task.id);
147
148
  return /* @__PURE__ */ __name(async function beforeEachCleanup() {
148
149
  const { __chromatic_isTakeSnapshotCalled: isTakeSnapshotCalled, __chromatic_pendingTakeSnapshots: pendingTakeSnapshots, __chromatic_isRegistered: isRegistered } = task.meta;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chromatic-com/vitest",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "description": "Chromatic Visual Regression Testing for Vitest",
5
5
  "repository": {
6
6
  "type": "git",