Skip to content

Commit

Permalink
Error page fixes and build errors (ethereum#2780)
Browse files Browse the repository at this point in the history
* fixes batch requests on isolated preloaders

* added 404 page for not found swarm content

* fixed coide climate issues

* show custom 404 error only for bzz://

* fixed borwser.js issue and sound and error pages

* trigger travis

* trigger travis

* adding globals to ESLint whitelist

* Small refactor; Fixing 3/4 tests

* Adjusting spectron version

* ESLint

* [Spectron] New fixture server; Fixes 4/4 test.

* Wallet shouldn't start Swarm

* Wallet shouldn't start Swarm

* Adding exception to eslint

* Fix wallet preloader issue
  • Loading branch information
frozeman authored and evertonfraga committed Jul 18, 2017
1 parent 72626a1 commit 846d450
Show file tree
Hide file tree
Showing 13 changed files with 116 additions and 98 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ globals: # don't warn about missing declarations
_: true
window: true
location: true

document: true
1 change: 1 addition & 0 deletions gulpTasks/building.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ gulp.task('copy-app-source-files', () => {
'!./tests/wallet/*',
`./icons/${type}/*`,
'./sounds/*',
'./errorPages/*',
'customProtocols.js'
], {
base: './'
Expand Down
3 changes: 1 addition & 2 deletions interface/client/mistAPIBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,9 @@ mistAPIBackend = function (event) {
appBar: (_.contains(allowedBrowserBarStyles, appBarClass) ? appBarClass : null)
}});
}

if (event.channel === 'mistAPI_sound') {
sound.pause();
sound.src = Blaze._escape(arg);
sound.src = Blaze._escape('file://'+ dirname +'/sounds/' + arg + '.mp3');
sound.play();
}

