Skip to content

Commit 3437b26

Browse files
committed
Replace merge.smart with a simple merge.
It's not a direct replacement, however this may cover all the needs. If needed, we can work on the merge strategy. Jest has a file system cache that is not cleared, not even using `jest.resetModules()`. As a workaround, we create the webpack config files with a unique suffix. Ref: jestjs/jest#11426 (comment)
1 parent 20d4350 commit 3437b26

File tree

2 files changed

+51
-21
lines changed

2 files changed

+51
-21
lines changed

lib/build.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var fs = require('fs');
33
var path = require('path');
44
var conf = require('./config');
55
var webpack = require('webpack');
6-
var merge = require('webpack-merge');
6+
const { merge } = require('webpack-merge');
77
const findUp = require('find-up');
88

99
const readdir = util.promisify(fs.readdir);
@@ -198,7 +198,7 @@ async function webpackConfig(
198198
if (userWebpackConfig) {
199199
var webpackAdditional = require(path.join(cwd, userWebpackConfig));
200200

201-
return merge.smart(webpackConfig, webpackAdditional);
201+
return merge(webpackConfig, webpackAdditional);
202202
}
203203

204204
return webpackConfig;

lib/build.spec.js

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -105,28 +105,58 @@ describe('build', () => {
105105
).rejects.toThrow('Cannot find module');
106106
});
107107

108-
it('should merge webpack custom config', async () => {
109-
const script = `module.exports = () => console.log("hello world")`;
110-
await writeFileInFunctions(script, 'index.js');
108+
describe('webpack custom config merge', () => {
109+
it('should merge plugins', async () => {
110+
const script = `module.exports = () => console.log("hello world")`;
111+
await writeFileInFunctions(script, 'index.js');
112+
113+
const webpackConfig = `
114+
const webpack = require('webpack');
115+
module.exports = { plugins: [new webpack.EnvironmentPlugin(['NODE_ENV'])] };
116+
`;
117+
118+
const suffix = expect.getState().currentTestName.replace(/\s+/g, '_');
119+
const userWebpackConfig = await writeFileInBuild(
120+
webpackConfig,
121+
`webpack/webpack_${suffix}.js`,
122+
);
123+
124+
const stats = await build.run(functions, {
125+
userWebpackConfig,
126+
});
127+
expect(stats.compilation.errors).toHaveLength(0);
128+
expect(stats.compilation.options.plugins).toHaveLength(3);
129+
expect(
130+
stats.compilation.options.plugins.map(
131+
(plugin) => plugin.constructor.name,
132+
),
133+
).toEqual(['IgnorePlugin', 'DefinePlugin', 'EnvironmentPlugin']);
134+
});
111135

112-
const webpackConfig = `module.exports = { resolve: { extensions: ['.custom'] } }`;
113-
const userWebpackConfig = await writeFileInBuild(
114-
webpackConfig,
115-
'webpack/webpack.js',
116-
);
136+
it('should merge resolve extensions', async () => {
137+
const script = `module.exports = () => console.log("hello world")`;
138+
await writeFileInFunctions(script, 'index.js');
117139

118-
const stats = await build.run(functions, {
119-
userWebpackConfig,
140+
const webpackConfig = `module.exports = { resolve: { extensions: ['.custom'] } }`;
141+
const suffix = expect.getState().currentTestName.replace(/\s+/g, '_');
142+
const userWebpackConfig = await writeFileInBuild(
143+
webpackConfig,
144+
`webpack/webpack_${suffix}.js`,
145+
);
146+
147+
const stats = await build.run(functions, {
148+
userWebpackConfig,
149+
});
150+
expect(stats.compilation.errors).toHaveLength(0);
151+
expect(stats.compilation.options.resolve.extensions).toEqual([
152+
'.wasm',
153+
'.mjs',
154+
'.js',
155+
'.json',
156+
'.ts',
157+
'.custom',
158+
]);
120159
});
121-
expect(stats.compilation.errors).toHaveLength(0);
122-
expect(stats.compilation.options.resolve.extensions).toEqual([
123-
'.wasm',
124-
'.mjs',
125-
'.js',
126-
'.json',
127-
'.ts',
128-
'.custom',
129-
]);
130160
});
131161

132162
describe('babel config file resolution', () => {

0 commit comments

Comments
 (0)