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

fail on console.error #256

Merged
merged 23 commits into from
Dec 21, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 2 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
build:
docker:
# specify the version you desire here
- image: circleci/node:8.0.0-browsers
- image: circleci/node:8.9.3-browsers

working_directory: ~/repo

Expand Down Expand Up @@ -42,6 +42,5 @@ jobs:
key: v1-dependencies-app-{{ checksum "app/package.json" }}

- run: yarn lint
# - run: npm run pack
- run: xvfb-run -e /dev/stdout -a npm run test
- run: yarn run test
- run: codeclimate-test-reporter < test/unit/coverage/lcov.info
20 changes: 11 additions & 9 deletions app/src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,17 @@ function setupLogging (root) {
}
}

process.on('exit', shutdown)
process.on('uncaughtException', function (err) {
logError('[Uncaught Exception]', err)
setTimeout(async () => {
await shutdown()
process.exit(1)
}, 200)
setTimeout(shutdown, 200)
})
if (!TEST) {
process.on('exit', shutdown)
process.on('uncaughtException', function (err) {
logError('[Uncaught Exception]', err)
setTimeout(async () => {
await shutdown()
process.exit(1)
}, 200)
setTimeout(shutdown, 200)
})
}

function consistentConfigDir (versionPath, genesisPath, configPath) {
return exists(genesisPath) && exists(versionPath) && exists(configPath)
Expand Down
12 changes: 8 additions & 4 deletions app/src/renderer/App.vue
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
<template lang="pug">
#app
app-header
#app-content: router-view
#app-content
router-view
app-footer
notifications(:notifications='notifications' theme='cosmos')
modal-help
session
</template>

<script>
import { mapGetters } from 'vuex'
import AppHeader from './components/common/AppHeader'
import AppHeader from 'common/AppHeader'
import AppFooter from 'common/AppFooter'
import Notifications from '@nylira/vue-notifications'
import ModalHelp from './components/common/NiModalHelp'
import Session from './components/common/NiSession'
import ModalHelp from 'common/NiModalHelp'
import Session from 'common/NiSession'
import store from './vuex/store'
export default {
name: 'app',
components: {
AppHeader,
AppFooter,
ModalHelp,
Notifications,
Session
Expand Down
14 changes: 5 additions & 9 deletions app/src/renderer/components/common/NiPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,27 @@
div(slot='subtitle') {{ subtitle }}
div(slot="menu"): slot(name="menu")
main.ni-page-main: slot
app-footer
</template>

<script>
import { mapGetters } from 'vuex'
import PerfectScrollbar from 'perfect-scrollbar'
import PageHeader from 'common/NiPageHeader'
import AppFooter from 'common/AppFooter'
import PageFooter from 'common/NiPageFooter'
export default {
name: 'ni-page',
props: ['title', 'subtitle', 'icon'],
components: {
PageHeader,
AppFooter
PageFooter
},
computed: {
...mapGetters(['config'])
},
mounted () {
let ps
if (this.config.desktop) {
ps = new PerfectScrollbar('.ni-page-main')
} else {
ps.destroy()
}
const container = this.$el.querySelector('.ni-page-main')
// eslint-disable-next-line no-new
new PerfectScrollbar(container)
}
}
</script>
Expand Down
2 changes: 2 additions & 0 deletions app/src/renderer/styles/app.styl
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ a

#app-content
flex 1
display flex
flex-flow column no-wrap

.desktop-only
display block
3 changes: 3 additions & 0 deletions app/src/renderer/vuex/modules/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export default ({ commit, basecoin }) => {
}
}
const mutations = {
setDevMode (state, value) {
state.devMode = value
},
setModalHelp (state, value) {
state.modals.help.active = value
},
Expand Down
2 changes: 1 addition & 1 deletion app/src/renderer/vuex/modules/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export default ({ commit, node }) => {
done(null, args)
dispatch('queryWalletBalances')
},
async loadDenoms () {
async loadDenoms ({ state, commit }) {
// read genesis.json to get default denoms

// wait for genesis.json to exist
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@
"testURL": "http://localhost",
"setupFiles": [
"./test/unit/helpers/fixed_time.js",
"./test/unit/helpers/setup.js"
"./test/unit/helpers/setup.js",
"./test/unit/helpers/console_error_throw.js"
]
},
"optionalDependencies": {
Expand Down
File renamed without changes.
12 changes: 12 additions & 0 deletions test/unit/helpers/console_error_throw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
global.console.error = (...args) => {
throw new Error(args.join(' '))
}

if (!process.env.LISTENING_TO_UNHANDLED_REJECTION) {
process.on('unhandledRejection', reason => {
throw reason
})
// Avoid memory leak by adding too many listeners
process.env.LISTENING_TO_UNHANDLED_REJECTION = true
}

12 changes: 11 additions & 1 deletion test/unit/helpers/node_mock.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
module.exports = {
// rest
getKey: () => ({}),
generateKey: () => ({key: '123'}),
queryAccount: () => null,
queryNonce: () => '123',
buildSend: (args) => {
if (args.to.addr.indexOf('fail') !== -1) return Promise.reject('Failed on purpose')
return Promise.resolve(null)
},
coinTxs: () => Promise.resolve({}),
candidates: () => Promise.resolve({data: []}),
postTx: () => Promise.resolve({
check_tx: { code: 0 },
deliver_tx: { code: 0 }
}),
sign: () => Promise.resolve(null)
sign: () => Promise.resolve(null),

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line break?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was to structure rest endpoints away from the rpc object

rpc: {
on: () => {},
subscribe: () => {},
validators: () => []
}
}
45 changes: 45 additions & 0 deletions test/unit/helpers/vuex-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import Vuex from 'vuex'
import VueRouter from 'vue-router'
import { shallow, mount, createLocalVue } from 'vue-test-utils'

import routes from 'renderer/routes'

const Modules = require('renderer/vuex/modules').default
const Getters = require('renderer/vuex/getters')

export default function vuexSetup () {
const modules = Modules({
node: require('../helpers/node_mock')
})

const localVue = createLocalVue()
localVue.use(Vuex)
localVue.use(VueRouter)

function init (componentConstructor, testType = shallow, {stubs, getters = {}}) {
let store = new Vuex.Store({
getters: Object.assign({}, Getters, getters),
modules
})
store.commit('setDevMode', true)

jest.spyOn(store, 'dispatch')
jest.spyOn(store, 'commit')

let router = new VueRouter({routes})

return {
store,
router,
wrapper: testType(componentConstructor, {
localVue, store, router, stubs
})
}
}

return {
localVue,
shallow: (componentConstructor, {stubs, getters} = {}) => init(componentConstructor, shallow, {stubs, getters}),
mount: (componentConstructor, {stubs, getters} = {}) => init(componentConstructor, mount, {stubs, getters})
}
}
6 changes: 3 additions & 3 deletions test/unit/specs/NISession.spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Vuex from 'vuex'
import { mount, createLocalVue } from 'vue-test-utils'
import NISession from 'common/NiSession'
import NiSession from 'common/NiSession'
const config = require('renderer/vuex/modules/config').default({})

const localVue = createLocalVue()
localVue.use(Vuex)

describe('NISessionWelcome', () => {
describe('NiSessionWelcome', () => {
let wrapper, store

beforeEach(() => {
Expand All @@ -16,7 +16,7 @@ describe('NISessionWelcome', () => {
},
modules: {config}
})
wrapper = mount(NISession, {
wrapper = mount(NiSession, {
localVue,
store,
stubs: {
Expand Down
41 changes: 41 additions & 0 deletions test/unit/specs/NiPage.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import Vuex from 'vuex'
import { mount, createLocalVue } from 'vue-test-utils'
import NiPage from 'common/NiPage'

const config = require('renderer/vuex/modules/config').default({})

const localVue = createLocalVue()
localVue.use(Vuex)

describe('NiPage', () => {
let wrapper
let store = new Vuex.Store({
getters: {
config: () => config.state
},
modules: {
config
}
})
store.commit = jest.fn()

beforeEach(() => {
store.commit.mockReset()
wrapper = mount(NiPage, {
localVue,
store,
propsData: {
title: 'Title',
subtitle: 'Subtitle',
icon: 'hello_icon'
},
stubs: {
'app-footer': '<app-footer />'
}
})
})

it('has the expected html structure', () => {
expect(wrapper.vm.$el).toMatchSnapshot()
})
})
61 changes: 16 additions & 45 deletions test/unit/specs/PageBalances.spec.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,16 @@
import Vuex from 'vuex'
import { mount, createLocalVue } from 'vue-test-utils'
import setup from '../helpers/vuex-setup'
import PageBalances from 'renderer/components/wallet/PageBalances'

const filters = require('renderer/vuex/modules/filters').default({})
const wallet = require('renderer/vuex/modules/wallet').default({
node: require('../helpers/node_mock')
})

const localVue = createLocalVue()
localVue.use(Vuex)

describe('PageBalances', () => {
let wrapper, store
let {mount} = setup()

beforeEach(() => {
store = new Vuex.Store({
getters: {
filters: () => filters.state,
wallet: () => wallet.state
},
modules: {
filters,
wallet
}
})
wrapper = mount(PageBalances, {
localVue,
store,
stub: {
AnchorCopy: true,
Btn: true,
ListItem: true,
ModalSearch: true,
Page: true,
Part: true,
ToolBar: true
}
})
let instance = mount(PageBalances)
wrapper = instance.wrapper
store = instance.store

store.commit('setWalletKey', '123abc456def')
store.commit('setWalletBalances', [{
denom: 'ATOM',
amount: 123
Expand All @@ -45,10 +19,8 @@ describe('PageBalances', () => {
amount: 456
}])
store.commit('setSearchQuery', ['balances', ''])
store.state.wallet.key.address = '123abc456def'

jest.spyOn(store, 'commit')
jest.spyOn(store, 'dispatch')
wrapper.update()
})

it('has the expected html structure', () => {
Expand All @@ -72,7 +44,7 @@ describe('PageBalances', () => {
})

it('should show the search on click', () => {
wrapper.find('.ni-tool-bar i').trigger('click')
wrapper.findAll('.ni-tool-bar i').at(1).trigger('click')
expect(wrapper.contains('.ni-modal-search')).toBe(true)
})

Expand All @@ -81,18 +53,17 @@ describe('PageBalances', () => {
})

it('should show the n/a message if there are no denoms', () => {
let {store, wrapper} = mount(PageBalances, {
'data-empty': '<data-empty />'
})
store.commit('setWalletBalances', [])
wrapper.update()
expect(wrapper.findAll('.ni-data-msg').length).toBe(1) // 1 n/a / 0 denoms
expect(wrapper.find('.ni-data-msg__title div').text().trim())
.toContain('N/A') // 1 address + 1 n/a
expect(wrapper.find('data-empty')).toBeDefined()
})

it('should not show the n/a message if there denoms', () => {
it('should not show the n/a message if there are denoms', () => {
wrapper.update()
expect(wrapper.findAll('.ni-li').length).toBe(2) // 2 denoms
expect(wrapper.findAll('.ni-li').at(0).html()).not.toContain('N/A')
expect(wrapper.findAll('.ni-li').at(1).html()).not.toContain('N/A')
expect(wrapper.vm.allDenomBalances.length).not.toBe(0)
expect(wrapper.vm.$el.querySelector('#no-balances')).toBe(null)
})
// TODO do we test mousetrap stuff??
})
Loading