diff --git a/apps/remix-ide-e2e/src/tests/remixd-dyn.test.ts b/apps/remix-ide-e2e/src/tests/remixd-dyn.test.ts index fb7ae82e51..fd3f637c58 100644 --- a/apps/remix-ide-e2e/src/tests/remixd-dyn.test.ts +++ b/apps/remix-ide-e2e/src/tests/remixd-dyn.test.ts @@ -1,6 +1,8 @@ 'use strict' import { NightwatchBrowser } from 'nightwatch' import { writeFileSync } from 'fs' +import { join } from 'path' +import { spawn } from 'child_process' import init from '../helpers/init' import * as hardhatCompilation from '../helpers/hardhat_compilation_14f7eb130f02e4d9abcd68528a373e96.json' import * as hardhat_compilation_Lock_dbg from '../helpers/hardhat_compilation_Lock.dbg.json' @@ -21,12 +23,17 @@ module.exports = { }, 'Should listen on compilation result from hardhat #group1': function (browser: NightwatchBrowser) { + let remixd browser.perform((done) => { + remixd = spawnRemixd(join(process.cwd(), '/apps/remix-ide', '/contracts/hardhat')) console.log('working directory', process.cwd()) - - writeFileSync('./apps/remix-ide/contracts/artifacts/contracts/Lock.dbg.json', JSON.stringify(hardhat_compilation_Lock_dbg)) - writeFileSync('./apps/remix-ide/contracts/artifacts/contracts/Lock.json', JSON.stringify(hardhat_compilation_Lock)) - writeFileSync('./apps/remix-ide/contracts/artifacts/build-info/14f7eb130f02e4d9abcd68528a373e96.json', JSON.stringify(hardhatCompilation)) + startRemixd(browser, done) + }) + .perform((done) => { + console.log('generating compilation result') + writeFileSync('./apps/remix-ide/contracts/hardhat/artifacts/contracts/Lock.dbg.json', JSON.stringify(hardhat_compilation_Lock_dbg)) + writeFileSync('./apps/remix-ide/contracts/hardhat/artifacts/contracts/Lock.json', JSON.stringify(hardhat_compilation_Lock)) + writeFileSync('./apps/remix-ide/contracts/hardhat/artifacts/build-info/14f7eb130f02e4d9abcd68528a373e96.json', JSON.stringify(hardhatCompilation)) done() }) .expect.element('*[data-id="terminalJournal"]').text.to.contain('receiving compilation result from hardhat').before(60000) @@ -35,23 +42,48 @@ module.exports = { .selectContract('Lock') .createContract('1') .expect.element('*[data-id="terminalJournal"]').text.to.contain('Unlock time should be in the future').before(60000) + + browser.perform(() => { + remixd.kill() + }) }, 'Should load compilation result from hardhat when remixd connects #group2': function (browser: NightwatchBrowser) { // artifacts/build-info/c7062fdd360381a85af23eeef31c98f8.json has already been created + let remixd browser + .perform((done) => { + writeFileSync('./apps/remix-ide/contracts/hardhat/artifacts/contracts/Lock.dbg.json', JSON.stringify(hardhat_compilation_Lock_dbg)) + writeFileSync('./apps/remix-ide/contracts/hardhat/artifacts/contracts/Lock.json', JSON.stringify(hardhat_compilation_Lock)) + writeFileSync('./apps/remix-ide/contracts/hardhat/artifacts/build-info/14f7eb130f02e4d9abcd68528a373e96.json', JSON.stringify(hardhatCompilation)) + done() + }) + .perform((done) => { + remixd = spawnRemixd(join(process.cwd(), '/apps/remix-ide', '/contracts/hardhat')) + console.log('working directory', process.cwd()) + startRemixd(browser, done) + }) .expect.element('*[data-id="terminalJournal"]').text.to.contain('receiving compilation result from hardhat').before(60000) browser.clickLaunchIcon('udapp') .selectContract('Lock') .createContract('1') .expect.element('*[data-id="terminalJournal"]').text.to.contain('Unlock time should be in the future').before(60000) + + browser.perform(() => { + remixd.kill() + }) }, 'Should listen on compilation result from foundry #group3': function (browser: NightwatchBrowser) { + let remixd browser.perform((done) => { + remixd = spawnRemixd(join(process.cwd(), '/apps/remix-ide', '/contracts/foundry')) console.log('working directory', process.cwd()) - writeFileSync('./apps/remix-ide/contracts/out/Counter.sol/Counter.json', JSON.stringify(foundryCompilation)) + startRemixd(browser, done) + }) + .perform((done) => { + writeFileSync('./apps/remix-ide/contracts/foundry/out/Counter.sol/Counter.json', JSON.stringify(foundryCompilation)) done() }) .expect.element('*[data-id="terminalJournal"]').text.to.contain('receiving compilation result from foundry').before(60000) @@ -70,13 +102,22 @@ module.exports = { browser.testConstantFunction(contractAaddress, 'number - call', null, '0:\nuint256: 1').perform(() => { done() }) - }) + }) + + browser.perform(() => { + remixd.kill() + }) }, 'Should listen on compilation result from truffle #group4': function (browser: NightwatchBrowser) { + let remixd browser.perform((done) => { + remixd = spawnRemixd(join(process.cwd(), '/apps/remix-ide', '/contracts/truffle')) console.log('working directory', process.cwd()) - writeFileSync('./apps/remix-ide/contracts/build/contracts/Migrations.json', JSON.stringify(truffle_compilation)) + startRemixd(browser, done) + }) + .perform((done) => { + writeFileSync('./apps/remix-ide/contracts/truffle/build/contracts/Migrations.json', JSON.stringify(truffle_compilation)) done() }) .expect.element('*[data-id="terminalJournal"]').text.to.contain('receiving compilation result from truffle').before(60000) @@ -87,6 +128,41 @@ module.exports = { .testFunction('last', { status: 'true Transaction mined and execution succeed' - }) + }) + + browser.perform(() => { + remixd.kill() + }) } } + +function spawnRemixd (path: string) { + const remixd = spawn('yarn run remixd', [`-s ${path}`], { cwd: process.cwd(), shell: true }) + remixd.stdout.on('data', function(data) { + console.log('stdout: ' + data.toString()) + }) + remixd.stderr.on('err', function(data) { + console.log('err: ' + data.toString()) + }) + return remixd +} + +function startRemixd (browser: NightwatchBrowser, done: any) { + const browserName = browser.options.desiredCapabilities.browserName + if (browserName === 'safari' || browserName === 'internet explorer') { + console.log('do not run remixd test for ' + browserName + ': sauce labs doesn\'t seems to handle websocket') + browser.end() + done() + return + } + + browser + .waitForElementVisible('#icon-panel', 2000) + .clickLaunchIcon('filePanel') + .clickLaunchIcon('pluginManager') + .scrollAndClick('#pluginManager *[data-id="pluginManagerComponentActivateButtonremixd"]') + .waitForElementVisible('*[data-id="remixdConnect-modal-footer-ok-react"]', 2000) + .pause(2000) + .click('*[data-id="remixdConnect-modal-footer-ok-react"]') + .perform(() => done()) +}