pull/1622/head
filip mertens 3 years ago
parent aacf2ebc75
commit 8760fdb94c
  1. 37
      apps/remix-ide-e2e/src/tests/migrateFileSystem.test.ts
  2. 7
      apps/remix-ide/src/assets/js/init.js
  3. 45
      apps/remix-ide/src/assets/js/migrate.js
  4. 1
      package.json

@ -2,15 +2,38 @@
import { NightwatchBrowser } from 'nightwatch'
import init from '../helpers/init'
declare global {
interface Window { testmode: boolean; }
}
module.exports = {
before: function (browser: NightwatchBrowser, done: VoidFunction) {
init(browser, done, 'http://127.0.0.1:8080?testmigration', false)
init(browser, done, 'http://127.0.0.1:8080?e2e_testmigration=true', false)
},
'Should have README file with TEST README as content': function (browser: NightwatchBrowser) {
browser.waitForElementVisible('*[data-id="remixIdeSidePanel"]', 5000)
.click('*[data-id="verticalIconsFileExplorerIcons"]')
.openFile('README.txt')
.getEditorValue((content) => {
browser.assert.equal(content, 'TEST README')
})
},
'Should have a workspace_test': function (browser: NightwatchBrowser) {
browser.waitForElementVisible('*[data-id="remixIdeSidePanel"]', 5000)
.click('*[data-id="workspacesSelect"] option[value="workspace_test"]')
.waitForElementVisible('*[data-id="treeViewLitreeViewItemtest_contracts"]')
},
'Should have a sol file with test data': function (browser: NightwatchBrowser) {
browser.waitForElementVisible('*[data-id="remixIdeSidePanel"]', 5000)
.click('*[data-id="treeViewLitreeViewItemtest_contracts"]')
.openFile('test_contracts/1_Storage.sol')
.getEditorValue((content) => {
browser.assert.equal(content, 'testing')
})
},
'Should load two workspaces': function (browser: NightwatchBrowser) {
browser.pause(60000).end()
'Should have a artifacts file with JSON test data': function (browser: NightwatchBrowser) {
browser.waitForElementVisible('*[data-id="remixIdeSidePanel"]', 5000)
.click('*[data-id="treeViewLitreeViewItemtest_contracts/artifacts"]')
.openFile('test_contracts/artifacts/Storage_metadata.json')
.getEditorValue((content) => {
const metadata = JSON.parse(content)
browser.assert.equal(metadata.test, 'data')
})
}
}

@ -91,16 +91,15 @@ window.onload = () => {
app.setAttribute('src', versions[versionToLoad])
document.body.appendChild(app)
}
const queryString = window.location.hash
window.testmigration = queryString.includes('testmigration')
window.remixFileSystemCallback = new RemixFileSystem()
window.remixFileSystemCallback.init('RemixFileSystem', { wipe: !!window.testmigration }).then(() => {
window.remixFileSystemCallback.init('RemixFileSystem').then(() => {
window.remixFileSystem = window.remixFileSystemCallback.promises
// check if .workspaces is present in indexeddb
window.remixFileSystem.stat('.workspaces').then((dir) => {
if (dir.isDirectory()) loadApp()
}).catch(() => {
// no indexeddb workspaces
// no indexeddb .workspaces -> run migration
// eslint-disable-next-line no-undef
migrateFilesFromLocalStorage(loadApp)
})

@ -1,6 +1,8 @@
// eslint-disable-next-line no-unused-vars
async function migrateFilesFromLocalStorage (cb) {
if (window.testmigration) localStorage.clear()
let testmigration = false // migration loads test data into localstorage with browserfs
// indexeddb will be empty by this point, so there is no danger but do a check for the origin to load test data so it runs only locally
testmigration = window.location.hash.includes('e2e_testmigration=true') && window.location.host === '127.0.0.1:8080' && window.location.protocol === 'http:'
// eslint-disable-next-line no-undef
BrowserFS.install(window)
// eslint-disable-next-line no-undef
@ -92,9 +94,8 @@ async function migrateFilesFromLocalStorage (cb) {
}
}
//
if (window.testmigration) await populateWorkspace(testData, browserFS)
if (testmigration) await populateWorkspace(testData, browserFS)
const files = await copyFolderToJson('/', null, null, browserFS)
console.log(files)
await populateWorkspace(files, window.remixFileSystem)
// eslint-disable-next-line no-undef
if (cb) cb()
@ -109,49 +110,23 @@ const testData = {
children: {
'.workspaces/default_workspace/README.txt': {
content: 'TEST README'
},
'.workspaces/default_workspace/contracts': {
children: {
'.workspaces/default_workspace/contracts/1_Storage.sol': {
content: "// SPDX-License-Identifier: GPL-3.0\n\npragma solidity >=0.7.0 <0.9.0;\n\n/**\n * @title Storage\n * @dev Store & retrieve value in a variable\n */\ncontract Storage {\n\n uint256 number;\n\n /**\n * @dev Store value in variable\n * @param num value to store\n */\n function store(uint256 num) public {\n number = num;\n }\n\n /**\n * @dev Return value \n * @return value of 'number'\n */\n function retrieve() public view returns (uint256){\n return number;\n }\n}"
},
'.workspaces/default_workspace/contracts/2_Owner.sol': {
content: 'Owner'
},
'.workspaces/default_workspace/contracts/3_Ballot.sol': {
content: 'Balllot'
}
}
},
'.workspaces/default_workspace/tests': {
children: {
'.workspaces/default_workspace/tests/4_Ballot_test.sol': {
content: 'test'
}
}
}
}
},
'.workspaces/workspace_test': {
children: {
'.workspaces/workspace_test/README.txt': {
'.workspaces/workspace_test/TEST_README.txt': {
content: 'TEST README'
},
'.workspaces/workspace_test/contracts': {
'.workspaces/workspace_test/test_contracts': {
children: {
'.workspaces/workspace_test/contracts/2_Owner.sol': {
content: 'Owner'
},
'.workspaces/workspace_test/contracts/3_Ballot.sol': {
content: 'Balllot'
},
'.workspaces/workspace_test/contracts/1_Storage.sol': {
'.workspaces/workspace_test/test_contracts/1_Storage.sol': {
content: 'testing'
},
'.workspaces/workspace_test/contracts/artifacts': {
'.workspaces/workspace_test/test_contracts/artifacts': {
children: {
'.workspaces/workspace_test/contracts/artifacts/Storage_metadata.json': {
content: 'artifact'
'.workspaces/workspace_test/test_contracts/artifacts/Storage_metadata.json': {
content: '{ "test": "data" }'
}
}
}

@ -86,6 +86,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",
"nightwatch_local_migrate_filesystem": "npm run build:e2e && nightwatch --config dist/apps/remix-ide-e2e/nightwatch.js dist/apps/remix-ide-e2e/src/tests/migrateFileSystem.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",

Loading…
Cancel
Save