@jsenv/snapshot 2.7.3 → 2.7.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/snapshot",
3
- "version": "2.7.3",
3
+ "version": "2.7.4",
4
4
  "description": "Snapshot testing",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -47,6 +47,18 @@ export const replaceFluctuatingValues = (
47
47
  );
48
48
  return value;
49
49
  };
50
+ const replaceSizes = (value) => {
51
+ // the size of files might slighly differ from an OS to an other
52
+ // we round the floats to make them predictable
53
+ // (happens for HTML files where one char is added on linux)
54
+ value = value.replace(
55
+ /(?<!\d|\.)(\d+(?:\.\d+)?)(\s*)(B|kB|MB)\b/g,
56
+ (match, size, space, unit) => {
57
+ return `${Math.round(parseFloat(size))}${space}${unit}`;
58
+ },
59
+ );
60
+ return value;
61
+ };
50
62
  const replaceThings = (value) => {
51
63
  if (stringType === "filesystem") {
52
64
  return replaceFilesystemWellKnownValues(value);
@@ -59,6 +71,7 @@ export const replaceFluctuatingValues = (
59
71
  });
60
72
  value = replaceHttpUrls(value);
61
73
  value = replaceDurations(value);
74
+ value = replaceSizes(value);
62
75
  return value;
63
76
  };
64
77
  if (stringType === "html" || stringType === "svg") {