@chromatic-com/cypress 0.12.6 → 0.12.8

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
@@ -3394,7 +3394,7 @@ var logger = process.env.LOG ? console : {
3394
3394
 
3395
3395
  // ../shared/src/resource-archiver/index.ts
3396
3396
  var _ResourceArchiver = class _ResourceArchiver {
3397
- constructor(cdpClient, allowedDomains, httpCredentials) {
3397
+ constructor(cdpClient, allowedDomains, httpCredentials, firstUrl) {
3398
3398
  __publicField(this, "archive", {});
3399
3399
  __publicField(this, "client");
3400
3400
  /**
@@ -3468,6 +3468,7 @@ var _ResourceArchiver = class _ResourceArchiver {
3468
3468
  }, "requestPaused"));
3469
3469
  this.client = cdpClient;
3470
3470
  this.httpCredentials = httpCredentials;
3471
+ this.firstUrl = firstUrl;
3471
3472
  this.assetDomains = (allowedDomains || []).map((domain) => {
3472
3473
  if (domain.startsWith("http")) {
3473
3474
  return domain;
@@ -3527,12 +3528,25 @@ var _ResourceArchiver = class _ResourceArchiver {
3527
3528
  const contentTypeHeader = responseHeaders.find(({ name }) => name.toLowerCase() === "content-type");
3528
3529
  const isFirstRequest = requestUrl.toString() === this.firstUrl.toString();
3529
3530
  if (isRequestFromAllowedDomain && !isFirstRequest) {
3531
+ logger.log("Archiving request", {
3532
+ url: request.url,
3533
+ statusCode: responseStatusCode,
3534
+ statusText: responseStatusText,
3535
+ contentType: contentTypeHeader?.value
3536
+ });
3530
3537
  this.archive[request.url] = {
3531
3538
  statusCode: responseStatusCode,
3532
3539
  statusText: responseStatusText,
3533
3540
  body: Buffer.from(body, base64Encoded ? "base64" : "utf8"),
3534
3541
  contentType: contentTypeHeader?.value
3535
3542
  };
3543
+ } else {
3544
+ logger.log("Skipping archiving of request", {
3545
+ url: request.url,
3546
+ firstUrl: this.firstUrl.toString(),
3547
+ isFirstRequest,
3548
+ isRequestFromAllowedDomain
3549
+ });
3536
3550
  }
3537
3551
  await this.clientSend(request, "Fetch.continueRequest", {
3538
3552
  requestId
@@ -3656,6 +3670,10 @@ var _ArchiveFile = class _ArchiveFile {
3656
3670
  if (!queryString)
3657
3671
  return pathname;
3658
3672
  const safeQueryString = this.hash(queryString);
3673
+ const extension = path2__default.default.extname(pathname);
3674
+ if (extension) {
3675
+ return `${pathname.substring(0, pathname.length - extension.length)}-${safeQueryString}${extension}`;
3676
+ }
3659
3677
  return `${pathname}-${safeQueryString}`;
3660
3678
  }
3661
3679
  truncateFileName(pathname) {
@@ -3795,8 +3813,7 @@ var _DOMSnapshot = class _DOMSnapshot {
3795
3813
  const currentSrc = this.mapSrcsetUrls(srcsetValue, sourceMap);
3796
3814
  if (currentSrc) {
3797
3815
  node.attributes.src = currentSrc;
3798
- delete node.attributes.srcset;
3799
- delete node.attributes.sizes;
3816
+ this.removeResponsiveImageAttributes(node.attributes);
3800
3817
  }
3801
3818
  }
3802
3819
  if (node.tagName === "picture") {
@@ -3821,6 +3838,7 @@ var _DOMSnapshot = class _DOMSnapshot {
3821
3838
  const imageElement = node.childNodes.find((childNode) => childNode.type === NodeType.Element && childNode.tagName === "img");
3822
3839
  if (imageElement && imageElement.attributes) {
3823
3840
  imageElement.attributes.src = sourceMap.get(matchingUrl);
3841
+ this.removeResponsiveImageAttributes(imageElement.attributes);
3824
3842
  }
3825
3843
  }
3826
3844
  }
@@ -3855,6 +3873,10 @@ var _DOMSnapshot = class _DOMSnapshot {
3855
3873
  });
3856
3874
  return currentSrc;
3857
3875
  }
3876
+ removeResponsiveImageAttributes(attributes) {
3877
+ delete attributes.srcset;
3878
+ delete attributes.sizes;
3879
+ }
3858
3880
  };
3859
3881
  __name(_DOMSnapshot, "DOMSnapshot");
3860
3882
  var DOMSnapshot = _DOMSnapshot;
@@ -3892,9 +3914,13 @@ var STORIES_FILE_EXT = "stories.json";
3892
3914
  var uniqueId = {
3893
3915
  value: 1
3894
3916
  };
3895
- function storiesFileName(testTitle) {
3917
+ function storiesFileName(testTitle, overwriteDuplicateNames = true) {
3918
+ let title = sanitize(testTitle);
3919
+ if (!overwriteDuplicateNames) {
3920
+ title += "-" + uniqueId.value++;
3921
+ }
3896
3922
  const fileName = [
3897
- sanitize(testTitle) + "-" + uniqueId.value++,
3923
+ title,
3898
3924
  STORIES_FILE_EXT
3899
3925
  ].join(".");
3900
3926
  const maxByteLength = MAX_FILE_NAME_BYTE_LENGTH - 25;
@@ -3905,8 +3931,9 @@ function createStories(storyTitle, domSnapshots, chromaticStorybookParams) {
3905
3931
  const title = collapseNewlines(storyTitle);
3906
3932
  return {
3907
3933
  title,
3908
- stories: Object.entries(domSnapshots).map(([snapshotName, { viewport }]) => {
3934
+ stories: Object.entries(domSnapshots).map(([snapshotName, { viewport, parameters }]) => {
3909
3935
  const name = collapseNewlines(snapshotName);
3936
+ const { chromatic: chromaticParams, ...restParameters } = parameters || {};
3910
3937
  return {
3911
3938
  name,
3912
3939
  // Viewport addon (Storybook 10+): `parameters.viewport.options` registers sizes; `globals.viewport`
@@ -3924,6 +3951,7 @@ function createStories(storyTitle, domSnapshots, chromaticStorybookParams) {
3924
3951
  },
3925
3952
  chromatic: {
3926
3953
  ...chromaticStorybookParams,
3954
+ ...chromaticParams,
3927
3955
  modes: buildStoryModesConfig([
3928
3956
  viewport
3929
3957
  ])
@@ -3935,7 +3963,8 @@ function createStories(storyTitle, domSnapshots, chromaticStorybookParams) {
3935
3963
  defaultViewport: viewportToString(findDefaultViewport([
3936
3964
  viewport
3937
3965
  ]))
3938
- }
3966
+ },
3967
+ ...restParameters
3939
3968
  }
3940
3969
  };
3941
3970
  })
@@ -3992,7 +4021,7 @@ function findDefaultViewport(viewports) {
3992
4021
  __name(findDefaultViewport, "findDefaultViewport");
3993
4022
 
3994
4023
  // ../shared/src/write-archive/index.ts
3995
- async function writeTestResult(e2eTestInfo, domSnapshots, archive, chromaticStorybookParams) {
4024
+ async function writeTestResult(e2eTestInfo, domSnapshots, archive, chromaticStorybookParams, testRunner) {
3996
4025
  const { titlePath, outputDir, pageUrl } = e2eTestInfo;
3997
4026
  const titlePathWithoutFileExtensions = titlePath.map((pathPart) => (
3998
4027
  // make sure we remove file extensions, even if the file name doesn't have .spec or .test or.cy
@@ -4013,10 +4042,13 @@ async function writeTestResult(e2eTestInfo, domSnapshots, archive, chromaticStor
4013
4042
  const archiveFile = new ArchiveFile(url, response, pageUrl);
4014
4043
  const origSrcPath = archiveFile.originalSrc();
4015
4044
  const fileSystemPath = archiveFile.toFileSystemPath();
4045
+ const responsePath = path2.join(archiveDir, fileSystemPath);
4016
4046
  if (origSrcPath !== fileSystemPath) {
4017
4047
  sourceMap.set(origSrcPath, fileSystemPath);
4018
4048
  }
4019
- await outputFile(path2.join(archiveDir, fileSystemPath), response.body);
4049
+ if (!fs.existsSync(responsePath)) {
4050
+ await outputFile(responsePath, response.body);
4051
+ }
4020
4052
  }));
4021
4053
  await Promise.all(Object.entries(domSnapshots).map(async ([name, domSnapshot]) => {
4022
4054
  const snapshot = new DOMSnapshot(domSnapshot);
@@ -4024,7 +4056,7 @@ async function writeTestResult(e2eTestInfo, domSnapshots, archive, chromaticStor
4024
4056
  const snapshotFile = snapshotFileName(snapshotId(title, name), domSnapshot.viewport);
4025
4057
  await outputFile(path2.join(archiveDir, snapshotFile), mappedSnapshot);
4026
4058
  }));
4027
- const storiesFile = storiesFileName(title);
4059
+ const storiesFile = storiesFileName(title, testRunner !== "vitest");
4028
4060
  const storiesJson = createStories(title, domSnapshots, chromaticStorybookParams);
4029
4061
  await outputJSONFile(path2.join(finalOutputDir, storiesFile), storiesJson);
4030
4062
  const errors = Object.entries(archive).filter(([, r]) => "error" in r);
@@ -4057,7 +4089,7 @@ var writeArchives = /* @__PURE__ */ __name(async ({ testTitlePath, domSnapshots,
4057
4089
  titlePath: testTitlePath,
4058
4090
  outputDir,
4059
4091
  pageUrl
4060
- }, allSnapshots, resourceArchive, chromaticStorybookParams);
4092
+ }, allSnapshots, resourceArchive, chromaticStorybookParams, "cypress");
4061
4093
  }, "writeArchives");
4062
4094
  var resourceArchiver = null;
4063
4095
  var host = "";
package/dist/index.mjs CHANGED
@@ -3387,7 +3387,7 @@ var logger = process.env.LOG ? console : {
3387
3387
 
3388
3388
  // ../shared/src/resource-archiver/index.ts
3389
3389
  var _ResourceArchiver = class _ResourceArchiver {
3390
- constructor(cdpClient, allowedDomains, httpCredentials) {
3390
+ constructor(cdpClient, allowedDomains, httpCredentials, firstUrl) {
3391
3391
  __publicField(this, "archive", {});
3392
3392
  __publicField(this, "client");
3393
3393
  /**
@@ -3461,6 +3461,7 @@ var _ResourceArchiver = class _ResourceArchiver {
3461
3461
  }, "requestPaused"));
3462
3462
  this.client = cdpClient;
3463
3463
  this.httpCredentials = httpCredentials;
3464
+ this.firstUrl = firstUrl;
3464
3465
  this.assetDomains = (allowedDomains || []).map((domain) => {
3465
3466
  if (domain.startsWith("http")) {
3466
3467
  return domain;
@@ -3520,12 +3521,25 @@ var _ResourceArchiver = class _ResourceArchiver {
3520
3521
  const contentTypeHeader = responseHeaders.find(({ name }) => name.toLowerCase() === "content-type");
3521
3522
  const isFirstRequest = requestUrl.toString() === this.firstUrl.toString();
3522
3523
  if (isRequestFromAllowedDomain && !isFirstRequest) {
3524
+ logger.log("Archiving request", {
3525
+ url: request.url,
3526
+ statusCode: responseStatusCode,
3527
+ statusText: responseStatusText,
3528
+ contentType: contentTypeHeader?.value
3529
+ });
3523
3530
  this.archive[request.url] = {
3524
3531
  statusCode: responseStatusCode,
3525
3532
  statusText: responseStatusText,
3526
3533
  body: Buffer.from(body, base64Encoded ? "base64" : "utf8"),
3527
3534
  contentType: contentTypeHeader?.value
3528
3535
  };
3536
+ } else {
3537
+ logger.log("Skipping archiving of request", {
3538
+ url: request.url,
3539
+ firstUrl: this.firstUrl.toString(),
3540
+ isFirstRequest,
3541
+ isRequestFromAllowedDomain
3542
+ });
3529
3543
  }
3530
3544
  await this.clientSend(request, "Fetch.continueRequest", {
3531
3545
  requestId
@@ -3649,6 +3663,10 @@ var _ArchiveFile = class _ArchiveFile {
3649
3663
  if (!queryString)
3650
3664
  return pathname;
3651
3665
  const safeQueryString = this.hash(queryString);
3666
+ const extension = path2.extname(pathname);
3667
+ if (extension) {
3668
+ return `${pathname.substring(0, pathname.length - extension.length)}-${safeQueryString}${extension}`;
3669
+ }
3652
3670
  return `${pathname}-${safeQueryString}`;
3653
3671
  }
3654
3672
  truncateFileName(pathname) {
@@ -3788,8 +3806,7 @@ var _DOMSnapshot = class _DOMSnapshot {
3788
3806
  const currentSrc = this.mapSrcsetUrls(srcsetValue, sourceMap);
3789
3807
  if (currentSrc) {
3790
3808
  node.attributes.src = currentSrc;
3791
- delete node.attributes.srcset;
3792
- delete node.attributes.sizes;
3809
+ this.removeResponsiveImageAttributes(node.attributes);
3793
3810
  }
3794
3811
  }
3795
3812
  if (node.tagName === "picture") {
@@ -3814,6 +3831,7 @@ var _DOMSnapshot = class _DOMSnapshot {
3814
3831
  const imageElement = node.childNodes.find((childNode) => childNode.type === NodeType.Element && childNode.tagName === "img");
3815
3832
  if (imageElement && imageElement.attributes) {
3816
3833
  imageElement.attributes.src = sourceMap.get(matchingUrl);
3834
+ this.removeResponsiveImageAttributes(imageElement.attributes);
3817
3835
  }
3818
3836
  }
3819
3837
  }
@@ -3848,6 +3866,10 @@ var _DOMSnapshot = class _DOMSnapshot {
3848
3866
  });
3849
3867
  return currentSrc;
3850
3868
  }
3869
+ removeResponsiveImageAttributes(attributes) {
3870
+ delete attributes.srcset;
3871
+ delete attributes.sizes;
3872
+ }
3851
3873
  };
3852
3874
  __name(_DOMSnapshot, "DOMSnapshot");
3853
3875
  var DOMSnapshot = _DOMSnapshot;
@@ -3885,9 +3907,13 @@ var STORIES_FILE_EXT = "stories.json";
3885
3907
  var uniqueId = {
3886
3908
  value: 1
3887
3909
  };
3888
- function storiesFileName(testTitle) {
3910
+ function storiesFileName(testTitle, overwriteDuplicateNames = true) {
3911
+ let title = sanitize(testTitle);
3912
+ if (!overwriteDuplicateNames) {
3913
+ title += "-" + uniqueId.value++;
3914
+ }
3889
3915
  const fileName = [
3890
- sanitize(testTitle) + "-" + uniqueId.value++,
3916
+ title,
3891
3917
  STORIES_FILE_EXT
3892
3918
  ].join(".");
3893
3919
  const maxByteLength = MAX_FILE_NAME_BYTE_LENGTH - 25;
@@ -3898,8 +3924,9 @@ function createStories(storyTitle, domSnapshots, chromaticStorybookParams) {
3898
3924
  const title = collapseNewlines(storyTitle);
3899
3925
  return {
3900
3926
  title,
3901
- stories: Object.entries(domSnapshots).map(([snapshotName, { viewport }]) => {
3927
+ stories: Object.entries(domSnapshots).map(([snapshotName, { viewport, parameters }]) => {
3902
3928
  const name = collapseNewlines(snapshotName);
3929
+ const { chromatic: chromaticParams, ...restParameters } = parameters || {};
3903
3930
  return {
3904
3931
  name,
3905
3932
  // Viewport addon (Storybook 10+): `parameters.viewport.options` registers sizes; `globals.viewport`
@@ -3917,6 +3944,7 @@ function createStories(storyTitle, domSnapshots, chromaticStorybookParams) {
3917
3944
  },
3918
3945
  chromatic: {
3919
3946
  ...chromaticStorybookParams,
3947
+ ...chromaticParams,
3920
3948
  modes: buildStoryModesConfig([
3921
3949
  viewport
3922
3950
  ])
@@ -3928,7 +3956,8 @@ function createStories(storyTitle, domSnapshots, chromaticStorybookParams) {
3928
3956
  defaultViewport: viewportToString(findDefaultViewport([
3929
3957
  viewport
3930
3958
  ]))
3931
- }
3959
+ },
3960
+ ...restParameters
3932
3961
  }
3933
3962
  };
3934
3963
  })
@@ -3985,7 +4014,7 @@ function findDefaultViewport(viewports) {
3985
4014
  __name(findDefaultViewport, "findDefaultViewport");
3986
4015
 
3987
4016
  // ../shared/src/write-archive/index.ts
3988
- async function writeTestResult(e2eTestInfo, domSnapshots, archive, chromaticStorybookParams) {
4017
+ async function writeTestResult(e2eTestInfo, domSnapshots, archive, chromaticStorybookParams, testRunner) {
3989
4018
  const { titlePath, outputDir, pageUrl } = e2eTestInfo;
3990
4019
  const titlePathWithoutFileExtensions = titlePath.map((pathPart) => (
3991
4020
  // make sure we remove file extensions, even if the file name doesn't have .spec or .test or.cy
@@ -4006,10 +4035,13 @@ async function writeTestResult(e2eTestInfo, domSnapshots, archive, chromaticStor
4006
4035
  const archiveFile = new ArchiveFile(url, response, pageUrl);
4007
4036
  const origSrcPath = archiveFile.originalSrc();
4008
4037
  const fileSystemPath = archiveFile.toFileSystemPath();
4038
+ const responsePath = join(archiveDir, fileSystemPath);
4009
4039
  if (origSrcPath !== fileSystemPath) {
4010
4040
  sourceMap.set(origSrcPath, fileSystemPath);
4011
4041
  }
4012
- await outputFile(join(archiveDir, fileSystemPath), response.body);
4042
+ if (!existsSync(responsePath)) {
4043
+ await outputFile(responsePath, response.body);
4044
+ }
4013
4045
  }));
4014
4046
  await Promise.all(Object.entries(domSnapshots).map(async ([name, domSnapshot]) => {
4015
4047
  const snapshot = new DOMSnapshot(domSnapshot);
@@ -4017,7 +4049,7 @@ async function writeTestResult(e2eTestInfo, domSnapshots, archive, chromaticStor
4017
4049
  const snapshotFile = snapshotFileName(snapshotId(title, name), domSnapshot.viewport);
4018
4050
  await outputFile(join(archiveDir, snapshotFile), mappedSnapshot);
4019
4051
  }));
4020
- const storiesFile = storiesFileName(title);
4052
+ const storiesFile = storiesFileName(title, testRunner !== "vitest");
4021
4053
  const storiesJson = createStories(title, domSnapshots, chromaticStorybookParams);
4022
4054
  await outputJSONFile(join(finalOutputDir, storiesFile), storiesJson);
4023
4055
  const errors = Object.entries(archive).filter(([, r]) => "error" in r);
@@ -4050,7 +4082,7 @@ var writeArchives = /* @__PURE__ */ __name(async ({ testTitlePath, domSnapshots,
4050
4082
  titlePath: testTitlePath,
4051
4083
  outputDir,
4052
4084
  pageUrl
4053
- }, allSnapshots, resourceArchive, chromaticStorybookParams);
4085
+ }, allSnapshots, resourceArchive, chromaticStorybookParams, "cypress");
4054
4086
  }, "writeArchives");
4055
4087
  var resourceArchiver = null;
4056
4088
  var host = "";
@@ -12,6 +12,9 @@ declare const _default: {
12
12
  renderer: string;
13
13
  };
14
14
  staticDirs: string[];
15
+ features: {
16
+ sidebarOnboardingChecklist: boolean;
17
+ };
15
18
  };
16
19
 
17
20
  export { _default as default };
@@ -47,7 +47,10 @@ var main_default = {
47
47
  },
48
48
  staticDirs: [
49
49
  path2.resolve(archivesDir(DEFAULT_OUTPUT_DIR), "archive")
50
- ]
50
+ ],
51
+ features: {
52
+ sidebarOnboardingChecklist: false
53
+ }
51
54
  };
52
55
 
53
56
  export { main_default as default };
@@ -3,7 +3,13 @@ import { addons } from 'storybook/manager-api';
3
3
  // ../shared/storybook-config/manager.ts
4
4
  addons.setConfig({
5
5
  sidebar: {
6
- // this ensures we use folders at the root-level instead of categories
6
+ // Ensures we use folders at the root-level instead of categories
7
7
  showRoots: false
8
+ },
9
+ layoutCustomisations: {
10
+ // Hide toolbar options that don't make sense in e2e setup
11
+ showToolbar: () => false,
12
+ // Hide bottom panel that's empty in e2e setup
13
+ showPanel: () => false
8
14
  }
9
15
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chromatic-com/cypress",
3
- "version": "0.12.6",
3
+ "version": "0.12.8",
4
4
  "description": "Chromatic Visual Regression Testing for Cypress",
5
5
  "repository": {
6
6
  "type": "git",