Merge branch 'develop'

This commit is contained in:
Jeronimo Vallelunga 2017-07-25 00:42:24 -03:00
commit efa80c11a4
4 changed files with 27 additions and 36 deletions

View File

@ -10,9 +10,8 @@ addons:
- gcc-4.8 - gcc-4.8
- g++-4.8 - g++-4.8
script: script:
- npm run test:ci - npm run ci:test
- npm run test:bundlesize:ci - npm run ci:example:build
- npm run example:deploy:ci
branches: branches:
only: only:
- master - master
@ -28,4 +27,4 @@ deploy:
on: on:
branch: master branch: master
after_success: after_success:
- npm run test:coverage:ci - npm run ci:report:coverage

View File

@ -5,24 +5,17 @@
"main": "build/index.js", "main": "build/index.js",
"scripts": { "scripts": {
"dev": "watch 'npm run build' src", "dev": "watch 'npm run build' src",
"eslint": "eslint src", "lint": "eslint src",
"tmp": "cp -R build/ .tmp",
"precopy": "if [ ! -d build ]; then npm run build; fi",
"postcopy": "find .tmp -type f -name '*.test.js' -delete",
"uglify": "uglifyjs ./.tmp/**/*.js -m -c -o bundle.js",
"preuglify": "npm run tmp",
"build": "babel src -d build", "build": "babel src -d build",
"prebuild": "npm run eslint", "prebuild": "npm run lint",
"test": "jest --config .jest.json --forceExit", "test": "jest --config .jest.json",
"test:bundlesize": "bundlesize", "test:bundlesize": "bundlesize",
"pretest:bundlesize": "npm run uglify",
"posttest:bundlesize": "rm -fR .tmp bundle.js",
"test:watch": "npm test -- --watch", "test:watch": "npm test -- --watch",
"test:coverage": "npm test -- --coverage", "test:coverage": "npm test -- --coverage",
"prepublish": "npm run build", "prepublish": "npm run build",
"release": "np", "release": "np",
"example:install": "npm run example:webapp:install",
"preexample:install": "npm run example:peripheral:install", "example:install": "npm run example:peripheral:install && npm run example:webapp:install",
"example:start": "npm run example:peripheral:start", "example:start": "npm run example:peripheral:start",
"example:deploy": "npm run example:webapp:deploy", "example:deploy": "npm run example:webapp:deploy",
"example:webapp:install": "cd example/webapp && yarn install", "example:webapp:install": "cd example/webapp && yarn install",
@ -31,12 +24,10 @@
"example:peripheral:install": "cd example/peripheral && yarn install", "example:peripheral:install": "cd example/peripheral && yarn install",
"example:peripheral:build": "cd example/peripheral && npm run build", "example:peripheral:build": "cd example/peripheral && npm run build",
"example:peripheral:start": "cd example/peripheral && npm start", "example:peripheral:start": "cd example/peripheral && npm start",
"test:ci": "jest --config .jest.ci.json",
"test:coverage:ci": "codecov -t $CODECOV_TOKEN", "ci:test": "jest --config .jest.ci.json",
"pretest:coverage:ci": "npm run test:coverage", "ci:report:coverage": "npm run test:coverage && codecov -t $CODECOV_TOKEN",
"test:bundlesize:ci": "npm run test:bundlesize", "ci:example:build": "npm run example:webapp:install && npm run example:webapp:build"
"example:deploy:ci": "npm run example:webapp:build",
"preexample:deploy:ci": "npm run example:webapp:install"
}, },
"babel": { "babel": {
"presets": [ "presets": [
@ -73,7 +64,6 @@
"eslint-plugin-react": "^7.1.0", "eslint-plugin-react": "^7.1.0",
"jest": "^20.0.4", "jest": "^20.0.4",
"np": "^2.16.0", "np": "^2.16.0",
"uglify-js": "^3.0.24",
"watch": "^1.0.2" "watch": "^1.0.2"
}, },
"dependencies": { "dependencies": {

View File

@ -1,6 +1,5 @@
/* global jest, test, expect, beforeEach, afterEach */ /* global jest, test, expect, beforeEach, afterEach */
import util from 'util'; import util from 'util';
import bleno from 'bleno';
import Characteristic from './characteristic'; import Characteristic from './characteristic';
@ -8,6 +7,8 @@ function Parent({ uuid, properties, descriptors }) {
this.uuid = uuid; this.uuid = uuid;
this.properties = properties; this.properties = properties;
this.descriptors = descriptors; this.descriptors = descriptors;
this.RESULT_ATTR_NOT_LONG = 'RESULT_ATTR_NOT_LONG';
this.RESULT_SUCCESS = 'RESULT_SUCCESS';
} }
let encode = null; let encode = null;
@ -33,54 +34,54 @@ test('new Characteristic', () => {
}); });
test('Characteristic.onWriteRequest: RESULT_ATTR_NOT_LONG', () => { test('Characteristic.onWriteRequest: RESULT_ATTR_NOT_LONG', () => {
const characteristic = Characteristic('mockUUID', bleno.Characteristic, util, 'mockDescriptor', { encode, decode }); const characteristic = Characteristic('mockUUID', Parent, util, 'mockDescriptor', { encode, decode });
const callback = jest.fn(); const callback = jest.fn();
characteristic.onWriteRequest(null, true, false, callback); characteristic.onWriteRequest(null, true, false, callback);
expect(callback).toBeCalledWith(bleno.Characteristic.RESULT_ATTR_NOT_LONG); expect(callback).toBeCalledWith('RESULT_ATTR_NOT_LONG');
}); });
test('Characteristic.onWriteRequest: RESULT_SUCCESS', () => { test('Characteristic.onWriteRequest: RESULT_SUCCESS', () => {
let callback = null; let callback = null;
const characteristic = Characteristic('mockUUID', bleno.Characteristic, util, 'mockDescriptor', { encode, decode }); const characteristic = Characteristic('mockUUID', Parent, util, 'mockDescriptor', { encode, decode });
callback = jest.fn(); callback = jest.fn();
const spyOnAction = jest.spyOn(characteristic, 'onAction'); const spyOnAction = jest.spyOn(characteristic, 'onAction');
characteristic.onWriteRequest(null, false, false, callback); characteristic.onWriteRequest(null, false, false, callback);
expect(spyOnAction).toBeCalledWith('mockDecode'); expect(spyOnAction).toBeCalledWith('mockDecode');
expect(callback).toBeCalledWith(bleno.Characteristic.RESULT_SUCCESS); expect(callback).toBeCalledWith('RESULT_SUCCESS');
callback = jest.fn(); callback = jest.fn();
characteristic.onAction = jest.fn(); characteristic.onAction = jest.fn();
characteristic.onWriteRequest(null, false, false, callback); characteristic.onWriteRequest(null, false, false, callback);
expect(characteristic.onAction).toBeCalledWith('mockDecode'); expect(characteristic.onAction).toBeCalledWith('mockDecode');
expect(callback).toBeCalledWith(bleno.Characteristic.RESULT_SUCCESS); expect(callback).toBeCalledWith('RESULT_SUCCESS');
}); });
test('Characteristic.onReadRequest: RESULT_ATTR_NOT_LONG', () => { test('Characteristic.onReadRequest: RESULT_ATTR_NOT_LONG', () => {
const characteristic = Characteristic('mockUUID', bleno.Characteristic, util, 'mockDescriptor', { encode, decode }); const characteristic = Characteristic('mockUUID', Parent, util, 'mockDescriptor', { encode, decode });
const callback = jest.fn(); const callback = jest.fn();
characteristic.onReadRequest(true, callback); characteristic.onReadRequest(true, callback);
expect(callback).toBeCalledWith(bleno.Characteristic.RESULT_ATTR_NOT_LONG, null); expect(callback).toBeCalledWith('RESULT_ATTR_NOT_LONG', null);
}); });
test('Characteristic.onReadRequest: RESULT_SUCCESS', () => { test('Characteristic.onReadRequest: RESULT_SUCCESS', () => {
const characteristic = Characteristic('mockUUID', bleno.Characteristic, util, 'mockDescriptor', { encode, decode }); const characteristic = Characteristic('mockUUID', Parent, util, 'mockDescriptor', { encode, decode });
const callback = jest.fn(); const callback = jest.fn();
characteristic.onReadRequest(false, callback); characteristic.onReadRequest(false, callback);
expect(callback).toBeCalledWith(bleno.Characteristic.RESULT_SUCCESS, characteristic.state); expect(callback).toBeCalledWith('RESULT_SUCCESS', characteristic.state);
}); });
test('Characteristic.onSubscribe', () => { test('Characteristic.onSubscribe', () => {
const characteristic = Characteristic('mockUUID', bleno.Characteristic, util, 'mockDescriptor', { encode, decode }); const characteristic = Characteristic('mockUUID', Parent, util, 'mockDescriptor', { encode, decode });
characteristic.onSubscribe(null, 'mockUpdateValueCallback'); characteristic.onSubscribe(null, 'mockUpdateValueCallback');
@ -88,7 +89,7 @@ test('Characteristic.onSubscribe', () => {
}); });
test('Characteristic.onUnsubscribe', () => { test('Characteristic.onUnsubscribe', () => {
const characteristic = Characteristic('mockUUID', bleno.Characteristic, util, 'mockDescriptor', { encode, decode }); const characteristic = Characteristic('mockUUID', Parent, util, 'mockDescriptor', { encode, decode });
characteristic.onSubscribe(null, 'mockUpdateValueCallback'); characteristic.onSubscribe(null, 'mockUpdateValueCallback');
characteristic.onUnsubscribe(); characteristic.onUnsubscribe();
@ -97,7 +98,7 @@ test('Characteristic.onUnsubscribe', () => {
}); });
test('Characteristic.updateState', () => { test('Characteristic.updateState', () => {
const characteristic = Characteristic('mockUUID', bleno.Characteristic, util, 'mockDescriptor', { encode, decode }); const characteristic = Characteristic('mockUUID', Parent, util, 'mockDescriptor', { encode, decode });
characteristic.updateState('mockState'); characteristic.updateState('mockState');
expect(characteristic.state).toBe('mockEncode'); expect(characteristic.state).toBe('mockEncode');

View File

@ -8,6 +8,7 @@ let decode = null;
let mockCharacteristic = null; let mockCharacteristic = null;
let BLENO = null; let BLENO = null;
jest.mock('bleno', () => jest.fn());
jest.mock('./service', () => jest.fn().mockReturnValue('mockService')); jest.mock('./service', () => jest.fn().mockReturnValue('mockService'));
jest.mock('./characteristic', () => () => mockCharacteristic); jest.mock('./characteristic', () => () => mockCharacteristic);
jest.mock('./descriptor', () => jest.fn()); jest.mock('./descriptor', () => jest.fn());