Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 50fbceb

Browse files
committed
generalize jupyter js tests design:
- init js_tests/ directory - mv test.js -> js_tests/connected_false.js - rename fixture ipynb accordingly - make test runner take two args (1 for html page, 1 for js test file) - add base test case in test_jupyter.py
1 parent 4645cc1 commit 50fbceb

File tree

5 files changed

+59
-27
lines changed

5 files changed

+59
-27
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use strict';
2+
3+
var test = require('../lib/tape-wrapper');
4+
5+
test('should have the correct number of script tags', function(t) {
6+
t.plan(1);
7+
8+
var nodes = document.querySelectorAll('script');
9+
t.equal(nodes.length, 8);
10+
});
11+
12+
test('should have one plotly.js graph', function(t) {
13+
t.plan(1);
14+
15+
var nodes = document.querySelectorAll('.js-plotly-plot');
16+
t.equal(nodes.length, 1);
17+
});
18+
19+
test('should inject raw plotly.js code into DOM', function(t) {
20+
t.plan(1);
21+
22+
var nodes = document.querySelectorAll('script');
23+
nodes = Array.prototype.slice.call(nodes, 0, 10);
24+
25+
var results = nodes.filter(function(node) {
26+
return node.innerHTML.substr(0, 19) === 'if(!window.Plotly){';
27+
});
28+
29+
t.equal(results.length, 1);
30+
});

plotly/tests/test_core/test_jupyter/lib/server.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@ var chrome = require('chrome-launch');
1111

1212
var PORT = 8080;
1313
var PATH_ROOT = path.join(__dirname, '..');
14-
var PATH_FIXTURES = path.join(PATH_ROOT, 'fixtures');
15-
var PATH_INDEX = path.join(PATH_FIXTURES, 'test.html');
16-
var PATH_INDEX_STUB = path.join(PATH_FIXTURES, 'test.tmp.html');
17-
var PATH_TEST_FILE = path.join(PATH_ROOT, 'test.js');
14+
var PATH_INDEX_STUB = path.join(PATH_ROOT, 'index.tmp.html');
1815
var PATH_TEST_BUNDLE = path.join(PATH_ROOT, 'test.tmp.js');
19-
var URL = 'http://localhost:' + PORT + '/fixtures/test.tmp.html';
16+
17+
var URL = 'http://localhost:' + PORT + '/index.tmp.html';
2018
var EXIT_CODE = 0;
2119

20+
if(process.argv.length !== 4) {
21+
throw new Error('must provide path to html and js files');
22+
}
23+
24+
var PATH_INDEX = process.argv[2];
25+
var PATH_TEST_FILE = process.argv[3];
2226

2327
main();
2428

plotly/tests/test_core/test_jupyter/test.js

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

plotly/tests/test_core/test_jupyter/test_jupyter.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,19 @@
1212

1313
PATH_ROOT = path.dirname(__file__)
1414
PATH_FIXTURES = path.join(PATH_ROOT, 'fixtures')
15-
PATH_TEST_NB = path.join(PATH_FIXTURES, 'test.ipynb')
16-
PATH_TEST_HTML = path.join(PATH_FIXTURES, 'test.html')
15+
PATH_JS_TESTS = path.join(PATH_ROOT, 'js_tests')
1716

1817

19-
class PlotlyJupyterTestCase(TestCase):
18+
class Common(TestCase):
19+
__test__ = False
20+
name = None
21+
2022
def setUp(self):
21-
with open(PATH_TEST_NB, 'r') as f:
23+
self.path_test_nb = path.join(PATH_FIXTURES, self.name + '.ipynb')
24+
self.path_test_html = path.join(PATH_FIXTURES, self.name + '.html')
25+
self.path_test_js = path.join(PATH_JS_TESTS, self.name + '.js')
26+
27+
with open(self.path_test_nb, 'r') as f:
2228
self.nb = nbformat.read(f, as_version=4)
2329

2430
if 'PYENV_VERSION' in environ:
@@ -32,11 +38,13 @@ def setUp(self):
3238
self.ep.preprocess(self.nb, {'metadata': {'path': '.'}})
3339
(self.body, _) = self.html_exporter.from_notebook_node(self.nb)
3440

35-
with open(PATH_TEST_HTML, 'w') as f:
41+
with open(self.path_test_html, 'w') as f:
3642
f.write(self.body)
3743

38-
def test_one(self):
39-
proc = subprocess.Popen(['npm', 'test'],
44+
def test_js(self):
45+
cmd = ['npm', 'test', '--', self.path_test_html, self.path_test_js]
46+
47+
proc = subprocess.Popen(cmd,
4048
cwd=PATH_ROOT,
4149
stdout=subprocess.PIPE,
4250
stderr=subprocess.PIPE)
@@ -45,3 +53,8 @@ def test_one(self):
4553

4654
if stderr:
4755
self.fail('One or more javascript test failed')
56+
57+
58+
class PlotlyJupyterConnectedFalseTestCase(Common):
59+
__test__ = True
60+
name = 'connected_false'

0 commit comments

Comments
 (0)