Skip to content

Commit

Permalink
Merge pull request #5498 from plotly/add-test-for-5411
Browse files Browse the repository at this point in the history
Add a test for enabling validation in node.js
  • Loading branch information
archmoj authored Feb 12, 2021
2 parents eb6365c + 49900af commit f125c24
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
9 changes: 6 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ jobs:
echo https://$CIRCLE_BUILD_NUM-$PROJECT_NUM-gh.circle-artifacts.com/0/dist/plotly.js
echo https://$CIRCLE_BUILD_NUM-$PROJECT_NUM-gh.circle-artifacts.com/0/dist/plotly.min.js
echo https://$CIRCLE_BUILD_NUM-$PROJECT_NUM-gh.circle-artifacts.com/0/dist/plot-schema.json
- run:
name: Test validation using node.js and jsdom
command: npm run test-plain-obj
- run:
name: Test plotly.min.js import using requirejs
command: npm run test-requirejs
- run:
name: Test plotly bundles againt unexpected characters
command: npm run no-bad-char
Expand All @@ -184,9 +190,6 @@ jobs:
environment:
NODE_OPTIONS: --max_old_space_size=4096
command: npm run no-dup-keys
- run:
name: Test plotly.min.js import using requirejs
command: npm run test-requirejs

workflows:
version: 2
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"test-syntax": "node tasks/test_syntax.js && npm run find-strings -- --no-output",
"test-bundle": "node tasks/test_bundle.js",
"test-requirejs": "node tasks/test_requirejs.js",
"test-plain-obj": "node tasks/test_plain_obj.js",
"test": "npm run test-jasmine -- --nowatch && npm run test-bundle && npm run test-image && npm run test-export && npm run test-syntax && npm run lint",
"start-test_dashboard": "node devtools/test_dashboard/server.js",
"start-image_viewer": "node devtools/image_viewer/server.js",
Expand Down
33 changes: 33 additions & 0 deletions tasks/test_plain_obj.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
var jsdom = require('jsdom');
var fs = require('fs');

var plotlyServerDom = new jsdom.JSDOM('', { runScripts: 'dangerously'});
// Mock a few things that jsdom doesn't support out-of-the-box
plotlyServerDom.window.URL.createObjectURL = function() {};

// Run Plotly inside jsdom
var plotlyJsPath = require.resolve('../dist/plotly.js');
var plotlyJsSource = fs.readFileSync(plotlyJsPath, 'utf-8');
plotlyServerDom.window.eval(plotlyJsSource);

var assertValidate = function(fig, exp) {
console.log(fig);

var errorList = plotlyServerDom.window.Plotly.validate(fig.data, fig.layout);

if(exp) {
if(errorList !== undefined) throw 'should be valid:';
} else {
if(errorList === undefined) throw 'should not be valid:';
}
};

assertValidate({
data: [{ y: [1] }],
layout: {}
}, true);

assertValidate({
data: [{ z: false }],
layout: {}
}, false);

0 comments on commit f125c24

Please sign in to comment.