diff --git a/apps/remix-ide-e2e/src/commands/renamePath.ts b/apps/remix-ide-e2e/src/commands/renamePath.ts index d87faf7261..7ac7606631 100644 --- a/apps/remix-ide-e2e/src/commands/renamePath.ts +++ b/apps/remix-ide-e2e/src/commands/renamePath.ts @@ -2,7 +2,7 @@ import EventEmitter from 'events' import { NightwatchBrowser } from 'nightwatch' class RenamePath extends EventEmitter { - command (this: NightwatchBrowser, path: string, newFileName: string, renamedPath: string) { + command(this: NightwatchBrowser, path: string, newFileName: string, renamedPath: string) { this.api.perform((done) => { renamePath(this.api, path, newFileName, renamedPath, () => { done() @@ -13,9 +13,9 @@ class RenamePath extends EventEmitter { } } -function renamePath (browser: NightwatchBrowser, path: string, newFileName: string, renamedPath: string, done: VoidFunction) { +function renamePath(browser: NightwatchBrowser, path: string, newFileName: string, renamedPath: string, done: VoidFunction) { browser.execute(function (path: string) { - function contextMenuClick (element) { + function contextMenuClick(element) { const evt = element.ownerDocument.createEvent('MouseEvents') const RIGHT_CLICK_BUTTON_CODE = 2 // the same for FF and IE @@ -32,15 +32,19 @@ function renamePath (browser: NightwatchBrowser, path: string, newFileName: stri } contextMenuClick(document.querySelector('[data-path="' + path + '"]')) }, [path], function () { - browser - .click('#menuitemrename') - .sendKeys('[data-input-path="' + path + '"]', newFileName) - .sendKeys('[data-input-path="' + path + '"]', browser.Keys.ENTER) - .waitForElementNotPresent('[data-path="' + path + '"]') - .waitForElementPresent('[data-path="' + renamedPath + '"]') - .perform(() => { - done() - }) + try { + browser + .click('#menuitemrename') + .sendKeys('[data-input-path="' + path + '"]', newFileName) + .sendKeys('[data-input-path="' + path + '"]', browser.Keys.ENTER) + .waitForElementNotPresent('[data-path="' + path + '"]') + .waitForElementPresent('[data-path="' + renamedPath + '"]'); + } catch (error) { + console.error('An error occurred:', error.message); + // Handle error (e.g., take a screenshot, log the error, etc.) + } finally { + done(); // Ensure done is called even if there's an error + } }) } diff --git a/apps/remix-ide-e2e/src/tests/remixd.test.ts b/apps/remix-ide-e2e/src/tests/remixd.test.ts index 994d44d18f..b6be54cb5f 100644 --- a/apps/remix-ide-e2e/src/tests/remixd.test.ts +++ b/apps/remix-ide-e2e/src/tests/remixd.test.ts @@ -51,6 +51,36 @@ const sources = [ } ] +function isPortInUse(port) { + return new Promise((resolve, reject) => { + const lsof = spawn('lsof', ['-i', `:${port}`]); + + let output = ''; + let error = ''; + + lsof.stdout.on('data', (data) => { + output += data.toString(); + }); + + lsof.stderr.on('data', (data) => { + error += data.toString(); + }); + + lsof.on('close', (code) => { + if (code === 0 && output) { + // Port is in use if lsof has output + resolve(true); + } else if (error) { + // Handle potential errors (e.g., lsof command not found) + reject(new Error(`lsof error: ${error}`)); + } else { + // Port is not in use + resolve(false); + } + }); + }); +} + module.exports = { '@disabled': true, before: function (browser, done) { @@ -59,15 +89,17 @@ module.exports = { after: function (browser) { browser.perform((done) => { - try { - console.log('remixd pid', remixd.pid); - treeKill(remixd.pid, 'SIGKILL', (err) => { - console.log('remixd killed', err) - }) - console.log('Service disconnected successfully.'); - } catch (error) { - console.error('Failed to disconnect service:', error); - } + isPortInUse(65520).then((inUse) => { + try { + console.log('remixd pid', remixd.pid); + treeKill(remixd.pid, 'SIGKILL', (err) => { + console.log('remixd killed', err) + }) + console.log('Service disconnected successfully.'); + } catch (error) { + console.error('Failed to disconnect service:', error); + } + }) done() }) }, @@ -334,7 +366,7 @@ function runTests(browser: NightwatchBrowser, done: any) { .waitForElementVisible('[data-path="folder1"]') .waitForElementVisible('[data-path="folder1/contract_' + browserName + '.sol"]') .click('[data-path="folder1/contract_' + browserName + '.sol"]') // rename a file and check - .pause(1000) + .pause() .saveScreenshot('./reports/screenshots/remixd1.png') .renamePath('folder1/contract_' + browserName + '.sol', 'renamed_contract_' + browserName, 'folder1/renamed_contract_' + browserName + '.sol') .pause(1000)