joplin-plugin-backup 1.1.0 → 1.1.1

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/README.md CHANGED
@@ -33,7 +33,7 @@ Go to `Tools > Options > Backup`
33
33
 
34
34
  | Option | Description | Default |
35
35
  | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------- |
36
- | `Backup path` | Where to save the backups to. <br>This path is exclusive for the Joplin backups, there should be no other data in it! | |
36
+ | `Backup path` | Where to save the backups to. <br>This path is exclusive for the Joplin backups, there should be no other data in it when you disable the `Create Subfolder` settings! | |
37
37
  | `Keep x backups` | How many backups should be kept | `1` |
38
38
  | `Backups interval in hours` | Create a backup every X hours | `24` |
39
39
  | `Only on change` | Creates a backup at the specified backup interval only if there was a change to a `note`, `tag`, `resource` or `notebook` | `false` |
@@ -15,6 +15,7 @@ function getTestPaths(): any {
15
15
  );
16
16
  testPath.joplinProfile = path.join(testPath.base, "joplin-desktop");
17
17
  testPath.templates = path.join(testPath.joplinProfile, "templates");
18
+ testPath.plugins = path.join(testPath.joplinProfile, "plugins");
18
19
  return testPath;
19
20
  }
20
21
 
@@ -39,6 +40,7 @@ async function createTestStructure() {
39
40
  fs.emptyDirSync(test.backupBasePath);
40
41
  fs.emptyDirSync(test.joplinProfile);
41
42
  fs.emptyDirSync(test.templates);
43
+ fs.emptyDirSync(test.plugins);
42
44
  }
43
45
 
44
46
  const testPath = getTestPaths();
@@ -573,6 +575,45 @@ describe("Backup", function () {
573
575
  });
574
576
 
