Skip to content

Commit

Permalink
rename requirejs to amdefine test then add new requirejs test
Browse files Browse the repository at this point in the history
  • Loading branch information
archmoj committed Jan 18, 2023
1 parent 5499547 commit e32ba76
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,9 @@ jobs:
- run:
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")
command: diff --unified --color dist/plot-schema.json test/plot-schema.json
- run:
name: Test plotly.min.js import using amdefine
command: npm run test-amdefine
- run:
name: Test plotly.min.js import using requirejs
command: npm run test-requirejs
Expand Down
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ node_modules
dist
build

tasks/test_amdefine.js
tasks/test_requirejs.js
test/jasmine/assets/jquery-1.8.3.min.js
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"test-export": "node test/image/export_test.js",
"test-syntax": "node tasks/test_syntax.js && npm run find-strings -- --no-output",
"test-bundle": "node tasks/test_bundle.js",
"test-amdefine": "node tasks/test_amdefine.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",
Expand Down
28 changes: 28 additions & 0 deletions tasks/test_amdefine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var JSDOM = require('jsdom').JSDOM;
global.document = new JSDOM('<!DOCTYPE html><head></head><html><body></body></html>').window.document;
global.window = document.defaultView;
global.window.document = global.document;
global.self = global.window;
global.Blob = global.window.Blob;
global.DOMParser = global.window.DOMParser;
global.getComputedStyle = global.window.getComputedStyle;
global.window.URL.createObjectURL = function() {};

// see: Building node modules with AMD or RequireJS https://requirejs.org/docs/node.html
if(typeof define !== 'function') {
var define = require('amdefine')(module);
}

define(function(require) {
var plotly = require('../dist/plotly.min.js');

if(plotly) {
console.log(plotly);
} else {
throw 'Error: loading with amdefine';
}

// The value returned from the function is
// used as the module export visible to Node.
return function() {};
});
18 changes: 8 additions & 10 deletions tasks/test_requirejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,19 @@ global.DOMParser = global.window.DOMParser;
global.getComputedStyle = global.window.getComputedStyle;
global.window.URL.createObjectURL = function() {};

// see: Building node modules with AMD or RequireJS https://requirejs.org/docs/node.html
if(typeof define !== 'function') {
var define = require('amdefine')(module);
}
var requirejs = require('requirejs');

define(function(require) {
var plotly = require('../dist/plotly.min.js');
requirejs.config({
paths: {
'plotly': '../dist/plotly.min'
}
});

requirejs(['plotly'],
function(plotly) {
if(plotly) {
console.log(plotly);
} else {
throw 'Error: loading with requirejs';
}

// The value returned from the function is
// used as the module export visible to Node.
return function() {};
});

0 comments on commit e32ba76

Please sign in to comment.