tests: add basic test for all widgets and add eslint to npm test
This commit is contained in:
parent
b228331aa8
commit
b1f0e893a8
5 changed files with 50 additions and 42 deletions
45
tests/test.js
Normal file
45
tests/test.js
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
// Very simple test: load a session with 1 widget of each type
|
||||
var fs = require('fs')
|
||||
|
||||
// create tmp session file
|
||||
|
||||
var session = [{tabs:[{widgets:[]}]}],
|
||||
sessionPath = 'test-session.json'
|
||||
|
||||
require('../scripts/client-shim')
|
||||
|
||||
var {widgets} = require('../src/client/app/widgets')
|
||||
for (let type in widgets) {
|
||||
session[0].tabs[0].widgets.push({type: type})
|
||||
}
|
||||
|
||||
fs.writeFileSync(sessionPath, JSON.stringify(session))
|
||||
|
||||
|
||||
// spawn o-s-c in headless mode and load tmp session
|
||||
|
||||
var {spawn} = require('child_process')
|
||||
|
||||
var proc = spawn('npx', `xvfb-run npm start -- -l ${sessionPath}`.split(' '), {detached: true})
|
||||
|
||||
proc.stdout.on('data', std)
|
||||
proc.stderr.on('data', std)
|
||||
|
||||
|
||||
function std(data){
|
||||
|
||||
if (data.includes('process error')) {
|
||||
console.error(data.toString())
|
||||
end()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// timeout after 5s -> no error
|
||||
setTimeout(end, 5000)
|
||||
|
||||
function end(fail){
|
||||
process.kill(-proc.pid)
|
||||
fs.unlinkSync(sessionPath)
|
||||
process.exit(fail ? 1 : 0)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue