@chromatic-com/vitest 0.0.10 → 0.1.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.
Files changed (2) hide show
  1. package/dist/plugin.js +46 -6
  2. package/package.json +1 -1
package/dist/plugin.js CHANGED
@@ -3799,8 +3799,7 @@ var DOMSnapshot = class {
3799
3799
  const currentSrc = this.mapSrcsetUrls(srcsetValue, sourceMap);
3800
3800
  if (currentSrc) {
3801
3801
  node.attributes.src = currentSrc;
3802
- delete node.attributes.srcset;
3803
- delete node.attributes.sizes;
3802
+ this.removeResponsiveImageAttributes(node.attributes);
3804
3803
  }
3805
3804
  }
3806
3805
  if (node.tagName === "picture") {
@@ -3825,6 +3824,7 @@ var DOMSnapshot = class {
3825
3824
  const imageElement = node.childNodes.find((childNode) => childNode.type === NodeType.Element && childNode.tagName === "img");
3826
3825
  if (imageElement && imageElement.attributes) {
3827
3826
  imageElement.attributes.src = sourceMap.get(matchingUrl);
3827
+ this.removeResponsiveImageAttributes(imageElement.attributes);
3828
3828
  }
3829
3829
  }
3830
3830
  }
@@ -3859,6 +3859,10 @@ var DOMSnapshot = class {
3859
3859
  });
3860
3860
  return currentSrc;
3861
3861
  }
3862
+ removeResponsiveImageAttributes(attributes) {
3863
+ delete attributes.srcset;
3864
+ delete attributes.sizes;
3865
+ }
3862
3866
  };
3863
3867
 
3864
3868
  // ../shared/src/utils/viewport.ts
@@ -3910,8 +3914,9 @@ function createStories(storyTitle, domSnapshots, chromaticStorybookParams) {
3910
3914
  const title = collapseNewlines(storyTitle);
3911
3915
  return {
3912
3916
  title,
3913
- stories: Object.entries(domSnapshots).map(([snapshotName, { viewport }]) => {
3917
+ stories: Object.entries(domSnapshots).map(([snapshotName, { viewport, parameters }]) => {
3914
3918
  const name = collapseNewlines(snapshotName);
3919
+ const { chromatic: chromaticParams, ...restParameters } = parameters || {};
3915
3920
  return {
3916
3921
  name,
3917
3922
  // Viewport addon (Storybook 10+): `parameters.viewport.options` registers sizes; `globals.viewport`
@@ -3929,6 +3934,7 @@ function createStories(storyTitle, domSnapshots, chromaticStorybookParams) {
3929
3934
  },
3930
3935
  chromatic: {
3931
3936
  ...chromaticStorybookParams,
3937
+ ...chromaticParams,
3932
3938
  modes: buildStoryModesConfig([
3933
3939
  viewport
3934
3940
  ])
@@ -3940,7 +3946,8 @@ function createStories(storyTitle, domSnapshots, chromaticStorybookParams) {
3940
3946
  defaultViewport: viewportToString(findDefaultViewport([
3941
3947
  viewport
3942
3948
  ]))
3943
- }
3949
+ },
3950
+ ...restParameters
3944
3951
  }
3945
3952
  };
3946
3953
  })
@@ -4323,7 +4330,16 @@ function createCommands(options) {
4323
4330
  snapshotBuffers[names] = {
4324
4331
  snapshot: Buffer.from(JSON.stringify(snapshot)),
4325
4332
  viewport,
4326
- pseudoClassIds
4333
+ pseudoClassIds,
4334
+ parameters: {
4335
+ chromatic: {
4336
+ vitest: {
4337
+ suites: getSuiteNames(entity),
4338
+ test: entity.name,
4339
+ snapshot: name
4340
+ }
4341
+ }
4342
+ }
4327
4343
  };
4328
4344
  }
4329
4345
  await writeTestResult({
@@ -4385,7 +4401,7 @@ function createCommands(options) {
4385
4401
  __name(createCommands, "createCommands");
4386
4402
  function getTitle(test) {
4387
4403
  const names = [
4388
- test.module.relativeModuleId
4404
+ removeFileExtensions(test.module.relativeModuleId)
4389
4405
  ];
4390
4406
  const hasManyProjects = test.project.vitest.projects.filter((project) => project.config.browser.name === "chromium").length > 1;
4391
4407
  if (hasManyProjects && test.project.name) {
@@ -4408,6 +4424,30 @@ function getSnapshotPrefix(test) {
4408
4424
  return names;
4409
4425
  }
4410
4426
  __name(getSnapshotPrefix, "getSnapshotPrefix");
4427
+ function getSuiteNames(test) {
4428
+ if (test.parent.type !== "suite") {
4429
+ return [];
4430
+ }
4431
+ const names = [];
4432
+ let current = test;
4433
+ while ("parent" in current && current.parent) {
4434
+ current = current.parent;
4435
+ if (current.type === "suite") {
4436
+ names.unshift(current.name);
4437
+ }
4438
+ }
4439
+ return names;
4440
+ }
4441
+ __name(getSuiteNames, "getSuiteNames");
4442
+ function removeFileExtensions(filepath) {
4443
+ const parts = filepath.split("/");
4444
+ const filename = parts.pop() || "";
4445
+ return parts.concat(
4446
+ // Trim filenames like "src/components/accordion/Accordion.browser.spec.tsx" -> "src/components/accordion/Accordion"
4447
+ filename.split(".")[0]
4448
+ ).join("/");
4449
+ }
4450
+ __name(removeFileExtensions, "removeFileExtensions");
4411
4451
 
4412
4452
  // src/node/plugin.ts
4413
4453
  var DEFAULT_TAG_DESCRIPTION = "Visual Regression Tests for `@chromatic-com/vitest`";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chromatic-com/vitest",
3
- "version": "0.0.10",
3
+ "version": "0.1.0",
4
4
  "description": "Chromatic Visual Regression Testing for Vitest",
5
5
  "repository": {
6
6
  "type": "git",