Skip to content

Commit

Permalink
Merge pull request #410 from cosmos/fabo/25-e2e-new
Browse files Browse the repository at this point in the history
Test build executables
  • Loading branch information
faboweb authored Jan 29, 2018
2 parents fc85ac9 + fcf5f78 commit 8ee224c
Show file tree
Hide file tree
Showing 11 changed files with 820 additions and 285 deletions.
29 changes: 8 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,36 +67,23 @@ $ yarn run uionly
---

### Production
Get the Gaia binary from [GitHub](`https://github.com/cosmos/gaia/releases`).

Build and run the app.
```bash
npm run pack && npm run build:darwin
open builds/Cosmos-darwin-x64/Cosmos.app
yarn run build:{darwin|win32|linux} -- --binary={path to the gaia binary}
open builds/Cosmos-{platform}-x64/Cosmos.app
```

When you are testing the build system you can skip the repackaging of the JS files.
```bash
$ npm run build -- --skip-pack
$ yarn run build:darwin -- --skip-pack --binary=...
```

---

### Build on Windows

- Install [golang](`https://golang.org/dl/`)
- Install [glide](`https://github.com/Masterminds/glide/releases`)
- Install [node](`https://nodejs.org/en/download/`)
- Install Yarn: `$ npm i -g yarn`
- Install Microsoft build tools: `$ npm install --global --production windows-build-tools`
- Set build tools to needed version `yarn config set msvs_version 2015 --global`
- Install [GNU MAKE](`http://gnuwin32.sourceforge.net/packages/make.htm`)
- Install [MinGW64](`https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/installer/mingw-w64-install.exe/download`)
- Add MAKE and MinGW64 to the PATH environment variable ([HOW TO](https://msdn.microsoft.com/de-de/library/windows/desktop/bb776899(v=vs.85).aspx))
- MAKE should be at `C:\Program Files (x86)\GnuWin32\bin`
- MinGW64 you have to look up at `C:\Program Files\mingw-w64\{{version}}\mingw64\bin`
- Pack the electron application: `$ npm run build:win32`
- Build the Setup: `$ npm run release:win32`
- The installer will be under `./builds/cosmos/Cosmos-win32`
To test if your build worked run:
```bash
$ yarn run test:exe {path to the build executable}
```

---

Expand Down
10 changes: 8 additions & 2 deletions app/src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const TEST = JSON.parse(process.env.COSMOS_TEST || 'false') !== false
// TODO default logging or default disable logging?
const LOGGING = JSON.parse(process.env.LOGGING || 'true') !== false
const MOCK = JSON.parse(process.env.MOCK || !TEST && DEV) !== false
const UI_ONLY = JSON.parse(process.env.COSMOS_UI_ONLY || 'false')
const winURL = DEV
? `http://localhost:${config.wds_port}`
: `file://${__dirname}/index.html`
Expand Down Expand Up @@ -118,7 +119,9 @@ function createWindow () {
webPreferences: { webSecurity: false }
})

if (!started) {
if (UI_ONLY) {
mainWindow.loadURL(winURL + '?node=localhost')
} else if (!started) {
mainWindow.loadURL(winURL)
} else {
startVueApp()
Expand Down Expand Up @@ -367,7 +370,7 @@ async function reconnect (seeds) {
}

async function main () {
if (JSON.parse(process.env.COSMOS_UI_ONLY || 'false')) {
if (UI_ONLY) {
return
}

Expand Down Expand Up @@ -464,6 +467,9 @@ async function main () {
lcdPort: LCD_PORT,
relayServerPort: RELAY_PORT,
mock: MOCK,
onSuccesfulStart: () => {
console.log('[START SUCCESS] Vue app successfuly started')
},
onReconnectReq: reconnect.bind(this, seeds)
})

Expand Down
7 changes: 6 additions & 1 deletion app/src/main/relayServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let randomBondTx = (address, delegator) => ({
height: 1000
})

module.exports = function ({relayServerPort, lcdPort, mock = false, onReconnectReq} = {}) {
module.exports = function ({relayServerPort, lcdPort, mock = false, onReconnectReq, onSuccesfulStart} = {}) {
let app = express()

// TODO this lets the server timeout until there is an external request
Expand Down Expand Up @@ -121,6 +121,11 @@ module.exports = function ({relayServerPort, lcdPort, mock = false, onReconnectR
res.send(nodeIP)
})

app.get('/startsuccess', async (req, res) => {
onSuccesfulStart()
res.sendStatus(200)
})

// proxy everything else to light client
app.use(proxy('http://localhost:' + lcdPort))

Expand Down
8 changes: 8 additions & 0 deletions app/src/renderer/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Resource from 'vue-resource'
import Router from 'vue-router'
import Vuelidate from 'vuelidate'
import shrinkStacktrace from '../helpers/shrink-stacktrace.js'
import axios from 'axios'

import App from './App'
import routes from './routes'
Expand Down Expand Up @@ -32,6 +33,13 @@ async function main () {
console.log('Connecting to node:', nodeIP)
const node = Node(nodeIP, relayPort)

node.lcdConnected()
.then(connected => {
if (connected) {
axios.get('http://localhost:8999/startsuccess')
}
})

const router = new Router({
scrollBehavior: () => ({ y: 0 }),
routes
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"node": ">=9.4.0"
},
"scripts": {
"build": "node tasks/release.js",
"build:clean": "cross-env PLATFORM_TARGET=clean node tasks/release.js",
"build:darwin": "cross-env PLATFORM_TARGET=darwin node tasks/release.js",
"build:linux": "cross-env PLATFORM_TARGET=linux node tasks/release.js",
Expand All @@ -31,6 +30,7 @@
"test": "npm run test:unit",
"test:unit": "cross-env LOGGING=false MOCK=false jest --maxWorkers=2",
"test:e2e": "tape \"test/e2e/!(main)*.js\"",
"test:exe": "node tasks/test-build.js",
"vue:route": "node tasks/vue/route.js",
"vuex:module": "node tasks/vuex/module.js"
},
Expand Down Expand Up @@ -107,6 +107,7 @@
"deterministic-tar": "^0.1.2",
"deterministic-zip": "^1.0.5",
"electron": "^1.7.5",
"electron-chromedriver": "^1.8.0",
"event-to-promise": "^0.8.0",
"express": "^4.16.2",
"express-http-proxy": "^1.1.0",
Expand All @@ -125,7 +126,7 @@
"stacktrace-js": "^2.0.0",
"stylus": "^0.54.5",
"stylus-loader": "^3.0.1",
"tendermint": "^2.0.3",
"tendermint": "2.0.3",
"tendermint-crypto": "github:mappum/js-crypto",
"toml": "^2.3.3",
"user-home": "^2.0.0",
Expand Down
17 changes: 17 additions & 0 deletions tasks/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// on windows some processes are not exiting when using child.kill so we use a windows specific comand
module.exports.cleanExitChild = function (child) {
return new Promise((resolve, reject) => {
var isWin = /^win/.test(process.platform)
if (!isWin) {
child.kill('SIGTERM')
} else {
var cp = require('child_process')
cp.exec('taskkill /PID ' + child.pid + ' /T /F', function (error, stdout, stderr) {
if (error !== null) {
console.log('exec error: ' + error)
}
})
}
child.on('exit', resolve)
})
}
19 changes: 1 addition & 18 deletions tasks/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const config = require('../config')
const spawn = require('child_process').spawn
const path = require('path')
const {cleanExitChild} = require('./common.js')

let YELLOW = '\x1b[33m'
let BLUE = '\x1b[34m'
Expand All @@ -11,24 +12,6 @@ let END = '\x1b[0m'
let NPM_BIN = path.join(path.dirname(__dirname), 'node_modules', '.bin')
let PATH = `${NPM_BIN}:${process.env.PATH}`

// on windows some processes are not exiting when using child.kill so we use a windows specific comand
function cleanExitChild (child) {
return new Promise((resolve, reject) => {
var isWin = /^win/.test(process.platform)
if (!isWin) {
child.kill('SIGTERM')
} else {
var cp = require('child_process')
cp.exec('taskkill /PID ' + child.pid + ' /T /F', function (error, stdout, stderr) {
if (error !== null) {
console.log('exec error: ' + error)
}
})
}
child.on('exit', resolve)
})
}

function format (command, data, color) {
return color + command + END +
' ' + // Two space offset
Expand Down
50 changes: 50 additions & 0 deletions tasks/test-build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const spawn = require('child_process').spawn
const {cleanExitChild} = require('./common.js')

function test (executablePath) {
return new Promise(async (resolve, reject) => {
let child
try {
child = spawn(executablePath, {
env: {
ELECTRON_ENABLE_LOGGING: 'true'
}
})

child.stdout.pipe(process.stdout)

child.stdout.on('data', async data => {
let msg = new Buffer(data, 'utf-8').toString()
if (msg.indexOf('[START SUCCESS]') !== -1) {
clearTimeout(wait)
await cleanExitChild(child)
resolve()
}
})

let wait = setTimeout(async () => {
await cleanExitChild(child)
reject()
}, 5000)
} catch (err) {
await cleanExitChild(child)
console.error('Unexpected error', err)
reject(err)
}
})
}

async function main () {
let executablePath = process.argv[2]

if (!executablePath) {
console.error('\nPlease define the executable you want to test like "yarn run test:exe ./Cosmos.exe"\n')
process.exit(-1)
}
await test(executablePath)
.then(() => console.log(executablePath, 'starts as expected'))
.catch(() => console.error(executablePath, 'did not start as expected'))
}

main()

1 change: 1 addition & 0 deletions test/e2e/launch.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module.exports = async function launch (t) {
startTimeout: 10000,
waitTimeout: 10000,
env: {
COSMOS_UI_ONLY: 'true',
COSMOS_TEST: 'true',
COSMOS_HOME: home,
COSMOS_NETWORK: join(__dirname, 'gaia-1')
Expand Down
10 changes: 5 additions & 5 deletions test/unit/specs/main.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ function sleep (ms) {
jest.mock('fs-extra', () => {
let fs = require('fs')
let mockFs = mockFsExtra()
mockFs.writeFile('./app/networks/gaia-1/config.toml', fs.readFileSync('./app/networks/gaia-1/config.toml', 'utf8'))
mockFs.writeFile('./app/networks/gaia-1/genesis.json', fs.readFileSync('./app/networks/gaia-1/genesis.json', 'utf8'))
mockFs.writeFile('./app/networks/gaia-2/config.toml', fs.readFileSync('./app/networks/gaia-2/config.toml', 'utf8'))
mockFs.writeFile('./app/networks/gaia-2/genesis.json', fs.readFileSync('./app/networks/gaia-2/genesis.json', 'utf8'))
return mockFs
})
let fs = require('fs-extra')
Expand Down Expand Up @@ -39,7 +39,7 @@ let childProcess
describe('Startup Process', () => {
Object.assign(process.env, {
COSMOS_TEST: true,
COSMOS_NETWORK: 'app/networks/gaia-1',
COSMOS_NETWORK: 'app/networks/gaia-2',
COSMOS_HOME: testRoot
})

Expand Down Expand Up @@ -80,7 +80,7 @@ describe('Startup Process', () => {
path.includes('gaia') &&
args.includes('client') &&
args.includes('init') &&
args.join('=').includes('--chain-id=gaia-1')
args.join('=').includes('--chain-id=gaia-2')
)
).toBeDefined()
})
Expand Down Expand Up @@ -193,7 +193,7 @@ describe('Startup Process', () => {
path.includes('gaia') &&
args.includes('client') &&
args.includes('init') &&
args.join('=').includes('--chain-id=gaia-1')
args.join('=').includes('--chain-id=gaia-2')
)
).toBeDefined()
})
Expand Down
Loading

0 comments on commit 8ee224c

Please sign in to comment.