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 = `
- Guess what
- This is an app with custom template
- {{ ... }}
-