Skip to content

Commit 9056f76

Browse files
committed
Converted over to Jest.
Removed unecessary dependencies.
1 parent 62bc78b commit 9056f76

12 files changed

Lines changed: 3614 additions & 4743 deletions

jest.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
testEnvironment: 'node',
4+
testPathIgnorePatterns: [
5+
"node_modules",
6+
"build",
7+
],
8+
};

package-lock.json

Lines changed: 3518 additions & 4663 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 15 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,18 @@
99
"clean": "rm -rf build/*",
1010
"b": "npm run build",
1111
"build": "tsc",
12+
"cb": "npm run clean-build",
1213
"clean-build": "npm run clean && npm run build",
1314
"build:watch": "tsc --watch",
1415
"clean-build:watch": "rm -rf build/* && tsc --watch",
16+
"prepublishOnly": "npm test && npm run clean-build",
17+
"l": "npm run lint",
18+
"lint": "tslint -c tslint.json 'src/**/*.{ts,tsx}'",
19+
"pretest": "npm run lint",
1520
"t": "npm run test",
16-
"test": "nyc mocha --opts ./src/test/mocha.opts",
17-
"test:watch": "mocha --watch --watch-extensions ts --opts ./src/test/mocha.opts",
21+
"test": "jest",
1822
"tw": "npm run test:watch",
19-
"prepublishOnly": "npm run lint && npm test && npm run clean && npm run build",
20-
"l": "npm run lint",
21-
"lint": "tslint -p tsconfig.json -t stylish",
22-
"fix-lint": "tslint --fix -p tsconfig.json -t stylish"
23+
"test:watch": "jest --watch"
2324
},
2425
"repository": {
2526
"type": "git",
@@ -33,50 +34,24 @@
3334
},
3435
"homepage": "https://github.com/data-forge/data-forge-plot#readme",
3536
"dependencies": {
36-
"@data-forge-plot/apex": "0.0.5",
37-
"@data-forge-plot/chart-def": "^1.0.4",
37+
"@data-forge-plot/apex": "0.0.7",
38+
"@data-forge-plot/chart-def": "^1.0.5",
3839
"@data-forge/serialization": "^1.0.0",
3940
"capture-template": "^1.1.10",
40-
"fs-jetpack": "^1.3.1",
4141
"inflate-template": "^1.1.6",
4242
"opn": "^5.5.0",
43-
"sugar": "^2.0.6"
43+
"typy": "^3.0.1"
4444
},
4545
"peerDependencies": {
4646
"data-forge": "^1.6.7"
4747
},
4848
"devDependencies": {
49-
"@types/chai": "^4.1.7",
50-
"@types/express": "^4.16.1",
51-
"@types/fs-extra": "^5.0.5",
52-
"@types/globby": "^8.0.0",
53-
"@types/handlebars": "^4.1.0",
54-
"@types/mocha": "^2.2.48",
49+
"@types/jest": "^24.0.6",
5550
"@types/node": "^8.10.45",
56-
"browserify": "^16.2.3",
57-
"chai": "^4.2.0",
58-
"fs-extra": "^6.0.1",
59-
"mocha": "^3.5.3",
60-
"nyc": "^11.9.0",
61-
"source-map-support": "^0.5.11",
62-
"ts-node": "^3.3.0",
51+
"jest": "^24.1.0",
52+
"ts-jest": "^23.10.5",
53+
"ts-node": "^8.0.3",
6354
"tslint": "^5.15.0",
64-
"typescript": "2.5.2"
65-
},
66-
"nyc": {
67-
"extension": [
68-
".ts"
69-
],
70-
"exclude": [
71-
"**/*.d.ts",
72-
"src/test/**/*",
73-
"build/**/*",
74-
"docs/**/*",
75-
"coverage/**/*"
76-
],
77-
"reporter": [
78-
"text-summary"
79-
],
80-
"all": true
55+
"typescript": "^3.4.3"
8156
}
8257
}

src/plot-api.ts

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import { assert } from "chai";
21
const opn = require("opn");
32
import * as path from "path";
4-
import * as Sugar from "sugar";
53
import { ISerializedDataFrame } from "@data-forge/serialization";
64
import { exportTemplate, IExportOptions } from "inflate-template";
75
import { captureImage, ICaptureOptions } from "capture-template";
86
import { ChartType, IChartDef, AxisType, HorizontalLabelPosition, VerticalLabelPosition, IPlotConfig as IExpandedPlotConfig, IAxisMap as IExpandedAxisMap, ISingleYAxisMap as IExpandedSingleYAxisMap } from "@data-forge-plot/chart-def";
97
import { ISingleAxisMap, ISingleYAxisMap, IPlotConfig, IAxisMap, IAxisConfig } from "./chart-def";
8+
import { isObject, isString, isArray } from "./utils";
109

1110
const DEFAULT_CHART_PACKAGE = "@data-forge-plot/apex";
1211

