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

Show full page error on crash #536

Merged
merged 15 commits into from
Mar 7, 2018
Prev Previous commit
Next Next commit
fixed tests
  • Loading branch information
faboweb committed Mar 6, 2018
commit 84c579a0dabfb9aae08c63d20eac83ff93eeb1fb
65 changes: 39 additions & 26 deletions test/unit/specs/main.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const {join} = require('path')
const {
join
} = require('path')
const mockFsExtra = require('../helpers/fs-mock').default

function sleep (ms) {
Expand Down Expand Up @@ -35,6 +37,10 @@ jest.mock('electron', () => {
}
on () {}
maximize () {}
},
Menu: class MockMenu {
buildFromTemplate () {}
setApplicationMenu () {}
}
}
return electron
Expand All @@ -49,15 +55,19 @@ childProcessMock((path, args) => ({
stdout: {
on: (type, cb) => {
if (args[0] === 'version' && type === 'data') {
cb({toString: () => 'v0.5.0'})
cb({
toString: () => 'v0.5.0'
})
}
}
},
stderr: {
on: (type, cb) => {
// test for init of gaia
if (type === 'data' && args[1] === 'init' && args.length === 4) {
cb({ toString: () => 'already is initialized' })
cb({
toString: () => 'already is initialized'
})
}
}
}
Expand Down Expand Up @@ -397,9 +407,9 @@ describe('Startup Process', () => {

expect(childProcess.spawn.mock.calls
.find(([path, args]) =>
path.includes('gaia') &&
args.includes('rest-server')
).length
path.includes('gaia') &&
args.includes('rest-server')
).length
).toBeGreaterThan(1)
})

Expand All @@ -408,13 +418,13 @@ describe('Startup Process', () => {
await initMain()
let configText = fs.readFileSync(join(testRoot, 'config.toml'), 'utf8')
configText = configText.split('\n')
.map(line => {
if (line.startsWith('seeds')) {
return 'seeds = ""'
} else {
return line
}
}).join('\n')
.map(line => {
if (line.startsWith('seeds')) {
return 'seeds = ""'
} else {
return line
}
}).join('\n')
fs.writeFileSync(join(testRoot, 'config.toml'), configText, 'utf8')

resetModulesKeepingFS()
Expand Down Expand Up @@ -453,9 +463,9 @@ describe('Startup Process', () => {
await initMain()
expect(childProcess.spawn.mock.calls
.find(([path, args]) =>
path.includes('gaia') &&
args.includes('init')
).length
path.includes('gaia') &&
args.includes('init')
).length
).toBe(3) // one to check in first round, one to check + one to init in the second round
})
})
Expand All @@ -468,8 +478,7 @@ describe('Startup Process', () => {
testFailingChildProcess('gaia', 'init')
})

describe('Electron startup', () => {
})
describe('Electron startup', () => {})
})

function mainSetup () {
Expand Down Expand Up @@ -510,15 +519,15 @@ function childProcessMock (mockExtend = () => ({})) {
jest.mock('child_process', () => ({
spawn: jest.fn((path, args) => Object.assign({}, {
stdout: {
on: () => { },
pipe: () => { }
on: () => {},
pipe: () => {}
},
stderr: {
on: () => { },
pipe: () => { }
on: () => {},
pipe: () => {}
},
on: () => { },
kill: () => { }
on: () => {},
kill: () => {}
}, mockExtend(path, args)))
}))
}
Expand All @@ -538,15 +547,19 @@ function failingChildProcess (mockName, mockCmd) {
stdout: {
on: (type, cb) => {
if (args[0] === 'version' && type === 'data') {
cb({toString: () => 'v0.5.0'})
cb({
toString: () => 'v0.5.0'
})
}
}
},
stderr: {
on: (type, cb) => {
// test for init of gaia
if (type === 'data' && args[1] === 'init' && args.length === 4) {
cb({ toString: () => 'already is initialized' })
cb({
toString: () => 'already is initialized'
})
}
}
}
Expand Down