use relative path, create folder if does not exist

pull/262/head
LianaHus 5 years ago committed by yann300
parent 39a67cb195
commit 508a663d48
  1. 3
      src/app.js
  2. 5
      src/app/files/fileProvider.js
  3. 38
      src/app/tabs/test-tab.js
  4. 20
      src/app/tabs/testTab/testTab.js

@ -396,7 +396,8 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
await appManager.activatePlugin(['contentImport', 'theme', 'editor', 'fileManager', 'compilerMetadata', 'compilerArtefacts', 'network', 'web3Provider', 'offsetToLineColumnConverter']) await appManager.activatePlugin(['contentImport', 'theme', 'editor', 'fileManager', 'compilerMetadata', 'compilerArtefacts', 'network', 'web3Provider', 'offsetToLineColumnConverter'])
await appManager.activatePlugin(['mainPanel', 'menuicons']) await appManager.activatePlugin(['mainPanel', 'menuicons'])
await appManager.activatePlugin(['home', 'sidePanel', 'hiddenPanel', 'pluginManager', 'fileExplorers', 'settings', 'contextualListener', 'scriptRunner', 'terminal', 'fetchAndCompile']) await appManager.activatePlugin(['sidePanel']) // activating host plugin separately
await appManager.activatePlugin(['home', 'hiddenPanel', 'pluginManager', 'fileExplorers', 'settings', 'contextualListener', 'scriptRunner', 'terminal', 'fetchAndCompile'])
const queryParams = new QueryParams() const queryParams = new QueryParams()
const params = queryParams.get() const params = queryParams.get()

