use relative path, create folder if does not exist

pull/11/head
LianaHus 4 years ago committed by ioedeveloper
parent 225002e5f8
commit 0d96830e9a
  1. 3
      apps/remix-ide/src/app.js
  2. 5
      apps/remix-ide/src/app/files/fileProvider.js
  3. 40
      apps/remix-ide/src/app/tabs/test-tab.js
  4. 20
      apps/remix-ide/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(['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 params = queryParams.get()

@ -116,9 +116,10 @@ class FileProvider {
}
createDir (path, cb) {
var unprefixedpath = this.removePrefix(path)
const unprefixedpath = this.removePrefix(path)
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()
let currentCheck = ''
paths.forEach((value) => {

@ -33,11 +33,12 @@ module.exports = class TestTab extends ViewPlugin {
this.runningTestsNumber = 0
this.readyTestsNumber = 0
this.areTestsRunning = false
appManager.event.on('activate', (name) => {
if (name === 'solidity') this.updateRunAction(fileManager.currentFile())
if (name === 'solidity') this.updateRunAction()
})
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.updateGenerateFileAction()
this.updateRunAction()
this.updateTestFileList()
})
this.fileManager.events.on('currentFileChanged', (file, provider) => this.updateForNewCurrent(file))
@ -86,6 +84,7 @@ module.exports = class TestTab extends ViewPlugin {
}
listTests () {
if (!this.data.allTests) return []
return this.data.allTests.map(
testFile => this.createSingleTest(testFile)
)
@ -281,7 +280,7 @@ module.exports = class TestTab extends ViewPlugin {
const stopBtnLabel = document.getElementById('runTestsTabStopActionLabel')
stopBtnLabel.innerText = 'Stop'
if (this.data.selectedTests.length !== 0) {
const runBtn = document.getElemenstById('runTestsTabRunAction')
const runBtn = document.getElementById('runTestsTabRunAction')
runBtn.removeAttribute('disabled')
}
this.areTestsRunning = false
@ -351,9 +350,10 @@ module.exports = class TestTab extends ViewPlugin {
})
}
updateCurrentPath(e) {
updateCurrentPath (e) {
this.testTabLogic.setCurrentPath(e.target.value)
// todo check if path exists if not create one.
this.updateRunAction()
this.updateForNewCurrent()
}
runTests () {
@ -401,13 +401,6 @@ module.exports = class TestTab extends ViewPlugin {
Generate
</button>
`
if (
!currentFile ||
(currentFile && currentFile.split('.').pop().toLowerCase() !== 'sol')
) {
//el.setAttribute('disabled', 'disabled')
//el.setAttribute('title', 'No solidity file selected')
}
if (!this.generateFileActionElement) {
this.generateFileActionElement = el
} else {
@ -418,13 +411,13 @@ module.exports = class TestTab extends ViewPlugin {
updateRunAction (currentFile) {
let el = yo`
<button id="runTestsTabRunAction" title="Run tests" data-id="testTabRunTestsTabRunAction" class="w-50 btn btn-primary" onclick="${() => this.runTests()}">
<button id="runTestsTabRunAction" title="Run tests" data-id="testTabRunTestsTabRunAction" class="w-50 btn btn-primary" onclick="${() => this.runTests()}">
<span class="fas fa-play ml-2"></span>
<label class="${css.labelOnBtn} btn btn-primary p-1 ml-2 m-0">Run</label>
</button>
`
const isSolidityActive = this.appManager.actives.includes('solidity')
if (!currentFile || !isSolidityActive || (currentFile && currentFile.split('.').pop().toLowerCase() !== 'sol')) {
const isSolidityActive = this.appManager.isActive('solidity')
if (!isSolidityActive || !this.listTests().length) {
el.setAttribute('disabled', 'disabled')
if (!currentFile || (currentFile && currentFile.split('.').pop().toLowerCase() !== 'sol')) {
el.setAttribute('title', 'No solidity file selected')
@ -458,6 +451,7 @@ module.exports = class TestTab extends ViewPlugin {
} else {
yo.update(this.testFilesListElement, el)
}
this.updateRunAction()
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>`
}
allPaths () {
const paths = ['browser', 'browser/test']
return paths
}
render () {
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>`
@ -503,11 +502,12 @@ module.exports = class TestTab extends ViewPlugin {
class="custom-select"
id="utPath"
name="utPath"
onchange=${(e)=>this.updateCurrentPath(e)}/>
style="background-image: var(--primary);"
onchange=${(e) => this.updateCurrentPath(e)}/>
${this.uiPathList}
</div>
`
let options = ['browser', 'browser/ll/test']
let options = ['browser', 'browser/test'] // this.allPaths()
options.forEach((path) => {
this.uiPathList.appendChild(yo`<option>${path}</option>`)
})

@ -1,6 +1,6 @@
const helper = require('../../../lib/helper.js')
const modalDialogCustom = require('../../ui/modal-dialog-custom')
const remixPath = require('path')
class TestTabLogic {
constructor (fileManager) {
@ -8,22 +8,24 @@ class TestTabLogic {
this.currentPath = 'browser/tests'
}
setCurrentPath(path) {
setCurrentPath (path) {
if (path.indexOf('/') === 0) return
this.currentPath = path
const fileProvider = this.fileManager.fileProviderOf(path.split('/')[0])
fileProvider.exists(path, (e, res) => { if (!res) fileProvider.createDir(path) })
}
generateTestFile () {
let fileName = this.fileManager.currentFile()
const hasCurrent = !!fileName
if (!fileName) fileName = this.currentPath + '/newFile.sol'
const hasCurrent = !!fileName && this.fileManager.currentFile().split('.').pop().toLowerCase() === 'sol'
if (!hasCurrent) fileName = this.currentPath + '/newFile.sol'
const fileProvider = this.fileManager.fileProviderOf(this.currentPath)
if (!fileProvider) return
const splittedFileName = fileName.split('/')
const fileNameToImport = (!hasCurrent) ? fileName : this.currentPath + '/' + splittedFileName[splittedFileName.length - 1]
//const fileNameToImport = (!fileName) ? fileName : splittedFileName[splittedFileName.length - 1]
let fileNameToImport = (!hasCurrent) ? fileName : this.currentPath + '/' + splittedFileName[splittedFileName.length - 1]
helper.createNonClashingNameWithPrefix(fileNameToImport, fileProvider, '_test', (error, newFile) => {
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)
})
}
@ -48,7 +50,9 @@ class TestTabLogic {
// @todo(#2758): If currently selected file is compiled and compilation result is available,
// 'contractName' should be <compiledContractName> + '_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;
import "remix_tests.sol"; // this import is automatically injected by Remix.
${comment}

Loading…
Cancel
Save