|
19 | 19 | * |
20 | 20 | */ |
21 | 21 |
|
22 | | -/*global describe, it, expect, beforeEach, beforeAll, afterAll, awaitsFor, awaitsForDone */ |
| 22 | +/*global describe, it, expect, beforeEach, beforeAll, afterAll, awaitsFor, awaitsForDone, spyOn */ |
23 | 23 |
|
24 | 24 | define(function (require, exports, module) { |
25 | 25 |
|
@@ -84,6 +84,58 @@ define(function (require, exports, module) { |
84 | 84 | await _verifySinglePreference(".brackets.json", 6); |
85 | 85 | }, 100000); |
86 | 86 |
|
| 87 | + it("should keep a newer project's preferences when an older project's load finishes last", async function () { |
| 88 | + const FileUtils = testWindow.brackets.test.FileUtils; |
| 89 | + const projectWithoutSettings = SpecRunnerUtils.getTestPath("/spec/WorkingSetView-test-files"); |
| 90 | + const realReadAsText = FileUtils.readAsText; |
| 91 | + let releaseStaleReads; |
| 92 | + const staleReadsReleased = new Promise(function (resolve) { |
| 93 | + releaseStaleReads = resolve; |
| 94 | + }); |
| 95 | + let heldReads = 0, settledReads = 0; |
| 96 | + // Hold the settings-free project's preference reads until the next |
| 97 | + // project has loaded, so its reload finishes last. |
| 98 | + spyOn(FileUtils, "readAsText").and.callFake(function (file, ...args) { |
| 99 | + const result = realReadAsText.call(FileUtils, file, ...args); |
| 100 | + const name = file.fullPath.split("/").pop(); |
| 101 | + if (!file.fullPath.startsWith(projectWithoutSettings + "/") || |
| 102 | + (name !== ".phcode.json" && name !== ".brackets.json")) { |
| 103 | + return result; |
| 104 | + } |
| 105 | + heldReads++; |
| 106 | + const held = new testWindow.$.Deferred(); |
| 107 | + staleReadsReleased.then(function () { |
| 108 | + result.always(function () { |
| 109 | + settledReads++; |
| 110 | + }).done(held.resolve).fail(held.reject); |
| 111 | + }); |
| 112 | + return held.promise(); |
| 113 | + }); |
| 114 | + spyOn(PreferencesManager, "_setProjectSettingsFile").and.callThrough(); |
| 115 | + try { |
| 116 | + // Start elsewhere, so opening the settings-free project is a real switch. |
| 117 | + await SpecRunnerUtils.loadProjectInTestWindow(testPath); |
| 118 | + await SpecRunnerUtils.loadProjectInTestWindow(projectWithoutSettings); |
| 119 | + await SpecRunnerUtils.loadProjectInTestWindow(testPathBracketsPrefsOnly); |
| 120 | + await awaitsForDone(SpecRunnerUtils.openProjectFiles(".brackets.json")); |
| 121 | + await awaitsFor(()=>{ |
| 122 | + return PreferencesManager.get("spaceUnits") === 6; |
| 123 | + }, "space units to be 6 from the newer project", 10000); |
| 124 | + expect(heldReads).toBeGreaterThan(0); |
| 125 | + } finally { |
| 126 | + releaseStaleReads(); |
| 127 | + } |
| 128 | + // Every held read settles, and whatever the older reload does next |
| 129 | + // runs before the next check. |
| 130 | + await awaitsFor(()=>{ |
| 131 | + return settledReads === heldReads; |
| 132 | + }, "the older project's reads to finish", 10000); |
| 133 | + |
| 134 | + const lastSettingsFile = PreferencesManager._setProjectSettingsFile.calls.mostRecent().args[0]; |
| 135 | + expect(lastSettingsFile.startsWith(testPathBracketsPrefsOnly + "/")).toBeTrue(); |
| 136 | + expect(PreferencesManager.get("spaceUnits")).toBe(6); |
| 137 | + }, 30000); |
| 138 | + |
87 | 139 | it("should .phcode.json take precedence over .brackets.json", async function () { |
88 | 140 | await SpecRunnerUtils.loadProjectInTestWindow(testPathBothPrefs); |
89 | 141 | await awaitsForDone(SpecRunnerUtils.openProjectFiles(".phcode.json")); |
|
0 commit comments