Skip to content

Commit 2244c34

Browse files
committed
fix: project manager integ tests fails
1 parent 56e3771 commit 2244c34

File tree

1 file changed

+36
-13
lines changed

1 file changed

+36
-13
lines changed

test/spec/ProjectManager-integ-test.js

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -729,17 +729,25 @@ define(function (require, exports, module) {
729729
// }, 10000);
730730

731731
describe("Project file/folder watch events", function () {
732-
let changedPath, addedSet, removedSet;
732+
let changedPathSet = new Set(),
733+
addedSet = new Set(),
734+
removedSet = new Set(), callCount = 0;
733735
function _recorderFn(_evt, _changedPath, _addedSet, _removedSet) {
734-
changedPath= _changedPath;
735-
addedSet = _addedSet;
736-
removedSet = _removedSet;
736+
callCount++;
737+
if(_changedPath){
738+
changedPathSet.add(_changedPath);
739+
}
740+
addedSet = new Set([...Array.from(addedSet), ...Array.from(_addedSet)]);
741+
removedSet = new Set([...Array.from(removedSet), ...Array.from(_removedSet)]);
737742
}
738743
beforeAll(async function () {
739744
ProjectManager.on(ProjectManager.EVENT_PROJECT_CHANGED_OR_RENAMED_PATH, _recorderFn);
740745
});
741746
beforeEach(async function () {
742-
changedPath = addedSet = removedSet = null;
747+
changedPathSet = new Set();
748+
addedSet = new Set();
749+
removedSet = new Set();
750+
callCount = 0;
743751
});
744752
afterAll(async function () {
745753
ProjectManager.off(ProjectManager.EVENT_PROJECT_CHANGED_OR_RENAMED_PATH, _recorderFn);
@@ -751,7 +759,10 @@ define(function (require, exports, module) {
751759
await awaitsFor(()=>{
752760
return addedSet && addedSet.has(createFilePath);
753761
}, ()=>`added files [${addedSet&& Array.from(addedSet)}] to have ${createFilePath}`);
754-
changedPath = addedSet = removedSet = null;
762+
changedPathSet = new Set();
763+
addedSet = new Set();
764+
removedSet = new Set();
765+
callCount = 0;
755766
await SpecRunnerUtils.deletePathAsync(createFilePath, true, FileSystem);
756767
await awaitsFor(()=>{
757768
return removedSet && removedSet.has(createFilePath);
@@ -764,10 +775,13 @@ define(function (require, exports, module) {
764775
await awaitsFor(()=>{
765776
return addedSet && addedSet.has(createFilePath);
766777
}, ()=>`added files [${addedSet&& Array.from(addedSet)}] to have ${createFilePath}`);
767-
changedPath = addedSet = removedSet = null;
778+
changedPathSet = new Set();
779+
addedSet = new Set();
780+
removedSet = new Set();
781+
callCount = 0;
768782
await jsPromise(SpecRunnerUtils.createTextFile(createFilePath, "changed", FileSystem));
769783
await awaitsFor(()=>{
770-
return changedPath === createFilePath;
784+
return changedPathSet.has(createFilePath);
771785
}, ()=>`removed files [${removedSet&& Array.from(removedSet)}] to have ${createFilePath}`);
772786
await SpecRunnerUtils.deletePathAsync(createFilePath, true, FileSystem);
773787
await awaitsFor(()=>{
@@ -780,12 +794,15 @@ define(function (require, exports, module) {
780794
await SpecRunnerUtils.ensureExistsDirAsync(createDirPath, "hello", FileSystem);
781795
await awaitsFor(()=>{
782796
return addedSet && addedSet.has(createDirPath);
783-
}, ()=>`added dir [${addedSet&& Array.from(addedSet)}] to have ${createDirPath}`);
784-
changedPath = addedSet = removedSet = null;
797+
}, ()=>`event count ${callCount} added dir [${addedSet&& Array.from(addedSet)}] to have ${createDirPath}`);
798+
changedPathSet = new Set();
799+
addedSet = new Set();
800+
removedSet = new Set();
801+
callCount = 0;
785802
await SpecRunnerUtils.deletePathAsync(createDirPath, true, FileSystem);
786803
await awaitsFor(()=>{
787804
return removedSet && removedSet.has(createDirPath);
788-
}, ()=>`removed dir [${removedSet&& Array.from(removedSet)}] to have ${createDirPath}`);
805+
}, ()=>`event count ${callCount} removed dir [${removedSet&& Array.from(removedSet)}] to have ${createDirPath}`);
789806
});
790807

791808
it("should renaming file in same dir raise added and removed event", async function () {
@@ -795,7 +812,10 @@ define(function (require, exports, module) {
795812
await awaitsFor(()=>{
796813
return addedSet && addedSet.has(createFilePath);
797814
}, ()=>`added files [${addedSet&& Array.from(addedSet)}] to have ${createFilePath}`);
798-
changedPath = addedSet = removedSet = null;
815+
changedPathSet = new Set();
816+
addedSet = new Set();
817+
removedSet = new Set();
818+
callCount = 0;
799819
await jsPromise(SpecRunnerUtils.rename(createFilePath, renamedFilePath));
800820
await awaitsFor(()=>{
801821
return removedSet && removedSet.has(createFilePath) && addedSet && addedSet.has(renamedFilePath);
@@ -812,7 +832,10 @@ define(function (require, exports, module) {
812832
await awaitsFor(()=>{
813833
return addedSet && addedSet.has(createDirPath);
814834
}, ()=>`added dir [${addedSet&& Array.from(addedSet)}] to have ${createDirPath}`);
815-
changedPath = addedSet = removedSet = null;
835+
changedPathSet = new Set();
836+
addedSet = new Set();
837+
removedSet = new Set();
838+
callCount = 0;
816839
await jsPromise(SpecRunnerUtils.rename(createDirPath, renamedDirPath));
817840
await awaitsFor(()=>{
818841
return removedSet && removedSet.has(createDirPath) && addedSet && addedSet.has(renamedDirPath);

0 commit comments

Comments
 (0)