Merge pull request #689 from ethereum/fixFileManagerAPI

Fix removePrefix from fileProvider
pull/713/head
yann300 4 years ago committed by GitHub
commit 24492e1f74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      apps/remix-ide-e2e/src/tests/fileExplorer.test.ts
  2. 16
      apps/remix-ide-e2e/src/tests/fileManager_api.test.ts
  3. 3
      apps/remix-ide/src/app/files/fileProvider.js
  4. 1
      apps/remix-ide/src/app/files/remixDProvider.js
  5. 3
      libs/remixd/src/utils.ts

@ -109,3 +109,4 @@ module.exports = {
tearDown: sauce
}

@ -88,6 +88,14 @@ module.exports = {
.executeScript(`remix.exeCurrent()`)
.pause(2000)
.waitForElementNotPresent('[data-id="treeViewLibrowser/old_contract.sol"]')
},
'Should execute `remove` api from file manager external api on a folder': function (browser: NightwatchBrowser) {
browser
.addFile('test_jsRemoveFolder.js', { content: executeRemoveOnFolder })
.executeScript('remix.exeCurrent()')
.pause(2000)
.waitForElementNotPresent('*[key="browser/tests"]')
.end()
},
@ -189,3 +197,11 @@ const executeRemove = `
run()
`
const executeRemoveOnFolder = `(async () => {
try {
await remix.call('fileManager', 'remove', 'browser')
} catch (e) {
console.log(e.message)
}
})()`

@ -170,7 +170,7 @@ class FileProvider {
const items = window.remixFileSystem.readdirSync(path)
if (items.length !== 0) {
items.forEach((item, index) => {
const curPath = `${path}/${item}`
const curPath = `${path}${path.endsWith('/') ? '' : '/'}${item}`
if (window.remixFileSystem.statSync(curPath).isDirectory()) { // delete folder
this.remove(curPath)
} else { // delete file
@ -238,6 +238,7 @@ class FileProvider {
removePrefix (path) {
path = path.indexOf(this.type) === 0 ? path.replace(this.type, '') : path
if (path === '') return '/'
return path
}

@ -166,6 +166,7 @@ module.exports = class RemixDProvider {
removePrefix (path) {
path = path.indexOf(this.type) === 0 ? path.replace(this.type, '') : path
if (path[0] === '/') return path.substring(1)
if (path === '') return '/'
return path
}

@ -11,9 +11,7 @@ import * as pathModule from 'path'
*/
function absolutePath (path: string, sharedFolder:string): string {
path = normalizePath(path)
if (path.indexOf(sharedFolder) !== 0) {
path = pathModule.resolve(sharedFolder, path)
}
return path
}
@ -34,6 +32,7 @@ function normalizePath (path: string): string {
if (process.platform === 'win32') {
return path.replace(/\\/g, '/')
}
if (path === '/') path = './'
return path
}

Loading…
Cancel
Save