From ca600b40d5b892faffd95cdfc194bb96e054179a Mon Sep 17 00:00:00 2001 From: Shinyaigeek Date: Sun, 12 Dec 2021 04:43:05 +0900 Subject: [PATCH] Chore: add test for preact aliasing --- .../jsx-automatic-preact-with-alias/index.js | 1 + .../node_modules/preact/jsx-runtime.js | 0 .../node_modules/preact/package.json | 3 +++ .../jsx-automatic-preact-with-alias/package.json | 12 ++++++++++++ .../jsx-automatic-preact-with-alias/yarn.lock | 0 .../core/integration-tests/test/transpilation.js | 15 ++++++++++++++- 6 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 packages/core/integration-tests/test/integration/jsx-automatic-preact-with-alias/index.js create mode 100644 packages/core/integration-tests/test/integration/jsx-automatic-preact-with-alias/node_modules/preact/jsx-runtime.js create mode 100644 packages/core/integration-tests/test/integration/jsx-automatic-preact-with-alias/node_modules/preact/package.json create mode 100644 packages/core/integration-tests/test/integration/jsx-automatic-preact-with-alias/package.json create mode 100644 packages/core/integration-tests/test/integration/jsx-automatic-preact-with-alias/yarn.lock diff --git a/packages/core/integration-tests/test/integration/jsx-automatic-preact-with-alias/index.js b/packages/core/integration-tests/test/integration/jsx-automatic-preact-with-alias/index.js new file mode 100644 index 00000000000..8d097d55d7f --- /dev/null +++ b/packages/core/integration-tests/test/integration/jsx-automatic-preact-with-alias/index.js @@ -0,0 +1 @@ +module.exports =
; diff --git a/packages/core/integration-tests/test/integration/jsx-automatic-preact-with-alias/node_modules/preact/jsx-runtime.js b/packages/core/integration-tests/test/integration/jsx-automatic-preact-with-alias/node_modules/preact/jsx-runtime.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/core/integration-tests/test/integration/jsx-automatic-preact-with-alias/node_modules/preact/package.json b/packages/core/integration-tests/test/integration/jsx-automatic-preact-with-alias/node_modules/preact/package.json new file mode 100644 index 00000000000..201dceb61ed --- /dev/null +++ b/packages/core/integration-tests/test/integration/jsx-automatic-preact-with-alias/node_modules/preact/package.json @@ -0,0 +1,3 @@ +{ + "name": "preact" +} diff --git a/packages/core/integration-tests/test/integration/jsx-automatic-preact-with-alias/package.json b/packages/core/integration-tests/test/integration/jsx-automatic-preact-with-alias/package.json new file mode 100644 index 00000000000..c9bd49e7568 --- /dev/null +++ b/packages/core/integration-tests/test/integration/jsx-automatic-preact-with-alias/package.json @@ -0,0 +1,12 @@ +{ + "private": true, + "dependencies": { + "preact": "^10.5" + }, + "alias": { + "react": "preact/compat", + "react-dom/test-utils": "preact/test-utils", + "react-dom": "preact/compat", + "react/jsx-runtime": "preact/jsx-runtime" + } +} diff --git a/packages/core/integration-tests/test/integration/jsx-automatic-preact-with-alias/yarn.lock b/packages/core/integration-tests/test/integration/jsx-automatic-preact-with-alias/yarn.lock new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/core/integration-tests/test/transpilation.js b/packages/core/integration-tests/test/transpilation.js index de40708e7e2..4ba0603190f 100644 --- a/packages/core/integration-tests/test/transpilation.js +++ b/packages/core/integration-tests/test/transpilation.js @@ -120,7 +120,7 @@ describe('transpilation', function () { await bundle(path.join(__dirname, '/integration/jsx-react-alias/index.js')); let file = await outputFS.readFile(path.join(distDir, 'index.js'), 'utf8'); - assert(file.includes('React.createElement("div"')); + assert(file.includes('h("div"')); }); it('should support compiling JSX in JS files with Preact dependency', async function () { @@ -183,6 +183,19 @@ describe('transpilation', function () { assert(file.includes('_jsxRuntime.jsx("div"')); }); + it('should support the automatic JSX runtime with preact with alias', async function () { + let b = await bundle( + path.join( + __dirname, + '/integration/jsx-automatic-preact-with-alias/index.js', + ), + ); + + let file = await outputFS.readFile(b.getBundles()[0].filePath, 'utf8'); + assert(file.includes('preact/jsx-runtime')); + assert(file.includes('_jsxRuntime.jsx("div"')); + }); + it('should support the automatic JSX runtime with explicit tsconfig.json', async function () { let b = await bundle( path.join(__dirname, '/integration/jsx-automatic-tsconfig/index.js'),