Skip to content
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

Add a test for enabling validation in node.js #5498

Merged
merged 1 commit into from
Feb 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);