|
1 | 1 | var minimist = require('minimist'); |
2 | | -var jsdom = require('jsdom'); |
3 | 2 | var path = require('path'); |
4 | 3 | var fs = require('fs'); |
| 4 | +var JSDOM = require('jsdom').JSDOM; |
| 5 | + |
| 6 | +var window = new JSDOM('', {runScripts: 'dangerously'}).window; |
5 | 7 |
|
6 | | -var plotlyServerDom = new jsdom.JSDOM('', { runScripts: 'dangerously'}); |
7 | 8 | // Mock a few things that jsdom doesn't support out-of-the-box |
8 | | -plotlyServerDom.window.URL.createObjectURL = function() {}; |
| 9 | +window.URL.createObjectURL = function() {}; |
9 | 10 |
|
10 | | -// Run Plotly inside jsdom |
11 | | -var plotlyJsPath = require.resolve('../build/plotly.js'); |
12 | | -var plotlyJsSource = fs.readFileSync(plotlyJsPath, 'utf-8'); |
13 | | -plotlyServerDom.window.eval(plotlyJsSource); |
| 11 | +var scriptEl = window.document.createElement('script'); |
| 12 | +scriptEl.textContent = fs.readFileSync('build/plotly.js', { encoding: 'utf-8' }); |
| 13 | +window.document.body.appendChild(scriptEl); |
| 14 | +var Plotly = window.Plotly; |
14 | 15 |
|
15 | 16 | var pathToRoot = path.join(__dirname, '..'); |
16 | 17 | var pathToMocks = path.join(pathToRoot, 'test', 'image', 'mocks'); |
@@ -39,7 +40,7 @@ for(var i = 0; i < list.length; i++) { |
39 | 40 |
|
40 | 41 | var filename = path.join(pathToMocks, name + '.json'); |
41 | 42 | var fig = JSON.parse(fs.readFileSync(filename)); |
42 | | - var out = plotlyServerDom.window.Plotly.validate(fig.data, fig.layout); |
| 43 | + var out = Plotly.validate(fig.data, fig.layout); |
43 | 44 |
|
44 | 45 | fail = false; |
45 | 46 | assert(name, out); |
|
0 commit comments