Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reenable tape e2e tests #457

Merged
merged 20 commits into from
Feb 13, 2018
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion app/src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function createWindow () {
} else {
startVueApp()
}
if (DEV || process.env.COSMOS_DEVTOOLS) {
if (DEV || JSON.parse(process.env.COSMOS_DEVTOOLS || 'false')) {
mainWindow.webContents.openDevTools()
}

Expand Down Expand Up @@ -153,6 +153,9 @@ function createWindow () {

function startProcess (name, args, env) {
let binPath
if (process.env.BINARY_PATH) {
binPath = process.env.BINARY_PATH
} else
if (DEV || TEST) {
// in dev mode or tests, use binaries installed in GOPATH
let GOPATH = process.env.GOPATH
Expand Down Expand Up @@ -305,11 +308,13 @@ if (!TEST) {
process.on('exit', shutdown)
process.on('uncaughtException', async function (err) {
logError('[Uncaught Exception]', err)
console.error('[Uncaught Exception]', err)
await shutdown()
process.exit(1)
})
process.on('unhandledRejection', async function (err) {
logError('[Unhandled Promise Rejection]', err)
console.error('[Unhandled Promise Rejection]', err)
await shutdown()
process.exit(1)
})
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"pack:renderer": "cross-env NODE_ENV=production webpack --colors --config webpack.renderer.config.js",
"test": "npm run lint && npm run test:unit",
"test:unit": "cross-env LOGGING=false MOCK=false jest --maxWorkers=2",
"test:e2e": "tape \"test/e2e/!(main)*.js\"",
"test:e2e": "tape \"test/e2e/*.js\"",
"test:exe": "node tasks/test-build.js",
"test:coverage": "http-server test/unit/coverage/lcov-report",
"vue:route": "node tasks/vue/route.js",
Expand Down
57 changes: 48 additions & 9 deletions test/e2e/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,64 @@ function sleep (ms) {
}

module.exports = {
navigate (t, client, linkText, titleText = linkText) {
t.test(`navigate to "${linkText}"`, async function (t) {
await client.$(`a*=${linkText}`).click()
await client.waitUntilTextExists('.ni-page-header-title', titleText)
t.pass(`navigated to "${linkText}"`)
t.end()
})
async openMenu (client) {
if (await client.isExisting('.app-menu')) {
return
}
// close notifications as they overlay the menu button
while (await client.isExisting(`.ni-notification`)) {
await client.$(`.ni-notification`).click()
}
await client.$('#app-menu-button').click()
await client.waitForExist('.app-menu', 1000)
},
async navigate (client, linkText, titleText = linkText) {
await module.exports.openMenu(client)
// click link
await client.$(`a*=${linkText}`).click()
await client.waitUntilTextExists('.ni-page-header-title', titleText)
console.log(`navigated to "${linkText}"`)
},
newTempDir () {
return join(tmpdir(), Math.random().toString(36).slice(2))
},
sleep,
async waitForText (el, text, timeout = 5000) {
async waitForText (elGetterFn, text, timeout = 5000) {
let start = Date.now()
while (await el().getText() !== text) {
while (await elGetterFn().getText() !== text) {
if (Date.now() - start >= timeout) {
throw Error('Timed out waiting for text')
}
await sleep(100)
}
},
async login (client, account = 'testkey') {
console.log('logging into ' + account)
let accountsSelect = '#sign-in-name select'

await selectOption(client, accountsSelect, account)

await client.$('#sign-in-password').setValue('1234567890')
await client.$('.ni-session-footer button').click()
await client.waitForExist('#app-content', 5000)

// checking if user is logged in
await module.exports.openMenu(client)
let activeUser = await client.$('.ni-li-user .ni-li-title').getText()
if (account !== activeUser) {
throw new Error('Incorrect user logged in')
}
},
async logout (client) {
console.log('logging out')
await module.exports.openMenu(client)

await client.$('.ni-li-user').click()
await client.$('.material-icons=exit_to_app').$('..').click()
}
}

async function selectOption (client, selectSelector, text) {
await client.$(selectSelector).click()
await client.keys(text.split())
}
164 changes: 123 additions & 41 deletions test/e2e/launch.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,76 @@ let { Application } = require('spectron')
let test = require('tape-promise/tape')
let electron = require('electron')
let { join } = require('path')
let { newTempDir } = require('./common.js')
let { spawn } = require('child_process')
let { newTempDir, login } = require('./common.js')

// re-use app instance
let app

module.exports = async function launch (t) {
if (app) return app

let home = newTempDir()
console.error(`ui home: ${home}`)

app = new Application({
path: electron,
args: [
join(__dirname, '../../app/dist/main.js'),
'--disable-gpu',
'--no-sandbox'
],
startTimeout: 10000,
waitTimeout: 10000,
env: {
COSMOS_UI_ONLY: 'true',
COSMOS_TEST: 'true',
COSMOS_HOME: home,
COSMOS_NETWORK: join(__dirname, 'gaia-1')
}
})
let app, home, cliHome, started
let binary = process.env.BINARY_PATH

await app.start()
module.exports = function launch (t) {
if (!started) {
started = new Promise(async (resolve, reject) => {
console.log('using binary', binary)

// TODO cleanup
home = newTempDir()
cliHome = join(newTempDir(), 'baseserver')
console.error(`ui home: ${home}`)
console.error(`node home: ${cliHome}`)

await startLocalNode()

app = new Application({
path: electron,
args: [
join(__dirname, '../../app/dist/main.js'),
'--disable-gpu',
'--no-sandbox'
],
startTimeout: 10000,
waitTimeout: 10000,
env: {
// COSMOS_UI_ONLY: 'true',
// COSMOS_TEST: 'true',
COSMOS_NODE: 'localhost',
NODE_ENV: 'production',
PREVIEW: 'true',
COSMOS_DEVTOOLS: 0, // open devtools will cause issues with spectron, you can open them later manually
COSMOS_HOME: home,
COSMOS_NETWORK: 'test/e2e/localtestnet'
}
})

t.test('launch app', function (t) {
t.ok(app.isRunning(), 'app is running')
t.end()
})
await startApp(app)
t.ok(app.isRunning(), 'app is running')

t.test('wait for app to load', async function (t) {
await app.client.waitForExist('.header-item-logo', 5000)
.then(() => t.pass('app loaded'))
.catch(e => {
printAppLog(app)
t.fail()
throw e
})
t.end()
})
console.log('stopping app to test consecutive run')
await app.stop()

await createAccount('testkey', 'chair govern physical divorce tape movie slam field gloom process pen universe allow pyramid private ability')
await createAccount('testreceiver', 'crash ten rug mosquito cart south allow pluck shine island broom deputy hungry photo drift absorb')
console.log('restored test accounts')

return app
await startApp(app)
t.ok(app.isRunning(), 'app is running')

await login(app.client, 'testkey')

resolve({app, home})
})
}

return started
}

test.onFinish(() => app ? app.stop() : null)
test.onFinish(async () => {
console.log('DONE: cleaning up')
await app ? app.stop() : null
// tape doesn't finish properly because of open processes like gaia
process.exit(0)
})

function printAppLog (app) {
app.client.getMainProcessLogs().then(function (logs) {
Expand All @@ -69,3 +89,65 @@ function printAppLog (app) {
})
})
}

async function startApp (app) {
await app.start()

await app.client.waitForExist('.ni-session', 5000)
.catch(e => {
printAppLog(app)
throw e
})
}

async function startLocalNode () {
await new Promise((resolve, reject) => {
let child = spawn(binary, [
'node', 'init',
'D0718DDFF62D301626B428A182F830CBB0AD21FC',
'--home', cliHome,
'--chain-id' , 'localtestnet'
])
child.once('exit', (code) => {
if (code === 0) resolve()
reject()
})
})
console.log('inited local node')

await new Promise((resolve, reject) => {
// TODO cleanup
let localnodeProcess = spawn(binary, [
'node', 'start',
'--home', cliHome
])
localnodeProcess.stderr.pipe(process.stderr)
localnodeProcess.stdout.once('data', data => {
let msg = data.toString()
if (!msg.includes('Failed') && !msg.includes('Error')) {
resolve()
}
reject()
})
localnodeProcess.once('exit', (code) => {
reject()
})
})
console.log('started local node')
}

async function createAccount (name, seed) {
await new Promise((resolve, reject) => {
let child = spawn(binary, [
'client', 'keys', 'recover', name,
'--home', join(home, 'baseserver')
])
child.stdin.write('1234567890\n')
child.stdin.write(seed + '\n')
child.stderr.pipe(process.stdout)
child.once('exit', (code) => {
if (code === 0) resolve()
reject()
})
})
}
36 changes: 15 additions & 21 deletions test/e2e/localtestnet/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,27 @@
# For more information, see https://github.com/toml-lang/toml

proxy_app = "tcp://127.0.0.1:46658"
moniker = "local"
moniker = "localhost"
fast_sync = true
db_backend = "memdb"
#log_level = "mempool:error,*:debug"

db_backend = "leveldb"
log_level = "state:info,*:error"
#log_level = "*:debug"


[rpc]
laddr = "tcp://127.0.0.1:46657"
laddr = "tcp://0.0.0.0:46657"

#[mempool]
#recheck = false
#broadcast = false
#wal_dir = ""

[consensus]
#max_block_size_txs = 10000
#create_empty_blocks = false
#timeout_propose = 10000
#skip_timeout_commit = true
#timeout_commit = 1
#wal_light = true
#block_part_size = 262144
create_empty_blocks_interval = 1
create_empty_blocks_interval = 60

[tx_index]
index_all_tags = true


[p2p]
#max_msg_packet_payload_size=65536
#send_rate=51200000 # 50 MB/s
#recv_rate=51200000 # 50 MB/s
laddr = "tcp://127.0.0.1:46656"
seeds = ""
max_num_peers = 300
pex = true
laddr = "tcp://0.0.0.0:46656"
seeds = "localhost:46656"
1 change: 1 addition & 0 deletions test/e2e/localtestnet/gaiaversion.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v0.5.0
39 changes: 0 additions & 39 deletions test/e2e/main.js

This file was deleted.

Loading