Skip to content

Commit

Permalink
Fix README written to wrong location when revisions are enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
personalizedrefrigerator committed Feb 17, 2024
1 parent b779203 commit a3e46fb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
53 changes: 28 additions & 25 deletions __test__/backup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ describe("Backup", function () {
when(spyOnsSettingsValue)
.mockImplementation(() => Promise.resolve("no mockImplementation"))
.calledWith("fileLogLevel").mockImplementation(() => Promise.resolve("error"))
.calledWith("path").mockImplementation(() => Promise.resolve(testPath.backupBasePath));
.calledWith("path").mockImplementation(() => Promise.resolve(testPath.backupBasePath))
.calledWith("zipArchive").mockImplementation(() => "no")
.calledWith("execFinishCmd").mockImplementation(() => "")
.calledWith("usePassword").mockImplementation(() => false);

/* prettier-ignore */
when(spyOnGlobalValue)
Expand Down Expand Up @@ -1025,30 +1028,30 @@ describe("Backup", function () {
});

describe("create backup readme", () => {
it("should create a README.md in the backup directory", async () => {
backup.backupStartTime = null;
backup.passwordEnabled = false;

when(spyOnsSettingsValue)
.calledWith("zipArchive")
.mockImplementation(() => "no");
when(spyOnsSettingsValue)
.calledWith("execFinishCmd")
.mockImplementation(() => "");

await backup.start();

// Should exist and be non-empty
const readmePath = path.join(
testPath.backupBasePath,
"JoplinBackup",
"README.md"
);
expect(await fs.pathExists(readmePath)).toBe(true);
expect(await fs.readFile(readmePath, "utf8")).not.toBe("");
it.each([{ backupRetention: 1 }, { backupRetention: 2 }])(
"should create a README.md in the backup directory (case %#)",
async ({ backupRetention }) => {
when(spyOnsSettingsValue)
.calledWith("backupRetention")
.mockImplementation(async () => backupRetention)
.calledWith("backupInfo")
.mockImplementation(() => Promise.resolve("[]"));

backup.backupStartTime = null;
await backup.start();

// Should exist and be non-empty
const readmePath = path.join(
testPath.backupBasePath,
"JoplinBackup",
"README.md"
);
expect(await fs.pathExists(readmePath)).toBe(true);
expect(await fs.readFile(readmePath, "utf8")).not.toBe("");

// Prevent "open handle" errors
backup.stopTimer();
});
// Prevent "open handle" errors
backup.stopTimer();
}
);
});
});
2 changes: 1 addition & 1 deletion src/Backup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,8 @@ class Backup {
await this.backupNotebooks();

const backupDst = await this.makeBackupSet();
await this.writeReadme(backupDst);

await this.writeReadme(this.backupBasePath);
await joplin.settings.setValue(
"lastBackup",
this.backupStartTime.getTime()
Expand Down

0 comments on commit a3e46fb

Please sign in to comment.