-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5498 from plotly/add-test-for-5411
Add a test for enabling validation in node.js
- Loading branch information
Showing
3 changed files
with
40 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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 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,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); |