You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by sh...@apache.org on 2021/05/07 05:03:57 UTC

[echarts] branch enhance-visual-regression-test updated: test: optimize loader

This is an automated email from the ASF dual-hosted git repository.

shenyi pushed a commit to branch enhance-visual-regression-test
in repository https://gitbox.apache.org/repos/asf/echarts.git


The following commit(s) were added to refs/heads/enhance-visual-regression-test by this push:
     new 210f650  test: optimize loader
210f650 is described below

commit 210f650d650b1aa2a4ec4ed4240aa842e1bfa796
Author: pissang <bm...@gmail.com>
AuthorDate: Fri May 7 13:02:16 2021 +0800

    test: optimize loader
    
    fix conflicts of json.js because current loader can load json files.
    fix require in callback
    fix defined id don't work
    add .js ext for .min files
    factory return as exports
---
 test/axis-interval.html             |  2 +-
 test/axis-lastLabel.html            | 10 ++---
 test/boxplot.html                   |  2 +-
 test/brush2.html                    |  2 +-
 test/candlestick-doji.html          |  2 +-
 test/candlestick-large.html         |  2 +-
 test/candlestick.html               |  2 +-
 test/candlestickConnect.html        |  2 +-
 test/clip.html                      |  2 +-
 test/data-transform-ecStat.html     |  1 -
 test/data-transform.html            |  2 +-
 test/dataView.html                  |  2 +-
 test/dataZoom-rainfall-connect.html |  2 +-
 test/dataZoom-rainfall-inside.html  |  6 +--
 test/dataZoom-rainfall.html         |  2 +-
 test/dataZoom-scroll.html           |  6 +--
 test/dataset-charts.html            |  4 +-
 test/encode.html                    |  2 +-
 test/geo-map.html                   |  3 +-
 test/lib/config.js                  |  3 +-
 test/lib/simpleRequire.js           | 77 ++++++++++++++++++++++++++++---------
 21 files changed, 88 insertions(+), 48 deletions(-)

