Skip to content

Commit b2cfbf0

Browse files
Switch from mocha to jest
1 parent b61e0ec commit b2cfbf0

8 files changed

Lines changed: 1808 additions & 350 deletions

File tree

jest.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
preset: 'ts-jest'
3+
};

package.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
"demo:watch": "webpack-dev-server --config webpack.demo.config.js --mode development",
1515
"demo:publish": "npm run demo:clean && npm run demo:build && npm run demo:upload",
1616
"prepack": "npm run test && npm run build && npm run demo:publish",
17-
"test": "mocha --require ts-node/register --watch-extensions js,ts,tsx src/*.spec.ts src/**/*.spec.ts",
18-
"test:watch": "npm run test -- --watch"
17+
"test": "jest",
18+
"test:watch": "jest --watch"
1919
},
2020
"repository": {
2121
"type": "git",
@@ -38,8 +38,7 @@
3838
"homepage": "https://github.com/janjakubnanista/downsample",
3939
"devDependencies": {
4040
"@material-ui/core": "^1.3.1",
41-
"@types/expect.js": "^0.3.29",
42-
"@types/mocha": "^5.2.4",
41+
"@types/jest": "^24.0.18",
4342
"@types/node": "^10.5.1",
4443
"@types/react": "^16.4.6",
4544
"@types/react-dom": "^16.0.6",
@@ -50,12 +49,12 @@
5049
"babel-preset-env": "^1.7.0",
5150
"babel-preset-react": "^6.24.1",
5251
"eslint": "^5.0.1",
53-
"expect.js": "^0.3.1",
5452
"gh-pages": "^1.2.0",
5553
"html-webpack-plugin": "^3.2.0",
56-
"mocha": "^5.2.0",
54+
"jest": "^24.9.0",
5755
"react": "^16.4.1",
5856
"react-dom": "^16.4.1",
57+
"ts-jest": "^24.1.0",
5958
"ts-loader": "^4.4.2",
6059
"ts-node": "^7.0.0",
6160
"typescript": "^2.9.2",

src/methods/LTD.spec.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import "mocha";
2-
import expect from "expect.js";
1+
import "jest";
32
import LTD from "./LTD";
43
import { DataPoint } from "../types";
54

@@ -20,31 +19,31 @@ describe("LTD", () => {
2019
];
2120

2221
it("should throw an error if desiredLength is negative", () => {
23-
expect(() => LTD(dateData, -1)).to.throwError();
22+
expect(() => LTD(dateData, -1)).toThrow();
2423
});
2524

2625
it("should return the whole data set if there are two data points", () => {
27-
expect(LTD(dateData.slice(0, 2), 1)).to.have.length(2);
26+
expect(LTD(dateData.slice(0, 2), 1)).toHaveLength(2);
2827
});
2928

3029
it("should return the whole data set if desiredLength is larger than the data set length", () => {
31-
expect(LTD(dateData, dateData.length + 40)).to.have.length(dateData.length);
30+
expect(LTD(dateData, dateData.length + 40)).toHaveLength(dateData.length);
3231
});
3332

3433
it("should return desired number of data points", () => {
35-
expect(LTD(dateData, 3)).to.have.length(3);
36-
expect(LTD(dateData, 5)).to.have.length(5);
37-
expect(LTD(dateData, 7)).to.have.length(7);
38-
expect(LTD(dateData, 8)).to.have.length(8);
34+
expect(LTD(dateData, 3)).toHaveLength(3);
35+
expect(LTD(dateData, 5)).toHaveLength(5);
36+
expect(LTD(dateData, 7)).toHaveLength(7);
37+
expect(LTD(dateData, 8)).toHaveLength(8);
3938
});
4039

4140
it("should preserve the first and last data points", () => {
42-
expect(LTD(dateData, 5)[0]).to.be.eql(dateData[0]);
43-
expect(LTD(dateData, 5)[4]).to.be.eql(dateData[dateData.length - 1]);
41+
expect(LTD(dateData, 5)[0]).toEqual(dateData[0]);
42+
expect(LTD(dateData, 5)[4]).toEqual(dateData[dateData.length - 1]);
4443
});
4544

4645
it("should downsample correctly", () => {
47-
expect(LTD(dateData, 5)).to.be.eql([
46+
expect(LTD(dateData, 5)).toEqual([
4847
{ x: new Date(635554800000), y: 0 },
4948
{ x: new Date(635554800090), y: 23 },
5049
{ x: new Date(635554800120), y: 6 },

src/methods/LTOB.spec.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import "mocha";
2-
import expect from "expect.js";
1+
import "jest";
32
import LTOB from "./LTOB";
43
import { DataPoint } from "../types";
54

@@ -17,31 +16,31 @@ describe("LTOB", () => {
1716
];
1817

1918
it("should throw an error if desiredLength is negative", () => {
20-
expect(() => LTOB(dateData, -1)).to.throwError();
19+
expect(() => LTOB(dateData, -1)).toThrow();
2120
});
2221

2322
it("should return the whole data set if there are two data points", () => {
24-
expect(LTOB(dateData.slice(0, 2), 1)).to.have.length(2);
23+
expect(LTOB(dateData.slice(0, 2), 1)).toHaveLength(2);
2524
});
2625

2726
it("should return the whole data set if desiredLength is larger than the data set length", () => {
28-
expect(LTOB(dateData, dateData.length + 40)).to.have.length(dateData.length);
27+
expect(LTOB(dateData, dateData.length + 40)).toHaveLength(dateData.length);
2928
});
3029

3130
it("should return desired number of data points", () => {
32-
expect(LTOB(dateData, 3)).to.have.length(3);
33-
expect(LTOB(dateData, 5)).to.have.length(5);
34-
expect(LTOB(dateData, 7)).to.have.length(7);
35-
expect(LTOB(dateData, 8)).to.have.length(8);
31+
expect(LTOB(dateData, 3)).toHaveLength(3);
32+
expect(LTOB(dateData, 5)).toHaveLength(5);
33+
expect(LTOB(dateData, 7)).toHaveLength(7);
34+
expect(LTOB(dateData, 8)).toHaveLength(8);
3635
});
3736

3837
it("should preserve the first and last data points", () => {
39-
expect(LTOB(dateData, 5)[0]).to.be.eql(dateData[0]);
40-
expect(LTOB(dateData, 5)[4]).to.be.eql(dateData[dateData.length - 1]);
38+
expect(LTOB(dateData, 5)[0]).toEqual(dateData[0]);
39+
expect(LTOB(dateData, 5)[4]).toEqual(dateData[dateData.length - 1]);
4140
});
4241

4342
it("should downsample correctly", () => {
44-
expect(LTOB(dateData, 5)).to.be.eql([
43+
expect(LTOB(dateData, 5)).toEqual([
4544
{ x: new Date(635554800000), y: 0 },
4645
{ x: new Date(635554800030), y: -1 },
4746
{ x: new Date(635554800040), y: 10 },

src/methods/LTTB.spec.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import "mocha";
2-
import expect from "expect.js";
1+
import "jest";
32
import LTTB from "./LTTB";
43
import { DataPoint } from "../types";
54

@@ -17,31 +16,31 @@ describe("LTTB", () => {
1716
];
1817

1918
it("should throw an error if desiredLength is negative", () => {
20-
expect(() => LTTB(dateData, -1)).to.throwError();
19+
expect(() => LTTB(dateData, -1)).toThrow();
2120
});
2221

2322
it("should return the whole data set if there are two data points", () => {
24-
expect(LTTB(dateData.slice(0, 2), 1)).to.have.length(2);
23+
expect(LTTB(dateData.slice(0, 2), 1)).toHaveLength(2);
2524
});
2625

2726
it("should return the whole data set if desiredLength is larger than the data set length", () => {
28-
expect(LTTB(dateData, dateData.length + 40)).to.have.length(dateData.length);
27+
expect(LTTB(dateData, dateData.length + 40)).toHaveLength(dateData.length);
2928
});
3029

3130
it("should return desired number of data points", () => {
32-
expect(LTTB(dateData, 3)).to.have.length(3);
33-
expect(LTTB(dateData, 5)).to.have.length(5);
34-
expect(LTTB(dateData, 7)).to.have.length(7);
35-
expect(LTTB(dateData, 8)).to.have.length(8);
31+
expect(LTTB(dateData, 3)).toHaveLength(3);
32+
expect(LTTB(dateData, 5)).toHaveLength(5);
33+
expect(LTTB(dateData, 7)).toHaveLength(7);
34+
expect(LTTB(dateData, 8)).toHaveLength(8);
3635
});
3736

3837
it("should preserve the first and last data points", () => {
39-
expect(LTTB(dateData, 5)[0]).to.be.eql(dateData[0]);
40-
expect(LTTB(dateData, 5)[4]).to.be.eql(dateData[dateData.length - 1]);
38+
expect(LTTB(dateData, 5)[0]).toEqual(dateData[0]);
39+
expect(LTTB(dateData, 5)[4]).toEqual(dateData[dateData.length - 1]);
4140
});
4241

4342
it("should downsample correctly", () => {
44-
expect(LTTB(dateData, 5)).to.be.eql([
43+
expect(LTTB(dateData, 5)).toEqual([
4544
{ x: new Date(635554800000), y: 0 },
4645
{ x: new Date(635554800020), y: 2 },
4746
{ x: new Date(635554800030), y: -2 },

src/utils.spec.ts

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import "mocha";
2-
import expect from "expect.js";
1+
import "jest";
32
import { NormalizedDataPoint } from "./types";
43
import { calculateTriangleArea, calculateAverageDataPoint, splitIntoBuckets } from "./utils";
54

@@ -10,49 +9,49 @@ describe("utils", () => {
109
const pointB: NormalizedDataPoint = [2, 2];
1110
const pointC: NormalizedDataPoint = [3, 2];
1211

13-
expect(calculateTriangleArea(pointA, pointB, pointC)).to.be(0);
12+
expect(calculateTriangleArea(pointA, pointB, pointC)).toBe(0);
1413
});
1514

1615
it("should return correct area for a triangle aligned with an axis", () => {
1716
const pointA: NormalizedDataPoint = [1, 0];
1817
const pointB: NormalizedDataPoint = [2, 5];
1918
const pointC: NormalizedDataPoint = [3, 0];
2019

21-
expect(calculateTriangleArea(pointA, pointB, pointC)).to.be(5);
20+
expect(calculateTriangleArea(pointA, pointB, pointC)).toBe(5);
2221
});
2322

2423
it("should return correct area for a triangle not aligned with an axis", () => {
2524
const pointA: NormalizedDataPoint = [1, 2];
2625
const pointB: NormalizedDataPoint = [2, 5];
2726
const pointC: NormalizedDataPoint = [3, 5];
2827

29-
expect(calculateTriangleArea(pointA, pointB, pointC)).to.be(1.5);
28+
expect(calculateTriangleArea(pointA, pointB, pointC)).toBe(1.5);
3029
});
3130

3231
it("should return correct area for a triangle covering negative quadrants", () => {
3332
const pointA: NormalizedDataPoint = [-1, -1];
3433
const pointB: NormalizedDataPoint = [0, 1];
3534
const pointC: NormalizedDataPoint = [1, -1];
3635

37-
expect(calculateTriangleArea(pointA, pointB, pointC)).to.be(2);
36+
expect(calculateTriangleArea(pointA, pointB, pointC)).toBe(2);
3837
});
3938
});
4039

4140
describe("calculateAverageDataPoint", () => {
4241
it("should return undefined when passed no data points", () => {
43-
expect(calculateAverageDataPoint()).to.be(undefined);
42+
expect(calculateAverageDataPoint()).toBe(undefined);
4443
});
4544

4645
it("should return the same point when passed one data point", () => {
47-
expect(calculateAverageDataPoint([0, 1])).to.eql([0, 1]);
46+
expect(calculateAverageDataPoint([0, 1])).toEqual([0, 1]);
4847
});
4948

5049
it("should return correct point average", () => {
5150
const pointA: NormalizedDataPoint = [-1, -1];
5251
const pointB: NormalizedDataPoint = [0, 2];
5352
const pointC: NormalizedDataPoint = [1, -1];
5453

55-
expect(calculateAverageDataPoint(pointA, pointB, pointC)).to.eql([0, 0]);
54+
expect(calculateAverageDataPoint(pointA, pointB, pointC)).toEqual([0, 0]);
5655
});
5756
});
5857

@@ -72,7 +71,7 @@ describe("utils", () => {
7271
expect(splitIntoBuckets([
7372
[0, 2],
7473
[1, -1]
75-
], 2)).to.eql([
74+
], 2)).toEqual([
7675
[
7776
[0, 2]
7877
],
@@ -83,17 +82,17 @@ describe("utils", () => {
8382
});
8483

8584
it("should return an array of desired length", () => {
86-
expect(splitIntoBuckets(data, 2)).to.have.length(2);
87-
expect(splitIntoBuckets(data, 3)).to.have.length(3);
88-
expect(splitIntoBuckets(data, 4)).to.have.length(4);
89-
expect(splitIntoBuckets(data, 5)).to.have.length(5);
85+
expect(splitIntoBuckets(data, 2)).toHaveLength(2);
86+
expect(splitIntoBuckets(data, 3)).toHaveLength(3);
87+
expect(splitIntoBuckets(data, 4)).toHaveLength(4);
88+
expect(splitIntoBuckets(data, 5)).toHaveLength(5);
9089
});
9190

9291
it("should return an array with the first and the last bucket containing the first and the last data points", () => {
93-
expect(splitIntoBuckets(data, 3)[0]).to.have.length(1);
94-
expect(splitIntoBuckets(data, 3)[0]).to.eql([[0, 2]]);
95-
expect(splitIntoBuckets(data, 3)[2]).to.have.length(1);
96-
expect(splitIntoBuckets(data, 3)[2]).to.eql([[7, -1]]);
92+
expect(splitIntoBuckets(data, 3)[0]).toHaveLength(1);
93+
expect(splitIntoBuckets(data, 3)[0]).toEqual([[0, 2]]);
94+
expect(splitIntoBuckets(data, 3)[2]).toHaveLength(1);
95+
expect(splitIntoBuckets(data, 3)[2]).toEqual([[7, -1]]);
9796
});
9897
});
9998
});

tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
]
1515
},
1616
"files": [
17-
"./node_modules/@types/mocha/index.d.ts",
1817
"./node_modules/@types/node/index.d.ts"
1918
],
2019
"include": [

0 commit comments

Comments
 (0)