Skip to content

Commit d74aee5

Browse files
committed
bring back amdefine test
1 parent 0d3d915 commit d74aee5

File tree

5 files changed

+58
-9
lines changed

5 files changed

+58
-9
lines changed

.circleci/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,9 @@ jobs:
470470
- run:
471471
name: Test plot-schema.json diff - If failed, after (npm start) you could run (npm run schema && git add test/plot-schema.json && git commit -m "update plot-schema diff")
472472
command: diff --unified --color dist/plot-schema.json test/plot-schema.json
473+
- run:
474+
name: Test plotly.min.js import using amdefine
475+
command: npm run test-amdefine
473476
- run:
474477
name: Test plotly bundles against es6
475478
command: npm run no-es6-dist

package-lock.json

Lines changed: 22 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151
"test-export": "node test/image/export_test.js",
5252
"test-syntax": "node tasks/test_syntax.js && npm run find-strings -- --no-output",
5353
"test-bundle": "node tasks/test_bundle.js",
54-
"test-requirejs": "node tasks/test_requirejs.mjs",
54+
"test-amdefine": "node tasks/test_amdefine.js",
55+
"test-requirejs": "node tasks/test_requirejs.js",
5556
"test-plain-obj": "node tasks/test_plain_obj.mjs",
5657
"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",
5758
"b64": "python3 test/image/generate_b64_mocks.py && node devtools/test_dashboard/server.mjs",
@@ -124,6 +125,7 @@
124125
"world-calendars": "^1.0.3"
125126
},
126127
"devDependencies": {
128+
"amdefine": "^1.0.1",
127129
"assert": "^2.1.0",
128130
"babel-loader": "^9.1.3",
129131
"browserify-transform-tools": "^1.7.0",

tasks/test_amdefine.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
var JSDOM = require('jsdom').JSDOM;
2+
global.document = new JSDOM('<!DOCTYPE html><head></head><html><body></body></html>').window.document;
3+
global.window = document.defaultView;
4+
global.window.document = global.document;
5+
global.self = global.window;
6+
global.Blob = global.window.Blob;
7+
global.DOMParser = global.window.DOMParser;
8+
global.getComputedStyle = global.window.getComputedStyle;
9+
global.window.URL.createObjectURL = function() {};
10+
11+
// see: Building node modules with AMD or RequireJS https://requirejs.org/docs/node.html
12+
if(typeof define !== 'function') {
13+
var define = require('amdefine')(module);
14+
}
15+
16+
define(function(require) {
17+
var plotly = require('../dist/plotly.min.js');
18+
19+
if(plotly && plotly.PlotSchema) {
20+
console.log(plotly);
21+
} else {
22+
throw 'Error: loading with amdefine';
23+
}
24+
25+
// The value returned from the function is
26+
// used as the module export visible to Node.
27+
return function() {};
28+
});

tasks/test_requirejs.mjs renamed to tasks/test_requirejs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { JSDOM } from 'jsdom';
1+
var JSDOM = require('jsdom').JSDOM;
22
global.document = new JSDOM('<!DOCTYPE html><head></head><html><body></body></html>').window.document;
33
global.window = document.defaultView;
44
global.window.document = global.document;
@@ -8,7 +8,7 @@ global.DOMParser = global.window.DOMParser;
88
global.getComputedStyle = global.window.getComputedStyle;
99
global.window.URL.createObjectURL = function() {};
1010

11-
import requirejs from 'requirejs';
11+
var requirejs = require('requirejs');
1212

1313
requirejs.config({
1414
paths: {

0 commit comments

Comments
 (0)