Skip to content

Commit e32ba76

Browse files
committed
rename requirejs to amdefine test then add new requirejs test
1 parent 5499547 commit e32ba76

File tree

5 files changed

+41
-10
lines changed

5 files changed

+41
-10
lines changed

.circleci/config.yml

+3
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,9 @@ jobs:
400400
- run:
401401
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")
402402
command: diff --unified --color dist/plot-schema.json test/plot-schema.json
403+
- run:
404+
name: Test plotly.min.js import using amdefine
405+
command: npm run test-amdefine
403406
- run:
404407
name: Test plotly.min.js import using requirejs
405408
command: npm run test-requirejs

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ node_modules
33
dist
44
build
55

6+
tasks/test_amdefine.js
67
tasks/test_requirejs.js
78
test/jasmine/assets/jquery-1.8.3.min.js

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"test-export": "node test/image/export_test.js",
4949
"test-syntax": "node tasks/test_syntax.js && npm run find-strings -- --no-output",
5050
"test-bundle": "node tasks/test_bundle.js",
51+
"test-amdefine": "node tasks/test_amdefine.js",
5152
"test-requirejs": "node tasks/test_requirejs.js",
5253
"test-plain-obj": "node tasks/test_plain_obj.js",
5354
"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",

tasks/test_amdefine.js

+28
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) {
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.js

+8-10
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,19 @@ global.DOMParser = global.window.DOMParser;
88
global.getComputedStyle = global.window.getComputedStyle;
99
global.window.URL.createObjectURL = function() {};
1010

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-
}
11+
var requirejs = require('requirejs');
1512

16-
define(function(require) {
17-
var plotly = require('../dist/plotly.min.js');
13+
requirejs.config({
14+
paths: {
15+
'plotly': '../dist/plotly.min'
16+
}
17+
});
1818

19+
requirejs(['plotly'],
20+
function(plotly) {
1921
if(plotly) {
2022
console.log(plotly);
2123
} else {
2224
throw 'Error: loading with requirejs';
2325
}
24-
25-
// The value returned from the function is
26-
// used as the module export visible to Node.
27-
return function() {};
2826
});

0 commit comments

Comments
 (0)