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 01211758b0
commit b62ec7fb74
5 changed files with 50 additions and 42 deletions

View file

@ -6,7 +6,7 @@ node_js:
before_install:
- sudo dpkg --add-architecture i386
- sudo apt-get update -qq
- sudo apt-get install -qq wine fakeroot
- sudo apt-get install -qq wine fakeroot xvfb
install: npm install
before_deploy:
deploy:

View file

@ -34,6 +34,7 @@
"electron-localshortcut": "3.1.0",
"electron-packager": "12.2.0",
"electron-packager-plugin-non-proprietary-codecs-ffmpeg": "^1.0.2",
"eslint": "^5.8.0",
"exorcist": "1.0.1",
"express": "4.16.4",
"file-saver": "2.0.0-rc.4",
@ -85,7 +86,7 @@
"watch-browser": "npm run build-client-js -- --watch",
"watch-css": "nodemon --watch src/scss -e scss -x \"npm run build-css -- --reload",
"deploy-docs": "node scripts/build-widgets-reference.js > resources/docs/widgets-reference.md && cd resources && mkdocs gh-deploy --clean && rm -rf site",
"test": "npm run build"
"test": "eslint src && npm run build && node tests/test.js"
},
"engines": {
"node": ">=6"

View file

@ -1,43 +1,4 @@
// Dirty browser window shim
document = {
createElementNS: x=>[],
addEventListener: ()=>{},
createRange: ()=>{
return {
createContextualFragment:()=>{return {
firstChild: {
querySelectorAll: x=>[]
}
}},
selectNode: ()=>{}
}
},
body: {
appendChild: ()=>{}
}
}
window = {
addEventListener: ()=>{},
location: {},
document: document,
navigator: {
platform:''
},
NodeList: Array,
WebSocket: Object
}
Object.assign(global, window)
// Required globals
DOM = require('../src/client/app/dom')
DOM.get = x=>[{addEventListener:()=>{}}]
DOM.init()
CANVAS_FRAMERATE = 1
LANG = 'en'
require('./client-shim')
// Here we go

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)
}