Skip to content

Commit d43eb8d

Browse files
committed
we don't even need to check the internal state of vitest
Rationale: if we need to regenerate the snapshots (vitest -u aor interactively), it's not to overcome the platform issues. For that you just have to rm all the files and start fresh…
1 parent e3811f6 commit d43eb8d

1 file changed

Lines changed: 11 additions & 14 deletions

File tree

test/plot.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,22 +106,19 @@ const imageRe = /data:image\/png;base64,[^"]+/g;
106106
// This lets toMatchFileSnapshot's exact comparison pass despite platform
107107
// differences in PNG encoding.
108108
async function withImages(html, outfile) {
109-
const updating = expect.getState().snapshotState["_updateSnapshot"] === "all";
110-
if (!updating) {
111-
try {
112-
const expected = await readFile(outfile, "utf8");
113-
const actualImages = Array.from(html.matchAll(imageRe), (m) => m[0]);
114-
const expectedImages = Array.from(expected.matchAll(imageRe), (m) => m[0]);
115-
if (actualImages.length !== expectedImages.length)
116-
throw new Error(`Expected ${expectedImages.length} images, got ${actualImages.length}`);
117-
for (let i = 0; i < actualImages.length; ++i) {
118-
if (actualImages[i] !== expectedImages[i] && (await compareImage(actualImages[i], expectedImages[i]))) {
119-
html = html.replace(actualImages[i], expectedImages[i]);
120-
}
109+
try {
110+
const expected = await readFile(outfile, "utf8");
111+
const actualImages = Array.from(html.matchAll(imageRe), (m) => m[0]);
112+
const expectedImages = Array.from(expected.matchAll(imageRe), (m) => m[0]);
113+
if (actualImages.length !== expectedImages.length)
114+
throw new Error(`Expected ${expectedImages.length} images, got ${actualImages.length}`);
115+
for (let i = 0; i < actualImages.length; ++i) {
116+
if (actualImages[i] !== expectedImages[i] && (await compareImage(actualImages[i], expectedImages[i]))) {
117+
html = html.replace(actualImages[i], expectedImages[i]);
121118
}
122-
} catch (error) {
123-
if (error.code !== "ENOENT") throw error;
124119
}
120+
} catch (error) {
121+
if (error.code !== "ENOENT") throw error;
125122
}
126123
return html;
127124
}

0 commit comments

Comments
 (0)