Skip to content

Commit 0509aa9

Browse files
authored
fix: Test suite now uses config files again (#1623)
1 parent 9039ba2 commit 0509aa9

File tree

6 files changed

+16
-32
lines changed

6 files changed

+16
-32
lines changed

Diff for: packages/cli/lib/lib/webpack/transform-config.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,13 @@ module.exports = async function (env, webpackConfig, isServer = false) {
107107
);
108108
}
109109

110-
const m = require('esm')(module)(myConfig);
110+
let m = require('esm')(module)(myConfig);
111+
112+
// The line above results in an empty object w/ Jest,
113+
// so we need to do the following in order to load it:
114+
if (Object.keys(m).length === 0) {
115+
m = require(myConfig);
116+
}
111117

112118
const transformers = parseConfig((m && m.default) || m);
113119

Diff for: packages/cli/tests/build.test.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,12 @@ describe('preact build', () => {
176176
});
177177

178178
it('should use custom `preact.config.js`', async () => {
179-
// app with custom template set via preact.config.js
179+
// app with stable output name via preact.config.js
180180
let dir = await subject('custom-webpack');
181181
await build(dir);
182182

183-
let file = join(dir, 'build/index.html');
184-
let html = await readFile(file, 'utf-8');
185-
186-
looksLike(html, images.webpack);
183+
let file = join(dir, 'build/bundle.js');
184+
expect(existsSync(file)).toBe(true);
187185
});
188186

189187
it('should use template from the code folder', async () => {

Diff for: packages/cli/tests/images/build.js

-15
Original file line numberDiff line numberDiff line change
@@ -191,21 +191,6 @@ exports.prerender.htmlSafe = `
191191
</body>
192192
`;
193193

194-
exports.webpack = `
195-
<!DOCTYPE html>
196-
<html lang="en">
197-
<head>
198-
<meta charset="utf-8">
199-
<title>preact-webpack</title>
200-
</head>
201-
<body>
202-
<h1>Guess what</h1>
203-
<h2>This is an app with custom template</h2>
204-
{{ ... }}
205-
</body>
206-
</html>
207-
`;
208-
209194
exports.template = `
210195
<!DOCTYPE html>
211196
<html lang="en">

Diff for: packages/cli/tests/lib/output.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const { existsSync, mkdirSync } = require('fs');
12
const copy = require('ncp');
23
const { resolve } = require('path');
34
const { promisify } = require('util');
@@ -10,6 +11,9 @@ function tmpDir() {
1011
.toString(36)
1112
.replace(/[^a-z]+/g, '')
1213
.substr(0, 12);
14+
if (!existsSync(output)) {
15+
mkdirSync(output, { recursive: true });
16+
}
1317
return resolve(output, str);
1418
}
1519

Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
const path = require('path');
2-
3-
module.exports = function (config, env, helpers) {
4-
if (env.ssr) return;
5-
helpers.setHtmlTemplate(config, path.resolve(__dirname, './template.html'));
1+
module.exports = function (config) {
2+
config.output.filename = '[name].js';
63
};

Diff for: packages/cli/tests/subjects/preload-chunks/preact.config.js

-6
This file was deleted.

0 commit comments

Comments
 (0)