From 630a5bb589940f51e06eb49a292b12e846c9dca0 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 21 Dec 2020 12:23:32 +0100 Subject: [PATCH] fix removePrefix --- .../src/tests/fileExplorer.test.ts | 3 ++- .../src/tests/fileManager_api.test.ts | 18 +++++++++++++++++- apps/remix-ide/src/app/files/fileProvider.js | 3 ++- apps/remix-ide/src/app/files/remixDProvider.js | 1 + 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/apps/remix-ide-e2e/src/tests/fileExplorer.test.ts b/apps/remix-ide-e2e/src/tests/fileExplorer.test.ts index 22c39e5de2..b9e7f89fd4 100644 --- a/apps/remix-ide-e2e/src/tests/fileExplorer.test.ts +++ b/apps/remix-ide-e2e/src/tests/fileExplorer.test.ts @@ -105,7 +105,8 @@ module.exports = { .waitForElementVisible('*[key="browser/fileExplorer.test.js"]') .waitForElementVisible('*[key="browser/generalSettings.test.js"]') .end() - }, + }, tearDown: sauce } + diff --git a/apps/remix-ide-e2e/src/tests/fileManager_api.test.ts b/apps/remix-ide-e2e/src/tests/fileManager_api.test.ts index 167f0caca3..80d0653a8e 100644 --- a/apps/remix-ide-e2e/src/tests/fileManager_api.test.ts +++ b/apps/remix-ide-e2e/src/tests/fileManager_api.test.ts @@ -87,7 +87,15 @@ module.exports = { .addFile('removeFile.js', { content: executeRemove }) .executeScript(`remix.exeCurrent()`) .pause(2000) - .waitForElementNotPresent('[data-id="treeViewLibrowser/old_contract.sol"]') + .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) + } +})()` diff --git a/apps/remix-ide/src/app/files/fileProvider.js b/apps/remix-ide/src/app/files/fileProvider.js index 1e05587bd9..aa18cdf645 100644 --- a/apps/remix-ide/src/app/files/fileProvider.js +++ b/apps/remix-ide/src/app/files/fileProvider.js @@ -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 } diff --git a/apps/remix-ide/src/app/files/remixDProvider.js b/apps/remix-ide/src/app/files/remixDProvider.js index 5c903b7c3e..ecbd416581 100644 --- a/apps/remix-ide/src/app/files/remixDProvider.js +++ b/apps/remix-ide/src/app/files/remixDProvider.js @@ -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 }