diff --git a/packages/cli/lib/lib/webpack/transform-config.js b/packages/cli/lib/lib/webpack/transform-config.js index a6ea20425..ffecda629 100644 --- a/packages/cli/lib/lib/webpack/transform-config.js +++ b/packages/cli/lib/lib/webpack/transform-config.js @@ -107,7 +107,13 @@ 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) { + m = require(myConfig); + } 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..bd9c4d3ea 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'); @@ -10,6 +11,9 @@ function tmpDir() { .toString(36) .replace(/[^a-z]+/g, '') .substr(0, 12); + if (!existsSync(output)) { + mkdirSync(output, { recursive: true }); + } return resolve(output, str); } 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; -};