tests: add basic test for all widgets and add eslint to npm test

This commit is contained in:
bordun 2018-10-29 13:01:13 +01:00
parent b228331aa8
commit b1f0e893a8
5 changed files with 50 additions and 42 deletions

1
tests/test-session.json Normal file
View file

@ -0,0 +1 @@
[{"tabs":[{"widgets":[{"type":"tab"},{"type":"root"},{"type":"fader"},{"type":"knob"},{"type":"encoder"},{"type":"range"},{"type":"toggle"},{"type":"push"},{"type":"switch"},{"type":"dropdown"},{"type":"xy"},{"type":"rgb"},{"type":"multixy"},{"type":"matrix"},{"type":"multitoggle"},{"type":"multipush"},{"type":"multifader"},{"type":"keyboard"},{"type":"led"},{"type":"rgbled"},{"type":"plot"},{"type":"eq"},{"type":"visualizer"},{"type":"meter"},{"type":"text"},{"type":"image"},{"type":"svg"},{"type":"frame"},{"type":"strip"},{"type":"panel"},{"type":"modal"},{"type":"clone"},{"type":"switcher"},{"type":"crossfader"},{"type":"input"},{"type":"keys"},{"type":"script"},{"type":"gyroscope"},{"type":"formula"}]}]}]

45
tests/test.js Normal file
View 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)
}