diff --git a/.travis.yml b/.travis.yml index fe6f96a..fd5b28f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,9 +10,8 @@ addons: - gcc-4.8 - g++-4.8 script: - - npm run test:ci - - npm run test:bundlesize:ci - - npm run example:deploy:ci + - npm run ci:test + - npm run ci:example:build branches: only: - master @@ -28,4 +27,4 @@ deploy: on: branch: master after_success: - - npm run test:coverage:ci \ No newline at end of file + - npm run ci:report:coverage \ No newline at end of file diff --git a/package.json b/package.json index 3f89aae..4963cae 100644 --- a/package.json +++ b/package.json @@ -5,24 +5,17 @@ "main": "build/index.js", "scripts": { "dev": "watch 'npm run build' src", - "eslint": "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", + "lint": "eslint src", "build": "babel src -d build", - "prebuild": "npm run eslint", - "test": "jest --config .jest.json --forceExit", + "prebuild": "npm run lint", + "test": "jest --config .jest.json", "test:bundlesize": "bundlesize", - "pretest:bundlesize": "npm run uglify", - "posttest:bundlesize": "rm -fR .tmp bundle.js", "test:watch": "npm test -- --watch", "test:coverage": "npm test -- --coverage", "prepublish": "npm run build", "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:deploy": "npm run example:webapp:deploy", "example:webapp:install": "cd example/webapp && yarn install", @@ -31,12 +24,10 @@ "example:peripheral:install": "cd example/peripheral && yarn install", "example:peripheral:build": "cd example/peripheral && npm run build", "example:peripheral:start": "cd example/peripheral && npm start", - "test:ci": "jest --config .jest.ci.json", - "test:coverage:ci": "codecov -t $CODECOV_TOKEN", - "pretest:coverage:ci": "npm run test:coverage", - "test:bundlesize:ci": "npm run test:bundlesize", - "example:deploy:ci": "npm run example:webapp:build", - "preexample:deploy:ci": "npm run example:webapp:install" + + "ci:test": "jest --config .jest.ci.json", + "ci:report:coverage": "npm run test:coverage && codecov -t $CODECOV_TOKEN", + "ci:example:build": "npm run example:webapp:install && npm run example:webapp:build" }, "babel": { "presets": [ @@ -73,7 +64,6 @@ "eslint-plugin-react": "^7.1.0", "jest": "^20.0.4", "np": "^2.16.0", - "uglify-js": "^3.0.24", "watch": "^1.0.2" }, "dependencies": { diff --git a/src/peripheral/bleno/characteristic.test.js b/src/peripheral/bleno/characteristic.test.js index 1a8b918..69e823a 100644 --- a/src/peripheral/bleno/characteristic.test.js +++ b/src/peripheral/bleno/characteristic.test.js @@ -1,6 +1,5 @@ /* global jest, test, expect, beforeEach, afterEach */ import util from 'util'; -import bleno from 'bleno'; import Characteristic from './characteristic'; @@ -8,6 +7,8 @@ function Parent({ uuid, properties, descriptors }) { this.uuid = uuid; this.properties = properties; this.descriptors = descriptors; + this.RESULT_ATTR_NOT_LONG = 'RESULT_ATTR_NOT_LONG'; + this.RESULT_SUCCESS = 'RESULT_SUCCESS'; } let encode = null; @@ -33,54 +34,54 @@ test('new Characteristic', () => { }); 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(); 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', () => { 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(); const spyOnAction = jest.spyOn(characteristic, 'onAction'); characteristic.onWriteRequest(null, false, false, callback); expect(spyOnAction).toBeCalledWith('mockDecode'); - expect(callback).toBeCalledWith(bleno.Characteristic.RESULT_SUCCESS); + expect(callback).toBeCalledWith('RESULT_SUCCESS'); callback = jest.fn(); characteristic.onAction = jest.fn(); characteristic.onWriteRequest(null, false, false, callback); expect(characteristic.onAction).toBeCalledWith('mockDecode'); - expect(callback).toBeCalledWith(bleno.Characteristic.RESULT_SUCCESS); + expect(callback).toBeCalledWith('RESULT_SUCCESS'); }); 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(); 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', () => { - const characteristic = Characteristic('mockUUID', bleno.Characteristic, util, 'mockDescriptor', { encode, decode }); + const characteristic = Characteristic('mockUUID', Parent, util, 'mockDescriptor', { encode, decode }); const callback = jest.fn(); characteristic.onReadRequest(false, callback); - expect(callback).toBeCalledWith(bleno.Characteristic.RESULT_SUCCESS, characteristic.state); + expect(callback).toBeCalledWith('RESULT_SUCCESS', characteristic.state); }); 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'); @@ -88,7 +89,7 @@ test('Characteristic.onSubscribe', () => { }); 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.onUnsubscribe(); @@ -97,7 +98,7 @@ test('Characteristic.onUnsubscribe', () => { }); 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'); expect(characteristic.state).toBe('mockEncode'); diff --git a/src/peripheral/bleno/index.test.js b/src/peripheral/bleno/index.test.js index 5a922bf..1a01926 100644 --- a/src/peripheral/bleno/index.test.js +++ b/src/peripheral/bleno/index.test.js @@ -8,6 +8,7 @@ let decode = null; let mockCharacteristic = null; let BLENO = null; +jest.mock('bleno', () => jest.fn()); jest.mock('./service', () => jest.fn().mockReturnValue('mockService')); jest.mock('./characteristic', () => () => mockCharacteristic); jest.mock('./descriptor', () => jest.fn());