hardhat test

pull/5370/head
bunsenstraat 5 months ago
parent 6269a30e83
commit 41e72b6dcf
  1. 13
      apps/remixdesktop/src/engine.ts
  2. 7
      apps/remixdesktop/src/plugins/fsPlugin.ts
  3. 3
      apps/remixdesktop/src/preload.ts
  4. 73
      apps/remixdesktop/test/tests/app/hardhat.test.ts

@ -13,6 +13,7 @@ import { SlitherPlugin } from './plugins/slitherPlugin';
import { AppUpdaterPlugin } from './plugins/appUpdater'; import { AppUpdaterPlugin } from './plugins/appUpdater';
import { FoundryPlugin } from './plugins/foundryPlugin'; import { FoundryPlugin } from './plugins/foundryPlugin';
import { HardhatPlugin } from './plugins/hardhatPlugin'; import { HardhatPlugin } from './plugins/hardhatPlugin';
import { isE2E } from './main';
const engine = new Engine() const engine = new Engine()
const appManager = new PluginManager() const appManager = new PluginManager()
@ -52,6 +53,18 @@ ipcMain.on('fs:openFolder', async (event, path?) => {
fsPlugin.openFolder(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) => { ipcMain.on('terminal:new', async (event) => {
xtermPlugin.new(event) xtermPlugin.new(event)

@ -94,6 +94,13 @@ export class FSPlugin extends ElectronBasePlugin {
client.openFolder(path) 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 = { const clientProfile: Profile = {

@ -19,7 +19,8 @@ contextBridge.exposeInMainWorld('electronAPI', {
isE2E: () => ipcRenderer.invoke('config:isE2E'), isE2E: () => ipcRenderer.invoke('config:isE2E'),
canTrackMatomo: () => ipcRenderer.invoke('config:canTrackMatomo'), canTrackMatomo: () => ipcRenderer.invoke('config:canTrackMatomo'),
trackEvent: (args: any[]) => ipcRenderer.invoke('matomo:trackEvent', args), 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) => { activatePlugin: (name: string) => {
return ipcRenderer.invoke('manager:activatePlugin', name) return ipcRenderer.invoke('manager:activatePlugin', name)
}, },

@ -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<void> {
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<void> {
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
}
Loading…
Cancel
Save