Skip to content

Commit f125c24

Browse files
authored
Merge pull request #5498 from plotly/add-test-for-5411
Add a test for enabling validation in node.js
2 parents eb6365c + 49900af commit f125c24

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

.circleci/config.yml

+6-3
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ jobs:
170170
echo https://$CIRCLE_BUILD_NUM-$PROJECT_NUM-gh.circle-artifacts.com/0/dist/plotly.js
171171
echo https://$CIRCLE_BUILD_NUM-$PROJECT_NUM-gh.circle-artifacts.com/0/dist/plotly.min.js
172172
echo https://$CIRCLE_BUILD_NUM-$PROJECT_NUM-gh.circle-artifacts.com/0/dist/plot-schema.json
173+
- run:
174+
name: Test validation using node.js and jsdom
175+
command: npm run test-plain-obj
176+
- run:
177+
name: Test plotly.min.js import using requirejs
178+
command: npm run test-requirejs
173179
- run:
174180
name: Test plotly bundles againt unexpected characters
175181
command: npm run no-bad-char
@@ -184,9 +190,6 @@ jobs:
184190
environment:
185191
NODE_OPTIONS: --max_old_space_size=4096
186192
command: npm run no-dup-keys
187-
- run:
188-
name: Test plotly.min.js import using requirejs
189-
command: npm run test-requirejs
190193

191194
workflows:
192195
version: 2

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"test-syntax": "node tasks/test_syntax.js && npm run find-strings -- --no-output",
4444
"test-bundle": "node tasks/test_bundle.js",
4545
"test-requirejs": "node tasks/test_requirejs.js",
46+
"test-plain-obj": "node tasks/test_plain_obj.js",
4647
"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",
4748
"start-test_dashboard": "node devtools/test_dashboard/server.js",
4849
"start-image_viewer": "node devtools/image_viewer/server.js",

tasks/test_plain_obj.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
var jsdom = require('jsdom');
2+
var fs = require('fs');
3+
4+
var plotlyServerDom = new jsdom.JSDOM('', { runScripts: 'dangerously'});
5+
// Mock a few things that jsdom doesn't support out-of-the-box
6+
plotlyServerDom.window.URL.createObjectURL = function() {};
7+
8+
// Run Plotly inside jsdom
9+
var plotlyJsPath = require.resolve('../dist/plotly.js');
10+
var plotlyJsSource = fs.readFileSync(plotlyJsPath, 'utf-8');
11+
plotlyServerDom.window.eval(plotlyJsSource);
12+
13+
var assertValidate = function(fig, exp) {
14+
console.log(fig);
15+
16+
var errorList = plotlyServerDom.window.Plotly.validate(fig.data, fig.layout);
17+
18+
if(exp) {
19+
if(errorList !== undefined) throw 'should be valid:';
20+
} else {
21+
if(errorList === undefined) throw 'should not be valid:';
22+
}
23+
};
24+
25+
assertValidate({
26+
data: [{ y: [1] }],
27+
layout: {}
28+
}, true);
29+
30+
assertValidate({
31+
data: [{ z: false }],
32+
layout: {}
33+
}, false);

0 commit comments

Comments
 (0)