refactor plugin

indexworkspace2
bunsenstraat 3 years ago
parent 350af625be
commit c767a1d1a2
  1. 9
      apps/remix-ide-e2e/src/local-plugin/src/app/Client.ts
  2. 122
      apps/remix-ide-e2e/src/local-plugin/src/app/app.tsx
  3. 12
      apps/remix-ide-e2e/src/local-plugin/src/app/logger.tsx
  4. 31
      apps/remix-ide-e2e/src/tests/plugin_api.ts

@ -66,15 +66,6 @@ export class WorkSpacePlugin extends PluginClient {
console.log("comp fin",x)
})
*/
await this.setCallBacks()
this.on(
'solidity',
'compilationFinished',
function (target, source, version, data) {
console.log('compile finished', target, source, version, data)
}
)
})
.catch(async (e) => {
console.log('ERROR CONNECTING', e)

@ -1,83 +1,99 @@
import React, { useState } from 'react'
import React, { useEffect, useRef, useState } from 'react'
import { WorkSpacePlugin } from './Client'
import { Logger } from './logger'
import { useBehaviorSubject } from './usesubscribe/index'
import { filePanelProfile } from '@remixproject/plugin-api/lib/file-system/file-panel/profile'
import { filSystemProfile } from '@remixproject/plugin-api/lib/file-system/file-manager/profile'
import { dGitProfile } from '@remixproject/plugin-api/lib/dgit/profile'
import { editorProfile } from '@remixproject/plugin-api/lib/editor/profile'
import { settingsProfile } from '@remixproject/plugin-api/lib/settings/profile'
import { networkProfile } from '@remixproject/plugin-api/lib/network/profile'
import { terminalProfile } from '@remixproject/plugin-api/lib/terminal/profile'
import { udappProfile } from '@remixproject/plugin-api/lib/udapp'
import { compilerProfile } from '@remixproject/plugin-api/lib/compiler'
import { contentImportProfile } from '@remixproject/plugin-api/lib/content-import'
import { unitTestProfile } from '@remixproject/plugin-api/lib/unit-testing'
import { windowProfile } from '@remixproject/plugin-api/lib/window'
import { pluginManagerProfile } from '@remixproject/plugin-api/lib/plugin-manager'
import { IFileSystem } from '@remixproject/plugin-api'
import { Profile } from '@remixproject/plugin-utils'
export const client = new WorkSpacePlugin()
function App () {
const [payload, setPayload] = useState<string>('')
const [result, setResult] = useState<string>()
const [append, setAppend] = useState<boolean>(false)
const [log, setLog] = useState<any>()
const [profiles, setProfiles] = useState<any[]>([pluginManagerProfile, filePanelProfile, filSystemProfile, dGitProfile, networkProfile, settingsProfile, editorProfile, terminalProfile, compilerProfile, udappProfile, contentImportProfile, unitTestProfile, windowProfile])
const handleChange = ({ target }: any) => {
setPayload(target.value)
}
useEffect(() => {
client.onload(async () => {
const customProfiles = ['solidity']
for (const name of customProfiles) {
const p = await client.call('manager', 'getProfile', name)
setProfiles(profiles => [p, ...profiles])
}
profiles.map((profile: Profile) => {
if (profile.events) {
profile.events.map((event: string) => {
console.log(profile.name, event)
client.on(profile.name as any, event, (...args:any) => {
console.log(event, args)
})
})
}
})
})
}, [])
const setAppendChange = ({ target }: any) => {
console.log('append', target.checked)
setAppend(target.checked)
}
const clientMethod = async (profile: Profile, method: string) => {
try {
let ob: any = null
try {
ob = JSON.parse(payload)
} catch (e) {}
const send = ob || [payload]
const result = await client.call(profile.name as any, method, ...send)
setLog(result)
} catch (e) {
setLog(e.message)
}
}
return (
<div className="App">
<div>v5</div>
<Logger append={append}></Logger>
<input id='appendToLog' type='checkbox' onChange={setAppendChange}/><label>append logs</label>
<button className='btn btn-primary btn-sm' onClick={async () => await client.zip()}>zip</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.ipfspush()}>ipfs push</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.ipfspull(payload)}>ipfs pull</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.ipfsConfig()}>ipfs config</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.getAccounts()}>get accounts</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.setSettings()}>set settings to injected</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.getSettings()}>get settings</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.soltest()}>run sol test</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.highlight(payload)}>highlight</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.addAnnotation(payload)}>annotation</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.clearAnnotations(payload)}>clear annotation</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.open(payload)}>openfile</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.readddir(payload)}>readdir</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.write(payload)}>write</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.switchfile(payload)}>switch to file</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.getcurrentfile()}>getcurrentfile</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.importcontent(payload)}>import content resolve</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.fetch(payload)}>api test fetch</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.axios(payload)}>api test axios</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.activate(payload)}>activate</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.deactivate(payload)}>deactivate</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.getresult()}>get compilation result</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.getcompilerconfig()}>get compiler config</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.getWorkSpace()}>get workspace</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.getWorkSpaces()}>get workspaces</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.createWorkSpace(payload)}>create workspace</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.gitinit(payload)}>git init</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.gitstatus(payload)}>git status</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.gitlog()}>git log</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.gitcommit()}>git commit</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.gitadd(payload)}>git add</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.gitremove(payload)}>git rm</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.gitlsfiles()}>git ls files</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.gitreadblob(payload)}>git read blob</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.gitresolveref()}>git resolve head</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.gitbranches()}>git branches</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.gitbranch(payload)}>git create branch</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.gitcheckout(payload)}>git checkout</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.gitcurrentbranch()}>git current branch</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.changetoinjected()}>change to injected</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.pinatapush()}>pinata write</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.pinlist()}>pinata list</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.setCallBacks()}>callbacks</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.log('')}>log</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.activatePlugin(payload)}>activate</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.deActivatePlugin(payload)}>deactivate</button>
<button className='btn btn-primary btn-sm' onClick={async () => await client.debug(payload)}>debug</button>
<div className="App container-fluid">
<h5>PLUGIN API TESTER</h5>
<Logger log={log} append={append}></Logger>
<input
className='form-control w-100'
type="text"
id="payload"
placeholder="Enter payload here..."
value={payload}
onChange={handleChange}
/>
<input className='' id='appendToLog' type='checkbox' onChange={setAppendChange} /><label> Append logs</label>
{profiles.map((profile: Profile) => {
const methods = profile.methods.map((method: string) => {
return <button data-id={`${profile.name}:${method}`} key={method} className='btn btn-primary btn-sm ml-1 mb-1' onClick={async () => await clientMethod(profile, method)}>{method}</button>
})
return <div key={profile.name} className='small'><label>{profile.name}</label><br></br>{methods}</div>
})}
</div>
)
}

