Files
plugin-manager/test/electron/preload.js

31 lines
894 B
JavaScript

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');
},
});