From f8d4b1724cf16b2f5a12129e94b61b2a0db7bbe3 Mon Sep 17 00:00:00 2001 From: Ryan Christian Date: Wed, 24 Nov 2021 05:02:29 -0600 Subject: [PATCH 1/3] fix: Test suite now uses config files again --- packages/cli/lib/lib/webpack/transform-config.js | 10 +++++++++- packages/cli/tests/build.test.js | 8 +++----- packages/cli/tests/images/build.js | 15 --------------- packages/cli/tests/lib/output.js | 4 ++++ .../subjects/custom-webpack/preact.config.js | 7 ++----- .../subjects/preload-chunks/preact.config.js | 6 ------ 6 files changed, 18 insertions(+), 32 deletions(-) delete mode 100644 packages/cli/tests/subjects/preload-chunks/preact.config.js diff --git a/packages/cli/lib/lib/webpack/transform-config.js b/packages/cli/lib/lib/webpack/transform-config.js index a6ea20425..af4c8c6c5 100644 --- a/packages/cli/lib/lib/webpack/transform-config.js +++ b/packages/cli/lib/lib/webpack/transform-config.js @@ -107,7 +107,15 @@ module.exports = async function (env, webpackConfig, isServer = false) { ); } - const m = require('esm')(module)(myConfig); + let m = require('esm')(module)(myConfig); + + // The line above results in an empty object w/ Jest, + // so we need to do the following in order to load it: + if (Object.keys(m).length === 0) { + try { + m = require(myConfig); + } catch {} + } const transformers = parseConfig((m && m.default) || m); diff --git a/packages/cli/tests/build.test.js b/packages/cli/tests/build.test.js index d610c5241..afc715606 100644 --- a/packages/cli/tests/build.test.js +++ b/packages/cli/tests/build.test.js @@ -176,14 +176,12 @@ describe('preact build', () => { }); it('should use custom `preact.config.js`', async () => { - // app with custom template set via preact.config.js + // app with stable output name via preact.config.js let dir = await subject('custom-webpack'); await build(dir); - let file = join(dir, 'build/index.html'); - let html = await readFile(file, 'utf-8'); - - looksLike(html, images.webpack); + let file = join(dir, 'build/bundle.js'); + expect(existsSync(file)).toBe(true); }); it('should use template from the code folder', async () => { diff --git a/packages/cli/tests/images/build.js b/packages/cli/tests/images/build.js index 42ea16206..0ce2a4f28 100644 --- a/packages/cli/tests/images/build.js +++ b/packages/cli/tests/images/build.js @@ -191,21 +191,6 @@ exports.prerender.htmlSafe = ` `; -exports.webpack = ` - - - - - preact-webpack - - -

Guess what

-

This is an app with custom template

- {{ ... }} - - -`; - exports.template = ` diff --git a/packages/cli/tests/lib/output.js b/packages/cli/tests/lib/output.js index 4864c5543..d4bc7d3d4 100644 --- a/packages/cli/tests/lib/output.js +++ b/packages/cli/tests/lib/output.js @@ -1,3 +1,4 @@ +const { existsSync, mkdirSync } = require('fs'); const copy = require('ncp'); const { resolve } = require('path'); const { promisify } = require('util'); @@ -16,6 +17,9 @@ function tmpDir() { async function subject(name) { let src = resolve(subjects, name); let dest = tmpDir(); + if (!existsSync(dest)) { + mkdirSync(dest, { recursive: true }); + } await promisify(copy)(src, dest); return dest; } diff --git a/packages/cli/tests/subjects/custom-webpack/preact.config.js b/packages/cli/tests/subjects/custom-webpack/preact.config.js index ac894d4fa..e85964678 100644 --- a/packages/cli/tests/subjects/custom-webpack/preact.config.js +++ b/packages/cli/tests/subjects/custom-webpack/preact.config.js @@ -1,6 +1,3 @@ -const path = require('path'); - -module.exports = function (config, env, helpers) { - if (env.ssr) return; - helpers.setHtmlTemplate(config, path.resolve(__dirname, './template.html')); +module.exports = function (config) { + config.output.filename = '[name].js'; }; diff --git a/packages/cli/tests/subjects/preload-chunks/preact.config.js b/packages/cli/tests/subjects/preload-chunks/preact.config.js deleted file mode 100644 index 08dfeb1bd..000000000 --- a/packages/cli/tests/subjects/preload-chunks/preact.config.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = config => { - config.optimization.splitChunks = { - minSize: 0, - }; - return config; -}; From 5ee6e5850ebd185af9e9a048237a7382d4e14dae Mon Sep 17 00:00:00 2001 From: Ryan Christian Date: Wed, 24 Nov 2021 14:31:42 -0600 Subject: [PATCH 2/3] chore: Removing unnecessary try/catch --- packages/cli/lib/lib/webpack/transform-config.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/cli/lib/lib/webpack/transform-config.js b/packages/cli/lib/lib/webpack/transform-config.js index af4c8c6c5..ffecda629 100644 --- a/packages/cli/lib/lib/webpack/transform-config.js +++ b/packages/cli/lib/lib/webpack/transform-config.js @@ -112,9 +112,7 @@ module.exports = async function (env, webpackConfig, isServer = false) { // The line above results in an empty object w/ Jest, // so we need to do the following in order to load it: if (Object.keys(m).length === 0) { - try { - m = require(myConfig); - } catch {} + m = require(myConfig); } const transformers = parseConfig((m && m.default) || m); From b1ec138d2d34dfb441492f7814c8ddbac7a3b454 Mon Sep 17 00:00:00 2001 From: Ryan Christian Date: Wed, 24 Nov 2021 14:50:01 -0600 Subject: [PATCH 3/3] chore: Moving over mkdir for file subject output --- packages/cli/tests/lib/output.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/cli/tests/lib/output.js b/packages/cli/tests/lib/output.js index d4bc7d3d4..bd9c4d3ea 100644 --- a/packages/cli/tests/lib/output.js +++ b/packages/cli/tests/lib/output.js @@ -11,15 +11,15 @@ function tmpDir() { .toString(36) .replace(/[^a-z]+/g, '') .substr(0, 12); + if (!existsSync(output)) { + mkdirSync(output, { recursive: true }); + } return resolve(output, str); } async function subject(name) { let src = resolve(subjects, name); let dest = tmpDir(); - if (!existsSync(dest)) { - mkdirSync(dest, { recursive: true }); - } await promisify(copy)(src, dest); return dest; }