Skip to content

Commit b656138

Browse files
committed
test: with extension registry cache using file
1 parent 33a66fc commit b656138

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/extensibility/ExtensionManager.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ define(function (require, exports, module) {
6161
// next update. This migration code can be removed after July 2025(6 Months).
6262
localStorage.removeItem(EXTENSION_REGISTRY_LOCAL_STORAGE_KEY);
6363

64+
const REGISTRY_CACHE_FILE = Phoenix.isTestWindow ?
65+
"test_registry_cache.json" : "registry_cache.json";
6466
const REGISTRY_CACHE_PATH = path.normalize(
65-
Phoenix.app.getExtensionsDirectory() + "/" + "registry_cache.json");
67+
Phoenix.app.getExtensionsDirectory() + "/" + REGISTRY_CACHE_FILE);
6668
function _getCachedRegistry() {
6769
// never rejects
6870
return new Promise((resolve) => {
@@ -89,6 +91,11 @@ define(function (require, exports, module) {
8991
});
9092
}
9193

94+
function _removeCachedRegistry() {
95+
const registryFile = FileSystem.getFileForPath(REGISTRY_CACHE_PATH);
96+
return registryFile.unlinkAsync();
97+
}
98+
9299
// semver.browser is an AMD-compatible module
93100
var semver = require("thirdparty/semver.browser");
94101

@@ -964,6 +971,8 @@ define(function (require, exports, module) {
964971
exports._reset = _reset;
965972
exports._setExtensions = _setExtensions;
966973
if(Phoenix.isTestWindow){
967-
exports.EXTENSION_REGISTRY_LOCAL_STORAGE_KEY = EXTENSION_REGISTRY_LOCAL_STORAGE_KEY;
974+
exports._getCachedRegistry = _getCachedRegistry;
975+
exports._putCachedRegistry = _putCachedRegistry;
976+
exports._removeCachedRegistry = _removeCachedRegistry;
968977
}
969978
});

test/spec/ExtensionManager-test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ define(function (require, exports, module) {
176176
});
177177

178178
it("should registry update cache registry locally", async function () {
179-
localStorage.removeItem(ExtensionManager.EXTENSION_REGISTRY_LOCAL_STORAGE_KEY);
179+
await ExtensionManager._removeCachedRegistry();
180180
await awaitsForDone(ExtensionManager.downloadRegistry(true), "fetching registry");
181-
expect(localStorage.getItem(ExtensionManager.EXTENSION_REGISTRY_LOCAL_STORAGE_KEY)).not.toBeNull();
181+
expect(await ExtensionManager._getCachedRegistry()).not.toBeNull();
182182
});
183183

184184
it("should fail if it can't access the registry", async function () {
@@ -419,7 +419,7 @@ define(function (require, exports, module) {
419419
var model;
420420

421421
beforeEach(async function () {
422-
localStorage.removeItem(ExtensionManager.EXTENSION_REGISTRY_LOCAL_STORAGE_KEY);
422+
await ExtensionManager._removeCachedRegistry();
423423
mockRegistry = JSON.parse(mockRegistryForSearch);
424424
model = new ExtensionManagerViewModel.RegistryViewModel();
425425
await awaitsForDone(model.initialize(), "model initialization");
@@ -515,7 +515,7 @@ define(function (require, exports, module) {
515515
var model;
516516

517517
beforeEach(async function () {
518-
localStorage.removeItem(ExtensionManager.EXTENSION_REGISTRY_LOCAL_STORAGE_KEY);
518+
await ExtensionManager._removeCachedRegistry();
519519
mockRegistry = JSON.parse(mockRegistryThemesText);
520520
model = new ExtensionManagerViewModel.ThemesViewModel();
521521
await awaitsForDone(model.initialize(), "model initialization");

0 commit comments

Comments
 (0)