diff --git a/test/axis-interval.html b/test/axis-interval.html
index af63f7a..b84c3c8 100644
--- a/test/axis-interval.html
+++ b/test/axis-interval.html
@@ -300,7 +300,7 @@ under the License.
     <script>
 
         require([
-            'data/rainfall.json',
+            'data/rainfall.json.js',
             'echarts'
         ], function (rainfallData, echarts) {
 
diff --git a/test/axis-lastLabel.html b/test/axis-lastLabel.html
index e53fd6f..d34e5a3 100644
--- a/test/axis-lastLabel.html
+++ b/test/axis-lastLabel.html
@@ -61,7 +61,7 @@ under the License.
         <script>
 
             require([
-                'data/rainfall.json',
+                'data/rainfall.json.js',
                 'echarts'
             ], function (rainfallData, echarts) {
 
@@ -126,7 +126,7 @@ under the License.
         <script>
 
             require([
-                'data/rainfall.json',
+                'data/rainfall.json.js',
                 'echarts'
             ], function (rainfallData, echarts) {
 
@@ -200,7 +200,7 @@ under the License.
         <script>
 
             require([
-                'data/rainfall.json',
+                'data/rainfall.json.js',
                 'echarts'
             ], function (rainfallData, echarts) {
 
@@ -285,7 +285,7 @@ under the License.
         <script>
 
             require([
-                'data/rainfall.json',
+                'data/rainfall.json.js',
                 'echarts'
             ], function (rainfallData, echarts) {
 
@@ -368,7 +368,7 @@ under the License.
         <script>
 
             require([
-                'data/rainfall.json',
+                'data/rainfall.json.js',
                 'echarts'
             ], function (rainfallData, echarts) {
 
diff --git a/test/boxplot.html b/test/boxplot.html
index 2ff4289..960851f 100644
--- a/test/boxplot.html
+++ b/test/boxplot.html
@@ -49,7 +49,7 @@ under the License.
 
             require([
                 'echarts',
-                'data/Michelson-Morley.json'
+                'data/Michelson-Morley.json.js'
             ], function (echarts, rawData) {
                 var env = echarts.env;
 
diff --git a/test/brush2.html b/test/brush2.html
index 442eece..08e7a08 100644
--- a/test/brush2.html
+++ b/test/brush2.html
@@ -150,7 +150,7 @@ under the License.
 
             require([
                 'echarts',
-                'data/stock-DJI.json'
+                'data/stock-DJI.json.js'
             ], function (echarts, rawData) {
 
                 chart = echarts.init(document.getElementById('main1'), null, {
diff --git a/test/candlestick-doji.html b/test/candlestick-doji.html
index 7d3104f..d118c37 100644
--- a/test/candlestick-doji.html
+++ b/test/candlestick-doji.html
@@ -46,7 +46,7 @@ under the License.
 
             require([
                 'echarts',
-                'data/security-sh-2013.json'
+                'data/security-sh-2013.json.js'
             ], function (echarts, rawData) {
 
                 chart = echarts.init(document.getElementById('main'), null, {
diff --git a/test/candlestick-large.html b/test/candlestick-large.html
index 6c6b1f0..2a5dd79 100644
--- a/test/candlestick-large.html
+++ b/test/candlestick-large.html
@@ -54,7 +54,7 @@ under the License.
              */
             require([
                 'echarts',
-                'data/stock-DJI.json'
+                'data/stock-DJI.json.js'
             ], update)
 
             function splitData(rawData) {
diff --git a/test/candlestick.html b/test/candlestick.html
index 255757b..0e7db9f 100644
--- a/test/candlestick.html
+++ b/test/candlestick.html
@@ -47,7 +47,7 @@ under the License.
 
             require([
                 'echarts',
-                'data/security-sh-2013.json'
+                'data/security-sh-2013.json.js'
             ], function (echarts, rawData) {
 
                 chart = echarts.init(document.getElementById('main'), null, {
diff --git a/test/candlestickConnect.html b/test/candlestickConnect.html
index 44e1f82..70379f8 100644
--- a/test/candlestickConnect.html
+++ b/test/candlestickConnect.html
@@ -55,7 +55,7 @@ under the License.
         <script>
 
             require([
-                'data/rainfall.json',
+                'data/rainfall.json.js',
                 'echarts'
             ], function (data, echarts) {
                 var axisData = [
diff --git a/test/clip.html b/test/clip.html
index e1393c6..e91bd56 100644
--- a/test/clip.html
+++ b/test/clip.html
@@ -1210,7 +1210,7 @@ under the License.
         <script>
             require([
                 'echarts',
-                'data/stock-DJI.json'
+                'data/stock-DJI.json.js'
             ], function (echarts, rawData) {
                 var option = {
                     dataset: {
diff --git a/test/data-transform-ecStat.html b/test/data-transform-ecStat.html
index 7388b35..5120594 100644
--- a/test/data-transform-ecStat.html
+++ b/test/data-transform-ecStat.html
@@ -28,7 +28,6 @@ under the License.
         <script src="lib/jquery.min.js"></script>
         <script src="lib/facePrint.js"></script>
         <script src="lib/testHelper.js"></script>
-        <script src="../dist/echarts.js"></script>
         <!-- <script src="ut/lib/canteen.js"></script> -->
         <link rel="stylesheet" href="lib/reset.css" />
     </head>
diff --git a/test/data-transform.html b/test/data-transform.html
index ff668e6..ef3c052 100644
--- a/test/data-transform.html
+++ b/test/data-transform.html
@@ -989,7 +989,7 @@ under the License.
 
 
         <script>
-        require(['echarts', 'data/Michelson-Morley.json'], function (echarts, rawData) {
+        require(['echarts', 'data/Michelson-Morley.json.js'], function (echarts, rawData) {
             var option = {
                 dataset: [{
                     source: rawData
diff --git a/test/dataView.html b/test/dataView.html
index 34ca942..9890c04 100644
--- a/test/dataView.html
+++ b/test/dataView.html
@@ -23,7 +23,7 @@ under the License.
         <meta charset="utf-8">
         <script src="lib/simpleRequire.js"></script>
         <script src="lib/config.js"></script>
-        <script src=""></script>
+        <script src="lib/jquery.min.js"></script>
         <script src="//cdn.datatables.net/1.10.11/js/jquery.dataTables.min.js"></script>
         <link rel="stylesheet" href="//cdn.datatables.net/1.10.11/css/jquery.dataTables.min.css">
         <meta name="viewport" content="width=device-width, initial-scale=1" />
diff --git a/test/dataZoom-rainfall-connect.html b/test/dataZoom-rainfall-connect.html
index cbdab37..9046d2d 100644
--- a/test/dataZoom-rainfall-connect.html
+++ b/test/dataZoom-rainfall-connect.html
@@ -60,7 +60,7 @@ under the License.
         <script>
 
             require([
-                'data/rainfall.json',
+                'data/rainfall.json.js',
                 'echarts'
             ], function (data, echarts) {
                 var chart1 = createChart1(data, echarts);
diff --git a/test/dataZoom-rainfall-inside.html b/test/dataZoom-rainfall-inside.html
index aee319e..f7b7eb4 100644
--- a/test/dataZoom-rainfall-inside.html
+++ b/test/dataZoom-rainfall-inside.html
@@ -60,7 +60,7 @@ under the License.
 
         <script>
             require([
-                'data/rainfall.json',
+                'data/rainfall.json.js',
                 'echarts'
             ], function (data, echarts) {
 
@@ -199,7 +199,7 @@ under the License.
 
         <script>
             require([
-                'data/rainfall.json',
+                'data/rainfall.json.js',
                 'echarts'
             ], function (data, echarts) {
 
@@ -287,7 +287,7 @@ under the License.
 
         <script>
             require([
-                'data/rainfall.json',
+                'data/rainfall.json.js',
                 'echarts'
             ], function (data, echarts) {
 
diff --git a/test/dataZoom-rainfall.html b/test/dataZoom-rainfall.html
index 5bf3c0e..c6d664f 100644
--- a/test/dataZoom-rainfall.html
+++ b/test/dataZoom-rainfall.html
@@ -40,7 +40,7 @@ under the License.
         <script>
 
             require([
-                'data/rainfall.json',
+                'data/rainfall.json.js',
                 'echarts'
             ], function (data, echarts) {
 
diff --git a/test/dataZoom-scroll.html b/test/dataZoom-scroll.html
index a071d51..279939e 100644
--- a/test/dataZoom-scroll.html
+++ b/test/dataZoom-scroll.html
@@ -51,7 +51,7 @@ under the License.
 
         <script>
             require([
-                'data/rainfall.json',
+                'data/rainfall.json.js',
                 'echarts'
             ], function (data, echarts) {
 
@@ -147,7 +147,7 @@ under the License.
 
         <script>
             require([
-                'data/rainfall.json',
+                'data/rainfall.json.js',
                 'echarts'
             ], function (data, echarts) {
 
@@ -249,7 +249,7 @@ under the License.
 
         <script>
             require([
-                'data/rainfall.json',
+                'data/rainfall.json.js',
                 'echarts'
             ], function (data, echarts) {
 
diff --git a/test/dataset-charts.html b/test/dataset-charts.html
index cdc4391..a060fd2 100644
--- a/test/dataset-charts.html
+++ b/test/dataset-charts.html
@@ -599,7 +599,7 @@ under the License.
 
         <script>
 
-            require(['echarts', 'data/stock-DJI.json'], function (echarts, source) {
+            require(['echarts', 'data/stock-DJI.json.js'], function (echarts, source) {
                 var option = {
                     legend: {},
                     tooltip: {trigger: 'axis'},
@@ -725,7 +725,7 @@ under the License.
 
         <script>
 
-            require(['echarts', 'data/stock-DJI.json'], function (echarts, source) {
+            require(['echarts', 'data/stock-DJI.json.js'], function (echarts, source) {
                 var option = {
                     legend: {},
                     tooltip: {trigger: 'axis'},
diff --git a/test/encode.html b/test/encode.html
index 7302693..49b2d0d 100644
--- a/test/encode.html
+++ b/test/encode.html
@@ -60,7 +60,7 @@ under the License.
 
             require([
                 'echarts',
-                'data/security-sh-2013.json'
+                'data/security-sh-2013.json.js'
             ], function (echarts, rawData) {
 
                 var dom = document.getElementById('dim');
diff --git a/test/geo-map.html b/test/geo-map.html
index cc57d40..7082182 100644
--- a/test/geo-map.html
+++ b/test/geo-map.html
@@ -452,7 +452,8 @@ under the License.
 
 
             require([
-                'echarts'
+                'echarts',
+                'map/js/china'
             ], function (echarts) {
 
                 require(['map/js/china'], function () {
diff --git a/test/lib/config.js b/test/lib/config.js
index a4a0f37..67dae59 100644
--- a/test/lib/config.js
+++ b/test/lib/config.js
@@ -62,9 +62,10 @@
                 'ecSimpleOptionPlayer': 'lib/ecSimpleOptionPlayer',
                 // 'ecStat': 'http://localhost:8001/echarts/echarts-stat/dist/ecStat',
                 'geoJson': '../geoData/geoJson',
-                'theme': 'theme',
+                'theme': '../theme',
                 'data': 'data',
                 'map': 'data/map',
+                'i18n': '../i18n',
                 'extension': '../dist/extension',
             }
         });
diff --git a/test/lib/simpleRequire.js b/test/lib/simpleRequire.js
index c88b181..ecf0b27 100644
--- a/test/lib/simpleRequire.js
+++ b/test/lib/simpleRequire.js
@@ -26,7 +26,6 @@
 // Limitations:
 //  1. Not support ancient browsers.
 //  2. Only `paths` can be configured
-//  3. Not support defined id.
 
 (function (global) {
 
@@ -36,22 +35,27 @@
     var currentDefinedDeps;
     var exportsPlaceholder = {};
 
+    var ALLOWED_EXTS = [
+        'gexf', 'txt', 'csv',    // text
+        'js', 'json'
+    ];
+
     // Promise to get modules exports.
     var mods = {};
 
     function loadText(url) {
-        new Promise(function (resolve, reject) {
+        return new Promise(function (resolve, reject) {
             var xhr = new XMLHttpRequest();
             xhr.onload = function (e) {
                 if (xhr.status === 200) {
                     resolve(xhr.responseText);
                 }
                 else {
-                    reject('Error loading ' + url);
+                    reject('require: failed to load ' + url);
                 }
             }
             xhr.onerror = function (e) {
-                reject('Error loading ' + url);
+                reject('require: failed to load ' + url);
             }
             xhr.open('GET', url);
             xhr.send();
@@ -59,7 +63,7 @@
     }
 
     function loadJSON(url) {
-        return loadJSON(url).then(function (text) {
+        return loadText(url).then(function (text) {
             return JSON.parse(text);
         });
     }
@@ -72,7 +76,7 @@
                 resolve();
             }
             script.onerror = function () {
-                reject('Error loading ' + url);
+                reject('require: failed to load ' + url);
             }
             script.src = url;
             document.head.appendChild(script);
@@ -91,9 +95,9 @@
             }
         }
 
-        var filename = p.split('/').pop();
+        var ext = getExt(p);
         // Add .js ext automatically
-        if (filename.indexOf('.') < 0) {
+        if (ALLOWED_EXTS.indexOf(ext) < 0) {
             p = p + '.js';
         }
 
@@ -104,6 +108,22 @@
         return str.split('.').pop();
     }
 
+    function invokeFactory(factory, depsPromise) {
+        if (typeof factory === 'function') {
+            return depsPromise.then(function (deps) {
+                var modExports = {};
+                var factoryRet = factory.apply(null, deps.map(function (dep) {
+                    return dep === exportsPlaceholder ? modExports : dep;
+                }));
+                return factoryRet || modExports;
+            });
+        }
+        else {
+            // define(JSONObject)
+            return factory;
+        }
+    }
+
     // Simplify the logic. don't support id.
     function define(modId, depsIds, factory) {
         if (factory == null) {
@@ -123,8 +143,14 @@
                 }
             }
         }
-        currentDefinedFactory = factory;
-        currentDefinedDeps = loadDeps(depsIds || []);
+
+        if (modId) {
+            mods[modId] = invokeFactory(factory, loadDeps(depsIds));
+        }
+        else {
+            currentDefinedFactory = factory;
+            currentDefinedDeps = loadDeps(depsIds || []);
+        }
     }
 
     function loadMod(modId) {
@@ -134,14 +160,7 @@
             function loaded(exports) {
                 var ret;
                 if (currentDefinedDeps) {
-                    var factory = currentDefinedFactory;
-                    ret = currentDefinedDeps.then(function (deps) {
-                        var modExports = {};
-                        factory.apply(null, deps.map(function (dep) {
-                            return dep === exportsPlaceholder ? modExports : dep;
-                        }));
-                        return modExports;
-                    });
+                    ret = invokeFactory(currentDefinedFactory, currentDefinedDeps);
                 }
                 else {
                     ret = exports;
@@ -177,14 +196,34 @@
             }
         }));
     }
+
+    var pendingRequireCallbacks = [];
+    var pendingRequireCallbackParams = [];
+    var requireCount = 0;
     function require(depsIds, cb) {
         if (typeof depsIds === 'string') {
             depsIds = [depsIds];
         }
         // Batch multiple requires callback theme in one frame.
         // Ensure all instances are started at one time and avoid time difference in visual regression test
+        var cbIdx = requireCount;
+        pendingRequireCallbacks.push(cb);
+        requireCount++;
+
         loadDeps(depsIds).then(function (deps) {
-            cb && cb.apply(null, deps);
+            pendingRequireCallbackParams[cbIdx] = deps;
+            requireCount--;
+
+            if (requireCount === 0) {   // Flush
+                var requireCallbackToFlush = pendingRequireCallbacks;
+                var requireCallbackParamsToFlush = pendingRequireCallbackParams;
+                // Clear before flush. Avoid more require in the callback.
+                pendingRequireCallbacks = [];
+                pendingRequireCallbackParams = [];
+                for (var i = 0; i < requireCallbackToFlush.length; i++) {
+                    requireCallbackToFlush[i] && requireCallbackToFlush[i].apply(null, requireCallbackParamsToFlush[i]);
+                }
+            }
         });
     }
 

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org