Skip to content

Commit ae106ff

Browse files
committed
test: integ test for ProjectManager.EVENT_PROJECT_CHANGED_OR_RENAMED_PATH
1 parent 6ff798f commit ae106ff

File tree

1 file changed

+78
-2
lines changed

1 file changed

+78
-2
lines changed

test/spec/ProjectManager-integ-test.js

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*
2020
*/
2121

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 */
2323

2424
define(function (require, exports, module) {
2525

@@ -738,12 +738,88 @@ define(function (require, exports, module) {
738738
beforeAll(async function () {
739739
ProjectManager.on(ProjectManager.EVENT_PROJECT_CHANGED_OR_RENAMED_PATH, _recorderFn);
740740
});
741+
beforeEach(async function () {
742+
changedPath = addedSet = removedSet = null;
743+
});
741744
afterAll(async function () {
742745
ProjectManager.off(ProjectManager.EVENT_PROJECT_CHANGED_OR_RENAMED_PATH, _recorderFn);
743746
});
744747

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+
});
746777

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);
747823
});
748824
});
749825

0 commit comments

Comments
 (0)