From 5a8d359c354394bc3175ab6896e1d4645b04894a Mon Sep 17 00:00:00 2001 From: David Huggins-Daines Date: Tue, 28 Mar 2023 10:54:10 -0400 Subject: [PATCH 1/3] test: add EXPORT_ES6 version of webpack test --- test/test_browser.py | 8 ++++++++ test/webpack/src/index.mjs | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 test/webpack/src/index.mjs diff --git a/test/test_browser.py b/test/test_browser.py index 787fb009d0b08..29631dacd1be0 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -5546,6 +5546,14 @@ def test_webpack(self): shutil.copyfile('webpack/src/hello.wasm', 'webpack/dist/hello.wasm') self.run_browser('webpack/dist/index.html', '/report_result?exit:0') + def test_webpack_es6(self): + shutil.copytree(test_file('webpack'), 'webpack') + with utils.chdir('webpack'): + self.compile_btest([test_file('hello_world.c'), '-sEXIT_RUNTIME', '-sMODULARIZE', '-sENVIRONMENT=web', + '-sEXPORT_ES6=1', '-o', 'src/hello.mjs']) + self.run_process(shared.get_npm_cmd('webpack') + ['--mode=development', '--no-devtool', './src/index.mjs']) + self.run_browser('webpack/dist/index.html', '/report_result?exit:0') + class emrun(RunnerCore): def test_emrun_info(self): diff --git a/test/webpack/src/index.mjs b/test/webpack/src/index.mjs new file mode 100644 index 0000000000000..f8e31622caab1 --- /dev/null +++ b/test/webpack/src/index.mjs @@ -0,0 +1,18 @@ +import createModule from "./hello.mjs"; + +var params = { + print: (function() { + var element = document.getElementById('output'); + return function(text) { + console.log(text); + element.innerHTML += text.replace('\n', '
', 'g') + '
'; + }; + })(), + canvas: document.getElementById('canvas'), +}; + +params.print("testing.."); + +createModule(params).then((instance) => { + console.log('loaded'); +}); From 66cd4572b1e998c7a02ad4e4fee597a1fd451cdb Mon Sep 17 00:00:00 2001 From: David Huggins-Daines Date: Tue, 28 Mar 2023 11:37:07 -0400 Subject: [PATCH 2/3] test: add esbuild (with import meta plugin) test --- package.json | 2 ++ test/esbuild/build.mjs | 11 +++++++++++ test/esbuild/dist/index.html | 6 ++++++ test/esbuild/src/index.mjs | 18 ++++++++++++++++++ test/test_browser.py | 9 +++++++++ 5 files changed, 46 insertions(+) create mode 100644 test/esbuild/build.mjs create mode 100644 test/esbuild/dist/index.html create mode 100644 test/esbuild/src/index.mjs diff --git a/package.json b/package.json index e04114fbd9e75..690ac81e6ec5b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,9 @@ { "private": true, "devDependencies": { + "@chialab/esbuild-plugin-meta-url": "^0.17.5", "es-check": "^6.2.1", + "esbuild": "^0.17.14", "eslint": "^8.16.0", "eslint-config-prettier": "^8.5.0", "prettier": "^2.7.1", diff --git a/test/esbuild/build.mjs b/test/esbuild/build.mjs new file mode 100644 index 0000000000000..310a335ec557f --- /dev/null +++ b/test/esbuild/build.mjs @@ -0,0 +1,11 @@ +import metaUrlPlugin from '@chialab/esbuild-plugin-meta-url'; +import * as esbuild from 'esbuild'; + +await esbuild.build({ + entryPoints: ['src/index.mjs'], + bundle: true, + outdir: 'dist', + format: 'esm', + logLevel: 'info', + plugins: [metaUrlPlugin()], +}); diff --git a/test/esbuild/dist/index.html b/test/esbuild/dist/index.html new file mode 100644 index 0000000000000..b33801772cdd0 --- /dev/null +++ b/test/esbuild/dist/index.html @@ -0,0 +1,6 @@ + + +

+ + + diff --git a/test/esbuild/src/index.mjs b/test/esbuild/src/index.mjs new file mode 100644 index 0000000000000..f8e31622caab1 --- /dev/null +++ b/test/esbuild/src/index.mjs @@ -0,0 +1,18 @@ +import createModule from "./hello.mjs"; + +var params = { + print: (function() { + var element = document.getElementById('output'); + return function(text) { + console.log(text); + element.innerHTML += text.replace('\n', '
', 'g') + '
'; + }; + })(), + canvas: document.getElementById('canvas'), +}; + +params.print("testing.."); + +createModule(params).then((instance) => { + console.log('loaded'); +}); diff --git a/test/test_browser.py b/test/test_browser.py index 29631dacd1be0..33f7368486ec7 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -27,6 +27,7 @@ from tools import shared from tools import ports from tools import utils +from tools import config from tools.shared import EMCC, WINDOWS, FILE_PACKAGER, PIPE from tools.utils import delete_file, delete_dir @@ -5554,6 +5555,14 @@ def test_webpack_es6(self): self.run_process(shared.get_npm_cmd('webpack') + ['--mode=development', '--no-devtool', './src/index.mjs']) self.run_browser('webpack/dist/index.html', '/report_result?exit:0') + def test_esbuild(self): + shutil.copytree(test_file('esbuild'), 'esbuild') + with utils.chdir('esbuild'): + self.compile_btest([test_file('hello_world.c'), '-sEXIT_RUNTIME', '-sMODULARIZE', '-sENVIRONMENT=web', + '-sEXPORT_ES6=1', '-o', 'src/hello.mjs']) + self.run_process(config.NODE_JS + ['build.mjs']) + self.run_browser('esbuild/dist/index.html', '/report_result?exit:0') + class emrun(RunnerCore): def test_emrun_info(self): From 873da44d31876302f17dadb50174177a51586e32 Mon Sep 17 00:00:00 2001 From: David Huggins-Daines Date: Tue, 28 Mar 2023 11:42:33 -0400 Subject: [PATCH 3/3] test: add test with rollup --- package.json | 2 ++ test/rollup/dist/index.html | 6 ++++++ test/rollup/rollup.config.mjs | 10 ++++++++++ test/rollup/src/index.mjs | 18 ++++++++++++++++++ test/test_browser.py | 8 ++++++++ 5 files changed, 44 insertions(+) create mode 100644 test/rollup/dist/index.html create mode 100644 test/rollup/rollup.config.mjs create mode 100644 test/rollup/src/index.mjs diff --git a/package.json b/package.json index 690ac81e6ec5b..410ff2975e94f 100644 --- a/package.json +++ b/package.json @@ -2,11 +2,13 @@ "private": true, "devDependencies": { "@chialab/esbuild-plugin-meta-url": "^0.17.5", + "@web/rollup-plugin-import-meta-assets": "^1.0.7", "es-check": "^6.2.1", "esbuild": "^0.17.14", "eslint": "^8.16.0", "eslint-config-prettier": "^8.5.0", "prettier": "^2.7.1", + "rollup": "^3.20.2", "source-map": "0.7.4", "webpack": "^5.76.1", "webpack-cli": "^5.0.1", diff --git a/test/rollup/dist/index.html b/test/rollup/dist/index.html new file mode 100644 index 0000000000000..b33801772cdd0 --- /dev/null +++ b/test/rollup/dist/index.html @@ -0,0 +1,6 @@ + + +

+ + + diff --git a/test/rollup/rollup.config.mjs b/test/rollup/rollup.config.mjs new file mode 100644 index 0000000000000..18ded404a22b3 --- /dev/null +++ b/test/rollup/rollup.config.mjs @@ -0,0 +1,10 @@ +import { importMetaAssets } from '@web/rollup-plugin-import-meta-assets'; + +export default { + input: 'src/index.mjs', + output: { + dir: 'dist', + format: 'es', + }, + plugins: [importMetaAssets()], +}; diff --git a/test/rollup/src/index.mjs b/test/rollup/src/index.mjs new file mode 100644 index 0000000000000..f8e31622caab1 --- /dev/null +++ b/test/rollup/src/index.mjs @@ -0,0 +1,18 @@ +import createModule from "./hello.mjs"; + +var params = { + print: (function() { + var element = document.getElementById('output'); + return function(text) { + console.log(text); + element.innerHTML += text.replace('\n', '
', 'g') + '
'; + }; + })(), + canvas: document.getElementById('canvas'), +}; + +params.print("testing.."); + +createModule(params).then((instance) => { + console.log('loaded'); +}); diff --git a/test/test_browser.py b/test/test_browser.py index 33f7368486ec7..0b2599fda555c 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -5563,6 +5563,14 @@ def test_esbuild(self): self.run_process(config.NODE_JS + ['build.mjs']) self.run_browser('esbuild/dist/index.html', '/report_result?exit:0') + def test_rollup(self): + shutil.copytree(test_file('rollup'), 'rollup') + with utils.chdir('rollup'): + self.compile_btest([test_file('hello_world.c'), '-sEXIT_RUNTIME', '-sMODULARIZE', '-sENVIRONMENT=web', + '-sEXPORT_ES6=1', '-o', 'src/hello.mjs']) + self.run_process(shared.get_npm_cmd('rollup') + ['-c', 'rollup.config.mjs']) + self.run_browser('rollup/dist/index.html', '/report_result?exit:0') + class emrun(RunnerCore): def test_emrun_info(self):