From 49900af761f2ee75c2b6749342835808dd5698a0 Mon Sep 17 00:00:00 2001 From: archmoj Date: Fri, 12 Feb 2021 11:36:10 -0500 Subject: [PATCH] add is-plain-object test for issue 5151 - pull 5411 --- .circleci/config.yml | 9 ++++++--- package.json | 1 + tasks/test_plain_obj.js | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 tasks/test_plain_obj.js diff --git a/.circleci/config.yml b/.circleci/config.yml index 09a2ef5c095..2e7a820da83 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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 @@ -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 diff --git a/package.json b/package.json index 0becbc78403..43df47eb4f6 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/tasks/test_plain_obj.js b/tasks/test_plain_obj.js new file mode 100644 index 00000000000..05464f3285e --- /dev/null +++ b/tasks/test_plain_obj.js @@ -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);