happo 6.5.1 → 6.6.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 (52) hide show
  1. package/dist/cli/cancelJob-HZDX6274.js +10 -0
  2. package/dist/cli/{chunk-SCQIFNJG.js → chunk-AFAI3HL3.js} +2 -2
  3. package/dist/cli/{chunk-7LVB6VSD.js → chunk-DUWOS4XT.js} +5 -5
  4. package/dist/cli/{chunk-7LVB6VSD.js.map → chunk-DUWOS4XT.js.map} +1 -1
  5. package/dist/cli/{chunk-4DIEFVB6.js → chunk-LCNHMIOU.js} +2 -2
  6. package/dist/cli/chunk-OXGH6FW4.js +84 -0
  7. package/dist/cli/chunk-OXGH6FW4.js.map +7 -0
  8. package/dist/cli/{chunk-Z3ISMK3L.js → chunk-PRPDWPU3.js} +3 -3
  9. package/dist/cli/{chunk-SVXHNTZV.js → chunk-QC2HOKDQ.js} +2 -2
  10. package/dist/cli/createAsyncComparison-FQQHINTM.js +10 -0
  11. package/dist/cli/{createAsyncReport-YYPR6QMH.js → createAsyncReport-IQO7YVCA.js} +4 -4
  12. package/dist/cli/{getFlakes-2IDWWM6K.js → getFlakes-HICLTPZC.js} +4 -4
  13. package/dist/cli/main.js +11 -11
  14. package/dist/cli/main.js.map +2 -2
  15. package/dist/cli/package-RZI6QOJX.js +7 -0
  16. package/dist/cli/{prepareSnapRequests-YRX3FLO3.js → prepareSnapRequests-VFWDWE5X.js} +156 -78
  17. package/dist/cli/prepareSnapRequests-VFWDWE5X.js.map +7 -0
  18. package/dist/cli/startJob-QZA4POSE.js +10 -0
  19. package/dist/cli/{wrapper-YSLGURLA.js → wrapper-IQJTUXE4.js} +7 -9
  20. package/dist/cli/wrapper-IQJTUXE4.js.map +7 -0
  21. package/dist/config/RemoteBrowserTarget.d.ts.map +1 -1
  22. package/dist/cypress/task.js +190 -86
  23. package/dist/cypress/task.js.map +4 -4
  24. package/dist/e2e/controller.d.ts.map +1 -1
  25. package/dist/e2e/wrapper.d.ts.map +1 -1
  26. package/dist/network/getSignedToken.d.ts +3 -0
  27. package/dist/network/getSignedToken.d.ts.map +1 -0
  28. package/dist/network/makeHappoAPIRequest.d.ts +0 -1
  29. package/dist/network/makeHappoAPIRequest.d.ts.map +1 -1
  30. package/dist/network/uploadAssets.d.ts.map +1 -1
  31. package/dist/playwright/index.js +190 -86
  32. package/dist/playwright/index.js.map +4 -4
  33. package/dist/utils/deterministicArchive.d.ts.map +1 -1
  34. package/package.json +4 -4
  35. package/dist/cli/cancelJob-RNJNTEO6.js +0 -10
  36. package/dist/cli/chunk-ZFINBURL.js +0 -54
  37. package/dist/cli/chunk-ZFINBURL.js.map +0 -7
  38. package/dist/cli/createAsyncComparison-7TQ6WCAL.js +0 -10
  39. package/dist/cli/package-XNDR47YX.js +0 -7
  40. package/dist/cli/prepareSnapRequests-YRX3FLO3.js.map +0 -7
  41. package/dist/cli/startJob-6UNQDHQ6.js +0 -10
  42. package/dist/cli/wrapper-YSLGURLA.js.map +0 -7
  43. /package/dist/cli/{cancelJob-RNJNTEO6.js.map → cancelJob-HZDX6274.js.map} +0 -0
  44. /package/dist/cli/{chunk-SCQIFNJG.js.map → chunk-AFAI3HL3.js.map} +0 -0
  45. /package/dist/cli/{chunk-4DIEFVB6.js.map → chunk-LCNHMIOU.js.map} +0 -0
  46. /package/dist/cli/{chunk-Z3ISMK3L.js.map → chunk-PRPDWPU3.js.map} +0 -0
  47. /package/dist/cli/{chunk-SVXHNTZV.js.map → chunk-QC2HOKDQ.js.map} +0 -0
  48. /package/dist/cli/{createAsyncComparison-7TQ6WCAL.js.map → createAsyncComparison-FQQHINTM.js.map} +0 -0
  49. /package/dist/cli/{createAsyncReport-YYPR6QMH.js.map → createAsyncReport-IQO7YVCA.js.map} +0 -0
  50. /package/dist/cli/{getFlakes-2IDWWM6K.js.map → getFlakes-HICLTPZC.js.map} +0 -0
  51. /package/dist/cli/{package-XNDR47YX.js.map → package-RZI6QOJX.js.map} +0 -0
  52. /package/dist/cli/{startJob-6UNQDHQ6.js.map → startJob-QZA4POSE.js.map} +0 -0
