@jsenv/snapshot 1.2.7 → 1.2.8
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 +2 -2
- package/src/file_snapshots.js +35 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/snapshot",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.8",
|
|
4
4
|
"description": "Snapshot testing",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@jsenv/filesystem": "4.6.5",
|
|
39
39
|
"@jsenv/urls": "2.2.3",
|
|
40
40
|
"@jsenv/utils": "2.1.1",
|
|
41
|
-
"@jsenv/assert": "3.0.
|
|
41
|
+
"@jsenv/assert": "3.0.3",
|
|
42
42
|
"prettier": "3.2.4"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
package/src/file_snapshots.js
CHANGED
|
@@ -13,7 +13,7 @@ import { urlToFilename, urlToRelativeUrl } from "@jsenv/urls";
|
|
|
13
13
|
import { CONTENT_TYPE } from "@jsenv/utils/src/content_type/content_type.js";
|
|
14
14
|
|
|
15
15
|
import { assert } from "@jsenv/assert";
|
|
16
|
-
import {
|
|
16
|
+
import { getStringAssertionErrorInfo } from "@jsenv/assert/src/error_info/strings.js";
|
|
17
17
|
|
|
18
18
|
export const takeFileSnapshot = (fileUrl) => {
|
|
19
19
|
fileUrl = assertAndNormalizeFileUrl(fileUrl);
|
|
@@ -83,11 +83,14 @@ const compareFileSnapshots = (actualFileSnapshot, expectedFileSnapshot) => {
|
|
|
83
83
|
const failureMessage = `snapshot comparison failed for "${filename}"`;
|
|
84
84
|
|
|
85
85
|
if (!actualFileSnapshot.stat) {
|
|
86
|
-
|
|
86
|
+
const fileNotFoundAssertionError =
|
|
87
|
+
assert.createAssertionError(`${failureMessage}
|
|
87
88
|
--- reason ---
|
|
88
89
|
file not found
|
|
89
90
|
--- file ---
|
|
90
91
|
${fileUrl}`);
|
|
92
|
+
fileNotFoundAssertionError.name = "FileNotFoundAssertionError";
|
|
93
|
+
throw fileNotFoundAssertionError;
|
|
91
94
|
}
|
|
92
95
|
if (!expectedFileSnapshot.stat) {
|
|
93
96
|
return;
|
|
@@ -98,26 +101,32 @@ ${fileUrl}`);
|
|
|
98
101
|
if (actualFileContent.equals(expectedFileContent)) {
|
|
99
102
|
return;
|
|
100
103
|
}
|
|
101
|
-
|
|
104
|
+
const fileContentAssertionError =
|
|
105
|
+
assert.createAssertionError(`${failureMessage}
|
|
102
106
|
--- reason ---
|
|
103
107
|
content has changed
|
|
104
108
|
--- file ---
|
|
105
109
|
${fileUrl}`);
|
|
110
|
+
fileContentAssertionError.name = "FileContentAssertionError";
|
|
111
|
+
throw fileContentAssertionError;
|
|
106
112
|
}
|
|
107
113
|
if (actualFileContent === expectedFileContent) {
|
|
108
114
|
return;
|
|
109
115
|
}
|
|
110
|
-
const
|
|
116
|
+
const errorInfo = getStringAssertionErrorInfo({
|
|
111
117
|
actual: actualFileContent,
|
|
112
118
|
expected: expectedFileContent,
|
|
113
119
|
name: `file content`,
|
|
114
120
|
format: assert.format,
|
|
115
121
|
});
|
|
116
|
-
|
|
122
|
+
const fileContentStringAssertionError =
|
|
123
|
+
assert.createAssertionError(`${failureMessage}
|
|
117
124
|
--- reason ---
|
|
118
|
-
${message}
|
|
125
|
+
${errorInfo.message}
|
|
119
126
|
--- file ---
|
|
120
127
|
${fileUrl}`);
|
|
128
|
+
fileContentStringAssertionError.name = errorInfo.type;
|
|
129
|
+
throw fileContentStringAssertionError;
|
|
121
130
|
};
|
|
122
131
|
|
|
123
132
|
export const takeDirectorySnapshot = (directoryUrl) => {
|
|
@@ -159,17 +168,23 @@ export const takeDirectorySnapshot = (directoryUrl) => {
|
|
|
159
168
|
(relativeUrl) => new URL(relativeUrl, directoryUrl).href,
|
|
160
169
|
);
|
|
161
170
|
if (missingFileCount === 1) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
171
|
+
const fileMissingAssertionError =
|
|
172
|
+
assert.createAssertionError(`${failureMessage}
|
|
173
|
+
--- reason ---
|
|
174
|
+
"${missingRelativeUrls[0]}" is missing
|
|
175
|
+
--- file missing ---
|
|
176
|
+
${missingUrls[0]}`);
|
|
177
|
+
fileMissingAssertionError.name = "FileMissingAssertionError";
|
|
178
|
+
throw fileMissingAssertionError;
|
|
167
179
|
}
|
|
168
|
-
|
|
180
|
+
const fileMissingAssertionError =
|
|
181
|
+
assert.createAssertionError(`${failureMessage}
|
|
169
182
|
--- reason ---
|
|
170
183
|
${missingFileCount} files are missing
|
|
171
184
|
--- files missing ---
|
|
172
185
|
${missingUrls.join("\n")}`);
|
|
186
|
+
fileMissingAssertionError.name = "FileMissingAssertionError";
|
|
187
|
+
throw fileMissingAssertionError;
|
|
173
188
|
}
|
|
174
189
|
}
|
|
175
190
|
|
|
@@ -185,17 +200,23 @@ ${missingUrls.join("\n")}`);
|
|
|
185
200
|
(relativeUrl) => new URL(relativeUrl, directoryUrl).href,
|
|
186
201
|
);
|
|
187
202
|
if (extraFileCount === 1) {
|
|
188
|
-
|
|
203
|
+
const extraFileAssertionError =
|
|
204
|
+
assert.createAssertionError(`${failureMessage}
|
|
189
205
|
--- reason ---
|
|
190
206
|
"${extraRelativeUrls[0]}" is unexpected
|
|
191
207
|
--- file unexpected ---
|
|
192
208
|
${extraUrls[0]}`);
|
|
209
|
+
extraFileAssertionError.name = "ExtraFileAssertionError";
|
|
210
|
+
throw extraFileAssertionError;
|
|
193
211
|
}
|
|
194
|
-
|
|
212
|
+
const extraFileAssertionError =
|
|
213
|
+
assert.createAssertionError(`${failureMessage}
|
|
195
214
|
--- reason ---
|
|
196
215
|
${extraFileCount} files are unexpected
|
|
197
216
|
--- files unexpected ---
|
|
198
217
|
${extraUrls.join("\n")}`);
|
|
218
|
+
extraFileAssertionError.name = "ExtraFileAssertionError";
|
|
219
|
+
throw extraFileAssertionError;
|
|
199
220
|
}
|
|
200
221
|
}
|
|
201
222
|
|