@chromatic-com/playwright 0.14.7 → 0.14.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/browser.mjs CHANGED
@@ -5275,7 +5275,6 @@ postcss$1.Root;
5275
5275
  postcss$1.Node;
5276
5276
 
5277
5277
  // src/browser.ts
5278
- window.__chromatic_takeSnapshot = takeSnapshot;
5279
5278
  async function takeSnapshot() {
5280
5279
  const mirror = createMirror();
5281
5280
  const domSnapshot = snapshot(document, {
@@ -5325,3 +5324,4 @@ async function toDataURL(url) {
5325
5324
  });
5326
5325
  }
5327
5326
  __name(toDataURL, "toDataURL");
5327
+ window.__chromatic_takeSnapshot = takeSnapshot;
package/dist/index.js CHANGED
@@ -3919,9 +3919,13 @@ var STORIES_FILE_EXT = "stories.json";
3919
3919
  var uniqueId = {
3920
3920
  value: 1
3921
3921
  };
3922
- function storiesFileName(testTitle) {
3922
+ function storiesFileName(testTitle, overwriteDuplicateNames = true) {
3923
+ let title = sanitize(testTitle);
3924
+ if (!overwriteDuplicateNames) {
3925
+ title += "-" + uniqueId.value++;
3926
+ }
3923
3927
  const fileName = [
3924
- sanitize(testTitle) + "-" + uniqueId.value++,
3928
+ title,
3925
3929
  STORIES_FILE_EXT
3926
3930
  ].join(".");
3927
3931
  const maxByteLength = MAX_FILE_NAME_BYTE_LENGTH - 25;
@@ -4022,7 +4026,7 @@ function findDefaultViewport(viewports) {
4022
4026
  __name(findDefaultViewport, "findDefaultViewport");
4023
4027
 
4024
4028
  // ../shared/src/write-archive/index.ts
4025
- async function writeTestResult(e2eTestInfo, domSnapshots, archive, chromaticStorybookParams) {
4029
+ async function writeTestResult(e2eTestInfo, domSnapshots, archive, chromaticStorybookParams, testRunner) {
4026
4030
  const { titlePath, outputDir, pageUrl } = e2eTestInfo;
4027
4031
  const titlePathWithoutFileExtensions = titlePath.map((pathPart) => (
4028
4032
  // make sure we remove file extensions, even if the file name doesn't have .spec or .test or.cy
@@ -4057,7 +4061,7 @@ async function writeTestResult(e2eTestInfo, domSnapshots, archive, chromaticStor
4057
4061
  const snapshotFile = snapshotFileName(snapshotId(title, name), domSnapshot.viewport);
4058
4062
  await outputFile(path2.join(archiveDir, snapshotFile), mappedSnapshot);
4059
4063
  }));
4060
- const storiesFile = storiesFileName(title);
4064
+ const storiesFile = storiesFileName(title, testRunner !== "vitest");
4061
4065
  const storiesJson = createStories(title, domSnapshots, chromaticStorybookParams);
4062
4066
  await outputJSONFile(path2.join(finalOutputDir, storiesFile), storiesJson);
4063
4067
  const errors = Object.entries(archive).filter(([, r]) => "error" in r);
@@ -4100,8 +4104,8 @@ __name(trackComplete, "trackComplete");
4100
4104
 
4101
4105
  // ../shared/src/constants.ts
4102
4106
  var DEFAULT_GLOBAL_RESOURCE_ARCHIVE_TIMEOUT_MS = 1e4;
4103
-
4104
- // src/takeSnapshot.ts
4107
+ var browserEntry = __require.resolve("@chromatic-com/playwright/browser");
4108
+ var browserScript = fs.readFileSync(browserEntry, "utf-8");
4105
4109
  var chromaticSnapshots = /* @__PURE__ */ new Map();
4106
4110
  async function takeSnapshot(page, nameOrTestInfo, maybeTestInfo) {
4107
4111
  let name;
@@ -4155,14 +4159,15 @@ async function takeSnapshot(page, nameOrTestInfo, maybeTestInfo) {
4155
4159
  }
4156
4160
  __name(takeSnapshot, "takeSnapshot");
4157
4161
  async function executeSnapshotScript(context) {
4158
- await context.addScriptTag({
4159
- type: "module",
4160
- path: __require.resolve("@chromatic-com/playwright/browser")
4161
- });
4162
- await context.waitForFunction(() => typeof window.__chromatic_takeSnapshot === "function");
4163
- const snapshot = await context.evaluate(async () => {
4164
- return JSON.stringify(await window.__chromatic_takeSnapshot());
4165
- });
4162
+ const snapshot = await context.evaluate(
4163
+ // Wrapper is needed to scope all inlined definitions of browser script, as
4164
+ // it contains bundled rrweb-snapshot that inlines variables like "const node = ...".
4165
+ `async function wrapper() {
4166
+ ${browserScript}
4167
+
4168
+ return JSON.stringify(await takeSnapshot());
4169
+ }()`
4170
+ );
4166
4171
  return JSON.parse(snapshot);
4167
4172
  }
4168
4173
  __name(executeSnapshotScript, "executeSnapshotScript");
@@ -4255,7 +4260,7 @@ var performChromaticSnapshot = /* @__PURE__ */ __name(async ({ page, delay, diff
4255
4260
  prefersReducedMotion,
4256
4261
  cropToViewport,
4257
4262
  ignoreSelectors
4258
- });
4263
+ }, "playwright");
4259
4264
  trackComplete();
4260
4265
  } finally {
4261
4266
  chromaticSnapshots.delete(testId);
package/dist/index.mjs CHANGED
@@ -2,7 +2,7 @@ import { createRequire } from 'module';
2
2
  import { test as test$1 } from '@playwright/test';
3
3
  export { expect } from '@playwright/test';
4
4
  import path2, { join } from 'path';
5
- import { existsSync, mkdirSync } from 'fs';
5
+ import { readFileSync, existsSync, mkdirSync } from 'fs';
6
6
  import { writeFile } from 'fs/promises';
7
7
  import { createHash } from 'crypto';
8
8
  import { toId, storyNameFromExport } from 'storybook/internal/csf';
@@ -3913,9 +3913,13 @@ var STORIES_FILE_EXT = "stories.json";
3913
3913
  var uniqueId = {
3914
3914
  value: 1
3915
3915
  };
3916
- function storiesFileName(testTitle) {
3916
+ function storiesFileName(testTitle, overwriteDuplicateNames = true) {
3917
+ let title = sanitize(testTitle);
3918
+ if (!overwriteDuplicateNames) {
3919
+ title += "-" + uniqueId.value++;
3920
+ }
3917
3921
  const fileName = [
3918
- sanitize(testTitle) + "-" + uniqueId.value++,
3922
+ title,
3919
3923
  STORIES_FILE_EXT
3920
3924
  ].join(".");
3921
3925
  const maxByteLength = MAX_FILE_NAME_BYTE_LENGTH - 25;
@@ -4016,7 +4020,7 @@ function findDefaultViewport(viewports) {
4016
4020
  __name(findDefaultViewport, "findDefaultViewport");
4017
4021
 
4018
4022
  // ../shared/src/write-archive/index.ts
4019
- async function writeTestResult(e2eTestInfo, domSnapshots, archive, chromaticStorybookParams) {
4023
+ async function writeTestResult(e2eTestInfo, domSnapshots, archive, chromaticStorybookParams, testRunner) {
4020
4024
  const { titlePath, outputDir, pageUrl } = e2eTestInfo;
4021
4025
  const titlePathWithoutFileExtensions = titlePath.map((pathPart) => (
4022
4026
  // make sure we remove file extensions, even if the file name doesn't have .spec or .test or.cy
@@ -4051,7 +4055,7 @@ async function writeTestResult(e2eTestInfo, domSnapshots, archive, chromaticStor
4051
4055
  const snapshotFile = snapshotFileName(snapshotId(title, name), domSnapshot.viewport);
4052
4056
  await outputFile(join(archiveDir, snapshotFile), mappedSnapshot);
4053
4057
  }));
4054
- const storiesFile = storiesFileName(title);
4058
+ const storiesFile = storiesFileName(title, testRunner !== "vitest");
4055
4059
  const storiesJson = createStories(title, domSnapshots, chromaticStorybookParams);
4056
4060
  await outputJSONFile(join(finalOutputDir, storiesFile), storiesJson);
4057
4061
  const errors = Object.entries(archive).filter(([, r]) => "error" in r);
@@ -4094,8 +4098,8 @@ __name(trackComplete, "trackComplete");
4094
4098
 
4095
4099
  // ../shared/src/constants.ts
4096
4100
  var DEFAULT_GLOBAL_RESOURCE_ARCHIVE_TIMEOUT_MS = 1e4;
4097
-
4098
- // src/takeSnapshot.ts
4101
+ var browserEntry = __require.resolve("@chromatic-com/playwright/browser");
4102
+ var browserScript = readFileSync(browserEntry, "utf-8");
4099
4103
  var chromaticSnapshots = /* @__PURE__ */ new Map();
4100
4104
  async function takeSnapshot(page, nameOrTestInfo, maybeTestInfo) {
4101
4105
  let name;
@@ -4149,14 +4153,15 @@ async function takeSnapshot(page, nameOrTestInfo, maybeTestInfo) {
4149
4153
  }
4150
4154
  __name(takeSnapshot, "takeSnapshot");
4151
4155
  async function executeSnapshotScript(context) {
4152
- await context.addScriptTag({
4153
- type: "module",
4154
- path: __require.resolve("@chromatic-com/playwright/browser")
4155
- });
4156
- await context.waitForFunction(() => typeof window.__chromatic_takeSnapshot === "function");
4157
- const snapshot = await context.evaluate(async () => {
4158
- return JSON.stringify(await window.__chromatic_takeSnapshot());
4159
- });
4156
+ const snapshot = await context.evaluate(
4157
+ // Wrapper is needed to scope all inlined definitions of browser script, as
4158
+ // it contains bundled rrweb-snapshot that inlines variables like "const node = ...".
4159
+ `async function wrapper() {
4160
+ ${browserScript}
4161
+
4162
+ return JSON.stringify(await takeSnapshot());
4163
+ }()`
4164
+ );
4160
4165
  return JSON.parse(snapshot);
4161
4166
  }
4162
4167
  __name(executeSnapshotScript, "executeSnapshotScript");
@@ -4249,7 +4254,7 @@ var performChromaticSnapshot = /* @__PURE__ */ __name(async ({ page, delay, diff
4249
4254
  prefersReducedMotion,
4250
4255
  cropToViewport,
4251
4256
  ignoreSelectors
4252
- });
4257
+ }, "playwright");
4253
4258
  trackComplete();
4254
4259
  } finally {
4255
4260
  chromaticSnapshots.delete(testId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chromatic-com/playwright",
3
- "version": "0.14.7",
3
+ "version": "0.14.9",
4
4
  "description": "Chromatic Visual Regression Testing for Playwright",
5
5
  "repository": {
6
6
  "type": "git",