From 0d96830e9ad25c497dab959ad8def7722338c054 Mon Sep 17 00:00:00 2001 From: LianaHus Date: Thu, 18 Jun 2020 21:18:32 +0200 Subject: [PATCH] use relative path, create folder if does not exist --- apps/remix-ide/src/app.js | 3 +- apps/remix-ide/src/app/files/fileProvider.js | 5 ++- apps/remix-ide/src/app/tabs/test-tab.js | 40 +++++++++---------- .../remix-ide/src/app/tabs/testTab/testTab.js | 20 ++++++---- 4 files changed, 37 insertions(+), 31 deletions(-) diff --git a/apps/remix-ide/src/app.js b/apps/remix-ide/src/app.js index d1860aa955..4a4e75719c 100644 --- a/apps/remix-ide/src/app.js +++ b/apps/remix-ide/src/app.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() diff --git a/apps/remix-ide/src/app/files/fileProvider.js b/apps/remix-ide/src/app/files/fileProvider.js index 1b02dd398b..d745fb0c4a 100644 --- a/apps/remix-ide/src/app/files/fileProvider.js +++ b/apps/remix-ide/src/app/files/fileProvider.js @@ -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) => { diff --git a/apps/remix-ide/src/app/tabs/test-tab.js b/apps/remix-ide/src/app/tabs/test-tab.js index 468a9df57e..943ba29978 100644 --- a/apps/remix-ide/src/app/tabs/test-tab.js +++ b/apps/remix-ide/src/app/tabs/test-tab.js @@ -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 ` - 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` - ` - 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`Progress: ${ready} finished (of ${this.runningTestsNumber})` } + allPaths () { + const paths = ['browser', 'browser/test'] + return paths + } + render () { this.onActivationInternal() this.testsOutput = yo` ` - let options = ['browser', 'browser/ll/test'] + let options = ['browser', 'browser/test'] // this.allPaths() options.forEach((path) => { this.uiPathList.appendChild(yo``) }) diff --git a/apps/remix-ide/src/app/tabs/testTab/testTab.js b/apps/remix-ide/src/app/tabs/testTab/testTab.js index 3988de6b8d..2f8a571a81 100644 --- a/apps/remix-ide/src/app/tabs/testTab/testTab.js +++ b/apps/remix-ide/src/app/tabs/testTab/testTab.js @@ -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 + '_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}