Expand Down
1 change: 0 additions & 1 deletion interface/client/templates/views/webview.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ Template['views_webview'].onRendered(function () {

// Forward SWARM status code errors to showError
webview.addEventListener('did-get-response-details', function (e) {
console.log(e);
if (e && e.resourceType === 'mainFrame' && /^bzz:\//i.test(e.newURL)) {
switch (e.httpResponseCode) {
case 500:
Expand Down
2 changes: 1 addition & 1 deletion interface/client/templates/webviewEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ webviewChangeUrl = function (tabId, e) {
}

// make sure to not store error pages in history
if (!url || url.indexOf('mist/errorPages/') !== -1) {
if (!url || url.indexOf('mist/errorPages/') !== -1 || url.indexOf('app.asar/errorPages/') !== -1) {
return;
}

Expand Down
4 changes: 4 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,10 @@ onReady = () => {
return ethereumNode.init();
})
.then(() => {
// Wallet shouldn't start Swarm
if (Settings.uiMode === 'wallet') {
return Promise.resolve();
}
return swarmNode.init();
})
.then(function sanityCheck() {
Expand Down
8 changes: 4 additions & 4 deletions modules/preloader/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ const postMessage = function (payload) {


// load ethereumProvider
const bignumber = fs.readFileSync(path.resolve('./modules/preloader/injected/BigNumber.js')).toString();
const eventEmitter3 = fs.readFileSync(path.resolve('./modules/preloader/injected/EventEmitter3.js')).toString();
let mistAPI = fs.readFileSync(path.resolve('./modules/preloader/injected/mistAPI.js')).toString();
const ethereumProvider = fs.readFileSync(path.resolve('./modules/preloader/injected/EthereumProvider.js')).toString();
const bignumber = fs.readFileSync(path.join(__dirname, '/injected/BigNumber.js')).toString();
const eventEmitter3 = fs.readFileSync(path.join(__dirname, '/injected/EventEmitter3.js')).toString();
let mistAPI = fs.readFileSync(path.join(__dirname, '/injected/mistAPI.js')).toString();
const ethereumProvider = fs.readFileSync(path.join(__dirname, '/injected/EthereumProvider.js')).toString();

mistAPI = mistAPI.replace('__version__', packageJson.version)
.replace('__license__', packageJson.license)
Expand Down
6 changes: 3 additions & 3 deletions modules/preloader/injected/mistAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,19 @@
bip: function playSound() {
postMessage({
type: 'mistAPI_sound',
message: 'file://'+ __dirname +'/../../../sounds/bip.mp3'
message: 'bip'
});
},
bloop: function playSound() {
postMessage({
type: 'mistAPI_sound',
message: 'file://'+ __dirname +'/../../../sounds/bloop.mp3'
message: 'bloop'
});
},
invite: function playSound() {
postMessage({
type: 'mistAPI_sound',
message: 'file://'+ __dirname +'/../../../sounds/invite.mp3'
message: 'invite'
});
},
},
Expand Down
3 changes: 2 additions & 1 deletion modules/preloader/walletMain.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
require('./dapps.js');
require('./include/openExternal.js');
require('./include/setBasePath')('interface/wallet');

const {webFrame} = require('electron');
const web3Admin = require('../web3Admin.js');

// make variables globally accessable
// window.dirname = __dirname;

webFrame.executeJavaScript("window.mistMode = 'wallet';");


// add admin later
setTimeout(() => {
web3Admin.extend(window.web3);
Expand Down
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
},
"devDependencies": {
"chai": "^3.5.0",
"chai-as-promised": "^6.0.0",
"co-mocha": "^1.2.0",
"del": "^2.2.2",
"ecstatic": "^2.1.0",
Expand All @@ -52,22 +51,20 @@
"eslint": "^3.14.1",
"eslint-config-airbnb-base": "^11.0.1",
"eslint-plugin-import": "^2.2.0",
"express": "^4.15.3",
"genomatic": "^1.0.0",
"geth-private": "^1.3.0",
"gh-release-assets": "^1.1.0",
"gulp": "^3.9.0",
"gulp-spawn-mocha": "^3.3.0",
"istanbul": "^0.4.5",
"json-structure-diff": "^0.0.2",
"merge-stream": "^1.0.0",
"minimist": "^1.2.0",
"mocha": "^3.2.0",
"optimist": "^0.6.1",
"require-dir": "^0.3.2",
"run-sequence": "^1.2.1",
"semver-compare": "^1.0.0",
"shelljs": "^0.7.7",
"spectron": "3.6.0",
"spectron": "3.4.1",
"xml2js": "^0.4.17"
}
}
4 changes: 4 additions & 0 deletions tests/.eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ globals: # don't warn about missing declarations
it: true
expect: true
chai: true
$: true
LastVisitedPages: true
History: true
localStorage: true
78 changes: 46 additions & 32 deletions tests/_base.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ const fs = require('fs');
const Web3 = require('web3');
const shell = require('shelljs');
const path = require('path');
const packageJson = require('../package.json');
const gethPrivate = require('geth-private');
const Application = require('spectron').Application;
const chai = require('chai');
const http = require('http');
const ecstatic = require('ecstatic');
const express = require('express');
const ClientBinaryManager = require('ethereum-client-binaries').Manager;
const Settings = require('../modules/settings');

chai.should();

Expand All @@ -28,12 +27,10 @@ const startGeth = function* () {
const manager = new ClientBinaryManager(config);
yield manager.init();

if (manager.clients.Geth.state.available) {
if (!manager.clients.Geth.state.available) {
gethPath = manager.clients.Geth.activeCli.fullPath;
}
else {
console.info('Downloading geth...');
let downloadedGeth = yield manager.download('Geth');
const downloadedGeth = yield manager.download('Geth');
gethPath = downloadedGeth.client.activeCli.fullPath;
console.info('Geth downloaded at:', gethPath);
}
Expand All @@ -57,6 +54,18 @@ const startGeth = function* () {
return geth;
};

const startFixtureServer = function (serverPort) {
const app = express();
app.use(express.static(path.join(__dirname, 'fixtures')));

app.get('/redirect', (req, res) => {
// Redirects to param ?url=XX
res.redirect(302, req.query.to);
});
app.listen(serverPort);
return app;
};

exports.mocha = (_module, options) => {
const tests = {};

Expand All @@ -82,11 +91,10 @@ exports.mocha = (_module, options) => {
this.geth = yield startGeth();

const appFileName = (options.app === 'wallet') ? 'Ethereum Wallet' : 'Mist';
const appVers = packageJson.version.replace(/\./ig, '-');
const platformArch = `${process.platform}-${process.arch}`;

let appPath;
let ipcProviderPath = path.join(this.geth.dataDir, 'geth.ipc');
const ipcProviderPath = path.join(this.geth.dataDir, 'geth.ipc');

switch (platformArch) {
case 'darwin-x64':
Expand Down Expand Up @@ -122,18 +130,23 @@ exports.mocha = (_module, options) => {
webdriverLogPath: webdriverLogFile,
chromeDriverLogPath: chromeLogFile,
});

yield this.app.start();
this.client = this.app.client;

/*
Starting HTTP server for HTML fixtures
*/
const serverPort = 8080;
this.httpServer = http.createServer(
ecstatic({root: path.join(__dirname, 'fixtures')})
).listen(serverPort);
this.httpServer = startFixtureServer(serverPort);
this.fixtureBaseUrl = `http://localhost:${serverPort}/`;

this.client = this.app.client;
// this.httpServer = http.createServer(
// ecstatic({root: path.join(__dirname, 'fixtures')})
// ).listen(serverPort);
// this.fixtureBaseUrl = `http://localhost:${serverPort}/`;
//
// this.client = this.app.client;

/*
Utility methods
Expand All @@ -143,8 +156,8 @@ exports.mocha = (_module, options) => {
}

// Loop over windows trying to select Main Window
let app = this;
let selectMainWindow = function* (mainWindowSearch) {
const app = this;
const selectMainWindow = function* (mainWindowSearch) {
let windowHandles = (yield app.client.windowHandles()).value;

for (let handle in windowHandles) {
Expand All @@ -157,15 +170,15 @@ exports.mocha = (_module, options) => {
// not main window. try again after 1 second.
yield Q.delay(1000);
yield selectMainWindow(mainWindowSearch);
}
};

const mainWindowSearch = (options.app === 'wallet') ? /^file:\/\/\/$/ : /interface\/index\.html$/;
yield selectMainWindow(mainWindowSearch);

this.mainWindowHandle = (yield this.client.windowHandle()).value;
},

* beforeEach () {
* beforeEach() {
yield this.app.client.window(this.mainWindowHandle);

yield this.client.execute(() => { // Code executed in context of browser
Expand All @@ -192,10 +205,9 @@ exports.mocha = (_module, options) => {
// yield this.client.reload();
},

* afterEach () {
},
// * afterEach() { },

* after () {
* after() {
if (this.app && this.app.isRunning()) {
console.log('Stopping app...');
yield this.app.stop();
Expand Down Expand Up @@ -339,14 +351,18 @@ const Utils = {
},

* selectTab(tabId) {
const tab = yield this.getUiElement(`.sidebar [data-tab-id=${tabId}]`);
yield this.getUiElement(`.sidebar [data-tab-id=${tabId}]`);
yield this.client.click(`.sidebar [data-tab-id=${tabId}] button.main`);
// TODO: returns webview reference
},
* getActiveWebview() {
const webview = '';
return webview;

* getSelectedWebviewParam(param) {
const selectedTabId = (yield this.client.execute(() => {
return localStorage.getItem('selectedTab');
})).value;
return yield this.client.getAttribute(`webview[data-id=${selectedTabId}]`, param);
},

* loadFixture(uri = '') {
const client = this.client;
yield client.setValue('#url-input', `${this.fixtureBaseUrl}${uri}`);
Expand All @@ -357,10 +373,12 @@ const Utils = {
});
}, 3000, 'expected to properly load fixture');
},

* getBrowserBarText() {
return yield this.client.getText('.url-breadcrumb');
},
*pinCurrentTab() {

* pinCurrentTab() {
const client = this.client;

yield this.openAndFocusNewWindow(() => {
Expand All @@ -374,7 +392,7 @@ const Utils = {
const pinnedWebview = (yield client.windowHandles()).value.pop();
return pinnedWebview;
},
*navigateTo(url) {
* navigateTo(url) {
const client = this.client;
yield client.setValue('#url-input', url);
yield client.submitForm('form.url');
Expand All @@ -386,19 +404,15 @@ const Utils = {
@param search: function that tells how to search by window
@param tries: amount of tries left until give up searching for
*/
*getWindowByUrl(search, tries = 5) {
* getWindowByUrl(search, tries = 5) {
if (tries < 0) throw new Error('Couldn\'t select window using given parameters.');

let windowHandles = (yield this.client.windowHandles()).value;

const windowHandles = (yield this.client.windowHandles()).value;
for (let handle in windowHandles) {
yield this.client.window(windowHandles[handle]);

const found = !!search(yield this.client.getUrl());
if (found) return true;
}
yield Q.delay(500);
yield this.getWindowByUrl(search, --tries);
yield this.getWindowByUrl(search, --tries); //eslint-disable-line
}

};
Loading

0 comments on commit 846d450

Please sign in to comment.