diff --git a/apps/remixdesktop/src/engine.ts b/apps/remixdesktop/src/engine.ts index 9a8fd78aad..534cdf850c 100644 --- a/apps/remixdesktop/src/engine.ts +++ b/apps/remixdesktop/src/engine.ts @@ -13,6 +13,7 @@ import { SlitherPlugin } from './plugins/slitherPlugin'; import { AppUpdaterPlugin } from './plugins/appUpdater'; import { FoundryPlugin } from './plugins/foundryPlugin'; import { HardhatPlugin } from './plugins/hardhatPlugin'; +import { isE2E } from './main'; const engine = new Engine() const appManager = new PluginManager() @@ -52,6 +53,18 @@ ipcMain.on('fs:openFolder', async (event, path?) => { fsPlugin.openFolder(event, path) }) +ipcMain.handle('fs:openFolder', async (event, webContentsId, path?) => { + if(!isE2E) return + console.log('openFolder', webContentsId, path) + fsPlugin.openFolder(webContentsId, path) +}) + +ipcMain.handle('fs:openFolderInSameWindow', async (event, webContentsId, path?) => { + if(!isE2E) return + console.log('openFolderInSameWindow', webContentsId, path) + fsPlugin.openFolderInSameWindow(webContentsId, path) +}) + ipcMain.on('terminal:new', async (event) => { xtermPlugin.new(event) diff --git a/apps/remixdesktop/src/plugins/fsPlugin.ts b/apps/remixdesktop/src/plugins/fsPlugin.ts index 65210e9da5..0f45727066 100644 --- a/apps/remixdesktop/src/plugins/fsPlugin.ts +++ b/apps/remixdesktop/src/plugins/fsPlugin.ts @@ -94,6 +94,13 @@ export class FSPlugin extends ElectronBasePlugin { client.openFolder(path) } } + + openFolderInSameWindow(webContentsId: any, path?: string): void { + const client = this.clients.find((c) => c.webContentsId === webContentsId) + if (client) { + client.openFolderInSameWindow(path) + } + } } const clientProfile: Profile = { diff --git a/apps/remixdesktop/src/preload.ts b/apps/remixdesktop/src/preload.ts index 9f757541c1..356e262347 100644 --- a/apps/remixdesktop/src/preload.ts +++ b/apps/remixdesktop/src/preload.ts @@ -19,7 +19,8 @@ contextBridge.exposeInMainWorld('electronAPI', { isE2E: () => ipcRenderer.invoke('config:isE2E'), canTrackMatomo: () => ipcRenderer.invoke('config:canTrackMatomo'), trackEvent: (args: any[]) => ipcRenderer.invoke('matomo:trackEvent', args), - + openFolder: (path: string) => ipcRenderer.invoke('fs:openFolder', webContentsId, path), + openFolderInSameWindow: (path: string) => ipcRenderer.invoke('fs:openFolderInSameWindow', webContentsId, path), activatePlugin: (name: string) => { return ipcRenderer.invoke('manager:activatePlugin', name) }, diff --git a/apps/remixdesktop/test/tests/app/hardhat.test.ts b/apps/remixdesktop/test/tests/app/hardhat.test.ts index e69de29bb2..492d95700b 100644 --- a/apps/remixdesktop/test/tests/app/hardhat.test.ts +++ b/apps/remixdesktop/test/tests/app/hardhat.test.ts @@ -0,0 +1,73 @@ +import { NightwatchBrowser } from 'nightwatch' +import { ChildProcess, spawn, execSync } from 'child_process' +import { homedir } from 'os' +import path from 'path' +import os from 'os' + +const dir = path.join('remix-desktop-test-' + Date.now().toString()) + +const tests = { + before: function (browser: NightwatchBrowser, done: VoidFunction) { + done() + }, + setuphardhat: function (browser: NightwatchBrowser) { + browser.perform(async (done) => { + await setupHardhatProject() + done() + }) + }, + addScript: function (browser: NightwatchBrowser) { + // run script in console + browser.executeAsync(function (dir, done) { + (window as any).electronAPI.openFolderInSameWindow('/tmp/' + dir).then(done) + }, [dir], () => { + console.log('done window opened') + }) + .waitForElementVisible('*[data-id="treeViewDivDraggableItemhardhat.config.js"]', 10000) + }, + compile: function (browser: NightwatchBrowser) { + browser.perform(async (done) => { + console.log('generating compilation result') + await compileHardhatProject() + done() + }) + .expect.element('*[data-id="terminalJournal"]').text.to.contain('receiving compilation result from Hardhat').before(60000) + } +} + +async function compileHardhatProject(): Promise { + console.log(process.cwd()) + try { + const server = spawn('npx hardhat compile', [], { cwd: '/tmp/' + dir, shell: true, detached: true }) + return new Promise((resolve, reject) => { + server.on('exit', function (exitCode) { + console.log("Child exited with code: " + exitCode); + console.log('end') + resolve() + }) + }) + } catch (e) { + console.log(e) + } +} + +async function setupHardhatProject(): Promise { + console.log('setup hardhat project', dir) + try { + const server = spawn(`git clone https://github.com/NomicFoundation/hardhat-boilerplate ${dir} && cd ${dir} && yarn install && yarn add "@typechain/ethers-v5@^10.1.0" && yarn add "@typechain/hardhat@^6.1.2" && yarn add "typechain@^8.1.0" && echo "END"`, [], { cwd: '/tmp/', shell: true, detached: true }) + return new Promise((resolve, reject) => { + server.on('exit', function (exitCode) { + console.log("Child exited with code: " + exitCode); + console.log('end') + resolve() + }) + }) + } catch (e) { + console.log(e) + } +} + + +module.exports = { + ...tests +} \ No newline at end of file