@@ -19,7 +19,7 @@ import asyncRetry from "async-retry";
19
19
  // package.json
20
20
  var package_default = {
21
21
  name: "happo",
22
- version: "6.5.1",
22
+ version: "6.6.0",
23
23
  description: "Catch unexpected visual and accessibility changes and UI bugs",
24
24
  license: "MIT",
25
25
  repository: {
@@ -80,10 +80,10 @@ var package_default = {
80
80
  all: "node ./scripts/allchecks.ts",
81
81
  build: "pnpm build:types && pnpm build:dist",
82
82
  "build:custom": "esbuild src/custom/__happo__/index.ts --bundle --format=iife --global-name=happoCustom --outfile=tmp/happo-custom/bundle.js --platform=browser --target=esnext",
83
- "build:dist": "./scripts/build.ts",
83
+ "build:dist": "node ./scripts/build.ts",
84
84
  "build:types": "pnpm tsc --pretty",
85
85
  "build:watch": "tsc --build --watch",
86
- clean: "rm -rf dist tmp/tsc tmp/happo-custom",
86
+ clean: "node ./scripts/clean.ts",
87
87
  lint: "eslint .",
88
88
  prepublishOnly: "pnpm clean && pnpm build",
89
89
  "storybook:dev": "storybook dev --config-dir src/storybook/__tests__/storybook-app -p ${PORT:-6007}",
@@ -143,7 +143,7 @@ var package_default = {
143
143
  "eslint-plugin-simple-import-sort": "^12.1.1",
144
144
  "eslint-plugin-unicorn": "^63.0.0",
145
145
  jiti: "^2.6.1",
146
- jsdom: "^28.0.0",
146
+ jsdom: "^29.0.0",
147
147
  multiparty: "^4.2.3",
148
148
  prettier: "^3.6.2",
149
149
  react: "^19.2.0",
@@ -655,12 +655,42 @@ async function loadConfigFile(configFilePath, environment, logger = console) {
655
655
  return configWithDefaults;
656
656
  }
657
657
 
658
- // src/network/makeHappoAPIRequest.ts
658
+ // src/network/getSignedToken.ts
659
659
  import { SignJWT } from "jose";
660
- async function signRequest(apiKey, apiSecret) {
661
- const encodedSecret = new TextEncoder().encode(apiSecret);
662
- return await new SignJWT({ key: apiKey }).setProtectedHeader({ alg: "HS256", kid: apiKey }).sign(encodedSecret);
660
+ var TOKEN_TTL_SECONDS = 5 * 60;
661
+ var TOKEN_REFRESH_BUFFER_SECONDS = 30;
662
+ var cache = /* @__PURE__ */ new Map();
663
+ function getCacheKey(apiKey, apiSecret) {
664
+ return `${apiKey}:${apiSecret}`;
663
665
  }
666
+ async function getSignedToken(apiKey, apiSecret) {
667
+ const cacheKey = getCacheKey(apiKey, apiSecret);
668
+ const cachedPromise = cache.get(cacheKey);
669
+ if (cachedPromise) {
670
+ const cached = await cachedPromise;
671
+ const nowSeconds = Date.now() / 1e3;
672
+ if (cached.expiresAt - nowSeconds > TOKEN_REFRESH_BUFFER_SECONDS) {
673
+ return cached.token;
674
+ }
675
+ }
676
+ const signingPromise = (async () => {
677
+ const nowSeconds = Date.now() / 1e3;
678
+ const expiresAt = Math.floor(nowSeconds) + TOKEN_TTL_SECONDS;
679
+ const encodedSecret = new TextEncoder().encode(apiSecret);
680
+ const token = await new SignJWT({ key: apiKey }).setProtectedHeader({ alg: "HS256", kid: apiKey }).setExpirationTime(expiresAt).sign(encodedSecret);
681
+ return { token, expiresAt };
682
+ })();
683
+ cache.set(cacheKey, signingPromise);
684
+ try {
685
+ const { token } = await signingPromise;
686
+ return token;
687
+ } catch (error) {
688
+ cache.delete(cacheKey);
689
+ throw error;
690
+ }
691
+ }
692
+
693
+ // src/network/makeHappoAPIRequest.ts
664
694
  async function makeHappoAPIRequest({ url, path: path3, method = "GET", formData, body }, { apiKey, apiSecret, endpoint }, {
665
695
  retryCount = 0,
666
696
  timeout = 6e4,
@@ -673,7 +703,7 @@ async function makeHappoAPIRequest({ url, path: path3, method = "GET", formData,
673
703
  "No fetch URL provided. Either `path` (preferred) or `url` must be provided."
674
704
  );
675
705
  }
676
- const signed = await signRequest(apiKey, apiSecret);
706
+ const signed = await getSignedToken(apiKey, apiSecret);
677
707
  const headers = {
678
708
  Authorization: `Bearer ${signed}`
679
709
  };
@@ -709,6 +739,7 @@ function createHash(data) {
709
739
 
710
740
  // src/config/RemoteBrowserTarget.ts
711
741
  var VIEWPORT_PATTERN = /^([0-9]+)x([0-9]+)$/;
742
+ var MAX_BULK_ITEMS_PER_REQUEST = 50;
712
743
  function computeDefaultChunks(estimatedSnapCount) {
713
744
  if (!Number.isFinite(estimatedSnapCount) || estimatedSnapCount <= 0) {
714
745
  return 1;
@@ -729,6 +760,71 @@ function getPageSlices(pages, chunks) {
729
760
  }
730
761
  return result;
731
762
  }
763
+ function buildChunkItem({
764
+ slice,
765
+ chunk,
766
+ pageSlice,
767
+ browserName,
768
+ viewport,
769
+ maxHeight,
770
+ otherOptions,
771
+ globalCSS,
772
+ staticPackage,
773
+ assetsPackage,
774
+ targetName
775
+ }) {
776
+ const payloadString = JSON.stringify({
777
+ viewport,
778
+ maxHeight,
779
+ ...otherOptions,
780
+ globalCSS,
781
+ snapPayloads: slice,
782
+ chunk,
783
+ staticPackage,
784
+ assetsPackage,
785
+ pages: pageSlice,
786
+ extendsSha: pageSlice ? pageSlice.extendsSha : void 0
787
+ });
788
+ const payloadHash = createHash(payloadString + (pageSlice ? Math.random() : ""));
789
+ const type = pageSlice && pageSlice.extendsSha ? "extends-report" : `browser-${browserName}`;
790
+ const item = { type, targetName, payloadString, payloadHash };
791
+ if (pageSlice?.extendsSha) {
792
+ item.extendsSha = pageSlice.extendsSha;
793
+ }
794
+ return item;
795
+ }
796
+ async function sendIndividualSnapRequest(item, config) {
797
+ const formData = {
798
+ type: item.type,
799
+ targetName: item.targetName,
800
+ payloadHash: item.payloadHash,
801
+ payload: new File([item.payloadString], "payload.json", {
802
+ type: "application/json"
803
+ })
804
+ };
805
+ if (item.extendsSha) {
806
+ formData.extendsSha = item.extendsSha;
807
+ }
808
+ const requestResult = await makeHappoAPIRequest(
809
+ {
810
+ path: `/api/snap-requests?payloadHash=${item.payloadHash}`,
811
+ method: "POST",
812
+ formData
813
+ },
814
+ config,
815
+ { retryCount: 5 }
816
+ );
817
+ if (!requestResult) {
818
+ throw new Error("No requestResult");
819
+ }
820
+ if (!("requestId" in requestResult)) {
821
+ throw new Error("No requestId in requestResult");
822
+ }
823
+ if (typeof requestResult.requestId !== "number") {
824
+ throw new TypeError("requestId is not a number");
825
+ }
826
+ return requestResult.requestId;
827
+ }
732
828
  var RemoteBrowserTarget = class {
733
829
  chunks;
734
830
  browserName;
@@ -767,73 +863,30 @@ var RemoteBrowserTarget = class {
767
863
  targetName,
768
864
  estimatedSnapsCount
769
865
  }, config) {
770
- const boundMakeRequest = async ({
771
- slice,
772
- chunk,
773
- pageSlice
774
- }) => {
775
- const payloadString = JSON.stringify({
776
- viewport: this.viewport,
777
- maxHeight: this.maxHeight,
778
- ...this.otherOptions,
779
- globalCSS,
780
- snapPayloads: slice,
781
- chunk,
782
- staticPackage,
783
- assetsPackage,
784
- pages: pageSlice,
785
- extendsSha: pageSlice ? pageSlice.extendsSha : void 0
786
- });
787
- const payloadHash = createHash(
788
- payloadString + (pageSlice ? Math.random() : "")
789
- );
790
- const formData = {
791
- type: pageSlice && pageSlice.extendsSha ? "extends-report" : `browser-${this.browserName}`,
792
- targetName,
793
- payloadHash,
794
- payload: new File([payloadString], "payload.json", {
795
- type: "application/json"
796
- })
797
- };
798
- if (pageSlice && pageSlice.extendsSha) {
799
- formData.extendsSha = pageSlice.extendsSha;
800
- }
801
- const requestResult = await makeHappoAPIRequest(
802
- {
803
- path: `/api/snap-requests?payloadHash=${payloadHash}`,
804
- method: "POST",
805
- json: true,
806
- formData
807
- },
808
- config,
809
- { retryCount: 5 }
810
- );
811
- if (!requestResult) {
812
- throw new Error("No requestResult");
813
- }
814
- if (!("requestId" in requestResult)) {
815
- throw new Error("No requestId in requestResult");
816
- }
817
- if (typeof requestResult.requestId !== "number") {
818
- throw new TypeError("requestId is not a number");
819
- }
820
- return requestResult.requestId;
866
+ const buildItemParams = {
867
+ browserName: this.browserName,
868
+ viewport: this.viewport,
869
+ maxHeight: this.maxHeight,
870
+ otherOptions: this.otherOptions,
871
+ globalCSS,
872
+ staticPackage,
873
+ assetsPackage,
874
+ targetName
821
875
  };
822
- const requestIds = [];
876
+ const items = [];
823
877
  if (staticPackage) {
824
878
  const effectiveChunks = this.chunks ?? Math.max(1, computeDefaultChunks(estimatedSnapsCount ?? 0));
825
879
  for (let i = 0; i < effectiveChunks; i += 1) {
826
- const requestId = await boundMakeRequest({
827
- chunk: effectiveChunks > 1 ? { index: i, total: effectiveChunks } : void 0
828
- });
829
- requestIds.push(requestId);
880
+ items.push(
881
+ buildChunkItem({
882
+ ...buildItemParams,
883
+ chunk: effectiveChunks > 1 ? { index: i, total: effectiveChunks } : void 0
884
+ })
885
+ );
830
886
  }
831
887
  } else if (pages) {
832
888
  for (const pageSlice of getPageSlices(pages, this.chunks ?? 1)) {
833
- const requestId = await boundMakeRequest({
834
- pageSlice
835
- });
836
- requestIds.push(requestId);
889
+ items.push(buildChunkItem({ ...buildItemParams, pageSlice }));
837
890
  }
838
891
  } else {
839
892
  const effectiveChunks = this.chunks ?? 1;
@@ -843,12 +896,63 @@ var RemoteBrowserTarget = class {
843
896
  i * snapsPerChunk,
844
897
  i * snapsPerChunk + snapsPerChunk
845
898
  );
846
- const requestId = await boundMakeRequest({
847
- slice
848
- });
849
- requestIds.push(requestId);
899
+ items.push(buildChunkItem({ ...buildItemParams, slice }));
850
900
  }
851
901
  }
902
+ if (items.length === 0) {
903
+ return [];
904
+ }
905
+ try {
906
+ const requestIds2 = Array.from({
907
+ length: items.length
908
+ });
909
+ for (let batchStart = 0; batchStart < items.length; batchStart += MAX_BULK_ITEMS_PER_REQUEST) {
910
+ const batch = items.slice(
911
+ batchStart,
912
+ batchStart + MAX_BULK_ITEMS_PER_REQUEST
913
+ );
914
+ const result = await makeHappoAPIRequest(
915
+ {
916
+ path: "/api/snap-requests/bulk",
917
+ method: "POST",
918
+ body: { items: batch }
919
+ },
920
+ config,
921
+ { retryCount: 5 }
922
+ );
923
+ if (result && "results" in result && Array.isArray(result.results) && result.results.length === batch.length) {
924
+ const bulkResults = result.results;
925
+ for (const [i, r] of bulkResults.entries()) {
926
+ requestIds2[batchStart + i] = typeof r.requestId === "number" ? r.requestId : void 0;
927
+ }
928
+ } else {
929
+ throw new Error(
930
+ "Bulk snap-requests endpoint returned an unexpected payload shape; aborting to avoid duplicate snap-requests."
931
+ );
932
+ }
933
+ }
934
+ for (const [i, item] of items.entries()) {
935
+ if (requestIds2[i] === void 0) {
936
+ requestIds2[i] = await sendIndividualSnapRequest(item, config);
937
+ }
938
+ }
939
+ return requestIds2.map((id, index) => {
940
+ if (id === void 0) {
941
+ throw new Error(
942
+ `Failed to obtain snap request ID for item at index ${index}`
943
+ );
944
+ }
945
+ return id;
946
+ });
947
+ } catch (error) {
948
+ if (!(error instanceof ErrorWithStatusCode && (error.statusCode === 404 || error.statusCode === 501))) {
949
+ throw error;
950
+ }
951
+ }
952
+ const requestIds = [];
953
+ for (const item of items) {
954
+ requestIds.push(await sendIndividualSnapRequest(item, config));
955
+ }
852
956
  return requestIds;
853
957
  }
854
958
  };
@@ -868,8 +972,7 @@ async function uploadAssets(buffer, options, config) {
868
972
  const signedUrlRes = await makeHappoAPIRequest(
869
973
  {
870
974
  path: `/api/snap-requests/assets/${hash}/signed-url`,
871
- method: "GET",
872
- json: true
975
+ method: "GET"
873
976
  },
874
977
  config,
875
978
  { retryCount: 3 }
@@ -921,8 +1024,7 @@ async function uploadAssets(buffer, options, config) {
921
1024
  const finalizeRes = await makeHappoAPIRequest(
922
1025
  {
923
1026
  path: `/api/snap-requests/assets/${hash}/signed-url/finalize`,
924
- method: "POST",
925
- json: true
1027
+ method: "POST"
926
1028
  },
927
1029
  config,
928
1030
  { retryCount: 3 }
@@ -988,6 +1090,9 @@ function validateArchive(totalBytes, entries) {
988
1090
  }
989
1091
 
990
1092
  // src/utils/deterministicArchive.ts
1093
+ function normalizeEntryName(name) {
1094
+ return name.replaceAll("\\", "/");
1095
+ }
991
1096
  var FILE_CREATION_DATE = new Date(2019, 1, 8, 13, 31, 55);
992
1097
  async function resolveFilesRecursiveForDir(dirOrFile) {
993
1098
  const resolvedDirOrFile = path2.resolve(dirOrFile);
@@ -1001,7 +1106,7 @@ async function resolveFilesRecursiveForDir(dirOrFile) {
1001
1106
  if (fileType.isFile()) {
1002
1107
  const fullPath = `${fileType.parentPath}/${fileType.name}`;
1003
1108
  fileEntries.push({
1004
- name: path2.relative(resolvedDirOrFile, fullPath),
1109
+ name: normalizeEntryName(path2.relative(resolvedDirOrFile, fullPath)),
1005
1110
  stream: fs3.createReadStream(fullPath)
1006
1111
  });
1007
1112
  }
@@ -1010,7 +1115,7 @@ async function resolveFilesRecursiveForDir(dirOrFile) {
1010
1115
  }
1011
1116
  return [
1012
1117
  {
1013
- name: path2.relative(process.cwd(), resolvedDirOrFile),
1118
+ name: normalizeEntryName(path2.relative(process.cwd(), resolvedDirOrFile)),
1014
1119
  stream: fs3.createReadStream(resolvedDirOrFile)
1015
1120
  }
1016
1121
  ];
@@ -1062,11 +1167,12 @@ async function deterministicArchive(dirsAndFiles, contentToArchive = []) {
1062
1167
  }
1063
1168
  }
1064
1169
  for (const file of contentToArchiveSorted) {
1065
- if (!seenFiles.has(file.name)) {
1170
+ const normalizedName = normalizeEntryName(file.name);
1171
+ if (!seenFiles.has(normalizedName)) {
1066
1172
  const data = await contentToUint8Array(file.content);
1067
- entryDataList.push({ name: file.name, data });
1068
- entries.push({ name: file.name, size: data.length });
1069
- seenFiles.add(file.name);
1173
+ entryDataList.push({ name: normalizedName, data });
1174
+ entries.push({ name: normalizedName, size: data.length });
1175
+ seenFiles.add(normalizedName);
1070
1176
  }
1071
1177
  }
1072
1178
  entryDataList.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
@@ -1589,8 +1695,7 @@ var Controller = class {
1589
1695
  const uploadUrlResult = await makeHappoAPIRequest(
1590
1696
  {
1591
1697
  path: `/api/images/${hash}/upload-url`,
1592
- method: "GET",
1593
- json: true
1698
+ method: "GET"
1594
1699
  },
1595
1700
  this.happoConfig,
1596
1701
  { retryCount: 2 }
@@ -1616,7 +1721,6 @@ var Controller = class {
1616
1721
  {
1617
1722
  url: uploadUrl,
1618
1723
  method: "POST",
1619
- json: true,
1620
1724
  formData: {
1621
1725
  file: new File([buffer], "image.png", { type: "image/png" })
1622
1726
  }