Skip to content

Commit

Permalink
infra: upgrade jest to 22.x, use ts-jest
Browse files Browse the repository at this point in the history
also fix broken tests after the rxjs 6.x upgrade
  • Loading branch information
urish committed Apr 25, 2018
1 parent 6af07a2 commit b588b44
Show file tree
Hide file tree
Showing 5 changed files with 764 additions and 492 deletions.
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,19 @@
},
"files": ["dist"],
"devDependencies": {
"@types/jest": "^21.1.6",
"@types/jest": "^22.2.3",
"event-target-shim": "^3.0.0",
"fuse-box": "^2.0.0",
"husky": "^0.14.3",
"jest": "^21.2.1",
"jest": "^22.4.3",
"lint-staged": "^7.0.4",
"prettier": "^1.12.1",
"text-encoding": "^0.6.4",
"ts-jest": "^22.4.4",
"tslint": "^5.8.0",
"typescript": "^2.8.3",
"web-bluetooth-mock": "^1.0.2"
"web-bluetooth-mock": "^1.0.2",
"zen-observable": "^0.8.8"
},
"dependencies": {
"@types/web-bluetooth": "^0.0.2",
Expand All @@ -38,7 +40,7 @@
"jest": {
"moduleFileExtensions": ["ts", "js"],
"transform": {
"^.+\\.ts$": "<rootDir>/typescript-preprocessor.js"
"^.+\\.ts$": "ts-jest"
},
"testMatch": ["**/*.spec.ts"]
},
Expand Down
85 changes: 69 additions & 16 deletions src/lib/muse-parse.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { from } from 'rxjs';
import { toArray } from 'rxjs/operators';

import {
decodeUnsigned12BitData, parseAccelerometer, parseControl, parseGyroscope, parseTelemetry,
decodeUnsigned12BitData,
parseAccelerometer,
parseControl,
parseGyroscope,
parseTelemetry,
} from './muse-parse';

import { from } from 'rxjs/observable/from';
import { toArray } from 'rxjs/operators/toArray';

describe('parseControl', () => {
it('should correctly parse JSON responses into objects', async () => {
const input = from([
Expand Down Expand Up @@ -32,17 +36,32 @@ describe('parseControl', () => {
'"rc":0}{"r',
'c":0}',
]);
const results = await parseControl(input).pipe(toArray()).toPromise();
const results = await parseControl(input)
.pipe(toArray())
.toPromise();
expect(results).toEqual([
{
ap: 'headset', bl: '1.2.3', bn: 27, fw: '1.2.13', hw: '3.1',
pv: 1, rc: 0, sp: 'RevE', tp: 'consumer',
ap: 'headset',
bl: '1.2.3',
bn: 27,
fw: '1.2.13',
hw: '3.1',
pv: 1,
rc: 0,
sp: 'RevE',
tp: 'consumer',
},
{ rc: 0 },
{ rc: 0 },
{
bp: 82, hn: 'Muse-1324', id: '07473435 32313630 004f003a',
ma: '00-55-da-b0-13-24', ps: 32, rc: 0, sn: '2031-TZRW-1324', ts: 0,
bp: 82,
hn: 'Muse-1324',
id: '07473435 32313630 004f003a',
ma: '00-55-da-b0-13-24',
ps: 32,
rc: 0,
sn: '2031-TZRW-1324',
ts: 0,
},
{ rc: 0 },
]);
Expand All @@ -52,15 +71,28 @@ describe('parseControl', () => {
describe('decodeUnsigned12BitData', () => {
it('should correctly decode 12-bit EEG samples received from muse', () => {
const input = new Uint8Array([87, 33, 192, 82, 73, 6, 106, 242, 49, 64, 88, 153, 128, 66, 254, 44, 119, 157]);
expect(decodeUnsigned12BitData(input))
.toEqual([1394, 448, 1316, 2310, 1711, 561, 1029, 2201, 2052, 766, 711, 1949]);
expect(decodeUnsigned12BitData(input)).toEqual([
1394,
448,
1316,
2310,
1711,
561,
1029,
2201,
2052,
766,
711,
1949,
]);
});
});

describe('parseTelemtry', () => {
it('should correctly parse Muse telemetry data', () => {
const input = new DataView(
new Uint8Array([1, 74, 181, 184, 7, 64, 15, 127, 0, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).buffer);
new Uint8Array([1, 74, 181, 184, 7, 64, 15, 127, 0, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).buffer,
);
expect(parseTelemetry(input)).toEqual({
batteryLevel: 90.859375,
fuelGaugeVoltage: 4083.2000000000003,
Expand All @@ -73,8 +105,29 @@ describe('parseTelemtry', () => {
describe('parseAccelerometer', () => {
it('should parse Muse accelerometer data and return (x,y,z) vectors in g units', () => {
const input = new DataView(
new Uint8Array([82, 109, 13, 178, 13, 157, 60, 115, 18, 5, 13, 73, 60, 53, 17,
183, 17, 227, 60, 143]).buffer);
new Uint8Array([
82,
109,
13,
178,
13,
157,
60,
115,
18,
5,
13,
73,
60,
53,
17,
183,
17,
227,
60,
143,
]).buffer,
);
expect(parseAccelerometer(input)).toEqual({
samples: [
{ x: 0.2139894112, y: 0.21270767200000001, z: 0.9445197200000001 },
Expand All @@ -89,8 +142,8 @@ describe('parseAccelerometer', () => {
describe('parseGyroscope', () => {
it('should parse Muse gyroscope data and return (x,y,z) vectors in deg/second units', () => {
const input = new DataView(
new Uint8Array([1, 109, 5, 12, 0, 157, 0, 115, 5, 5, 0, 73, 0, 53, 5,
183, 0, 227, 0, 143]).buffer);
new Uint8Array([1, 109, 5, 12, 0, 157, 0, 115, 5, 5, 0, 73, 0, 53, 5, 183, 0, 227, 0, 143]).buffer,
);
expect(parseGyroscope(input)).toEqual({
samples: [
{ x: 9.660025599999999, y: 1.1738575999999998, z: 0.8598319999999999 },
Expand Down
98 changes: 58 additions & 40 deletions src/lib/zip-samples.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { Observable } from 'rxjs/Observable';

import { of } from 'rxjs/observable/of';
import { toArray } from 'rxjs/operators/toArray';
import { Observable, of } from 'rxjs';
import { toArray } from 'rxjs/operators';

import { zipSamples } from './zip-samples';

Expand All @@ -11,72 +9,92 @@ describe('zipSamples', () => {
it('should zip all eeg channels into one array', async () => {
const input = of(
{
electrode: 2, index: 100, timestamp: 1000,
samples: [2.01, 2.02, 2.03, 2.04, 2.05, 2.06, 2.07, 2.08, 2.09, 2.10, 2.11, 2.12],
electrode: 2,
index: 100,
timestamp: 1000,
samples: [2.01, 2.02, 2.03, 2.04, 2.05, 2.06, 2.07, 2.08, 2.09, 2.1, 2.11, 2.12],
},
{
electrode: 1, index: 100, timestamp: 1000,
samples: [1.01, 1.02, 1.03, 1.04, 1.05, 1.06, 1.07, 1.08, 1.09, 1.10, 1.11, 1.12],
electrode: 1,
index: 100,
timestamp: 1000,
samples: [1.01, 1.02, 1.03, 1.04, 1.05, 1.06, 1.07, 1.08, 1.09, 1.1, 1.11, 1.12],
},
{
electrode: 4, index: 100, timestamp: 1000,
samples: [4.01, 4.02, 4.03, 4.04, 4.05, 4.06, 4.07, 4.08, 4.09, 4.10, 4.11, 4.12],
electrode: 4,
index: 100,
timestamp: 1000,
samples: [4.01, 4.02, 4.03, 4.04, 4.05, 4.06, 4.07, 4.08, 4.09, 4.1, 4.11, 4.12],
},
{
electrode: 0, index: 100, timestamp: 1000,
samples: [0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.10, 0.11, 0.12],
electrode: 0,
index: 100,
timestamp: 1000,
samples: [0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1, 0.11, 0.12],
},
{
electrode: 3, index: 100, timestamp: 1000,
samples: [3.01, 3.02, 3.03, 3.04, 3.05, 3.06, 3.07, 3.08, 3.09, 3.10, 3.11, 3.12],
electrode: 3,
index: 100,
timestamp: 1000,
samples: [3.01, 3.02, 3.03, 3.04, 3.05, 3.06, 3.07, 3.08, 3.09, 3.1, 3.11, 3.12],
},
{
electrode: 2, index: 101, timestamp: 1046.875,
samples: [12.01, 12.02, 12.03, 12.04, 12.05, 12.06, 12.07, 12.08, 12.09, 12.10, 12.11, 12.12],
electrode: 2,
index: 101,
timestamp: 1046.875,
samples: [12.01, 12.02, 12.03, 12.04, 12.05, 12.06, 12.07, 12.08, 12.09, 12.1, 12.11, 12.12],
},
{
electrode: 1, index: 101, timestamp: 1046.875,
samples: [11.01, 11.02, 11.03, 11.04, 11.05, 11.06, 11.07, 11.08, 11.09, 11.10, 11.11, 11.12],
electrode: 1,
index: 101,
timestamp: 1046.875,
samples: [11.01, 11.02, 11.03, 11.04, 11.05, 11.06, 11.07, 11.08, 11.09, 11.1, 11.11, 11.12],
},
{
electrode: 4, index: 101, timestamp: 1046.875,
samples: [14.01, 14.02, 14.03, 14.04, 14.05, 14.06, 14.07, 14.08, 14.09, 14.10, 14.11, 14.12],
electrode: 4,
index: 101,
timestamp: 1046.875,
samples: [14.01, 14.02, 14.03, 14.04, 14.05, 14.06, 14.07, 14.08, 14.09, 14.1, 14.11, 14.12],
},
{
electrode: 0, index: 101, timestamp: 1046.875,
samples: [10.01, 10.02, 10.03, 10.04, 10.05, 10.06, 10.07, 10.08, 10.09, 10.10, 10.11, 10.12],
electrode: 0,
index: 101,
timestamp: 1046.875,
samples: [10.01, 10.02, 10.03, 10.04, 10.05, 10.06, 10.07, 10.08, 10.09, 10.1, 10.11, 10.12],
},
{
electrode: 3, index: 101, timestamp: 1046.875,
samples: [13.01, 13.02, 13.03, 13.04, 13.05, 13.06, 13.07, 13.08, 13.09, 13.10, 13.11, 13.12],
electrode: 3,
index: 101,
timestamp: 1046.875,
samples: [13.01, 13.02, 13.03, 13.04, 13.05, 13.06, 13.07, 13.08, 13.09, 13.1, 13.11, 13.12],
},
);
const zipped = zipSamples(input);
const result = await zipped.pipe(toArray()).toPromise();
expect(result).toEqual([
{ index: 100, timestamp: 1000.00000, data: [0.01, 1.01, 2.01, 3.01, 4.01] },
{ index: 100, timestamp: 1000.0, data: [0.01, 1.01, 2.01, 3.01, 4.01] },
{ index: 100, timestamp: 1003.90625, data: [0.02, 1.02, 2.02, 3.02, 4.02] },
{ index: 100, timestamp: 1007.81250, data: [0.03, 1.03, 2.03, 3.03, 4.03] },
{ index: 100, timestamp: 1007.8125, data: [0.03, 1.03, 2.03, 3.03, 4.03] },
{ index: 100, timestamp: 1011.71875, data: [0.04, 1.04, 2.04, 3.04, 4.04] },
{ index: 100, timestamp: 1015.62500, data: [0.05, 1.05, 2.05, 3.05, 4.05] },
{ index: 100, timestamp: 1015.625, data: [0.05, 1.05, 2.05, 3.05, 4.05] },
{ index: 100, timestamp: 1019.53125, data: [0.06, 1.06, 2.06, 3.06, 4.06] },
{ index: 100, timestamp: 1023.43750, data: [0.07, 1.07, 2.07, 3.07, 4.07] },
{ index: 100, timestamp: 1023.4375, data: [0.07, 1.07, 2.07, 3.07, 4.07] },
{ index: 100, timestamp: 1027.34375, data: [0.08, 1.08, 2.08, 3.08, 4.08] },
{ index: 100, timestamp: 1031.25000, data: [0.09, 1.09, 2.09, 3.09, 4.09] },
{ index: 100, timestamp: 1035.15625, data: [0.10, 1.10, 2.10, 3.10, 4.10] },
{ index: 100, timestamp: 1039.06250, data: [0.11, 1.11, 2.11, 3.11, 4.11] },
{ index: 100, timestamp: 1031.25, data: [0.09, 1.09, 2.09, 3.09, 4.09] },
{ index: 100, timestamp: 1035.15625, data: [0.1, 1.1, 2.1, 3.1, 4.1] },
{ index: 100, timestamp: 1039.0625, data: [0.11, 1.11, 2.11, 3.11, 4.11] },
{ index: 100, timestamp: 1042.96875, data: [0.12, 1.12, 2.12, 3.12, 4.12] },
{ index: 101, timestamp: 1046.87500, data: [10.01, 11.01, 12.01, 13.01, 14.01] },
{ index: 101, timestamp: 1046.875, data: [10.01, 11.01, 12.01, 13.01, 14.01] },
{ index: 101, timestamp: 1050.78125, data: [10.02, 11.02, 12.02, 13.02, 14.02] },
{ index: 101, timestamp: 1054.68750, data: [10.03, 11.03, 12.03, 13.03, 14.03] },
{ index: 101, timestamp: 1054.6875, data: [10.03, 11.03, 12.03, 13.03, 14.03] },
{ index: 101, timestamp: 1058.59375, data: [10.04, 11.04, 12.04, 13.04, 14.04] },
{ index: 101, timestamp: 1062.50000, data: [10.05, 11.05, 12.05, 13.05, 14.05] },
{ index: 101, timestamp: 1062.5, data: [10.05, 11.05, 12.05, 13.05, 14.05] },
{ index: 101, timestamp: 1066.40625, data: [10.06, 11.06, 12.06, 13.06, 14.06] },
{ index: 101, timestamp: 1070.31250, data: [10.07, 11.07, 12.07, 13.07, 14.07] },
{ index: 101, timestamp: 1070.3125, data: [10.07, 11.07, 12.07, 13.07, 14.07] },
{ index: 101, timestamp: 1074.21875, data: [10.08, 11.08, 12.08, 13.08, 14.08] },
{ index: 101, timestamp: 1078.12500, data: [10.09, 11.09, 12.09, 13.09, 14.09] },
{ index: 101, timestamp: 1082.03125, data: [10.10, 11.10, 12.10, 13.10, 14.10] },
{ index: 101, timestamp: 1085.93750, data: [10.11, 11.11, 12.11, 13.11, 14.11] },
{ index: 101, timestamp: 1078.125, data: [10.09, 11.09, 12.09, 13.09, 14.09] },
{ index: 101, timestamp: 1082.03125, data: [10.1, 11.1, 12.1, 13.1, 14.1] },
{ index: 101, timestamp: 1085.9375, data: [10.11, 11.11, 12.11, 13.11, 14.11] },
{ index: 101, timestamp: 1089.84375, data: [10.12, 11.12, 12.12, 13.12, 14.12] },
]);
});
Expand All @@ -91,9 +109,9 @@ describe('zipSamples', () => {
const zipped = zipSamples(input);
const result = await zipped.pipe(toArray()).toPromise();
expect(result).toEqual([
{ index: 50, timestamp: 5000.00000, data: [0.01, NaN, 2.01, 3.01, 4.01] },
{ index: 50, timestamp: 5000.0, data: [0.01, NaN, 2.01, 3.01, 4.01] },
{ index: 50, timestamp: 5003.90625, data: [0.02, NaN, 2.02, 3.02, 4.02] },
{ index: 50, timestamp: 5007.81250, data: [0.03, NaN, 2.03, 3.03, 4.03] },
{ index: 50, timestamp: 5007.8125, data: [0.03, NaN, 2.03, 3.03, 4.03] },
{ index: 50, timestamp: 5011.71875, data: [0.04, NaN, 2.04, 3.04, 4.04] },
]);
});
Expand Down
8 changes: 0 additions & 8 deletions typescript-preprocessor.js

This file was deleted.

Loading

0 comments on commit b588b44

Please sign in to comment.