@chromatic-com/playwright 0.14.4 → 0.14.6

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
@@ -3403,7 +3403,7 @@ var logger = process.env.LOG ? console : {
3403
3403
 
3404
3404
  // ../shared/src/resource-archiver/index.ts
3405
3405
  var _ResourceArchiver = class _ResourceArchiver {
3406
- constructor(cdpClient, allowedDomains, httpCredentials) {
3406
+ constructor(cdpClient, allowedDomains, httpCredentials, firstUrl) {
3407
3407
  __publicField(this, "archive", {});
3408
3408
  __publicField(this, "client");
3409
3409
  /**
@@ -3477,6 +3477,7 @@ var _ResourceArchiver = class _ResourceArchiver {
3477
3477
  }, "requestPaused"));
3478
3478
  this.client = cdpClient;
3479
3479
  this.httpCredentials = httpCredentials;
3480
+ this.firstUrl = firstUrl;
3480
3481
  this.assetDomains = (allowedDomains || []).map((domain) => {
3481
3482
  if (domain.startsWith("http")) {
3482
3483
  return domain;
@@ -3536,12 +3537,25 @@ var _ResourceArchiver = class _ResourceArchiver {
3536
3537
  const contentTypeHeader = responseHeaders.find(({ name }) => name.toLowerCase() === "content-type");
3537
3538
  const isFirstRequest = requestUrl.toString() === this.firstUrl.toString();
3538
3539
  if (isRequestFromAllowedDomain && !isFirstRequest) {
3540
+ logger.log("Archiving request", {
3541
+ url: request.url,
3542
+ statusCode: responseStatusCode,
3543
+ statusText: responseStatusText,
3544
+ contentType: contentTypeHeader?.value
3545
+ });
3539
3546
  this.archive[request.url] = {
3540
3547
  statusCode: responseStatusCode,
3541
3548
  statusText: responseStatusText,
3542
3549
  body: Buffer.from(body, base64Encoded ? "base64" : "utf8"),
3543
3550
  contentType: contentTypeHeader?.value
3544
3551
  };
3552
+ } else {
3553
+ logger.log("Skipping archiving of request", {
3554
+ url: request.url,
3555
+ firstUrl: this.firstUrl.toString(),
3556
+ isFirstRequest,
3557
+ isRequestFromAllowedDomain
3558
+ });
3545
3559
  }
3546
3560
  await this.clientSend(request, "Fetch.continueRequest", {
3547
3561
  requestId
@@ -3804,8 +3818,7 @@ var _DOMSnapshot = class _DOMSnapshot {
3804
3818
  const currentSrc = this.mapSrcsetUrls(srcsetValue, sourceMap);
3805
3819
  if (currentSrc) {
3806
3820
  node.attributes.src = currentSrc;
3807
- delete node.attributes.srcset;
3808
- delete node.attributes.sizes;
3821
+ this.removeResponsiveImageAttributes(node.attributes);
3809
3822
  }
3810
3823
  }
3811
3824
  if (node.tagName === "picture") {
@@ -3830,6 +3843,7 @@ var _DOMSnapshot = class _DOMSnapshot {
3830
3843
  const imageElement = node.childNodes.find((childNode) => childNode.type === NodeType.Element && childNode.tagName === "img");
3831
3844
  if (imageElement && imageElement.attributes) {
3832
3845
  imageElement.attributes.src = sourceMap.get(matchingUrl);
3846
+ this.removeResponsiveImageAttributes(imageElement.attributes);
3833
3847
  }
3834
3848
  }
3835
3849
  }
@@ -3864,6 +3878,10 @@ var _DOMSnapshot = class _DOMSnapshot {
3864
3878
  });
3865
3879
  return currentSrc;
3866
3880
  }
3881
+ removeResponsiveImageAttributes(attributes) {
3882
+ delete attributes.srcset;
3883
+ delete attributes.sizes;
3884
+ }
3867
3885
  };
3868
3886
  __name(_DOMSnapshot, "DOMSnapshot");
3869
3887
  var DOMSnapshot = _DOMSnapshot;
@@ -3914,8 +3932,9 @@ function createStories(storyTitle, domSnapshots, chromaticStorybookParams) {
3914
3932
  const title = collapseNewlines(storyTitle);
3915
3933
  return {
3916
3934
  title,
3917
- stories: Object.entries(domSnapshots).map(([snapshotName, { viewport }]) => {
3935
+ stories: Object.entries(domSnapshots).map(([snapshotName, { viewport, parameters }]) => {
3918
3936
  const name = collapseNewlines(snapshotName);
3937
+ const { chromatic: chromaticParams, ...restParameters } = parameters || {};
3919
3938
  return {
3920
3939
  name,
3921
3940
  // Viewport addon (Storybook 10+): `parameters.viewport.options` registers sizes; `globals.viewport`
@@ -3933,6 +3952,7 @@ function createStories(storyTitle, domSnapshots, chromaticStorybookParams) {
3933
3952
  },
3934
3953
  chromatic: {
3935
3954
  ...chromaticStorybookParams,
3955
+ ...chromaticParams,
3936
3956
  modes: buildStoryModesConfig([
3937
3957
  viewport
3938
3958
  ])
@@ -3944,7 +3964,8 @@ function createStories(storyTitle, domSnapshots, chromaticStorybookParams) {
3944
3964
  defaultViewport: viewportToString(findDefaultViewport([
3945
3965
  viewport
3946
3966
  ]))
3947
- }
3967
+ },
3968
+ ...restParameters
3948
3969
  }
3949
3970
  };
3950
3971
  })
@@ -4022,10 +4043,13 @@ async function writeTestResult(e2eTestInfo, domSnapshots, archive, chromaticStor
4022
4043
  const archiveFile = new ArchiveFile(url, response, pageUrl);
4023
4044
  const origSrcPath = archiveFile.originalSrc();
4024
4045
  const fileSystemPath = archiveFile.toFileSystemPath();
4046
+ const responsePath = path2.join(archiveDir, fileSystemPath);
4025
4047
  if (origSrcPath !== fileSystemPath) {
4026
4048
  sourceMap.set(origSrcPath, fileSystemPath);
4027
4049
  }
4028
- await outputFile(path2.join(archiveDir, fileSystemPath), response.body);
4050
+ if (!fs.existsSync(responsePath)) {
4051
+ await outputFile(responsePath, response.body);
4052
+ }
4029
4053
  }));
4030
4054
  await Promise.all(Object.entries(domSnapshots).map(async ([name, domSnapshot]) => {
4031
4055
  const snapshot = new DOMSnapshot(domSnapshot);
@@ -4135,6 +4159,7 @@ async function executeSnapshotScript(context) {
4135
4159
  type: "module",
4136
4160
  path: __require.resolve("@chromatic-com/playwright/browser")
4137
4161
  });
4162
+ await context.waitForFunction(() => typeof window.__chromatic_takeSnapshot === "function");
4138
4163
  const snapshot = await context.evaluate(async () => {
4139
4164
  return JSON.stringify(await window.__chromatic_takeSnapshot());
4140
4165
  });
@@ -4216,38 +4241,21 @@ var performChromaticSnapshot = /* @__PURE__ */ __name(async ({ page, delay, diff
4216
4241
  }
4217
4242
  const resourceArchive = await completeArchive();
4218
4243
  const snapshots = chromaticSnapshots.get(testId) || /* @__PURE__ */ new Map();
4219
- const chromaticStorybookParams = {
4220
- ...delay && {
4221
- delay
4222
- },
4223
- ...diffIncludeAntiAliasing && {
4224
- diffIncludeAntiAliasing
4225
- },
4226
- ...diffThreshold && {
4227
- diffThreshold
4228
- },
4229
- ...forcedColors && {
4230
- forcedColors
4231
- },
4232
- ...pauseAnimationAtEnd && {
4233
- pauseAnimationAtEnd
4234
- },
4235
- ...prefersReducedMotion && {
4236
- prefersReducedMotion
4237
- },
4238
- ...cropToViewport && {
4239
- cropToViewport
4240
- },
4241
- ...ignoreSelectors && {
4242
- ignoreSelectors
4243
- }
4244
- };
4245
4244
  const outputDir = path2.join(testInfo.outputDir, "..");
4246
4245
  await writeTestResult({
4247
4246
  ...testInfo,
4248
4247
  outputDir,
4249
4248
  pageUrl: page.url()
4250
- }, Object.fromEntries(snapshots), resourceArchive, chromaticStorybookParams);
4249
+ }, Object.fromEntries(snapshots), resourceArchive, {
4250
+ delay,
4251
+ diffIncludeAntiAliasing,
4252
+ diffThreshold,
4253
+ forcedColors,
4254
+ pauseAnimationAtEnd,
4255
+ prefersReducedMotion,
4256
+ cropToViewport,
4257
+ ignoreSelectors
4258
+ });
4251
4259
  trackComplete();
4252
4260
  } finally {
4253
4261
  chromaticSnapshots.delete(testId);
package/dist/index.mjs CHANGED
@@ -3397,7 +3397,7 @@ var logger = process.env.LOG ? console : {
3397
3397
 
3398
3398
  // ../shared/src/resource-archiver/index.ts
3399
3399
  var _ResourceArchiver = class _ResourceArchiver {
3400
- constructor(cdpClient, allowedDomains, httpCredentials) {
3400
+ constructor(cdpClient, allowedDomains, httpCredentials, firstUrl) {
3401
3401
  __publicField(this, "archive", {});
3402
3402
  __publicField(this, "client");
3403
3403
  /**
@@ -3471,6 +3471,7 @@ var _ResourceArchiver = class _ResourceArchiver {
3471
3471
  }, "requestPaused"));
3472
3472
  this.client = cdpClient;
3473
3473
  this.httpCredentials = httpCredentials;
3474
+ this.firstUrl = firstUrl;
3474
3475
  this.assetDomains = (allowedDomains || []).map((domain) => {
3475
3476
  if (domain.startsWith("http")) {
3476
3477
  return domain;
@@ -3530,12 +3531,25 @@ var _ResourceArchiver = class _ResourceArchiver {
3530
3531
  const contentTypeHeader = responseHeaders.find(({ name }) => name.toLowerCase() === "content-type");
3531
3532
  const isFirstRequest = requestUrl.toString() === this.firstUrl.toString();
3532
3533
  if (isRequestFromAllowedDomain && !isFirstRequest) {
3534
+ logger.log("Archiving request", {
3535
+ url: request.url,
3536
+ statusCode: responseStatusCode,
3537
+ statusText: responseStatusText,
3538
+ contentType: contentTypeHeader?.value
3539
+ });
3533
3540
  this.archive[request.url] = {
3534
3541
  statusCode: responseStatusCode,
3535
3542
  statusText: responseStatusText,
3536
3543
  body: Buffer.from(body, base64Encoded ? "base64" : "utf8"),
3537
3544
  contentType: contentTypeHeader?.value
3538
3545
  };
3546
+ } else {
3547
+ logger.log("Skipping archiving of request", {
3548
+ url: request.url,
3549
+ firstUrl: this.firstUrl.toString(),
3550
+ isFirstRequest,
3551
+ isRequestFromAllowedDomain
3552
+ });
3539
3553
  }
3540
3554
  await this.clientSend(request, "Fetch.continueRequest", {
3541
3555
  requestId
@@ -3798,8 +3812,7 @@ var _DOMSnapshot = class _DOMSnapshot {
3798
3812
  const currentSrc = this.mapSrcsetUrls(srcsetValue, sourceMap);
3799
3813
  if (currentSrc) {
3800
3814
  node.attributes.src = currentSrc;
3801
- delete node.attributes.srcset;
3802
- delete node.attributes.sizes;
3815
+ this.removeResponsiveImageAttributes(node.attributes);
3803
3816
  }
3804
3817
  }
3805
3818
  if (node.tagName === "picture") {
@@ -3824,6 +3837,7 @@ var _DOMSnapshot = class _DOMSnapshot {
3824
3837
  const imageElement = node.childNodes.find((childNode) => childNode.type === NodeType.Element && childNode.tagName === "img");
3825
3838
  if (imageElement && imageElement.attributes) {
3826
3839
  imageElement.attributes.src = sourceMap.get(matchingUrl);
3840
+ this.removeResponsiveImageAttributes(imageElement.attributes);
3827
3841
  }
3828
3842
  }
3829
3843
  }
@@ -3858,6 +3872,10 @@ var _DOMSnapshot = class _DOMSnapshot {
3858
3872
  });
3859
3873
  return currentSrc;
3860
3874
  }
3875
+ removeResponsiveImageAttributes(attributes) {
3876
+ delete attributes.srcset;
3877
+ delete attributes.sizes;
3878
+ }
3861
3879
  };
3862
3880
  __name(_DOMSnapshot, "DOMSnapshot");
3863
3881
  var DOMSnapshot = _DOMSnapshot;
@@ -3908,8 +3926,9 @@ function createStories(storyTitle, domSnapshots, chromaticStorybookParams) {
3908
3926
  const title = collapseNewlines(storyTitle);
3909
3927
  return {
3910
3928
  title,
3911
- stories: Object.entries(domSnapshots).map(([snapshotName, { viewport }]) => {
3929
+ stories: Object.entries(domSnapshots).map(([snapshotName, { viewport, parameters }]) => {
3912
3930
  const name = collapseNewlines(snapshotName);
3931
+ const { chromatic: chromaticParams, ...restParameters } = parameters || {};
3913
3932
  return {
3914
3933
  name,
3915
3934
  // Viewport addon (Storybook 10+): `parameters.viewport.options` registers sizes; `globals.viewport`
@@ -3927,6 +3946,7 @@ function createStories(storyTitle, domSnapshots, chromaticStorybookParams) {
3927
3946
  },
3928
3947
  chromatic: {
3929
3948
  ...chromaticStorybookParams,
3949
+ ...chromaticParams,
3930
3950
  modes: buildStoryModesConfig([
3931
3951
  viewport
3932
3952
  ])
@@ -3938,7 +3958,8 @@ function createStories(storyTitle, domSnapshots, chromaticStorybookParams) {
3938
3958
  defaultViewport: viewportToString(findDefaultViewport([
3939
3959
  viewport
3940
3960
  ]))
3941
- }
3961
+ },
3962
+ ...restParameters
3942
3963
  }
3943
3964
  };
3944
3965
  })
@@ -4016,10 +4037,13 @@ async function writeTestResult(e2eTestInfo, domSnapshots, archive, chromaticStor
4016
4037
  const archiveFile = new ArchiveFile(url, response, pageUrl);
4017
4038
  const origSrcPath = archiveFile.originalSrc();
4018
4039
  const fileSystemPath = archiveFile.toFileSystemPath();
4040
+ const responsePath = join(archiveDir, fileSystemPath);
4019
4041
  if (origSrcPath !== fileSystemPath) {
4020
4042
  sourceMap.set(origSrcPath, fileSystemPath);
4021
4043
  }
4022
- await outputFile(join(archiveDir, fileSystemPath), response.body);
4044
+ if (!existsSync(responsePath)) {
4045
+ await outputFile(responsePath, response.body);
4046
+ }
4023
4047
  }));
4024
4048
  await Promise.all(Object.entries(domSnapshots).map(async ([name, domSnapshot]) => {
4025
4049
  const snapshot = new DOMSnapshot(domSnapshot);
@@ -4129,6 +4153,7 @@ async function executeSnapshotScript(context) {
4129
4153
  type: "module",
4130
4154
  path: __require.resolve("@chromatic-com/playwright/browser")
4131
4155
  });
4156
+ await context.waitForFunction(() => typeof window.__chromatic_takeSnapshot === "function");
4132
4157
  const snapshot = await context.evaluate(async () => {
4133
4158
  return JSON.stringify(await window.__chromatic_takeSnapshot());
4134
4159
  });
@@ -4210,38 +4235,21 @@ var performChromaticSnapshot = /* @__PURE__ */ __name(async ({ page, delay, diff
4210
4235
  }
4211
4236
  const resourceArchive = await completeArchive();
4212
4237
  const snapshots = chromaticSnapshots.get(testId) || /* @__PURE__ */ new Map();
4213
- const chromaticStorybookParams = {
4214
- ...delay && {
4215
- delay
4216
- },
4217
- ...diffIncludeAntiAliasing && {
4218
- diffIncludeAntiAliasing
4219
- },
4220
- ...diffThreshold && {
4221
- diffThreshold
4222
- },
4223
- ...forcedColors && {
4224
- forcedColors
4225
- },
4226
- ...pauseAnimationAtEnd && {
4227
- pauseAnimationAtEnd
4228
- },
4229
- ...prefersReducedMotion && {
4230
- prefersReducedMotion
4231
- },
4232
- ...cropToViewport && {
4233
- cropToViewport
4234
- },
4235
- ...ignoreSelectors && {
4236
- ignoreSelectors
4237
- }
4238
- };
4239
4238
  const outputDir = join(testInfo.outputDir, "..");
4240
4239
  await writeTestResult({
4241
4240
  ...testInfo,
4242
4241
  outputDir,
4243
4242
  pageUrl: page.url()
4244
- }, Object.fromEntries(snapshots), resourceArchive, chromaticStorybookParams);
4243
+ }, Object.fromEntries(snapshots), resourceArchive, {
4244
+ delay,
4245
+ diffIncludeAntiAliasing,
4246
+ diffThreshold,
4247
+ forcedColors,
4248
+ pauseAnimationAtEnd,
4249
+ prefersReducedMotion,
4250
+ cropToViewport,
4251
+ ignoreSelectors
4252
+ });
4245
4253
  trackComplete();
4246
4254
  } finally {
4247
4255
  chromaticSnapshots.delete(testId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chromatic-com/playwright",
3
- "version": "0.14.4",
3
+ "version": "0.14.6",
4
4
  "description": "Chromatic Visual Regression Testing for Playwright",
5
5
  "repository": {
6
6
  "type": "git",