Skip to content

Commit 642f0ff

Browse files
committed
Merge pull request #206 from plotly/bundle-tests
Add testing framework to test custom bundles
2 parents 54bfe7a + 90a2538 commit 642f0ff

File tree

12 files changed

+228
-10
lines changed

12 files changed

+228
-10
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ build/*
66
!build/ploticon.js
77
!build/README.md
88

9-
npm-debug.log
9+
npm-debug.log*

circle.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ test:
2121
override:
2222
- sudo lxc-attach -n "$(docker inspect --format '{{.Id}}' mytestbed)" -- bash -c "cd /var/www/streambed/image_server/plotly.js && node test/image/compare_pixels_test.js"
2323
- npm run citest-jasmine
24+
- npm run test-bundle
2425
- npm run test-syntax

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,16 @@
2424
"preprocess": "node tasks/preprocess.js",
2525
"bundle": "node tasks/bundle.js",
2626
"header": "node tasks/header.js",
27-
"build": "npm run preprocess && npm run bundle && npm run header",
27+
"build": "npm dedupe && npm run preprocess && npm run bundle && npm run header",
2828
"cibuild": "node tasks/cibundle.js",
2929
"watch": "node tasks/watch_plotly.js",
3030
"lint": "eslint . || true",
3131
"test-jasmine": "karma start test/jasmine/karma.conf.js",
3232
"citest-jasmine": "karma start test/jasmine/karma.ciconf.js",
3333
"test-image": "./tasks/test_image.sh",
3434
"test-syntax": "node test/syntax_test.js",
35-
"test": "npm run test-jasmine && npm test-image && npm test-syntax",
35+
"test-bundle": "node tasks/test_bundle.js",
36+
"test": "npm run citest-jasmine && npm run test-image && npm run test-syntax && npm run test-bundle",
3637
"start-test_dashboard": "node devtools/test_dashboard/server.js",
3738
"start-image_viewer": "node devtools/image_viewer/server.js",
3839
"baseline": "./tasks/baseline.sh",

tasks/test_bundle.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
var path = require('path');
2+
var exec = require('child_process').exec;
3+
4+
var glob = require('glob');
5+
6+
var constants = require('./util/constants');
7+
var pathToJasmineBundleTests = path.join(constants.pathToJasmineBundleTests);
8+
9+
10+
glob(pathToJasmineBundleTests + '/*.js', function(err, files) {
11+
files.forEach(function(file) {
12+
var baseName = path.basename(file);
13+
var cmd = 'npm run citest-jasmine -- bundle_tests/' + baseName;
14+
15+
exec(cmd, function(err, stdout) {
16+
console.log(stdout);
17+
18+
if(err) throw err;
19+
});
20+
});
21+
});

tasks/util/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ module.exports = {
4848
pathToTestImagesDiffList: path.join(pathToBuild, 'list_of_incorrect_images.txt'),
4949

5050
pathToJasmineTests: path.join(pathToRoot, 'test/jasmine/tests'),
51+
pathToJasmineBundleTests: path.join(pathToRoot, 'test/jasmine/bundle_tests'),
5152

5253
uglifyOptions: {
5354
fromString: true,

test/jasmine/bundle_tests/bar_test.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
var d3 = require('d3');
2+
3+
var Plotly = require('@lib/core');
4+
var PlotlyBar = require('@lib/bar');
5+
6+
var createGraphDiv = require('../assets/create_graph_div');
7+
var destroyGraphDiv = require('../assets/destroy_graph_div');
8+
9+
10+
describe('Bundle with bar', function() {
11+
'use strict';
12+
13+
Plotly.register(PlotlyBar);
14+
15+
var mock = require('@mocks/bar_line.json');
16+
17+
beforeEach(function(done) {
18+
Plotly.plot(createGraphDiv(), mock.data, mock.layout).then(done);
19+
});
20+
21+
afterEach(destroyGraphDiv);
22+
23+
it('should graph scatter traces', function() {
24+
var nodes = d3.selectAll('g.trace.scatter');
25+
26+
expect(nodes.size()).toEqual(1);
27+
});
28+
29+
it('should graph bar traces', function() {
30+
var nodes = d3.selectAll('g.trace.bars');
31+
32+
expect(nodes.size()).toEqual(1);
33+
});
34+
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
var d3 = require('d3');
2+
3+
var Plotly = require('@lib/core');
4+
var PlotlyChoropleth = require('@lib/choropleth');
5+
6+
var createGraphDiv = require('../assets/create_graph_div');
7+
var destroyGraphDiv = require('../assets/destroy_graph_div');
8+
9+
10+
describe('Bundle with choropleth', function() {
11+
'use strict';
12+
13+
Plotly.register(PlotlyChoropleth);
14+
15+
var mock = require('@mocks/geo_multiple-usa-choropleths.json');
16+
17+
beforeEach(function(done) {
18+
Plotly.plot(createGraphDiv(), mock.data, mock.layout).then(done);
19+
});
20+
21+
afterEach(destroyGraphDiv);
22+
23+
it('should graph choropleth traces', function() {
24+
var nodes = d3.selectAll('g.trace.choropleth');
25+
26+
expect(nodes.size()).toEqual(4);
27+
});
28+
});
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
var d3 = require('d3');
2+
3+
var Plotly = require('@lib/core');
4+
var PlotlyContour = require('@lib/contour');
5+
6+
var createGraphDiv = require('../assets/create_graph_div');
7+
var destroyGraphDiv = require('../assets/destroy_graph_div');
8+
9+
10+
describe('Bundle with contour', function() {
11+
'use strict';
12+
13+
Plotly.register(PlotlyContour);
14+
15+
var mock = require('@mocks/contour_scatter.json');
16+
17+
beforeEach(function(done) {
18+
Plotly.plot(createGraphDiv(), mock.data, mock.layout).then(done);
19+
});
20+
21+
afterEach(destroyGraphDiv);
22+
23+
it('should graph scatter traces', function() {
24+
var nodes = d3.selectAll('g.trace.scatter');
25+
26+
expect(nodes.size()).toEqual(1);
27+
});
28+
29+
it('should graph contour traces', function() {
30+
var nodes = d3.selectAll('g.contour');
31+
32+
expect(nodes.size()).toEqual(1);
33+
});
34+
});
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
var d3 = require('d3');
2+
3+
var Plotly = require('@lib/core');
4+
5+
var createGraphDiv = require('../assets/create_graph_div');
6+
var destroyGraphDiv = require('../assets/destroy_graph_div');
7+
8+
9+
describe('Bundle with core only', function() {
10+
'use strict';
11+
12+
var mock = require('@mocks/bar_line.json');
13+
14+
beforeEach(function(done) {
15+
spyOn(console, 'warn');
16+
17+
Plotly.plot(createGraphDiv(), mock.data, mock.layout).then(done);
18+
});
19+
20+
afterEach(destroyGraphDiv);
21+
22+
it('should graph scatter traces', function() {
23+
var nodes = d3.selectAll('g.trace.scatter');
24+
25+
expect(nodes.size()).toEqual(mock.data.length);
26+
});
27+
28+
it('should not graph bar traces', function() {
29+
var nodes = d3.selectAll('g.trace.bars');
30+
31+
expect(nodes.size()).toEqual(0);
32+
});
33+
34+
it('should warn users about unregistered bar trace type', function() {
35+
expect(console.warn).toHaveBeenCalled();
36+
});
37+
});
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
var d3 = require('d3');
2+
3+
var Plotly = require('@lib/core');
4+
var PlotlyHistogram2dContour = require('@lib/histogram2dcontour');
5+
var PlotlyHistogram = require('@lib/histogram');
6+
7+
var createGraphDiv = require('../assets/create_graph_div');
8+
var destroyGraphDiv = require('../assets/destroy_graph_div');
9+
10+
11+
describe('Bundle with histogram2dcontour and histogram', function() {
12+
'use strict';
13+
14+
Plotly.register([PlotlyHistogram2dContour, PlotlyHistogram]);
15+
16+
var mock = require('@mocks/2dhistogram_contour_subplots.json');
17+
18+
beforeEach(function(done) {
19+
Plotly.plot(createGraphDiv(), mock.data, mock.layout).then(done);
20+
});
21+
22+
afterEach(destroyGraphDiv);
23+
24+
it('should graph scatter traces', function() {
25+
var nodes = d3.selectAll('g.trace.scatter');
26+
27+
expect(nodes.size()).toEqual(1);
28+
});
29+
30+
it('should graph contour traces', function() {
31+
var nodes = d3.selectAll('g.contour');
32+
33+
expect(nodes.size()).toEqual(1);
34+
});
35+
36+
it('should graph histogram traces', function() {
37+
var nodes = d3.selectAll('g.bars');
38+
39+
expect(nodes.size()).toEqual(2);
40+
});
41+
});

0 commit comments

Comments
 (0)