uci-base/test/base.test.mjs

92 lines
2.1 KiB
JavaScript

import { spawn } from 'child_process'
import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'
import Base from '../src/base'
chai.use(chaiAsPromised)
const expect = chai.expect
const USOCKET = '/opt/sockets/samplecs.sock'
const delay = time => new Promise(res=>setTimeout(()=>res(),time))
let app = new Base({id:'uci-base-app', desc:'a consumer app', path:USOCKET})
// app.ucpp = 'cprocessPacket'
//
// app.processPacket = async function (packet) {
// console.log('packet received from socket')
// console.dir(packet)
// app.emit('test2', packet)
// }
describe('Base Class', function () {
it('Has an id', function () {
expect(app.id).to.equal('uci-base-app')
})
it('Has a description', function () {
expect(app.desc).to.equal('a consumer app')
})
it('Is basic emitter', function () {
app.on('etest',function(data){
expect(data).to.equal('test')
})
app.emit('etest', 'test')
})
})
;
(async () => {
let socket={}
socket = spawn('node',['-r', '@std/esm', './test/base.socket'])
await delay(500) // wait for socket to get going
await app.init()
//
// let packet = {sender:'test consumer', cmd:'test', data:'some data'}
// app.test = (packet) =>{
// console.dir('packet',packet)
// }
// app.send(packet)
// await delay(1000)
socket.kill()
})().catch(err => {
console.error('FATAL: UNABLE TO START SYSTEM!\n',err)
})
// describe('Base Class - sockets', function () {
//
// let socket={}
//
// before(async function(){
// socket = spawn('node',['-r', '@std/esm', './test/base.socket'])
// await delay(500) // wait for socket to get going
// // await app.init()
// })
//
// after(async function(){
// socket.kill()
// })
//
// it('Can communicate via unix socket', async function () {
// let packet = {sender:'test consumer', cmd:'test', data:'some data'}
// app.test = (packet) =>{
// console.dir('packet',packet)
// // expect(packet.processed).to.equal(true)
// expect(packet.data).to.equal('some data')
// }
// app.send(packet)
// await delay(1000)
// })
// })