@@ -22,7 +21,7 @@ async function findChartTemplatePath(): Promise<string> {
2221
return chartTemplatesPath;
2322
}
2423

25-
export async function startPlot(): Promise<void> {
24+
export async function startPlot(): Promise<void> {
2625
/*TODO:
2726
globalChartRenderer = new ChartRenderer();
2827
@@ -270,7 +269,15 @@ export abstract class AbstractPlotAPI implements IPlotAPI {
270269
* Configure the default x axis.
271270
*/
272271
x(seriesName: string): IXAxisConfigAPI {
273-
this.globalAxisMap.x.series = seriesName;
272+
if (!this.globalAxisMap.x) {
273+
this.globalAxisMap.x = {
274+
series: seriesName,
275+
};
276+
}
277+
else {
278+
this.globalAxisMap.x.series = seriesName;
279+
}
280+
274281
return new XAxisConfigAPI(
275282
"x",
276283
seriesName,
@@ -379,7 +386,7 @@ export abstract class AbstractPlotAPI implements IPlotAPI {
379386
if (defaultedGlobalAxis.y.length === 0) {
380387
// Default the primary Y axis.
381388
defaultedGlobalAxis.y = this.data.columnOrder
382-
.filter(columnName => columnName !== defaultedGlobalAxis.x.series)
389+
.filter(columnName => defaultedGlobalAxis.x === undefined || columnName !== defaultedGlobalAxis.x.series)
383390
.map(columnName => ({
384391
series: columnName,
385392
}));
@@ -414,7 +421,9 @@ export class PlotAPI extends AbstractPlotAPI {
414421
}
415422

416423
constructor(data: ISerializedDataFrame, plotConfig: IPlotConfig, showLegendDefault: boolean, globalAxisMap?: IAxisMap) {
417-
assert.isObject(data, "Expected 'data' parameter to PlotAPI constructor to be a serialized dataframe.");
424+
if (!isObject(data)) {
425+
throw new Error("Expected 'data' parameter to PlotAPI constructor to be a serialized dataframe.");
426+
}
418427

419428
// Clone the def and plot map so they can be updated by the fluent API.
420429
const expandedPlotConfig: IExpandedPlotConfig = Object.assign({}, plotConfig) as IExpandedPlotConfig;
@@ -505,7 +514,7 @@ export class PlotAPI extends AbstractPlotAPI {
505514

506515
if (globalAxisMap) {
507516
if (globalAxisMap.x) {
508-
if (Sugar.Object.isString(globalAxisMap.x)) {
517+
if (isString(globalAxisMap.x)) {
509518
expandedGlobalAxisMap.x = {
510519
series: globalAxisMap.x,
511520
};
@@ -516,16 +525,16 @@ export class PlotAPI extends AbstractPlotAPI {
516525
}
517526

518527
if (globalAxisMap.y) {
519-
if (Sugar.Object.isString(globalAxisMap.y)) {
528+
if (isString(globalAxisMap.y)) {
520529
expandedGlobalAxisMap.y = [
521530
{
522531
series: globalAxisMap.y,
523532
},
524533
];
525534
}
526-
else if (Sugar.Object.isArray(globalAxisMap.y)) {
535+
else if (isArray(globalAxisMap.y)) {
527536
expandedGlobalAxisMap.y = (globalAxisMap.y as any[]).map(series => {
528-
if (Sugar.Object.isString(series)) {
537+
if (isString(series)) {
529538
return {
530539
series,
531540
};
@@ -546,16 +555,16 @@ export class PlotAPI extends AbstractPlotAPI {
546555
}
547556

548557
if (globalAxisMap.y2) {
549-
if (Sugar.Object.isString(globalAxisMap.y2)) {
558+
if (isString(globalAxisMap.y2)) {
550559
expandedGlobalAxisMap.y2 = [
551560
{
552561
series: globalAxisMap.y2,
553562
},
554563
];
555564
}
556-
else if (Sugar.Object.isArray(globalAxisMap.y2)) {
565+
else if (isArray(globalAxisMap.y2)) {
557566
expandedGlobalAxisMap.y2 = (globalAxisMap.y2 as any[]).map(series => {
558-
if (Sugar.Object.isString(series)) {
567+
if (isString(series)) {
559568
return {
560569
series,
561570
};
@@ -737,7 +746,7 @@ class YAxisConfigAPI extends AxisConfigAPI<IYAxisConfigAPI, ISingleYAxisMap> imp
737746
if (!this.singleAxisMap.x) {
738747
this.singleAxisMap.x = { series: seriesName };
739748
}
740-
else if (Sugar.Object.isString(this.singleAxisMap.x)) {
749+
else if (isString(this.singleAxisMap.x)) {
741750
this.singleAxisMap.x = { series: seriesName };
742751
}
743752
else {

src/test/dataframe-fluent.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { expect } from "chai";
2-
import "mocha";
1+
import "jest";
32
import { DataFrame } from "data-forge";
43
import "../index";
54

@@ -11,7 +10,7 @@ describe("data-forge-plot - dataframe fluent", () => {
1110
const plotAPI = series.plot()
1211
.y("A");
1312

14-
expect(plotAPI.serialize()).to.eql({
13+
expect(plotAPI.serialize()).toEqual({
1514
data: {
1615
columnOrder: [
1716
"A",

src/test/dataframe.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { expect } from "chai";
2-
import "mocha";
1+
import "jest";
32
import { DataFrame } from "data-forge";
43
import "../index";
54

@@ -9,7 +8,7 @@ describe("data-forge-plot - dataframe configuration", () => {
98

109
const series = new DataFrame({ index: [1, 2, 3], values: [{ A: 10 }, { A: 20 }, { A: 30 } ] });
1110
const plotAPI = series.plot();
12-
expect(plotAPI.serialize()).to.eql({
11+
expect(plotAPI.serialize()).toEqual({
1312
data: {
1413
columnOrder: [
1514
"A",
@@ -71,6 +70,6 @@ describe("data-forge-plot - dataframe configuration", () => {
7170

7271
const series = new DataFrame({ index: [ 1 ], values: [{ A: 10 } ] });
7372
const plotAPI = series.plot();
74-
expect(plotAPI.serialize().plotConfig.legend.show).to.eql(true);
73+
expect(plotAPI.serialize().plotConfig.legend.show).toEqual(true);
7574
});
7675
});

src/test/mocha.opts

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/test/serialization.test.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { expect } from "chai";
2-
import "mocha";
1+
import "jest";
32
import "../index";
43
import { PlotAPI } from "../plot-api";
54
import { IChartDef, ChartType, AxisType } from "@data-forge-plot/chart-def";
@@ -74,24 +73,24 @@ describe("serialization", () => {
7473

7574
const plot = PlotAPI.deserialize(chartDef);
7675
const serialized = plot.serialize();
77-
expect(serialized).to.eql(chartDef);
76+
expect(serialized).toEqual(chartDef);
7877
});
7978

8079
it("serialization defaults legend show 1", () => {
8180
const plot = new PlotAPI(exampleData, {}, true, {});
8281
const serialized = plot.serialize();
83-
expect(serialized.plotConfig.legend.show).to.eql(true);
82+
expect(serialized.plotConfig.legend.show).toEqual(true);
8483
});
8584

8685
it("serialization defaults legend show 2", () => {
8786
const plot = new PlotAPI(exampleData, { legend: {} }, false, {});
8887
const serialized = plot.serialize();
89-
expect(serialized.plotConfig.legend.show).to.eql(false);
88+
expect(serialized.plotConfig.legend.show).toEqual(false);
9089
});
9190

9291
it("serialization preserves legend show", () => {
9392
const plot = new PlotAPI(exampleData, { legend: { show: false }}, true, {});
9493
const serialized = plot.serialize();
95-
expect(serialized.plotConfig.legend.show).to.eql(false);
94+
expect(serialized.plotConfig.legend.show).toEqual(false);
9695
});
9796
});

src/test/series.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { expect } from "chai";
2-
import "mocha";
1+
import "jest";
32
import { Series } from "data-forge";
43
import "../index";
54

@@ -9,7 +8,7 @@ describe("data-forge-plot - series", () => {
98

109
const series = new Series({ index: [1, 2, 3], values: [10, 20, 30] });
1110
const plotAPI = series.plot();
12-
expect(plotAPI.serialize()).to.eql({
11+
expect(plotAPI.serialize()).toEqual({
1312
data: {
1413
columnOrder: [
1514
"__value__",
@@ -71,6 +70,6 @@ describe("data-forge-plot - series", () => {
7170

7271
const series = new Series({ index: [ 1 ], values: [ 10 ] });
7372
const plotAPI = series.plot();
74-
expect(plotAPI.serialize().plotConfig.legend.show).to.eql(false);
73+
expect(plotAPI.serialize().plotConfig.legend.show).toEqual(false);
7574
});
7675
});

src/utils.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const t = require("typy").default;
2+
3+
export function isObject(v: any): boolean {
4+
return t(v).isObject && !isDate(v);
5+
}
6+
7+
export function isFunction(v: any): v is Function {
8+
return t(v).isFunction;
9+
}
10+
11+
export function isString(v: any): v is string {
12+
return t(v).isString;
13+
}
14+
15+
export function isDate(v: any): v is Date {
16+
return Object.prototype.toString.call(v) === "[object Date]";
17+
}
18+
19+
export function isBoolean(v: any): v is boolean {
20+
return t(v).isBoolean;
21+
}
22+
23+
export function isNumber(v: any): v is number {
24+
return t(v).isNumber;
25+
}
26+
27+
export function isArray(v: any): v is Array<any> {
28+
return t(v).isArray;
29+
}
30+
31+
export function isUndefined(v: any): boolean {
32+
return v === undefined;
33+
}

0 commit comments

Comments
 (0)