Skip to content

Commit

Permalink
Merge branch 'release-1.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
jourdanrodrigues committed Oct 16, 2017
2 parents d7e90de + c1f7bca commit 620399b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ npm i
npm start
```

### Without a board

Perform tests in the other systems that depends on this one without having a real board.

```bash
npm run start-mocked
```

## Testing

The test environment uses a [mocked Firmata library][mock_firmata] (doesn't need a real board).
Expand Down
20 changes: 18 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,23 @@ if (!process.env.SOCKET_HOST) {
const socket = require('socket.io-client').connect(process.env.SOCKET_HOST)
const five = require('johnny-five')

const port = process.env.PORT
const board = port ? new five.Board({port}) : new five.Board()
const boardOptions = {}

if (process.argv.indexOf('--mock-board') !== -1) {
boardOptions.io = new (require('mock-firmata').Firmata)()
setTimeout(() => {
board.emit('ready')
process.on('exit', () => {
board.emit('close')
})
}, 500) // Give it half of a second to set the event listeners from "events.js"; then, trigger "ready"
} else {
const port = process.env.PORT
if (port) {
boardOptions.port = port
}
}

const board = new five.Board(boardOptions)

require('./events')({socket, board})
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "hardware-handler",
"version": "0.0.1",
"description": "A HAIoT project for connecting a board running Firmata software to the system.",
"version": "1.0.0",
"description": "Connecting a board to the HAIoT system.",
"main": "index.js",
"engines": {
"npm": "5.5.1",
Expand All @@ -28,6 +28,7 @@
},
"scripts": {
"start": "./node_modules/.bin/supervisor -w index.js,.env index.js",
"start-mocked": "node . --mock-board",
"test": "./node_modules/.bin/nyc ./node_modules/.bin/_mocha --require should --report lcovonly ./test/",
"generate-coverage": "./node_modules/.bin/nyc report --reporter=lcov"
},
Expand Down

0 comments on commit 620399b

Please sign in to comment.