release: v0.20.0

This commit is contained in:
Ralksta
2026-10-02 18:14:23 +02:00
committed by GitHub
parent 81ce886b01
commit 5f831f719a
209 changed files with 13807 additions and 803 deletions

View File

@@ -11,7 +11,9 @@ vi.mock('fs/promises', () => ({
unlink: vi.fn(async () => undefined),
writeFile: vi.fn(async () => undefined),
rename: vi.fn(async () => undefined),
readFile: vi.fn(),
readFile: vi.fn(async () => {
throw Object.assign(new Error('ENOENT'), { code: 'ENOENT' });
}),
},
}));
@@ -95,7 +97,7 @@ describe('writeYamlFile backup failure', () => {
});
it('aborts the save when the file exists but the backup copy fails', async () => {
vi.mocked(fs.access).mockResolvedValueOnce(undefined);
vi.mocked(fs.readFile).mockResolvedValueOnce(Buffer.from('albums: []\n'));
vi.mocked(fs.copyFile).mockRejectedValueOnce(
Object.assign(new Error('EACCES'), { code: 'EACCES' }),
);
@@ -105,7 +107,7 @@ describe('writeYamlFile backup failure', () => {
});
it('aborts when checking whether the file exists fails for a reason other than ENOENT', async () => {
vi.mocked(fs.access).mockRejectedValueOnce(
vi.mocked(fs.readFile).mockRejectedValueOnce(
Object.assign(new Error('EACCES'), { code: 'EACCES' }),
);
@@ -113,3 +115,24 @@ describe('writeYamlFile backup failure', () => {
expect(fs.writeFile).not.toHaveBeenCalled();
});
});
/**
* A save that changes nothing used to snapshot anyway; with ten backups kept,
* a few of those pushed the real ones out (QA A-19).
*/
describe('writeYamlFile no-op save', () => {
beforeEach(() => vi.clearAllMocks());
it('takes no backup when the file already holds exactly these bytes', async () => {
await writeGalleryYaml(gallery);
const written = vi.mocked(fs.writeFile).mock.calls[0][1] as string;
vi.mocked(fs.readFile).mockResolvedValueOnce(Buffer.from(written));
await writeGalleryYaml(gallery);
expect(fs.copyFile).not.toHaveBeenCalled();
vi.mocked(fs.readFile).mockResolvedValueOnce(Buffer.from(written + '# edited\n'));
await writeGalleryYaml(gallery);
expect(fs.copyFile).toHaveBeenCalledTimes(1);
});
});