Skip to content

Commit

Permalink
Add first test
Browse files Browse the repository at this point in the history
  • Loading branch information
joyarzun committed Jul 18, 2017
1 parent 414f217 commit ef561ac
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/Sonus.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const Sonus = require('../index')
const mockData = "mydata"
const mockStream = require('./mockStream')(mockData)
const speech = {}
speech.createRecognizeStream = mockStream
const hotwords = [{
file: 'resources/snowboy.umdl',
hotword: 'snowboy'
}]
const sonus = Sonus.init({
hotwords
}, speech)

describe("Sonus", () => {
beforeEach(() => {
Sonus.start(sonus)
})

afterEach(() => {
Sonus.stop(sonus)
})

it("listen event", () => {
sonus.on('hotword', () => console.log("!"))
sonus.on('final-result', console.log)
})

it("trigger hotword", () => {
sonus.on('hotword', () => console.log("!"))
sonus.on('final-result', (data) => {
expect(data).toBe(mockData)
})
Sonus.trigger(sonus, 1)
})
})
25 changes: 25 additions & 0 deletions test/mockStream.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var Readable = require("stream").Readable
var util = require("util")
var _transcript
module.exports = transcript => {
_transcript = transcript
return mockStream
}

function mockStream(options) {
if (!(this instanceof mockStream)) return new mockStream(options)
if (!options) options = {}
options.objectMode = true
Readable.call(this, options)
}

util.inherits(mockStream, Readable)

mockStream.prototype._read = function read() {
this.emit("data", {
results: [{
isFinal: true,
transcript: _transcript
}]
})
}

0 comments on commit ef561ac

Please sign in to comment.