feat: Enhance Electron test harness with preload script and CSP configuration

This commit is contained in:
2026-04-19 03:05:29 +10:00
parent dcc17946ef
commit 6f506c59a4
5 changed files with 98 additions and 31 deletions

31
test/electron/preload.js Normal file
View File

@@ -0,0 +1,31 @@
const { contextBridge } = require('electron');
const fs = require('fs');
const path = require('path');
const { pathToFileURL } = require('url');
const pluginManagerBrowserEntryPath = path.join(
__dirname,
'node_modules',
'@paarrot',
'plugin-manager',
'dist',
'index.browser.js'
);
const examplePluginPath = path.join(__dirname, 'plugins', 'example-plugin', 'index.js');
/**
* Provides the small Node-backed surface area the test harness needs while the
* renderer stays in an isolated browser context.
*/
contextBridge.exposeInMainWorld('electronTestApi', {
getHarnessBootstrap() {
return {
pluginManagerEntryUrl: pathToFileURL(pluginManagerBrowserEntryPath).href,
examplePluginPath,
examplePluginCode: fs.readFileSync(examplePluginPath, 'utf-8'),
};
},
async readTextFile(filePath) {
return fs.promises.readFile(filePath, 'utf-8');
},
});