-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Test plotly.min.js in Require.js environment #914
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ var common = require('./util/common'); | |
makeCredentialsFile(); | ||
makeSetPlotConfigFile(); | ||
makeTestImageFolders(); | ||
makeRequireJSFixture(); | ||
|
||
// Create a credentials json file, | ||
// to be required in jasmine test suites and test dashboard | ||
|
@@ -52,6 +53,16 @@ function makeTestImageFolders() { | |
makeOne(constants.pathToTestImagesDiff, 'test image diff folder'); | ||
} | ||
|
||
// Make script file that define plotly in a RequireJS context | ||
function makeRequireJSFixture() { | ||
var bundle = fs.readFileSync(constants.pathToPlotlyDistMin, 'utf-8'), | ||
template = 'define(\'plotly\', function(require, exports, module) { {{bundle}} });', | ||
index = template.replace('{{bundle}}', bundle); | ||
|
||
common.writeFile(constants.pathToRequireJSFixture, index); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this basically mimics how plotly.py inject |
||
logger('make build/requirejs_fixture.js'); | ||
} | ||
|
||
function logger(task) { | ||
console.log('ok ' + task); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
var STR_TO_REPLACE = 'require("+a(r)+");'; | ||
var STR_NEW = 'require("+ a(r) +");'; | ||
|
||
/* Uber hacky in-house fix to | ||
* | ||
* https://github.com/substack/webworkify/issues/29 | ||
* | ||
* so that plotly.min.js loads in Jupyter NBs, more info here: | ||
* | ||
* https://github.com/plotly/plotly.py/pull/545 | ||
* | ||
*/ | ||
module.exports = function patchMinified(minifiedCode) { | ||
return minifiedCode.replace(STR_TO_REPLACE, STR_NEW); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
describe('plotly.js + require.js', function() { | ||
'use strict'; | ||
|
||
it('should preserve require.js globals', function() { | ||
expect(window.requirejs).toBeDefined(); | ||
expect(window.define).toBeDefined(); | ||
expect(window.require).toBeDefined(); | ||
}); | ||
|
||
it('should be able to import plotly.min.js', function(done) { | ||
require(['plotly'], function(Plotly) { | ||
expect(Plotly).toBeDefined(); | ||
done(); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,10 +13,13 @@ | |
* | ||
*/ | ||
|
||
var constants = require('../../tasks/util/constants'); | ||
|
||
var arg = process.argv[4]; | ||
|
||
var testFileGlob = arg ? arg : 'tests/*_test.js'; | ||
var isSingleSuiteRun = (arg && arg.indexOf('bundle_tests/') === -1); | ||
var isRequireJSTest = (arg && arg.indexOf('bundle_tests/requirejs') !== -1); | ||
|
||
var pathToMain = '../../lib/index.js'; | ||
var pathToJQuery = 'assets/jquery-1.8.3.min.js'; | ||
|
@@ -113,6 +116,13 @@ if(isSingleSuiteRun) { | |
func.defaultConfig.preprocessors[pathToMain] = ['browserify']; | ||
func.defaultConfig.preprocessors[testFileGlob] = ['browserify']; | ||
} | ||
else if(isRequireJSTest) { | ||
func.defaultConfig.files = [ | ||
constants.pathToRequireJS, | ||
constants.pathToRequireJSFixture, | ||
testFileGlob | ||
]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: don't browserify the |
||
} | ||
else { | ||
func.defaultConfig.files = [ | ||
pathToJQuery, | ||
|
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.
Important I chose to test Require.js import with the
dist/plotly.min.js
bundle only.That means that Require.js will only be tested on
npm version
commits (when thedist/
is updated).Main reason for this shotcut: minifying the full plotly.js bundle take about 1 minute on CI.