@ -116,9 +116,10 @@ class FileProvider {
} }
createDir (path, cb) { createDir (path, cb) {
var unprefixedpath = this.removePrefix(path) const unprefixedpath = this.removePrefix(path)
const paths = unprefixedpath.split('/') const paths = unprefixedpath.split('/')
paths.pop() // last element should the filename const last = paths[paths.length - 1]
if (last.indexOf('.') !== -1) paths.pop() // check if the last element is the filename and remove it
if (paths.length && paths[0] === '') paths.shift() if (paths.length && paths[0] === '') paths.shift()
let currentCheck = '' let currentCheck = ''
paths.forEach((value) => { paths.forEach((value) => {

@ -33,11 +33,12 @@ module.exports = class TestTab extends ViewPlugin {
this.runningTestsNumber = 0 this.runningTestsNumber = 0
this.readyTestsNumber = 0 this.readyTestsNumber = 0
this.areTestsRunning = false this.areTestsRunning = false
appManager.event.on('activate', (name) => { appManager.event.on('activate', (name) => {
if (name === 'solidity') this.updateRunAction(fileManager.currentFile()) if (name === 'solidity') this.updateRunAction()
}) })
appManager.event.on('deactivate', (name) => { appManager.event.on('deactivate', (name) => {
if (name === 'solidity') this.updateRunAction(fileManager.currentFile()) if (name === 'solidity') this.updateRunAction()
}) })
} }
@ -56,9 +57,6 @@ module.exports = class TestTab extends ViewPlugin {
}) })
this.fileManager.events.on('noFileSelected', () => { this.fileManager.events.on('noFileSelected', () => {
this.updateGenerateFileAction()
this.updateRunAction()
this.updateTestFileList()
}) })
this.fileManager.events.on('currentFileChanged', (file, provider) => this.updateForNewCurrent(file)) this.fileManager.events.on('currentFileChanged', (file, provider) => this.updateForNewCurrent(file))
@ -86,6 +84,7 @@ module.exports = class TestTab extends ViewPlugin {
} }
listTests () { listTests () {
if (!this.data.allTests) return []
return this.data.allTests.map( return this.data.allTests.map(
testFile => this.createSingleTest(testFile) testFile => this.createSingleTest(testFile)
) )
@ -281,7 +280,7 @@ module.exports = class TestTab extends ViewPlugin {
const stopBtnLabel = document.getElementById('runTestsTabStopActionLabel') const stopBtnLabel = document.getElementById('runTestsTabStopActionLabel')
stopBtnLabel.innerText = 'Stop' stopBtnLabel.innerText = 'Stop'
if (this.data.selectedTests.length !== 0) { if (this.data.selectedTests.length !== 0) {
const runBtn = document.getElemenstById('runTestsTabRunAction') const runBtn = document.getElementById('runTestsTabRunAction')
runBtn.removeAttribute('disabled') runBtn.removeAttribute('disabled')
} }
this.areTestsRunning = false this.areTestsRunning = false
@ -351,9 +350,10 @@ module.exports = class TestTab extends ViewPlugin {
}) })
} }
updateCurrentPath(e) { updateCurrentPath (e) {
this.testTabLogic.setCurrentPath(e.target.value) this.testTabLogic.setCurrentPath(e.target.value)
// todo check if path exists if not create one. this.updateRunAction()
this.updateForNewCurrent()
} }
runTests () { runTests () {
@ -401,13 +401,6 @@ module.exports = class TestTab extends ViewPlugin {
Generate Generate
</button> </button>
` `
if (
!currentFile ||
(currentFile && currentFile.split('.').pop().toLowerCase() !== 'sol')
) {
//el.setAttribute('disabled', 'disabled')
//el.setAttribute('title', 'No solidity file selected')
}
if (!this.generateFileActionElement) { if (!this.generateFileActionElement) {
this.generateFileActionElement = el this.generateFileActionElement = el
} else { } else {
@ -423,8 +416,8 @@ module.exports = class TestTab extends ViewPlugin {
<label class="${css.labelOnBtn} btn btn-primary p-1 ml-2 m-0">Run</label> <label class="${css.labelOnBtn} btn btn-primary p-1 ml-2 m-0">Run</label>
</button> </button>
` `
const isSolidityActive = this.appManager.actives.includes('solidity') const isSolidityActive = this.appManager.isActive('solidity')
if (!currentFile || !isSolidityActive || (currentFile && currentFile.split('.').pop().toLowerCase() !== 'sol')) { if (!isSolidityActive || !this.listTests().length) {
el.setAttribute('disabled', 'disabled') el.setAttribute('disabled', 'disabled')
if (!currentFile || (currentFile && currentFile.split('.').pop().toLowerCase() !== 'sol')) { if (!currentFile || (currentFile && currentFile.split('.').pop().toLowerCase() !== 'sol')) {
el.setAttribute('title', 'No solidity file selected') el.setAttribute('title', 'No solidity file selected')
@ -458,6 +451,7 @@ module.exports = class TestTab extends ViewPlugin {
} else { } else {
yo.update(this.testFilesListElement, el) yo.update(this.testFilesListElement, el)
} }
this.updateRunAction()
return this.testFilesListElement return this.testFilesListElement
} }
@ -489,6 +483,11 @@ module.exports = class TestTab extends ViewPlugin {
return yo`<span class='text-info h6'>Progress: ${ready} finished (of ${this.runningTestsNumber})</span>` return yo`<span class='text-info h6'>Progress: ${ready} finished (of ${this.runningTestsNumber})</span>`
} }
allPaths () {
const paths = ['browser', 'browser/test']
return paths
}
render () { render () {
this.onActivationInternal() this.onActivationInternal()
this.testsOutput = yo`<div class="mx-3 mb-2 pb-4 border-top border-primary" hidden='true' id="solidityUnittestsOutput" data-id="testTabSolidityUnitTestsOutput"></a>` this.testsOutput = yo`<div class="mx-3 mb-2 pb-4 border-top border-primary" hidden='true' id="solidityUnittestsOutput" data-id="testTabSolidityUnitTestsOutput"></a>`
@ -503,11 +502,12 @@ module.exports = class TestTab extends ViewPlugin {
class="custom-select" class="custom-select"
id="utPath" id="utPath"
name="utPath" name="utPath"
onchange=${(e)=>this.updateCurrentPath(e)}/> style="background-image: var(--primary);"
onchange=${(e) => this.updateCurrentPath(e)}/>
${this.uiPathList} ${this.uiPathList}
</div> </div>
` `
let options = ['browser', 'browser/ll/test'] let options = ['browser', 'browser/test'] // this.allPaths()
options.forEach((path) => { options.forEach((path) => {
this.uiPathList.appendChild(yo`<option>${path}</option>`) this.uiPathList.appendChild(yo`<option>${path}</option>`)
}) })

@ -1,6 +1,6 @@
const helper = require('../../../lib/helper.js') const helper = require('../../../lib/helper.js')
const modalDialogCustom = require('../../ui/modal-dialog-custom') const modalDialogCustom = require('../../ui/modal-dialog-custom')
const remixPath = require('path')
class TestTabLogic { class TestTabLogic {
constructor (fileManager) { constructor (fileManager) {
@ -8,22 +8,24 @@ class TestTabLogic {
this.currentPath = 'browser/tests' this.currentPath = 'browser/tests'
} }
setCurrentPath(path) { setCurrentPath (path) {
if (path.indexOf('/') === 0) return
this.currentPath = path this.currentPath = path
const fileProvider = this.fileManager.fileProviderOf(path.split('/')[0])
fileProvider.exists(path, (e, res) => { if (!res) fileProvider.createDir(path) })
} }
generateTestFile () { generateTestFile () {
let fileName = this.fileManager.currentFile() let fileName = this.fileManager.currentFile()
const hasCurrent = !!fileName const hasCurrent = !!fileName && this.fileManager.currentFile().split('.').pop().toLowerCase() === 'sol'
if (!fileName) fileName = this.currentPath + '/newFile.sol' if (!hasCurrent) fileName = this.currentPath + '/newFile.sol'
const fileProvider = this.fileManager.fileProviderOf(this.currentPath) const fileProvider = this.fileManager.fileProviderOf(this.currentPath)
if (!fileProvider) return if (!fileProvider) return
const splittedFileName = fileName.split('/') const splittedFileName = fileName.split('/')
const fileNameToImport = (!hasCurrent) ? fileName : this.currentPath + '/' + splittedFileName[splittedFileName.length - 1] let fileNameToImport = (!hasCurrent) ? fileName : this.currentPath + '/' + splittedFileName[splittedFileName.length - 1]
//const fileNameToImport = (!fileName) ? fileName : splittedFileName[splittedFileName.length - 1]
helper.createNonClashingNameWithPrefix(fileNameToImport, fileProvider, '_test', (error, newFile) => { helper.createNonClashingNameWithPrefix(fileNameToImport, fileProvider, '_test', (error, newFile) => {
if (error) return modalDialogCustom.alert('Failed to create file. ' + newFile + ' ' + error) if (error) return modalDialogCustom.alert('Failed to create file. ' + newFile + ' ' + error)
if (!fileProvider.set(newFile, this.generateTestContractSample(hasCurrent, fileNameToImport))) return modalDialogCustom.alert('Failed to create test file ' + newFile) if (!fileProvider.set(newFile, this.generateTestContractSample(hasCurrent, fileName))) return modalDialogCustom.alert('Failed to create test file ' + newFile)
this.fileManager.open(newFile) this.fileManager.open(newFile)
}) })
} }
@ -48,7 +50,9 @@ class TestTabLogic {
// @todo(#2758): If currently selected file is compiled and compilation result is available, // @todo(#2758): If currently selected file is compiled and compilation result is available,
// 'contractName' should be <compiledContractName> + '_testSuite' // 'contractName' should be <compiledContractName> + '_testSuite'
generateTestContractSample (hasCurrent, fileToImport, contractName = 'testSuite') { generateTestContractSample (hasCurrent, fileToImport, contractName = 'testSuite') {
const comment = hasCurrent ? `import "${fileToImport}";` : '// Import here the file to test.' let relative = remixPath.relative(this.currentPath, remixPath.dirname(fileToImport))
if (relative === '') relative = '.'
const comment = hasCurrent ? `import "${relative}/${remixPath.basename(fileToImport)}";` : '// Import here the file to test.'
return `pragma solidity >=0.4.22 <0.7.0; return `pragma solidity >=0.4.22 <0.7.0;
import "remix_tests.sol"; // this import is automatically injected by Remix. import "remix_tests.sol"; // this import is automatically injected by Remix.
${comment} ${comment}

Loading…
Cancel
Save