Skip to content

Commit 724624f

Browse files
Improved support for detecting changes and undoing them while testing
1 parent e2020cf commit 724624f

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

test/utils.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,17 @@ async function getArchive(folderPath) {
3030
const packNext = await archive.getPack();
3131
const changed = [];
3232
for (const fileName in packPrev) {
33+
if (fileName.includes(".prettier-caches")) continue;
3334
const filePrev = packPrev[fileName];
3435
const fileNext = packNext[fileName];
3536
if (filePrev.contents === fileNext.contents) continue;
3637
changed.push(fileName);
3738
}
39+
for (const fileName in packNext) {
40+
if (fileName.includes(".prettier-caches")) continue;
41+
if (packPrev[fileName]) continue;
42+
changed.push(fileName);
43+
}
3844
return changed;
3945
}),
4046
getDiff: async () => {
@@ -55,7 +61,11 @@ async function getArchive(folderPath) {
5561
for (const fileName of changed) {
5662
const filePath = path.join(folderPath, fileName);
5763
const filePrev = packPrev[fileName];
58-
await fs.writeFile(filePath, filePrev.contents, filePrev.encoding);
64+
if (filePrev) {
65+
await fs.writeFile(filePath, filePrev.contents, filePrev.encoding);
66+
} else {
67+
await fs.rm(filePath);
68+
}
5969
}
6070
},
6171
};

0 commit comments

Comments
 (0)