Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove extension when folder is removed during runtime
Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com>
- Loading branch information
1 parent
c93ee4e
commit ea15cb4
Showing
8 changed files
with
228 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import { ExtensionLoader } from "../extension-loader"; | ||
|
||
const manifestPath = "manifest/path"; | ||
const manifestPath2 = "manifest/path2"; | ||
const manifestPath3 = "manifest/path3"; | ||
|
||
jest.mock( | ||
"electron", | ||
() => ({ | ||
ipcRenderer: { | ||
invoke: jest.fn(async (channel: string, ...args: any[]) => { | ||
if (channel === "extensions:loaded") { | ||
return [ | ||
[ | ||
manifestPath, | ||
{ | ||
manifest: { | ||
name: "TestExtension", | ||
version: "1.0.0", | ||
}, | ||
manifestPath, | ||
isBundled: false, | ||
isEnabled: true, | ||
}, | ||
], | ||
[ | ||
manifestPath2, | ||
{ | ||
manifest: { | ||
name: "TestExtension2", | ||
version: "2.0.0", | ||
}, | ||
manifestPath: manifestPath2, | ||
isBundled: false, | ||
isEnabled: true, | ||
}, | ||
], | ||
]; | ||
} | ||
}), | ||
on: jest.fn( | ||
(channel: string, listener: (event: any, ...args: any[]) => void) => { | ||
if (channel === "extensions:loaded") { | ||
// First initialize with extensions 1 and 2 | ||
// and then broadcast event to remove extensioin 2 and add extension number 3 | ||
setTimeout(() => { | ||
listener({}, [ | ||
[ | ||
manifestPath, | ||
{ | ||
manifest: { | ||
name: "TestExtension", | ||
version: "1.0.0", | ||
}, | ||
manifestPath, | ||
isBundled: false, | ||
isEnabled: true, | ||
}, | ||
], | ||
[ | ||
manifestPath3, | ||
{ | ||
manifest: { | ||
name: "TestExtension3", | ||
version: "3.0.0", | ||
}, | ||
manifestPath3, | ||
isBundled: false, | ||
isEnabled: true, | ||
}, | ||
], | ||
]); | ||
}, 10); | ||
} | ||
} | ||
), | ||
}, | ||
}), | ||
{ | ||
virtual: true, | ||
} | ||
); | ||
|
||
describe("ExtensionLoader", () => { | ||
it("renderer updates extension after ipc broadcast", async (done) => { | ||
const extensionLoader = new ExtensionLoader(); | ||
|
||
expect(extensionLoader.userExtensions).toMatchInlineSnapshot(`Map {}`); | ||
|
||
await extensionLoader.init(); | ||
|
||
setTimeout(() => { | ||
// Assert the extensions after the extension broadcast event | ||
expect(extensionLoader.userExtensions).toMatchInlineSnapshot(` | ||
Map { | ||
"manifest/path" => Object { | ||
"isBundled": false, | ||
"isEnabled": true, | ||
"manifest": Object { | ||
"name": "TestExtension", | ||
"version": "1.0.0", | ||
}, | ||
"manifestPath": "manifest/path", | ||
}, | ||
"manifest/path3" => Object { | ||
"isBundled": false, | ||
"isEnabled": true, | ||
"manifest": Object { | ||
"name": "TestExtension3", | ||
"version": "3.0.0", | ||
}, | ||
"manifestPath3": "manifest/path3", | ||
}, | ||
} | ||
`); | ||
|
||
done(); | ||
}, 10); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.