Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Test suite now uses config files again #1623

Merged
merged 3 commits into from
Nov 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/cli/lib/lib/webpack/transform-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
8 changes: 3 additions & 5 deletions packages/cli/tests/build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
15 changes: 0 additions & 15 deletions packages/cli/tests/images/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,21 +191,6 @@ exports.prerender.htmlSafe = `
</body>
`;

exports.webpack = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>preact-webpack</title>
</head>
<body>
<h1>Guess what</h1>
<h2>This is an app with custom template</h2>
{{ ... }}
</body>
</html>
`;

exports.template = `
<!DOCTYPE html>
<html lang="en">
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/tests/lib/output.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { existsSync, mkdirSync } = require('fs');
const copy = require('ncp');
const { resolve } = require('path');
const { promisify } = require('util');
Expand All @@ -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);
}

Expand Down
7 changes: 2 additions & 5 deletions packages/cli/tests/subjects/custom-webpack/preact.config.js
Original file line number Diff line number Diff line change
@@ -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';
};
6 changes: 0 additions & 6 deletions packages/cli/tests/subjects/preload-chunks/preact.config.js

This file was deleted.