Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add tests for future refactoring #53

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"extends": "eslint:recommended",
"env": {
"node": true,
"es6": true
"es6": true,
"jest": true
},
"rules": {
"no-console": 0
Expand Down
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
dist: trusty
language: node_js
node_js:
- "--lts"

before_install:
- sudo apt-get -qq update
- sudo apt-get install -y sox libatlas-base-dev

cache:
directories:
- node_modules
- node_modules
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "Open source cross platform decentralized always-on speech recognition framework",
"main": "index.js",
"scripts": {
"test": "eslint ."
"test": "jest",
"lint": "eslint ."
},
"repository": {
"type": "git",
Expand All @@ -31,6 +32,7 @@
"snowboy": "^1.1.0"
},
"devDependencies": {
"eslint": "^3.7.0"
"eslint": "^3.7.0",
"jest": "^20.0.4"
}
}
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
}]
})
}