575
577
  describe("Backup retention", function () {
578
+ it(`file/Folder deletion`, async () => {
579
+ const backupRetention = 2;
580
+ const set1 = path.join(testPath.backupBasePath, "202101011630");
581
+ const set2 = path.join(testPath.backupBasePath, "202101021630.7z");
582
+ const set3 = path.join(testPath.backupBasePath, "202101031630");
583
+ const set4 = path.join(testPath.backupBasePath, "202101041630.7z");
584
+
585
+ fs.emptyDirSync(set1);
586
+ fs.closeSync(fs.openSync(set2, "w"));
587
+ fs.emptyDirSync(set3);
588
+ fs.closeSync(fs.openSync(set4, "w"));
589
+
590
+ const backupInfo = [
591
+ { name: "202101011630", date: 1609515000 },
592
+ { name: "202101021630.7z", date: 1609601400 },
593
+ { name: "202101031630", date: 1609687800 },
594
+ { name: "202101041630.7z", date: 1609774200 },
595
+ ];
596
+
597
+ when(spyOnsSettingsValue)
598
+ .calledWith("backupInfo")
599
+ .mockImplementation(() => Promise.resolve(JSON.stringify(backupInfo)));
600
+
601
+ expect(fs.existsSync(set1)).toBe(true);
602
+ expect(fs.existsSync(set2)).toBe(true);
603
+ expect(fs.existsSync(set3)).toBe(true);
604
+ expect(fs.existsSync(set4)).toBe(true);
605
+ await backup.deleteOldBackupSets(
606
+ testPath.backupBasePath,
607
+ backupRetention
608
+ );
609
+
610
+ expect(fs.existsSync(set1)).toBe(false);
611
+ expect(fs.existsSync(set2)).toBe(false);
612
+ expect(fs.existsSync(set3)).toBe(true);
613
+ expect(fs.existsSync(set4)).toBe(true);
614
+ expect(fs.readdirSync(testPath.backupBasePath).length).toBe(2);
615
+ });
616
+
576
617
  it(`Backups < retention`, async () => {
577
618
  const backupRetention = 3;
578
619
  const folder1 = path.join(testPath.backupBasePath, "202101011630");
@@ -585,11 +626,15 @@ describe("Backup", function () {
585
626
  { name: "202101011630", date: 1 },
586
627
  { name: "202101021630", date: 2 },
587
628
  ];
588
- /* prettier-ignore */
629
+
589
630
  when(spyOnsSettingsValue)
590
- .calledWith("backupInfo").mockImplementation(() => Promise.resolve(JSON.stringify(backupInfo)));
631
+ .calledWith("backupInfo")
632
+ .mockImplementation(() => Promise.resolve(JSON.stringify(backupInfo)));
591
633
 
592
- backup.deleteOldBackupSets(testPath.backupBasePath, backupRetention);
634
+ await backup.deleteOldBackupSets(
635
+ testPath.backupBasePath,
636
+ backupRetention
637
+ );
593
638
 
594
639
  const folderAnz = fs
595
640
  .readdirSync(testPath.backupBasePath, { withFileTypes: true })
@@ -616,11 +661,15 @@ describe("Backup", function () {
616
661
  { name: "202101021630", date: 2 },
617
662
  { name: "202101031630", date: 3 },
618
663
  ];
619
- /* prettier-ignore */
664
+
620
665
  when(spyOnsSettingsValue)
621
- .calledWith("backupInfo").mockImplementation(() => Promise.resolve(JSON.stringify(backupInfo)));
666
+ .calledWith("backupInfo")
667
+ .mockImplementation(() => Promise.resolve(JSON.stringify(backupInfo)));
622
668
 
623
- backup.deleteOldBackupSets(testPath.backupBasePath, backupRetention);
669
+ await backup.deleteOldBackupSets(
670
+ testPath.backupBasePath,
671
+ backupRetention
672
+ );
624
673
  const folderAnz = fs
625
674
  .readdirSync(testPath.backupBasePath, { withFileTypes: true })
626
675
  .filter((dirent) => dirent.isDirectory()).length;
@@ -653,9 +702,10 @@ describe("Backup", function () {
653
702
  { name: "202101041630", date: 4 },
654
703
  { name: "202101051630", date: 5 },
655
704
  ];
656
- /* prettier-ignore */
705
+
657
706
  when(spyOnsSettingsValue)
658
- .calledWith("backupInfo").mockImplementation(() => Promise.resolve(JSON.stringify(backupInfo)));
707
+ .calledWith("backupInfo")
708
+ .mockImplementation(() => Promise.resolve(JSON.stringify(backupInfo)));
659
709
 
660
710
  await backup.deleteOldBackupSets(
661
711
  testPath.backupBasePath,
@@ -835,12 +885,14 @@ describe("Backup", function () {
835
885
  const userstyle = path.join(testPath.joplinProfile, "userstyle.css");
836
886
  const userchrome = path.join(testPath.joplinProfile, "userchrome.css");
837
887
  const keymap = path.join(testPath.joplinProfile, "keymap-desktop.json");
888
+ const plugin = path.join(testPath.plugins, "test-plugin.jpl");
838
889
 
839
890
  fs.writeFileSync(template, "template");
840
891
  fs.writeFileSync(settings, "settings");
841
892
  fs.writeFileSync(userstyle, "userstyle");
842
893
  fs.writeFileSync(userchrome, "userchrome");
843
894
  fs.writeFileSync(keymap, "keymap");
895
+ fs.writeFileSync(plugin, "plugin");
844
896
 
845
897
  fs.emptyDirSync(testPath.activeBackupJob);
846
898
 
@@ -870,8 +922,15 @@ describe("Backup", function () {
870
922
  "profile",
871
923
  "keymap-desktop.json"
872
924
  );
925
+ const backupPlugin = path.join(
926
+ testPath.activeBackupJob,
927
+ "profile",
928
+ "plugins",
929
+ "test-plugin.jpl"
930
+ );
873
931
 
874
932
  backup.activeBackupPath = testPath.activeBackupJob;
933
+ backup.backupPlugins = true;
875
934
  await backup.backupProfileData();
876
935
 
877
936
  expect(fs.existsSync(backupTemplate)).toBe(true);
@@ -879,6 +938,7 @@ describe("Backup", function () {
879
938
  expect(fs.existsSync(backupUserstyle)).toBe(true);
880
939
  expect(fs.existsSync(backupUserchrome)).toBe(true);
881
940
  expect(fs.existsSync(backupKeymap)).toBe(true);
941
+ expect(fs.existsSync(backupPlugin)).toBe(true);
882
942
 
883
943
  expect(backup.log.error).toHaveBeenCalledTimes(0);
884
944
  expect(backup.log.warn).toHaveBeenCalledTimes(0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "joplin-plugin-backup",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "scripts": {
5
5
  "dist": "webpack --joplin-plugin-config buildMain && webpack --joplin-plugin-config buildExtraScripts && webpack --joplin-plugin-config createArchive",
6
6
  "prepare": "npm run dist && husky install",
@@ -2,7 +2,7 @@
2
2
  "manifest_version": 1,
3
3
  "id": "io.github.jackgruber.backup",
4
4
  "app_min_version": "2.1.3",
5
- "version": "1.1.0",
5
+ "version": "1.1.1",
6
6
  "name": "Simple Backup",
7
7
  "description": "Plugin to create manual and automatic backups.",
8
8
  "author": "JackGruber",
@@ -16,6 +16,6 @@
16
16
  "7zip",
17
17
  "encrypted"
18
18
  ],
19
- "_publish_hash": "sha256:8d8c6a3bb92fafc587269aea58b623b05242d42c0766a05bbe25c3ba2bbdf8ee",
20
- "_publish_commit": "master:00ed52133c659e0f3ac1a55f70b776c42fca0a6d"
19
+ "_publish_hash": "sha256:616b034ec484e83bf972adab454c9c00d23d9bd0b21574beba7915e42ff7415a",
20
+ "_publish_commit": "master:98221472e60f34026ac739368c2831193f564654"
21
21
  }