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 2020/12/30 10:04:53 UTC

[incubator-echarts-examples] branch next updated: Update test script and description

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

shenyi pushed a commit to branch next
in repository https://gitbox.apache.org/repos/asf/incubator-echarts-examples.git


The following commit(s) were added to refs/heads/next by this push:
     new 99c12ff  Update test script and description
99c12ff is described below

commit 99c12ff355b08b7a8796a4fe4e111cc733ac0143
Author: pissang <bm...@gmail.com>
AuthorDate: Wed Dec 30 18:04:34 2020 +0800

    Update test script and description
---
 README.md          | 25 ++++++++++++++++++++++++
 package.json       |  2 ++
 test/README.md     |  6 ++++++
 test/config.js     |  6 ++++++
 test/main.js       | 56 +++++++++++++++++++++++++++++++++++++++---------------
 test/tsconfig.json |  6 +-----
 6 files changed, 81 insertions(+), 20 deletions(-)

diff --git a/README.md b/README.md
index b1450b5..e6ab090 100644
--- a/README.md
+++ b/README.md
@@ -38,6 +38,31 @@ Only for default theme
 node tool/build-example.js -t default
 ```
 
+## Run bundler tests.
+
+Run all the examples to test module importing, minimal bundling and DTS correctness.
+
+Before run the tests. you need to update the examples.
+
+```shell
+node tool/build-example.js
+```
+
+Then update the `echartsDir` and `zrenderDir` path in test/config.js
+
+If you want to test with esbuild bundler.
+
+```shell
+npm run test:esbuild
+```
+
+Otherwise it will use webpack bundler.
+
+```shell
+npm run test:webpack
+```
+
+
 ## Edit example
 
 All test cases are in the `public/data` folder. The comment in the header
diff --git a/package.json b/package.json
index 5bd2dc1..649886a 100644
--- a/package.json
+++ b/package.json
@@ -9,6 +9,8 @@
     "release": "npm run build && node build/copyResource.js --env asf",
     "dev": "npx concurrently --kill-others \"npm:watch\" \"npm:server\"",
     "build:example": "node tool/build-example.js",
+    "test:webpack": "node test/main.js --bundler webpack",
+    "test:esbuild": "node test/main.js --bundler esbuild",
     "server": "node build/server.js"
   },
   "devDependencies": {
diff --git a/test/README.md b/test/README.md
index 02da1ff..839e778 100644
--- a/test/README.md
+++ b/test/README.md
@@ -1,3 +1,9 @@
 # Tests
 
 Run all the examples to test module importing, partial bundling and DTS correctness.
+
+## Usage
+
+```shell
+npm run test:
+```
\ No newline at end of file
diff --git a/test/config.js b/test/config.js
new file mode 100644
index 0000000..de27b3f
--- /dev/null
+++ b/test/config.js
@@ -0,0 +1,6 @@
+const nodePath = require('path');
+
+module.exports = {
+    echartsDir: nodePath.resolve(__dirname, '../../echarts-next'),
+    zrenderDir: nodePath.resolve(__dirname, '../../zrender-next')
+}
\ No newline at end of file
diff --git a/test/main.js b/test/main.js
index 50dedc5..a65313c 100644
--- a/test/main.js
+++ b/test/main.js
@@ -12,21 +12,43 @@ const chalk = require('chalk');
 const nStatic = require('node-static');
 const webpack = require('webpack');
 const {RawSource} = require('webpack-sources');
-
+const argparse = require('argparse');
 const esbuild = require('esbuild');
 const puppeteer = require('puppeteer');
+const config = require('./config');
 const pixelmatch = require('pixelmatch');
 
+const parser = new argparse.ArgumentParser({
+    addHelp: true
+});
+parser.addArgument(['--bundler'], {
+    help: 'Bundler, can be webpack or esbuild'
+});
+parser.addArgument(['-m', '--minify'], {
+    action: 'storeTrue',
+    help: 'If minify'
+});
+parser.addArgument(['--echarts'], {
+    help: 'ECharts folder relative to cwd'
+});
+parser.addArgument(['--zrender'], {
+    help: 'ZRender folder relative to cwd'
+});
+const args = parser.parseArgs();
+
 const EXAMPLE_DIR =  `${__dirname}/../public/`;
 const TMP_DIR = `${__dirname}/tmp`;
 const RUN_CODE_DIR = `${TMP_DIR}/tests`;
 const BUNDLE_DIR = `${TMP_DIR}/bundles`;
 const SCREENSHOTS_DIR = `${TMP_DIR}/screenshots`;
 
-const MINIFY_BUNDLE = true;
+const ECHARTS_DIR = nodePath.resolve(__dirname, args.echarts || config.echartsDir);
+const ZRENDER_DIR = nodePath.resolve(__dirname, args.zrender || config.zrenderDir);
+
+const MINIFY_BUNDLE = args.minify;
 // const TEST_THEME = 'dark-blue';
 const TEST_THEME = '';
-const USE_WEBPACK = true;
+const USE_WEBPACK = !(args.bundler === 'esbuild');
 
 const TEMPLATE_CODE = `
 echarts.registerPreprocessor(function (option) {
@@ -85,6 +107,10 @@ async function prepare() {
 async function buildRunCode() {
     const files = await globby(`${EXAMPLE_DIR}/data/option/*.json`);
 
+    if (!files.length) {
+        throw new Error('You need to run `node tool/build-example.js` before run this test.');
+    }
+
     await runTasks(files, async (fileName) => {
         const optionCode = await fse.readFile(fileName, 'utf-8');
         const option = JSON.parse(optionCode);
@@ -159,7 +185,11 @@ async function compileTs(tsTestFiles, result) {
     const config = JSON.parse(fs.readFileSync(nodePath.join(__dirname, 'tsconfig.json'), 'utf-8'));
 
     const {options, errors} = ts.convertCompilerOptionsFromJson({
-        ...config.compilerOptions
+        ...config.compilerOptions,
+        "paths": {
+            "echarts": [ECHARTS_DIR],
+            "echarts/*": [ECHARTS_DIR + '/*']
+        }
     }, nodePath.resolve(__dirname));
 
     if (errors.length) {
@@ -212,7 +242,7 @@ async function webpackBundle(esbuildService, entry, result) {
             },
             // Use esbuild as minify, terser is tooooooo slow for so much tests.
             optimization: {
-                minimizer: [{
+                minimizer: MINIFY_BUNDLE ? [{
                     apply(compiler) {
                         compiler.hooks.compilation.tap(
                             'ESBuild Minify',
@@ -239,12 +269,12 @@ async function webpackBundle(esbuildService, entry, result) {
                           );
 
                     }
-                }]
+                }] : []
             },
             resolve: {
                 alias: {
-                    echarts: nodePath.join(__dirname, '../../echarts-next'),
-                    zrender: nodePath.join(__dirname, '../../zrender-next')
+                    echarts: ECHARTS_DIR,
+                    zrender: ZRENDER_DIR
                 }
             }
         }, (err, stats) => {
@@ -282,9 +312,7 @@ function esbuildBundle(entry, result, minify) {
         name: 'echarts-resolver',
         setup(build) {
             build.onResolve({ filter: /^(echarts\/|echarts$)/ }, args => {
-                const path = args.path.replace(
-                    /^echarts/, nodePath.join(__dirname, '../../echarts-next')
-                );
+                const path = args.path.replace(/^echarts/, ECHARTS_DIR);
                 return {
                     path: args.path === 'echarts' ? (path + '/index.js') : (path + '.js')
                 };
@@ -295,9 +323,7 @@ function esbuildBundle(entry, result, minify) {
         name: 'zrender-resolver',
         setup(build) {
             build.onResolve({ filter: /^zrender/ }, args => {
-                const path = args.path.replace(
-                    /^zrender/, nodePath.join(__dirname, '../../zrender-next')
-                ) + '.js';
+                const path = args.path.replace(/^zrender/, ZRENDER_DIR) + '.js';
                 return { path };
             });
         }
@@ -441,7 +467,7 @@ async function main() {
     console.log('Compiling TypeScript');
     await compileTs(tsFiles, result);
 
-    console.log('Bundling');
+    console.log(`Bundling with ${USE_WEBPACK ? 'webpack' : 'esbuild'}`);
     await bundle(await globby(nodePath.join(RUN_CODE_DIR, '*.js')), result);
 
     console.log('Running examples');
diff --git a/test/tsconfig.json b/test/tsconfig.json
index 197d9ad..ad6231a 100644
--- a/test/tsconfig.json
+++ b/test/tsconfig.json
@@ -8,10 +8,6 @@
         "pretty": true,
         "outDir": "tmp/tests",
 
-        "baseUrl": "./",
-        "paths": {
-            "echarts": ["../../echarts-next"],
-            "echarts/*": ["../../echarts-next/*"]
-        }
+        "baseUrl": "./"
     }
 }
\ No newline at end of file


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