Merge pull request #5102 from ethereum/failtestfaster

fix remixd test
pull/5075/head
bunsenstraat 3 months ago committed by GitHub
commit c987302731
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 27
      apps/remix-ide-e2e/src/commands/renamePath.ts
  2. 80
      apps/remix-ide-e2e/src/tests/remixd.test.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,18 @@ 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);
} finally {
done(); // Ensure done is called even if there's an error
}
})
}

@ -2,10 +2,9 @@
import { NightwatchBrowser } from 'nightwatch'
import init from '../helpers/init'
import { join } from 'path'
import { ChildProcess, spawn } from 'child_process'
import { ChildProcess, exec, spawn } from 'child_process'
import { homedir } from 'os'
import kill from 'tree-kill'
import treeKill from 'tree-kill'
let remixd: ChildProcess
const assetsTestContract = `import "./contract.sol";
@ -50,15 +49,30 @@ const sources = [
}
]
module.exports = {
'@disabled': true,
before: function (browser, done) {
init(browser, done)
},
after: function (browser) {
browser.perform((done) => {
console.log('remixd', remixd.pid)
kill(remixd.pid)
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);
}
try {
resetGitToHead()
} catch (error) {
console.error('Failed to restore git changes:', error);
}
done()
})
},
@ -66,12 +80,14 @@ module.exports = {
'@sources': function () {
return sources
},
'run Remixd tests #group1': function (browser) {
'run Remixd tests #group1': function (browser: NightwatchBrowser) {
browser.perform(async (done) => {
try {
remixd = await spawnRemixd(join(process.cwd(), '/apps/remix-ide', '/contracts'))
} catch (err) {
console.error(err)
// fail
browser.assert.fail('Failed to start remixd')
}
console.log('working directory', process.cwd())
connectRemixd(browser, done)
@ -86,7 +102,12 @@ module.exports = {
remix try to resolve it against the node_modules and installed_contracts folder.
*/
browser.perform(async (done) => {
try{
remixd = await spawnRemixd(join(process.cwd(), '/apps/remix-ide', '/contracts'))
} catch (err) {
console.error(err)
browser.assert.fail('Failed to start remixd')
}
console.log('working directory', process.cwd())
connectRemixd(browser, done)
})
@ -97,7 +118,12 @@ module.exports = {
},
'Import from node_modules and reference a github import #group3': function (browser) {
browser.perform(async (done) => {
try{
remixd = await spawnRemixd(join(process.cwd(), '/apps/remix-ide', '/contracts'))
} catch (err) {
console.error(err)
browser.assert.fail('Failed to start remixd')
}
console.log('working directory', process.cwd())
connectRemixd(browser, done)
})
@ -117,7 +143,12 @@ module.exports = {
'Should listen on compilation result from hardhat #group4': function (browser: NightwatchBrowser) {
browser.perform(async (done) => {
try{
remixd = await spawnRemixd(join(process.cwd(), '/apps/remix-ide/hardhat-boilerplate'))
} catch (err) {
console.error(err)
browser.assert.fail('Failed to start remixd')
}
console.log('working directory', process.cwd())
connectRemixd(browser, done)
})
@ -188,7 +219,12 @@ module.exports = {
browser.perform(async (done) => {
console.log('working directory', homedir() + '/foundry_tmp/hello_foundry')
try{
remixd = await spawnRemixd(join(homedir(), '/foundry_tmp/hello_foundry'))
} catch (err) {
console.error(err)
browser.assert.fail('Failed to start remixd')
}
connectRemixd(browser, done)
})
.perform(async (done) => {
@ -249,7 +285,12 @@ module.exports = {
'Should disable git when running remixd #group9': function (browser: NightwatchBrowser) {
browser.perform(async (done) => {
try{
remixd = await spawnRemixd(join(process.cwd(), '/apps/remix-ide', '/contracts/hardhat'))
} catch (err) {
console.error(err)
browser.assert.fail('Failed to start remixd')
}
console.log('working directory', process.cwd())
connectRemixd(browser, done)
})
@ -281,6 +322,7 @@ module.exports = {
remixd = await spawnRemixd(join(process.cwd(), '/apps/remix-ide', '/contracts'))
} catch (err) {
console.error(err)
browser.assert.fail('Failed to start remixd')
}
console.log('working directory', process.cwd())
connectRemixd(browser, done)
@ -322,8 +364,11 @@ function runTests(browser: NightwatchBrowser, done: any) {
.setEditorValue('contract test1Changed { function get () returns (uint) { return 10; }}')
.testEditorValue('contract test1Changed { function get () returns (uint) { return 10; }}')
.setEditorValue('contract test1 { function get () returns (uint) { return 10; }}')
.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)
.renamePath('folder1/contract_' + browserName + '.sol', 'renamed_contract_' + browserName, 'folder1/renamed_contract_' + browserName + '.sol')
.pause(1000)
.removeFile('folder1/contract_' + browserName + '_toremove.sol', 'localhost')
@ -558,3 +603,26 @@ async function installSlither(): Promise<void> {
console.log(e)
}
}
function resetGitToHead() {
if (process.env.CIRCLECI) {
console.log("Running on CircleCI, resetting Git to HEAD...");
} else {
console.log("Not running on CircleCI, skipping Git reset.");
return
}
const command = 'git reset --hard HEAD && git clean -fd';
exec(command, (error, stdout, stderr) => {
if (error) {
console.error(`Error executing command: ${command}\n${error.message}`);
return;
}
if (stderr) {
console.error(`Error output from command: ${command}\n${stderr}`);
return;
}
console.log(`Git reset to HEAD successfully.\n${stdout}`);
});
}
Loading…
Cancel
Save