From 7bdf308a9a28c4b1e7fc43d5c7e27a1baf9c7d36 Mon Sep 17 00:00:00 2001 From: bunsenstraat Date: Sat, 16 Oct 2021 13:45:41 +0200 Subject: [PATCH] e2e --- .../src/local-plugin/src/app/Client.ts | 8 +- .../src/local-plugin/src/app/app.tsx | 4 +- .../src/local-plugin/tests/plugin-api.test.ts | 15 ++-- .../src/tests/plugin_api.test.ts | 86 +++++++++++++++++++ .../src/assets/js/workspace_1632313874650 | 1 + package-lock.json | 49 ++++++++++- package.json | 6 +- 7 files changed, 151 insertions(+), 18 deletions(-) create mode 100644 apps/remix-ide-e2e/src/tests/plugin_api.test.ts create mode 160000 apps/remix-ide/src/assets/js/workspace_1632313874650 diff --git a/apps/remix-ide-e2e/src/local-plugin/src/app/Client.ts b/apps/remix-ide-e2e/src/local-plugin/src/app/Client.ts index 25fefb8eb8..169af33c8d 100644 --- a/apps/remix-ide-e2e/src/local-plugin/src/app/Client.ts +++ b/apps/remix-ide-e2e/src/local-plugin/src/app/Client.ts @@ -176,12 +176,12 @@ export class WorkSpacePlugin extends PluginClient { async test (p: string) {} - async activate () { - this.call('manager', 'activatePlugin', 'remixd') + async activate (id: string) { + this.call('manager', 'activatePlugin', id) } - async deactivate () { - this.call('manager', 'deactivatePlugin', '111') + async deactivate (id: string) { + this.call('manager', 'deactivatePlugin', id) } async getresult () { diff --git a/apps/remix-ide-e2e/src/local-plugin/src/app/app.tsx b/apps/remix-ide-e2e/src/local-plugin/src/app/app.tsx index 0353f36d47..b26a5297b2 100644 --- a/apps/remix-ide-e2e/src/local-plugin/src/app/app.tsx +++ b/apps/remix-ide-e2e/src/local-plugin/src/app/app.tsx @@ -43,8 +43,8 @@ function App () { - - + + diff --git a/apps/remix-ide-e2e/src/local-plugin/tests/plugin-api.test.ts b/apps/remix-ide-e2e/src/local-plugin/tests/plugin-api.test.ts index 9f723f0f82..7a489dadf9 100644 --- a/apps/remix-ide-e2e/src/local-plugin/tests/plugin-api.test.ts +++ b/apps/remix-ide-e2e/src/local-plugin/tests/plugin-api.test.ts @@ -17,9 +17,9 @@ interface dataIdSelectorInterface extends Selector { } const setCompilerVersion = async (t: TestController, version: string) => { - const citySelect = Selector('#versionSelector') + const citySelect = Selector('#evmVersionSelector') const cityOption = citySelect.find('option') - await t.click(citySelect).click(cityOption.withAttribute('value', 'builtin')) + await t.click(citySelect).click(cityOption.withAttribute('value', 'london')) } const ClickLaunchIcon = async (t: TestController, icon: string) => { @@ -56,7 +56,7 @@ const localPluginData = { ] } -test('install plugin', async t => { +test.only('install plugin', async t => { // exists doesn't wait with timeouts, this is a hack but it works, it will wait for buttons to appear // https://testcafe.io/documentation/402829/guides/basic-guides/select-page-elements#selector-timeout await Selector('Button', { timeout: 120000 }).innerText @@ -64,9 +64,14 @@ test('install plugin', async t => { await t.click(Selector('Button').withText('Sure')) } await t.click('.introjs-skipbutton') - // await ClickLaunchIcon(t, 'solidity') + await ClickLaunchIcon(t, 'solidity') + + await t.click(Selector("#optimize")) + await setCompilerVersion(t, 'builtin') + await t.wait(10000) // await setCompilerVersion(t, 'builtin') - await installPlugin(t, localPluginData) + + // await installPlugin(t, localPluginData) }) test.disablePageReloads('switch to plugin', async t => { diff --git a/apps/remix-ide-e2e/src/tests/plugin_api.test.ts b/apps/remix-ide-e2e/src/tests/plugin_api.test.ts new file mode 100644 index 0000000000..5129345e31 --- /dev/null +++ b/apps/remix-ide-e2e/src/tests/plugin_api.test.ts @@ -0,0 +1,86 @@ +'use strict' +import { NightwatchBrowser } from 'nightwatch' +import init from '../helpers/init' + +declare global { + interface Window { testmode: boolean; } +} + +const localPluginData = { + pluginName: 'localPlugin', + pluginDisplayName: 'Local Plugin', + pluginCanActivate: 'dGitProvider,flattener,solidityUnitTesting', + pluginUrl: 'http://localhost:2020' +} + +const assertLog = function (browser: NightwatchBrowser, buttonText: string, msg: any, payload: string) { + if (payload) { + browser.clearValue('//*[@id="payload"]').setValue('//*[@id="payload"]', payload).pause(1000) + } + if (msg && typeof msg !== 'string') msg = JSON.stringify(msg) + browser + .useXpath().waitForElementVisible(`//*[text()='${buttonText}']`).click(`//*[text()='${buttonText}']`) + .pause(2000) + + if (msg) { + browser.waitForElementVisible('//*[@id="log"]').assert.containsText('//*[@id="log"]', msg) + } +} + +module.exports = { + before: function (browser: NightwatchBrowser, done: VoidFunction) { + init(browser, done, 'http://127.0.0.1:8080', false) + }, + + 'Should Load Plugin Manager': function (browser: NightwatchBrowser) { + browser.waitForElementVisible('*[data-id="remixIdeSidePanel"]') + .pause(3000) + .click('*[plugin="pluginManager"]') + .pause(3000) + .waitForElementVisible('*[data-id="pluginManagerComponentPluginManager"]') + .assert.containsText('*[data-id="sidePanelSwapitTitle"]', 'PLUGIN MANAGER') + }, + + 'Should connect a local plugin': function (browser: NightwatchBrowser) { + browser.waitForElementVisible('*[data-id="pluginManagerComponentPluginManager"]') + .execute(function () { + window.testmode = true + }) + .click('*[data-id="pluginManagerComponentPluginSearchButton"]') + .waitForElementVisible('*[data-id="pluginManagerLocalPluginModalDialogModalDialogContainer-react"]') + .click('*[data-id="pluginManagerLocalPluginModalDialogModalDialogModalBody-react"]') + .waitForElementVisible('*[data-id="localPluginName"]') + .clearValue('*[data-id="localPluginName"]').setValue('*[data-id="localPluginName"]', localPluginData.pluginName) + .clearValue('*[data-id="localPluginDisplayName"]').setValue('*[data-id="localPluginDisplayName"]', localPluginData.pluginDisplayName) + .clearValue('*[data-id="localPluginUrl"]').setValue('*[data-id="localPluginUrl"]', localPluginData.pluginUrl) + .clearValue('*[data-id="localPluginCanActivate"]').setValue('*[data-id="localPluginCanActivate"]', localPluginData.pluginCanActivate) + .click('*[data-id="localPluginRadioButtoniframe"]') + .click('*[data-id="localPluginRadioButtonsidePanel"]') + .click('*[data-id="pluginManagerLocalPluginModalDialogModalDialogModalFooter-react"]') + .click('*[data-id="pluginManagerLocalPluginModalDialog-modal-footer-ok-react') + .waitForElementVisible('[data-id="verticalIconsKindlocalPlugin"]') + .click('[data-id="verticalIconsKindlocalPlugin"]') + // @ts-ignore + .frame(0) + }, + + 'Should get current workspace': function (browser: NightwatchBrowser) { + assertLog(browser, 'get workspace', { name: 'default_workspace', isLocalhost: false, absolutePath: '.workspaces/default_workspace' }, null) + }, + 'Should get current files': function (browser: NightwatchBrowser) { + assertLog(browser, 'readdir', { contracts: { isDirectory: true }, scripts: { isDirectory: true }, tests: { isDirectory: true }, 'README.txt': { isDirectory: false } }, null) + }, + 'Should throw error on current file': function (browser: NightwatchBrowser) { + assertLog(browser, 'getcurrentfile', 'Error from IDE : Error: No such file or directory No file selected', null) + }, + 'Should open readme.txt': function (browser: NightwatchBrowser) { + assertLog(browser, 'openfile', null, 'README.txt') + }, + 'Should have current file': function (browser: NightwatchBrowser) { + assertLog(browser, 'getcurrentfile', 'README.txt', null) + }, + 'Should activate solidityUnitTesting': function (browser: NightwatchBrowser) { + assertLog(browser, 'activate', null, 'solidityUnitTesting') + } + +} diff --git a/apps/remix-ide/src/assets/js/workspace_1632313874650 b/apps/remix-ide/src/assets/js/workspace_1632313874650 new file mode 160000 index 0000000000..6af4ed6169 --- /dev/null +++ b/apps/remix-ide/src/assets/js/workspace_1632313874650 @@ -0,0 +1 @@ +Subproject commit 6af4ed6169ee4165ce86457f98c0a568bd9d7491 diff --git a/package-lock.json b/package-lock.json index fd5de4c2c2..226eda8245 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25119,6 +25119,12 @@ "isobject": "^3.0.1" } }, + "is-port-reachable": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/is-port-reachable/-/is-port-reachable-3.1.0.tgz", + "integrity": "sha512-vjc0SSRNZ32s9SbZBzGaiP6YVB+xglLShhgZD/FHMZUXBvQWaV9CtzgeVhjccFJrI6RAMV+LX7NYxueW/A8W5A==", + "dev": true + }, "is-posix-bracket": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/is-posix-bracket/-/is-posix-bracket-0.1.1.tgz", @@ -42384,15 +42390,17 @@ "integrity": "sha1-9RWxoWLek8LM7y/AyjPztVQ+OMg=" }, "selenium-standalone": { - "version": "6.24.0", - "resolved": "https://registry.npmjs.org/selenium-standalone/-/selenium-standalone-6.24.0.tgz", - "integrity": "sha512-Dun2XgNAgCfJNrrSzuv7Z7Wj7QTvBKpqx0VXFz7bW9T9FUe5ytzgzoCEEshwDVMh0Dv6sCgdZg7VDhM/q2yPPQ==", + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/selenium-standalone/-/selenium-standalone-7.1.0.tgz", + "integrity": "sha512-Pc7U48qwB4LVy/XczBrPPXwUhEPl3XQSik8SjLfj2qzBEtZqrjyzOlnnXq4aVCdr5wH9FiFJm8LwheJbK2+/oQ==", "dev": true, "requires": { - "commander": "^2.20.3", + "commander": "^7.2.0", "cross-spawn": "^7.0.3", "debug": "^4.3.1", + "fs-extra": "^10.0.0", "got": "^11.8.2", + "is-port-reachable": "^3.0.0", "lodash.mapvalues": "^4.6.0", "lodash.merge": "^4.6.2", "minimist": "^1.2.5", @@ -42433,6 +42441,12 @@ "responselike": "^2.0.0" } }, + "commander": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-7.2.0.tgz", + "integrity": "sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw==", + "dev": true + }, "cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", @@ -42468,6 +42482,17 @@ "integrity": "sha512-4tvttepXG1VaYGrRibk5EwJd1t4udunSOVMdLSAL6mId1ix438oPwPZMALY41FCijukO1L0twNcGsdzS7dHgDg==", "dev": true }, + "fs-extra": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.0.0.tgz", + "integrity": "sha512-C5owb14u9eJwizKGdchcDUQeFtlSHHthBk8pbX9Vc1PFZrLombudjDnNns88aYslCyF6IY5SUw3Roz6xShcEIQ==", + "dev": true, + "requires": { + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" + } + }, "get-stream": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.2.0.tgz", @@ -42502,6 +42527,16 @@ "integrity": "sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ==", "dev": true }, + "jsonfile": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", + "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", + "dev": true, + "requires": { + "graceful-fs": "^4.1.6", + "universalify": "^2.0.0" + } + }, "keyv": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.0.3.tgz", @@ -42577,6 +42612,12 @@ "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", "dev": true }, + "universalify": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", + "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==", + "dev": true + }, "which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", diff --git a/package.json b/package.json index e0ef5e476e..ad8a7d9ab8 100644 --- a/package.json +++ b/package.json @@ -90,7 +90,7 @@ "nightwatch_local_runAndDeploy": "npm run build:e2e && nightwatch --config dist/apps/remix-ide-e2e/nightwatch.js dist/apps/remix-ide-e2e/src/tests/runAndDeploy.js --env=chrome-runAndDeploy", "nightwatch_local_url": "npm run build:e2e && nightwatch --config dist/apps/remix-ide-e2e/nightwatch.js dist/apps/remix-ide-e2e/src/tests/url.spec.js --env=chrome", "nightwatch_local_verticalIconscontextmenu": "npm run build:e2e && nightwatch --config dist/apps/remix-ide-e2e/nightwatch.js dist/apps/remix-ide-e2e/src/tests/verticalIconsPanel.spec.js --env=chrome", - "testcafe_local_pluginApi": "testcafe --config-file apps/remix-ide-e2e/src/local-plugin/.testcaferc.js apps/remix-ide-e2e/src/local-plugin/tests/plugin-api.test.ts", + "testcafe_local_pluginApi": "npm run build:e2e && nightwatch --config dist/apps/remix-ide-e2e/nightwatch.js dist/apps/remix-ide-e2e/src/tests/plugin_api.test.js --env=chrome", "onchange": "onchange apps/remix-ide/build/app.js -- npm-run-all lint", "remixd": "nx build remixd && nx serve remixd --folder=./apps/remix-ide/contracts --remixide=http://127.0.0.1:8080", "selenium": "selenium-standalone start", @@ -276,7 +276,7 @@ "mkdirp": "^0.5.1", "mocha": "^8.0.1", "nanohtml": "^1.6.3", - "nightwatch": "^1.5.1", + "nightwatch": "^1.7.11", "nodemon": "^2.0.4", "notify-error": "^1.2.0", "npm-link-local": "^1.1.0", @@ -288,7 +288,7 @@ "remix-tabs": "1.1.3", "request": "^2.83.0", "rimraf": "^2.6.1", - "selenium-standalone": "^6.17.0", + "selenium-standalone": "^7.1.0", "semver": "^6.3.0", "solc": "0.7.4", "swarmgw": "^0.3.1",