-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Add JS tests for Jupyter NBs #549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
eba8bd7
first pass js jupyter tests
etpinard 673d0a3
un-ignore fixture ipynb files
etpinard f02b6a7
standardize optional requirements for CircleCI
etpinard cedb7f1
add requirements for jupyter test on circleci
etpinard 590f485
improve jupyter test design:
etpinard 2892049
split ipynb fixture and js test file into two cases:
etpinard 27966e5
Move `test_jupyter` into *optional* test cases.
theengineear 28e2fe0
Add `jupyter` to optional tox deps.
theengineear 8850feb
Cache jupyter node_modules deps.
theengineear 053cdd6
Quick fix for intermittent image server tests.
theengineear 7da7ed2
Use node a version that Circle has preinstalled.
theengineear File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
fixtures/*.html | ||
!fixtures/*.ipynb |
57 changes: 57 additions & 0 deletions
57
plotly/tests/test_optional/test_jupyter/fixtures/connected_false.ipynb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"from plotly.offline import plot, iplot, init_notebook_mode\n", | ||
"import plotly.graph_objs as go\n", | ||
"\n", | ||
"# Make plotly work with Jupyter notebook\n", | ||
"init_notebook_mode()\n", | ||
"\n", | ||
"keys=['one','two','three']\n", | ||
"values=[1,2,3]\n", | ||
"\n", | ||
"iplot({\n", | ||
" \"data\": [go.Bar(x=keys, y=values)],\n", | ||
" \"layout\": go.Layout(title=\"Sample Bar Chart\")\n", | ||
"})" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": true | ||
}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.5.2" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 1 | ||
} |
57 changes: 57 additions & 0 deletions
57
plotly/tests/test_optional/test_jupyter/fixtures/connected_true.ipynb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"from plotly.offline import plot, iplot, init_notebook_mode\n", | ||
"import plotly.graph_objs as go\n", | ||
"\n", | ||
"# Make plotly work with Jupyter notebook\n", | ||
"init_notebook_mode(connected=True)\n", | ||
"\n", | ||
"keys=['one','two','three']\n", | ||
"values=[1,2,3]\n", | ||
"\n", | ||
"iplot({\n", | ||
" \"data\": [go.Bar(x=keys, y=values)],\n", | ||
" \"layout\": go.Layout(title=\"Sample Bar Chart\")\n", | ||
"})" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": true | ||
}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.5.2" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 1 | ||
} |
31 changes: 31 additions & 0 deletions
31
plotly/tests/test_optional/test_jupyter/js_tests/connected_false.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict'; | ||
|
||
var test = require('../lib/tape-wrapper'); | ||
|
||
test('should load plotly.js', function(t) { | ||
t.plan(1); | ||
|
||
window.require(['plotly'], function(Plotly) { | ||
t.equal(typeof Plotly, 'object'); | ||
}); | ||
}); | ||
|
||
test('should have one plotly.js graph', function(t) { | ||
t.plan(1); | ||
|
||
var nodes = document.querySelectorAll('.js-plotly-plot'); | ||
t.equal(nodes.length, 1); | ||
}); | ||
|
||
test('should inject raw plotly.js code into DOM', function(t) { | ||
t.plan(1); | ||
|
||
var nodes = document.querySelectorAll('script'); | ||
nodes = Array.prototype.slice.call(nodes, 0, 10); | ||
|
||
var results = nodes.filter(function(node) { | ||
return node.innerHTML.substr(0, 19) === 'if(!window.Plotly){'; | ||
}); | ||
|
||
t.equal(results.length, 1); | ||
}); |
31 changes: 31 additions & 0 deletions
31
plotly/tests/test_optional/test_jupyter/js_tests/connected_true.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict'; | ||
|
||
var test = require('../lib/tape-wrapper'); | ||
|
||
test('should load plotly.js', function(t) { | ||
t.plan(1); | ||
|
||
window.require(['plotly'], function(Plotly) { | ||
t.equal(typeof Plotly, 'object'); | ||
}); | ||
}); | ||
|
||
test('should have one plotly.js graph', function(t) { | ||
t.plan(1); | ||
|
||
var nodes = document.querySelectorAll('.js-plotly-plot'); | ||
t.equal(nodes.length, 1); | ||
}); | ||
|
||
test('should link to plotly.js CDN', function(t) { | ||
t.plan(1); | ||
|
||
var nodes = document.querySelectorAll('script'); | ||
nodes = Array.prototype.slice.call(nodes, 0); | ||
|
||
var results = nodes.filter(function(node) { | ||
return node.src === 'https://cdn.plot.ly/plotly-latest.min.js'; | ||
}); | ||
|
||
t.equal(results.length, 1); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
var http = require('http'); | ||
var url = require('url'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
|
||
var ecstatic = require('ecstatic'); | ||
var browserify = require('browserify'); | ||
var cheerio = require('cheerio'); | ||
var tapParser = require('tap-parser'); | ||
var chrome = require('chrome-launch'); | ||
|
||
var PORT = 8080; | ||
var PATH_ROOT = path.join(__dirname, '..'); | ||
var PATH_INDEX_STUB = path.join(PATH_ROOT, 'index.tmp.html'); | ||
var PATH_TEST_BUNDLE = path.join(PATH_ROOT, 'test.tmp.js'); | ||
|
||
var URL = 'http://localhost:' + PORT + '/index.tmp.html'; | ||
var EXIT_CODE = 0; | ||
|
||
if(process.argv.length !== 4) { | ||
throw new Error('must provide path to html and js files'); | ||
} | ||
|
||
var PATH_INDEX = process.argv[2]; | ||
var PATH_TEST_FILE = process.argv[3]; | ||
|
||
main(); | ||
|
||
function main() { | ||
scanInput(); | ||
|
||
stubIndex() | ||
.then(bundleTests) | ||
.then(startServer) | ||
.then(launch); | ||
} | ||
|
||
function scanInput() { | ||
var reqFiles = [PATH_INDEX, PATH_TEST_FILE]; | ||
|
||
reqFiles.forEach(function(filePath) { | ||
if(!doesFileExist(filePath)) { | ||
throw new Error(filePath + ' does not exist'); | ||
} | ||
}); | ||
} | ||
|
||
function stubIndex() { | ||
return new Promise(function(resolve, reject) { | ||
var html = fs.readFileSync(PATH_INDEX, 'utf-8'); | ||
var $ = cheerio.load(html); | ||
|
||
$('body').append('<script type="text/javascript" src="../test.tmp.js"></script>'); | ||
|
||
fs.writeFile(PATH_INDEX_STUB, $.html(), resolve); | ||
}); | ||
} | ||
|
||
function bundleTests() { | ||
return new Promise(function(resolve, reject) { | ||
var wsBundle = fs.createWriteStream(PATH_TEST_BUNDLE); | ||
|
||
browserify(PATH_TEST_FILE, { debug: true }) | ||
.bundle() | ||
.pipe(wsBundle); | ||
|
||
wsBundle.on('close', resolve); | ||
}); | ||
} | ||
|
||
function startServer() { | ||
return new Promise(function(resolve, reject) { | ||
var server = http.createServer(ecstatic({ root: PATH_ROOT })); | ||
|
||
server.on('request', handle); | ||
|
||
server.listen(PORT, resolve); | ||
}); | ||
} | ||
|
||
function handle(req, res) { | ||
var query = url.parse(req.url).query || ''; | ||
var parser = tapParser(); | ||
|
||
function is(query, root) { | ||
return query.indexOf(root) !== -1; | ||
} | ||
|
||
if(is(query, 'data')) handleData(req, res); | ||
if(is(query, 'done')) handleDone(); | ||
|
||
function handleData(req, res) { | ||
req.pipe(parser); | ||
req.pipe(process.stdout); | ||
} | ||
|
||
parser.on('assert', function(assert) { | ||
if(EXIT_CODE === 0 && assert.ok === false) EXIT_CODE = 1; | ||
}) | ||
|
||
function handleDone() { | ||
removeBuildFiles(); | ||
process.exit(EXIT_CODE); | ||
} | ||
} | ||
|
||
function launch() { | ||
chrome(URL); | ||
} | ||
|
||
function removeBuildFiles() { | ||
fs.unlinkSync(PATH_INDEX_STUB); | ||
fs.unlinkSync(PATH_TEST_BUNDLE); | ||
} | ||
|
||
function doesFileExist(filePath) { | ||
try { | ||
if(fs.statSync(filePath).isFile()) return true; | ||
} | ||
catch(e) { | ||
return false; | ||
} | ||
|
||
return false; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@theengineear this didn't go down so smooth on Circle.