setWorkspace

pull/5370/head
aniket-engg 3 years ago committed by Aniket
parent 88b060d58d
commit 142b5f9321
  1. 22
      apps/remix-ide/src/app/tabs/test-tab.js
  2. 2
      libs/remix-ui/solidity-unit-testing/src/lib/logic/testTabLogic.ts
  3. 53
      libs/remix-ui/solidity-unit-testing/src/lib/solidity-unit-testing.tsx

@ -39,13 +39,6 @@ module.exports = class TestTab extends ViewPlugin {
this.offsetToLineColumnConverter = offsetToLineColumnConverter
this.allFilesInvolved = ['.deps/remix-tests/remix_tests.sol', '.deps/remix-tests/remix_accounts.sol']
this.element = document.createElement('div')
appManager.event.on('activate', (name) => {
if (name === 'solidity') this.updateRunAction()
})
appManager.event.on('deactivate', (name) => {
if (name === 'solidity') this.updateRunAction()
})
}
onActivationInternal () {
@ -86,7 +79,6 @@ module.exports = class TestTab extends ViewPlugin {
}
await this.testRunner.init()
await this.createTestLibs()
// this.updateRunAction()
}
onDeactivation () {
@ -97,9 +89,6 @@ module.exports = class TestTab extends ViewPlugin {
}
listenToEvents() {
this.on('filePanel', 'setWorkspace', async () => {
this.setCurrentPath(this.defaultPath)
})
this.on('filePanel', 'workspaceCreated', async () => {
this.createTestLibs()
@ -120,17 +109,6 @@ module.exports = class TestTab extends ViewPlugin {
return this.testFromSource(fileContent, path)
}
/**
* Changes the current path of Unit Testing Plugin
* @param path - the path from where UT plugin takes _test.sol files to run
*/
async setCurrentPath (path) {
this.testTabLogic.setCurrentPath(path)
this.inputPath.value = path
this.updateDirList(path)
await this.updateForNewCurrent()
}
/*
Test is not associated with the UI
*/

@ -6,7 +6,6 @@ export class TestTabLogic {
currentPath
helper
constructor (fileManager: any, helper: any) {
console.log('Inside TestTabLogic constructor--from SUT-fileManager--->', fileManager)
this.fileManager = fileManager
this.helper = helper
this.currentPath = '/tests'
@ -48,7 +47,6 @@ export class TestTabLogic {
this.helper.createNonClashingNameWithPrefix(fileNameToImport, fileProvider, '_test', (error: any, newFile: any) => {
// if (error) return modalDialogCustom.alert('Failed to create file. ' + newFile + ' ' + error)
const isFileCreated = fileProvider.set(newFile, this.generateTestContractSample(hasCurrent, fileName))
console.log('isFileCreated---->', isFileCreated)
// if (!isFileCreated) return modalDialogCustom.alert('Failed to create test file ' + newFile)
this.fileManager.open(newFile)
this.fileManager.syncEditor(newFile)

@ -69,22 +69,22 @@ export const SolidityUnitTesting = (props: Record<string, any>) => {
setTestsExecutionStoppedErrorHidden(true)
}
const updateForNewCurrent = async (file = null) => {
// Ensure that when someone clicks on compilation error and that opens a new file
// Test result, which is compilation error in this case, is not cleared
if (currentErrors) {
if (Array.isArray(currentErrors) && currentErrors.length > 0) {
const errFiles = currentErrors.map(err => { if (err.sourceLocation && err.sourceLocation.file) return err.sourceLocation.file }) // eslint-disable-line
if (errFiles.includes(file)) return
} else if (currentErrors.sourceLocation && currentErrors.sourceLocation.file && currentErrors.sourceLocation.file === file) return
}
// if current file is changed while debugging and one of the files imported in test file are opened
// do not clear the test results in SUT plugin
if (isDebugging && testTab.allFilesInvolved.includes(file)) return
allTests = []
updateTestFileList()
clearResults()
try {
const updateForNewCurrent = async (file = null) => {
// Ensure that when someone clicks on compilation error and that opens a new file
// Test result, which is compilation error in this case, is not cleared
if (currentErrors) {
if (Array.isArray(currentErrors) && currentErrors.length > 0) {
const errFiles = currentErrors.map(err => { if (err.sourceLocation && err.sourceLocation.file) return err.sourceLocation.file }) // eslint-disable-line
if (errFiles.includes(file)) return
} else if (currentErrors.sourceLocation && currentErrors.sourceLocation.file && currentErrors.sourceLocation.file === file) return
}
// if current file is changed while debugging and one of the files imported in test file are opened
// do not clear the test results in SUT plugin
if (isDebugging && testTab.allFilesInvolved.includes(file)) return
allTests = []
updateTestFileList()
clearResults()
try {
testTabLogic.getTests(async (error: any, tests: any) => {
// if (error) return tooltip(error)
allTests = tests
@ -94,8 +94,19 @@ export const SolidityUnitTesting = (props: Record<string, any>) => {
if (!areTestsRunning) await updateRunAction(file)
})
} catch (e) {
console.log(e)
}
console.log(e)
}
}
/**
* Changes the current path of Unit Testing Plugin
* @param path - the path from where UT plugin takes _test.sol files to run
*/
const setCurrentPath = async (path: string) => {
testTabLogic.setCurrentPath(path)
setInputPathValue(path)
updateDirList(path)
await updateForNewCurrent()
}
useEffect(() => {
@ -119,9 +130,13 @@ export const SolidityUnitTesting = (props: Record<string, any>) => {
}
})
testTab.on('filePanel', 'setWorkspace', async () => {
setCurrentPath(defaultPath)
})
testTab.fileManager.events.on('noFileSelected', () => {})
testTab.fileManager.events.on('currentFileChanged', (file: any, provider: any) => updateForNewCurrent(file))
}, []) // eslint-disable-line
const updateDirList = (path: string) => {

Loading…
Cancel
Save