feat: Enhance Electron test harness with preload script and CSP configuration
This commit is contained in:
31
test/electron/preload.js
Normal file
31
test/electron/preload.js
Normal 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');
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user