|
19 | 19 | * |
20 | 20 | */ |
21 | 21 |
|
22 | | -/*global describe, it, expect, afterEach, awaitsFor, awaitsForDone, beforeAll, afterAll, awaits, jsPromise */ |
| 22 | +/*global describe, it, expect, afterEach, awaitsFor, awaitsForDone, beforeEach, beforeAll, afterAll, awaits, jsPromise */ |
23 | 23 |
|
24 | 24 | define(function (require, exports, module) { |
25 | 25 |
|
@@ -738,12 +738,88 @@ define(function (require, exports, module) { |
738 | 738 | beforeAll(async function () { |
739 | 739 | ProjectManager.on(ProjectManager.EVENT_PROJECT_CHANGED_OR_RENAMED_PATH, _recorderFn); |
740 | 740 | }); |
| 741 | + beforeEach(async function () { |
| 742 | + changedPath = addedSet = removedSet = null; |
| 743 | + }); |
741 | 744 | afterAll(async function () { |
742 | 745 | ProjectManager.off(ProjectManager.EVENT_PROJECT_CHANGED_OR_RENAMED_PATH, _recorderFn); |
743 | 746 | }); |
744 | 747 |
|
745 | | - it("should download project command work", async function () { |
| 748 | + it("should creating new file and deleting raise added and removed event", async function () { |
| 749 | + const createFilePath = `${tempDir}/test_add.txt`; |
| 750 | + await jsPromise(SpecRunnerUtils.createTextFile(createFilePath, "hello", FileSystem)); |
| 751 | + await awaitsFor(()=>{ |
| 752 | + return addedSet && addedSet.has(createFilePath); |
| 753 | + }, ()=>`added files [${addedSet&& Array.from(addedSet)}] to have ${createFilePath}`); |
| 754 | + changedPath = addedSet = removedSet = null; |
| 755 | + await SpecRunnerUtils.deletePathAsync(createFilePath, true, FileSystem); |
| 756 | + await awaitsFor(()=>{ |
| 757 | + return removedSet && removedSet.has(createFilePath); |
| 758 | + }, ()=>`removed files [${removedSet&& Array.from(removedSet)}] to have ${createFilePath}`); |
| 759 | + }); |
| 760 | + |
| 761 | + it("should writing on an existing file raise change event", async function () { |
| 762 | + const createFilePath = `${tempDir}/test_add.txt`; |
| 763 | + await jsPromise(SpecRunnerUtils.createTextFile(createFilePath, "hello", FileSystem)); |
| 764 | + await awaitsFor(()=>{ |
| 765 | + return addedSet && addedSet.has(createFilePath); |
| 766 | + }, ()=>`added files [${addedSet&& Array.from(addedSet)}] to have ${createFilePath}`); |
| 767 | + changedPath = addedSet = removedSet = null; |
| 768 | + await jsPromise(SpecRunnerUtils.createTextFile(createFilePath, "changed", FileSystem)); |
| 769 | + await awaitsFor(()=>{ |
| 770 | + return changedPath === createFilePath; |
| 771 | + }, ()=>`removed files [${removedSet&& Array.from(removedSet)}] to have ${createFilePath}`); |
| 772 | + await SpecRunnerUtils.deletePathAsync(createFilePath, true, FileSystem); |
| 773 | + await awaitsFor(()=>{ |
| 774 | + return removedSet && removedSet.has(createFilePath); |
| 775 | + }, ()=>`removed files [${removedSet&& Array.from(removedSet)}] to have ${createFilePath}`); |
| 776 | + }); |
746 | 777 |
|
| 778 | + it("should creating new directory and deleting raise added and removed event", async function () { |
| 779 | + const createDirPath = `${tempDir}/newDir_event_test`; |
| 780 | + await SpecRunnerUtils.ensureExistsDirAsync(createDirPath, "hello", FileSystem); |
| 781 | + await awaitsFor(()=>{ |
| 782 | + return addedSet && addedSet.has(createDirPath); |
| 783 | + }, ()=>`added dir [${addedSet&& Array.from(addedSet)}] to have ${createDirPath}`); |
| 784 | + changedPath = addedSet = removedSet = null; |
| 785 | + await SpecRunnerUtils.deletePathAsync(createDirPath, true, FileSystem); |
| 786 | + await awaitsFor(()=>{ |
| 787 | + return removedSet && removedSet.has(createDirPath); |
| 788 | + }, ()=>`removed dir [${removedSet&& Array.from(removedSet)}] to have ${createDirPath}`); |
| 789 | + }); |
| 790 | + |
| 791 | + it("should renaming file in same dir raise added and removed event", async function () { |
| 792 | + const createFilePath = `${tempDir}/test_add1.txt`; |
| 793 | + const renamedFilePath = `${tempDir}/rename_1.txt`; |
| 794 | + await jsPromise(SpecRunnerUtils.createTextFile(createFilePath, "hello", FileSystem)); |
| 795 | + await awaitsFor(()=>{ |
| 796 | + return addedSet && addedSet.has(createFilePath); |
| 797 | + }, ()=>`added files [${addedSet&& Array.from(addedSet)}] to have ${createFilePath}`); |
| 798 | + changedPath = addedSet = removedSet = null; |
| 799 | + await jsPromise(SpecRunnerUtils.rename(createFilePath, renamedFilePath)); |
| 800 | + await awaitsFor(()=>{ |
| 801 | + return removedSet && removedSet.has(createFilePath) && addedSet && addedSet.has(renamedFilePath); |
| 802 | + }, ()=> |
| 803 | + `removed files [${removedSet&& Array.from(removedSet)}] to have ${createFilePath}` + |
| 804 | + `added files [${addedSet&& Array.from(addedSet)}] to have ${renamedFilePath}`); |
| 805 | + await SpecRunnerUtils.deletePathAsync(renamedFilePath, true, FileSystem); |
| 806 | + }); |
| 807 | + |
| 808 | + it("should renaming dir in same dir raise added and removed event", async function () { |
| 809 | + const createDirPath = `${tempDir}/dir_event_Rename`; |
| 810 | + const renamedDirPath = `${tempDir}/dir_event_Rename_done`; |
| 811 | + await SpecRunnerUtils.ensureExistsDirAsync(createDirPath, "hello", FileSystem); |
| 812 | + await awaitsFor(()=>{ |
| 813 | + return addedSet && addedSet.has(createDirPath); |
| 814 | + }, ()=>`added dir [${addedSet&& Array.from(addedSet)}] to have ${createDirPath}`); |
| 815 | + changedPath = addedSet = removedSet = null; |
| 816 | + await jsPromise(SpecRunnerUtils.rename(createDirPath, renamedDirPath)); |
| 817 | + await awaitsFor(()=>{ |
| 818 | + return removedSet && removedSet.has(createDirPath) && addedSet && addedSet.has(renamedDirPath); |
| 819 | + }, ()=> |
| 820 | + `removed dir [${removedSet&& Array.from(removedSet)}] to have ${createDirPath}` + |
| 821 | + `added dir [${addedSet&& Array.from(addedSet)}] to have ${renamedDirPath}`); |
| 822 | + await SpecRunnerUtils.deletePathAsync(renamedDirPath, true, FileSystem); |
747 | 823 | }); |
748 | 824 | }); |
749 | 825 |
|
|
0 commit comments