@jsenv/snapshot 2.7.2 → 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.2",
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") {
@@ -45,12 +45,20 @@ export const snapshotTests = async (
45
45
  sideEffectFileUrl = new URL(sideEffectFileUrl, testFileUrl);
46
46
  }
47
47
 
48
+ const dirUrlMap = new Map();
49
+ const sideEffectsMap = new Map();
48
50
  const testMap = new Map();
49
51
  const onlyTestMap = new Map();
50
52
  const test = (scenario, fn, options) => {
53
+ if (testMap.has(scenario) || onlyTestMap.has(scenario)) {
54
+ console.warn(`test override "${scenario}"`);
55
+ }
51
56
  testMap.set(scenario, { fn, options, callSite: getCallerLocation(2) });
52
57
  };
53
58
  test.ONLY = (scenario, fn, options) => {
59
+ if (testMap.has(scenario) || onlyTestMap.has(scenario)) {
60
+ console.warn(`test override "${scenario}"`);
61
+ }
54
62
  onlyTestMap.set(scenario, { fn, options, callSite: getCallerLocation(2) });
55
63
  };
56
64
  fnRegisteringTest({ test });
@@ -89,6 +97,7 @@ export const snapshotTests = async (
89
97
  callSite: linkToEachSource ? callSite : undefined,
90
98
  baseDirectory: String(new URL("./", callSite.url)),
91
99
  });
100
+ sideEffectsMap.set(scenario, sideEffects);
92
101
  const testScenario = asValidFilename(scenario);
93
102
  let outDirectoryRelativeUrl = outDirectoryPattern
94
103
  .replaceAll("[test_name]", testName)
@@ -109,6 +118,8 @@ export const snapshotTests = async (
109
118
  const outFileUrl = new URL(outFileRelativeUrl, testFileUrl).href;
110
119
  return outFileUrl;
111
120
  };
121
+ const outFileDirectoryUrl = generateOutFileUrl("");
122
+ dirUrlMap.set(scenario, outFileDirectoryUrl);
112
123
  const sideEffectsMarkdown = renderSideEffects(sideEffects, {
113
124
  sideEffectFileUrl,
114
125
  outDirectoryUrl,
@@ -125,6 +136,8 @@ export const snapshotTests = async (
125
136
  mockFluctuatingValues: false,
126
137
  throwWhenDiff,
127
138
  });
139
+
140
+ return { dirUrlMap, sideEffectsMap };
128
141
  };
129
142
 
130
143
  const generateExecutingLink = (sourceFileUrl, sideEffectFileUrl) => {