@ -1,21 +1,21 @@
import React, { useEffect, useState } from 'react'
import { useBehaviorSubject } from './usesubscribe/index'
import { client } from './app'
interface loggerProps {
append: boolean
append: boolean,
log: any
}
export const Logger: React.FC<loggerProps> = (props) => {
const log = useBehaviorSubject(client.feedback)
const [value, setValue] = useState<string>('')
useEffect(() => {
setValue(value => {
const addValue = typeof log === 'string' ? log : JSON.stringify(log)
const addValue = typeof props.log === 'string' ? props.log : JSON.stringify(props.log)
return props.append ? `${value} ${addValue}` : addValue
})
}, [log])
}, [props])
return (<div id='log'>{value}</div>)
return (<div className="jumbotron text-break">{value}</div>)
}

@ -18,8 +18,13 @@ const getBrowserLogs = function (browser: NightwatchBrowser) {
console.log(logEntries)
})
}
const assertLog = function (browser: NightwatchBrowser, buttonText: string, msg: any, payload: string) {
/*
* PLUGINACTION
* buttonText: which button to click
* msg: what to expect from the log
* payload: extra param for the call
*/
const pluginAction = function (browser: NightwatchBrowser, buttonText: string, msg: any, payload: string) {
if (payload) {
browser.clearValue('//*[@id="payload"]').setValue('//*[@id="payload"]', payload).pause(1000)
}
@ -82,22 +87,22 @@ module.exports = {
},
'Should get current workspace': function (browser: NightwatchBrowser) {
assertLog(browser, 'get workspace', { name: 'default_workspace', isLocalhost: false, absolutePath: '.workspaces/default_workspace' }, null)
pluginAction(browser, 'get workspace', { name: 'default_workspace', isLocalhost: false, absolutePath: '.workspaces/default_workspace' }, null)
},
'Should get current files': function (browser: NightwatchBrowser) {
assertLog(browser, 'readdir', { contracts: { isDirectory: true }, scripts: { isDirectory: true }, tests: { isDirectory: true }, 'README.txt': { isDirectory: false } }, null)
pluginAction(browser, 'readdir', { contracts: { isDirectory: true }, scripts: { isDirectory: true }, tests: { isDirectory: true }, 'README.txt': { isDirectory: false } }, null)
},
'Should throw error on current file': function (browser: NightwatchBrowser) {
assertLog(browser, 'getcurrentfile', 'Error from IDE : Error: No such file or directory No file selected', null)
pluginAction(browser, 'getcurrentfile', 'Error from IDE : Error: No such file or directory No file selected', null)
},
'Should open readme.txt': function (browser: NightwatchBrowser) {
assertLog(browser, 'openfile', null, 'README.txt')
pluginAction(browser, 'openfile', null, 'README.txt')
},
'Should have current file': function (browser: NightwatchBrowser) {
assertLog(browser, 'getcurrentfile', 'README.txt', null)
pluginAction(browser, 'getcurrentfile', 'README.txt', null)
},
'Should activate solidityUnitTesting': function (browser: NightwatchBrowser) {
assertLog(browser, 'activate', null, 'solidityUnitTesting')
pluginAction(browser, 'activate', null, 'solidityUnitTesting')
browser.frameParent()
assertPluginIsActive(browser, 'solidityUnitTesting')
// @ts-ignore
@ -105,13 +110,13 @@ module.exports = {
},
'Should switch to file': function (browser: NightwatchBrowser) {
assertLog(browser, 'switch to file', null, 'contracts/1_Storage.sol')
assertLog(browser, 'getcurrentfile', 'contracts/1_Storage.sol', null)
assertLog(browser, 'switch to file', null, 'README.txt')
assertLog(browser, 'getcurrentfile', 'README.txt', null)
pluginAction(browser, 'switch to file', null, 'contracts/1_Storage.sol')
pluginAction(browser, 'getcurrentfile', 'contracts/1_Storage.sol', null)
pluginAction(browser, 'switch to file', null, 'README.txt')
pluginAction(browser, 'getcurrentfile', 'README.txt', null)
},
'Should write to file': function (browser: NightwatchBrowser) {
assertLog(browser, 'write', 'README.txt', null)
pluginAction(browser, 'write', 'README.txt', null)
}
}

Loading…
Cancel
Save