Browse Source

Adds code coverage report the output of `npm test` and adds detailed … (#3575)

* Adds code coverage report the output of `npm test` and adds detailed html code coverage report using the command `npm run-script test-cov`

* Switch over to using functions in lib/ rather than dist/, so that code coverage stats are complete.

* Import vis at the top level to keep ItemSet passing

* Remove requirement for dist/vis in TimelineItemSet
mbroad/code-climate-coverage-develop
macleodbroad-wf 7 years ago
committed by Yotam Berkowitz
parent
commit
197f36a6ff
11 changed files with 80 additions and 84 deletions
  1. +3
    -1
      package.json
  2. +4
    -4
      test/DataSet.test.js
  3. +3
    -4
      test/DataView.test.js
  4. +2
    -3
      test/Graph3d.test.js
  5. +17
    -17
      test/Label.test.js
  6. +22
    -22
      test/Network.test.js
  7. +2
    -4
      test/PointItem.test.js
  8. +4
    -5
      test/TestSupport.js
  9. +3
    -5
      test/TimeStep.test.js
  10. +17
    -14
      test/TimelineItemSet.test.js
  11. +3
    -5
      test/TimelineRange.test.js

+ 3
- 1
package.json View File

@ -26,7 +26,8 @@
], ],
"main": "./dist/vis.js", "main": "./dist/vis.js",
"scripts": { "scripts": {
"test": "mocha --compilers js:babel-core/register",
"test": "nyc mocha --compilers js:babel-core/register",
"test-cov": "nyc --reporter=html mocha --compilers js:babel-core/register",
"build": "gulp", "build": "gulp",
"lint": "gulp lint", "lint": "gulp lint",
"watch": "gulp watch", "watch": "gulp watch",
@ -63,6 +64,7 @@
"merge-stream": "^1.0.1", "merge-stream": "^1.0.1",
"mocha": "^3.4.2", "mocha": "^3.4.2",
"mocha-jsdom": "^1.1.0", "mocha-jsdom": "^1.1.0",
"nyc": "^11.2.1",
"rimraf": "^2.6.1", "rimraf": "^2.6.1",
"test-console": "^1.0.0", "test-console": "^1.0.0",
"uglify-js": "^2.8.29", "uglify-js": "^2.8.29",

+ 4
- 4
test/DataSet.test.js View File

@ -1,8 +1,8 @@
var assert = require('assert'); var assert = require('assert');
var vis = require('../dist/vis');
var moment = vis.moment;
var DataSet = vis.DataSet;
var Queue = vis.Queue;
var DataSet = require('../lib/DataSet');
var Queue = require('../lib/Queue');
// TODO: test the source code immediately, but this is ES6 // TODO: test the source code immediately, but this is ES6
var now = new Date(); var now = new Date();

+ 3
- 4
test/DataView.test.js View File

@ -1,8 +1,7 @@
var assert = require('assert'); var assert = require('assert');
var vis = require('../dist/vis');
var moment = vis.moment;
var DataSet = vis.DataSet;
var DataView = vis.DataView;
var DataSet = require('../lib/DataSet');
var DataView = require('../lib/DataView');
// TODO: test the source code immediately, but this is ES6 // TODO: test the source code immediately, but this is ES6
// TODO: improve DataView tests, split up in one test per function // TODO: improve DataView tests, split up in one test per function

+ 2
- 3
test/Graph3d.test.js View File

@ -1,6 +1,5 @@
var assert = require('assert'); var assert = require('assert');
var vis = require('../dist/vis');
var Graph3d = vis.Graph3d;
var Graph3d = require('../lib/graph3d/Graph3d');
var jsdom_global = require('jsdom-global'); var jsdom_global = require('jsdom-global');
var canvasMockify = require('./canvas-mock'); var canvasMockify = require('./canvas-mock');
var stdout = require('test-console').stdout; var stdout = require('test-console').stdout;
@ -56,7 +55,7 @@ describe('Graph3d', function () {
style: 'dot' style: 'dot'
}; };
var graph = new vis.Graph3d(this.container, data, options);
var graph = new Graph3d(this.container, data, options);
assert.equal(graph.style, DOT_STYLE, "Style not set to expected 'dot'"); assert.equal(graph.style, DOT_STYLE, "Style not set to expected 'dot'");
graph.setOptions({ style: 'bar'}); // Call should just work, no exception thrown graph.setOptions({ style: 'bar'}); // Call should just work, no exception thrown

+ 17
- 17
test/Label.test.js View File

@ -8,14 +8,14 @@
* Currently, only "size[px] name color" is valid, always 3 items with this exact spacing. * Currently, only "size[px] name color" is valid, always 3 items with this exact spacing.
* All other combinations should either be rejected as error or handled gracefully. * All other combinations should either be rejected as error or handled gracefully.
*/ */
var assert = require('assert')
var assert = require('assert');
var Label = require('../lib/network/modules/components/shared/Label').default; var Label = require('../lib/network/modules/components/shared/Label').default;
var NodesHandler = require('../lib/network/modules/NodesHandler').default; var NodesHandler = require('../lib/network/modules/NodesHandler').default;
var util = require('../lib/util'); var util = require('../lib/util');
var jsdom_global = require('jsdom-global'); var jsdom_global = require('jsdom-global');
var canvasMockify = require('./canvas-mock'); var canvasMockify = require('./canvas-mock');
var vis = require('../dist/vis');
var Network = vis.network;
var DataSet = require('../lib/DataSet');
var Network = require('../lib/network/Network');
/************************************************************** /**************************************************************
@ -477,7 +477,7 @@ describe('Node Labels', function() {
// create a network // create a network
var container = document.getElementById('mynetwork'); var container = document.getElementById('mynetwork');
var data = { var data = {
nodes: new vis.DataSet(dataNodes),
nodes: new DataSet(dataNodes),
edges: [] edges: []
}; };
@ -501,7 +501,7 @@ describe('Node Labels', function() {
util.deepExtend(options, newOptions); util.deepExtend(options, newOptions);
} }
var network = new vis.Network(container, data, options);
var network = new Network(container, data, options);
return [network, data, options]; return [network, data, options];
} }
@ -678,8 +678,8 @@ describe('Edge Labels', function() {
// create a network // create a network
var container = document.getElementById('mynetwork'); var container = document.getElementById('mynetwork');
var data = { var data = {
nodes: new vis.DataSet(dataNodes),
edges: new vis.DataSet(dataEdges),
nodes: new DataSet(dataNodes),
edges: new DataSet(dataEdges),
}; };
var options = { var options = {
@ -694,7 +694,7 @@ describe('Edge Labels', function() {
util.deepExtend(options, newOptions); util.deepExtend(options, newOptions);
} }
var network = new vis.Network(container, data, options);
var network = new Network(container, data, options);
return [network, data, options]; return [network, data, options];
} }
@ -823,8 +823,8 @@ describe('Shorthand Font Options', function() {
// create a network // create a network
var container = document.getElementById('mynetwork'); var container = document.getElementById('mynetwork');
var data = { var data = {
nodes: new vis.DataSet(dataNodes),
edges: new vis.DataSet(dataEdges),
nodes: new DataSet(dataNodes),
edges: new DataSet(dataEdges),
}; };
var options = { var options = {
@ -847,7 +847,7 @@ describe('Shorthand Font Options', function() {
} }
}; };
var network = new vis.Network(container, data, options);
var network = new Network(container, data, options);
return [network, data]; return [network, data];
} }
@ -1114,7 +1114,7 @@ describe('Shorthand Font Options', function() {
// create a network // create a network
var container = document.getElementById('mynetwork'); var container = document.getElementById('mynetwork');
var data = { var data = {
nodes: new vis.DataSet(dataNodes),
nodes: new DataSet(dataNodes),
edges: [] edges: []
}; };
@ -1145,7 +1145,7 @@ describe('Shorthand Font Options', function() {
}, },
}; };
var network = new vis.Network(container, data, options);
var network = new Network(container, data, options);
assert.equal(modBold(1).color, 'red'); // Group value assert.equal(modBold(1).color, 'red'); // Group value
assert(fontOption(1).multi); // Group value assert(fontOption(1).multi); // Group value
@ -1487,7 +1487,7 @@ describe('Shorthand Font Options', function() {
enabled: false enabled: false
} }
}; };
var network = new vis.Network(container, data, options);
var network = new Network(container, data, options);
var nodes_expected = [ var nodes_expected = [
{ nodeId: 100, minWdt: -1, maxWdt: 200, minHgt: -1, valign: 'middle'}, { nodeId: 100, minWdt: -1, maxWdt: 200, minHgt: -1, valign: 'middle'},
@ -1614,12 +1614,12 @@ describe('Shorthand Font Options', function() {
// Kept in for regression testing. // Kept in for regression testing.
var container = document.getElementById('mynetwork'); var container = document.getElementById('mynetwork');
var data = { var data = {
nodes: new vis.DataSet(nodes),
edges: new vis.DataSet(edges)
nodes: new DataSet(nodes),
edges: new DataSet(edges)
}; };
var options = {}; var options = {};
var network = new vis.Network(container, data, options);
var network = new Network(container, data, options);
done(); done();
}); });

+ 22
- 22
test/Network.test.js View File

@ -12,8 +12,8 @@
*/ */
var fs = require('fs'); var fs = require('fs');
var assert = require('assert'); var assert = require('assert');
var vis = require('../dist/vis');
var Network = vis.network;
var DataSet = require('../lib/DataSet');
var Network = require('../lib/network/Network');
var stdout = require('test-console').stdout; var stdout = require('test-console').stdout;
var Validator = require("./../lib/shared/Validator").default; var Validator = require("./../lib/shared/Validator").default;
var jsdom_global = require('jsdom-global'); var jsdom_global = require('jsdom-global');
@ -78,7 +78,7 @@ function createSampleNetwork(options) {
var NumInitialNodes = 8; var NumInitialNodes = 8;
var NumInitialEdges = 6; var NumInitialEdges = 6;
var nodes = new vis.DataSet([
var nodes = new DataSet([
{id: 1, label: '1'}, {id: 1, label: '1'},
{id: 2, label: '2'}, {id: 2, label: '2'},
{id: 3, label: '3'}, {id: 3, label: '3'},
@ -88,7 +88,7 @@ function createSampleNetwork(options) {
{id: 13, label: '13'}, {id: 13, label: '13'},
{id: 14, label: '14'}, {id: 14, label: '14'},
]); ]);
var edges = new vis.DataSet([
var edges = new DataSet([
{from: 1, to: 2}, {from: 1, to: 2},
{from: 2, to: 3}, {from: 2, to: 3},
{from: 3, to: 4}, {from: 3, to: 4},
@ -117,7 +117,7 @@ function createSampleNetwork(options) {
options = merge(defaultOptions, options); options = merge(defaultOptions, options);
var network = new vis.Network(container, data, options);
var network = new Network(container, data, options);
assertNumNodes(network, NumInitialNodes); assertNumNodes(network, NumInitialNodes);
assertNumEdges(network, NumInitialEdges); assertNumEdges(network, NumInitialEdges);
@ -409,7 +409,7 @@ describe('Network', function () {
var container = document.getElementById('mynetwork'); var container = document.getElementById('mynetwork');
for (var n = 0; n < awkwardData.length; ++n) { for (var n = 0; n < awkwardData.length; ++n) {
var network = new vis.Network(container, awkwardData[n], {}); // Should not throw
var network = new Network(container, awkwardData[n], {}); // Should not throw
} }
}); });
@ -517,14 +517,14 @@ describe('Edge', function () {
* Support routine for next unit test * Support routine for next unit test
*/ */
function createDataforColorChange() { function createDataforColorChange() {
var nodes = new vis.DataSet([
var nodes = new DataSet([
{id: 1, label: 'Node 1' }, // group:'Group1'}, {id: 1, label: 'Node 1' }, // group:'Group1'},
{id: 2, label: 'Node 2', group:'Group2'}, {id: 2, label: 'Node 2', group:'Group2'},
{id: 3, label: 'Node 3'}, {id: 3, label: 'Node 3'},
]); ]);
// create an array with edges // create an array with edges
var edges = new vis.DataSet([
var edges = new DataSet([
{id: 1, from: 1, to: 2}, {id: 1, from: 1, to: 2},
{id: 2, from: 1, to: 3, color: { inherit: 'to'}}, {id: 2, from: 1, to: 3, color: { inherit: 'to'}},
{id: 3, from: 3, to: 3, color: { color: '#00FF00'}}, {id: 3, from: 3, to: 3, color: { color: '#00FF00'}},
@ -556,7 +556,7 @@ describe('Edge', function () {
}; };
// Test passing options on init. // Test passing options on init.
var network = new vis.Network(container, data, options);
var network = new Network(container, data, options);
var edges = network.body.edges; var edges = network.body.edges;
assert.equal(edges[1].options.color.inherit, 'to'); // new default assert.equal(edges[1].options.color.inherit, 'to'); // new default
assert.equal(edges[2].options.color.inherit, 'to'); // set in edge assert.equal(edges[2].options.color.inherit, 'to'); // set in edge
@ -574,7 +574,7 @@ describe('Edge', function () {
assert.equal(edges[4].options.color.inherit, 'from'); // set in edge assert.equal(edges[4].options.color.inherit, 'from'); // set in edge
// Check no options // Check no options
network = new vis.Network(container, data, {});
network = new Network(container, data, {});
edges = network.body.edges; edges = network.body.edges;
assert.equal(edges[1].options.color.inherit, 'from'); // default assert.equal(edges[1].options.color.inherit, 'from'); // default
assert.equal(edges[2].options.color.inherit, 'to'); // set in edge assert.equal(edges[2].options.color.inherit, 'to'); // set in edge
@ -605,7 +605,7 @@ describe('Edge', function () {
var data = createDataforColorChange(); var data = createDataforColorChange();
// Check no options // Check no options
var network = new vis.Network(container, data, {});
var network = new Network(container, data, {});
var edges = network.body.edges; var edges = network.body.edges;
assert.equal(edges[1].options.color.inherit, 'from'); // default assert.equal(edges[1].options.color.inherit, 'from'); // default
assert.equal(edges[2].options.color.inherit, 'to'); // set in edge assert.equal(edges[2].options.color.inherit, 'to'); // set in edge
@ -636,7 +636,7 @@ describe('Edge', function () {
}; };
// Test passing options on init. // Test passing options on init.
var network = new vis.Network(container, data, options);
var network = new Network(container, data, options);
var edges = network.body.edges; var edges = network.body.edges;
assert.equal(edges[1].options.color.color, color); assert.equal(edges[1].options.color.color, color);
assert.equal(edges[1].options.color.inherit, false); // Explicit color, so no inherit assert.equal(edges[1].options.color.inherit, false); // Explicit color, so no inherit
@ -655,7 +655,7 @@ describe('Edge', function () {
assert.equal(edges[4].options.color.color, defaultColor); assert.equal(edges[4].options.color.color, defaultColor);
// Check no options // Check no options
network = new vis.Network(container, data, {});
network = new Network(container, data, {});
edges = network.body.edges; edges = network.body.edges;
// At this point, color has not changed yet // At this point, color has not changed yet
assert.equal(edges[1].options.color.color, defaultColor); assert.equal(edges[1].options.color.color, defaultColor);
@ -680,10 +680,10 @@ describe('Edge', function () {
it('has reconnected edges', function () { it('has reconnected edges', function () {
var node1 = {id:1, label:"test1"}; var node1 = {id:1, label:"test1"};
var node2 = {id:2, label:"test2"}; var node2 = {id:2, label:"test2"};
var nodes = new vis.DataSet([node1, node2]);
var nodes = new DataSet([node1, node2]);
var edge = {id:1, from: 1, to:2}; var edge = {id:1, from: 1, to:2};
var edges = new vis.DataSet([edge]);
var edges = new DataSet([edge]);
var data = { var data = {
nodes: nodes, nodes: nodes,
@ -691,7 +691,7 @@ describe('Edge', function () {
}; };
var container = document.getElementById('mynetwork'); var container = document.getElementById('mynetwork');
var network = new vis.Network(container, data);
var network = new Network(container, data);
//remove node causing edge to become disconnected //remove node causing edge to become disconnected
nodes.remove(node2.id); nodes.remove(node2.id);
@ -893,7 +893,7 @@ describe('Clustering', function () {
*/ */
function createOutlierGraph() { function createOutlierGraph() {
// create an array with nodes // create an array with nodes
var nodes = new vis.DataSet([
var nodes = new DataSet([
{id: 1, label: '1', group:'Group1'}, {id: 1, label: '1', group:'Group1'},
{id: 2, label: '2', group:'Group2'}, {id: 2, label: '2', group:'Group2'},
{id: 3, label: '3', group:'Group3'}, {id: 3, label: '3', group:'Group3'},
@ -902,7 +902,7 @@ describe('Clustering', function () {
]); ]);
// create an array with edges // create an array with edges
var edges = new vis.DataSet([
var edges = new DataSet([
{from: 1, to: 3}, {from: 1, to: 3},
{from: 1, to: 2}, {from: 1, to: 2},
{from: 2, to: 4}, {from: 2, to: 4},
@ -924,7 +924,7 @@ describe('Clustering', function () {
} }
}; };
var network = new vis.Network (container, data, options);
var network = new Network (container, data, options);
return network; return network;
} }
@ -1320,8 +1320,8 @@ describe('runs example ', function () {
// create a network // create a network
var data = { var data = {
nodes: new vis.DataSet(nodes),
edges: new vis.DataSet(edges)
nodes: new DataSet(nodes),
edges: new DataSet(edges)
}; };
if (noPhysics) { if (noPhysics) {
@ -1330,7 +1330,7 @@ describe('runs example ', function () {
options.physics = false; options.physics = false;
} }
var network = new vis.Network(container, data, options);
var network = new Network(container, data, options);
return network; return network;
}; };

+ 2
- 4
test/PointItem.test.js View File

@ -1,10 +1,8 @@
var assert = require('assert'); var assert = require('assert');
var vis = require('../dist/vis');
var jsdom = require('mocha-jsdom'); var jsdom = require('mocha-jsdom');
var moment = vis.moment;
var timeline = vis.timeline;
var moment = require('../lib/module/moment');
var PointItem = require("../lib/timeline/component/item/PointItem"); var PointItem = require("../lib/timeline/component/item/PointItem");
var Range = timeline.Range;
var Range = require('../lib/timeline/Range');
var TestSupport = require('./TestSupport'); var TestSupport = require('./TestSupport');
describe('Timeline PointItem', function () { describe('Timeline PointItem', function () {

+ 4
- 5
test/TestSupport.js View File

@ -1,5 +1,4 @@
var vis = require('../dist/vis');
var DataSet = vis.DataSet;
var DataSet = require('../lib/DataSet');
module.exports = { module.exports = {
buildMockItemSet: function() { buildMockItemSet: function() {
@ -35,8 +34,8 @@ module.exports = {
}, },
hiddenDates: [], hiddenDates: [],
util: {} util: {}
}
body.dom.rollingModeBtn = document.createElement('div')
};
body.dom.rollingModeBtn = document.createElement('div');
return body return body
} }
}
};

+ 3
- 5
test/TimeStep.test.js View File

@ -1,9 +1,7 @@
var assert = require('assert'); var assert = require('assert');
var vis = require('../dist/vis');
var jsdom = require('mocha-jsdom')
var moment = vis.moment;
var timeline = vis.timeline;
var TimeStep = timeline.TimeStep;
var jsdom = require('mocha-jsdom');
var moment = require('../lib/module/moment');
var TimeStep = require('../lib/timeline/TimeStep');
var TestSupport = require('./TestSupport'); var TestSupport = require('./TestSupport');
describe('TimeStep', function () { describe('TimeStep', function () {

+ 17
- 14
test/TimelineItemSet.test.js View File

@ -1,15 +1,19 @@
var assert = require('assert'); var assert = require('assert');
var DataSet = require('../lib/DataSet');
var DateUtil = require('../lib/timeline/DateUtil');
var Range = require('../lib/timeline/Range');
var ItemSet = require('../lib/timeline/component/ItemSet');
describe('Timeline ItemSet', function () { describe('Timeline ItemSet', function () {
before(function () { before(function () {
delete require.cache[require.resolve('../dist/vis')]
this.jsdom = require('jsdom-global')(); this.jsdom = require('jsdom-global')();
this.vis = require('../dist/vis');
var TestSupport = require('./TestSupport');
var rangeBody = TestSupport.buildSimpleTimelineRangeBody();
this.testrange = new this.vis.timeline.Range(rangeBody);
this.TestSupport = require('./TestSupport');
var rangeBody = this.TestSupport.buildSimpleTimelineRangeBody();
this.testrange = new Range(rangeBody);
this.testrange.setRange(new Date(2017, 1, 26, 13, 26, 3, 320), new Date(2017, 1, 26, 13, 26, 4, 320), false, false, null); this.testrange.setRange(new Date(2017, 1, 26, 13, 26, 3, 320), new Date(2017, 1, 26, 13, 26, 4, 320), false, false, null);
this.testitems = new this.vis.DataSet({
this.testitems = new DataSet({
type: { type: {
start: 'Date', start: 'Date',
end: 'Date' end: 'Date'
@ -18,11 +22,11 @@ describe('Timeline ItemSet', function () {
// add single items with different date types // add single items with different date types
this.testitems.add({id: 1, content: 'Item 1', start: new Date(2017, 1, 26, 13, 26, 3, 600), type: 'point'}); this.testitems.add({id: 1, content: 'Item 1', start: new Date(2017, 1, 26, 13, 26, 3, 600), type: 'point'});
this.testitems.add({id: 2, content: 'Item 2', start: new Date(2017, 1, 26, 13, 26, 5, 600), type: 'point'}); this.testitems.add({id: 2, content: 'Item 2', start: new Date(2017, 1, 26, 13, 26, 5, 600), type: 'point'});
})
});
after(function () { after(function () {
this.jsdom(); this.jsdom();
})
});
var getBasicBody = function() { var getBasicBody = function() {
var body = { var body = {
@ -56,20 +60,20 @@ describe('Timeline ItemSet', function () {
}, },
util: { util: {
} }
}
};
return body; return body;
}; };
it('should initialise with minimal data', function () { it('should initialise with minimal data', function () {
var body = getBasicBody(); var body = getBasicBody();
var itemset = new this.vis.timeline.components.ItemSet(body, {});
var itemset = new ItemSet(body, {});
assert(itemset); assert(itemset);
}); });
it('should redraw() and have the right classNames', function () { it('should redraw() and have the right classNames', function () {
var body = getBasicBody(); var body = getBasicBody();
body.range = this.testrange; body.range = this.testrange;
var itemset = new this.vis.timeline.components.ItemSet(body, {});
var itemset = new ItemSet(body, {});
itemset.redraw(); itemset.redraw();
assert.equal(itemset.dom.frame.className, 'vis-itemset'); assert.equal(itemset.dom.frame.className, 'vis-itemset');
assert.equal(itemset.dom.background.className, 'vis-background'); assert.equal(itemset.dom.background.className, 'vis-background');
@ -80,14 +84,13 @@ describe('Timeline ItemSet', function () {
it('should start with no items', function () { it('should start with no items', function () {
var body = getBasicBody(); var body = getBasicBody();
var itemset = new this.vis.timeline.components.ItemSet(body, {});
var itemset = new ItemSet(body, {});
assert.equal(itemset.getItems(), null); assert.equal(itemset.getItems(), null);
}); });
it('should store items correctly', function() { it('should store items correctly', function() {
var body = getBasicBody(); var body = getBasicBody();
body.range = this.testrange; body.range = this.testrange;
var DateUtil = this.vis.timeline.DateUtil;
body.util.toScreen = function(time) { body.util.toScreen = function(time) {
return DateUtil.toScreen({ return DateUtil.toScreen({
body: { body: {
@ -100,7 +103,7 @@ describe('Timeline ItemSet', function () {
} }
}, time, 900) }, time, 900)
}; };
var itemset = new this.vis.timeline.components.ItemSet(body, {});
var itemset = new ItemSet(body, {});
itemset.setItems(this.testitems); itemset.setItems(this.testitems);
assert.equal(itemset.getItems().length, 2); assert.equal(itemset.getItems().length, 2);
assert.deepEqual(itemset.getItems(), this.testitems); assert.deepEqual(itemset.getItems(), this.testitems);

+ 3
- 5
test/TimelineRange.test.js View File

@ -1,9 +1,7 @@
var assert = require('assert'); var assert = require('assert');
var vis = require('../dist/vis');
var jsdom = require('mocha-jsdom')
var moment = vis.moment;
var timeline = vis.timeline;
var Range = timeline.Range;
var jsdom = require('mocha-jsdom');
var moment = require('../lib/module/moment');
var Range = require('../lib/timeline/Range');
var TestSupport = require('./TestSupport'); var TestSupport = require('./TestSupport');
describe('Timeline Range', function () { describe('Timeline Range', function () {

Loading…
Cancel
Save