Skip to content

Commit f5498c9

Browse files
authored
test: support webapck5 (#2553)
1 parent 4fc5ecd commit f5498c9

File tree

3 files changed

+42
-9
lines changed

3 files changed

+42
-9
lines changed

test/helpers/isWebpack5.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
const webpack = require('webpack');
4+
5+
const isWebpack5 = webpack.version[0] === '5';
6+
7+
module.exports = isWebpack5;

test/server/Server.test.js

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const { noop } = require('webpack-dev-middleware/lib/util');
77
const Server = require('../../lib/Server');
88
const config = require('../fixtures/simple-config/webpack.config');
99
const port = require('../ports-map').Server;
10+
const isWebpack5 = require('../helpers/isWebpack5');
1011

1112
jest.mock('sockjs/lib/transport');
1213

@@ -34,11 +35,20 @@ describe('Server', () => {
3435
})
3536
);
3637

37-
expect(
38-
server.middleware.context.compiler.options.entry.map((p) => {
38+
let entries;
39+
40+
if (isWebpack5) {
41+
entries = server.middleware.context.compiler.options.entry.main.import.map(
42+
(p) => {
43+
return relative('.', p).split(sep);
44+
}
45+
);
46+
} else {
47+
entries = server.middleware.context.compiler.options.entry.map((p) => {
3948
return relative('.', p).split(sep);
40-
})
41-
).toMatchSnapshot();
49+
});
50+
}
51+
expect(entries).toMatchSnapshot();
4252
expect(server.middleware.context.compiler.options.plugins).toEqual([
4353
new webpack.HotModuleReplacementPlugin(),
4454
]);
@@ -59,11 +69,21 @@ describe('Server', () => {
5969
})
6070
);
6171

62-
expect(
63-
server.middleware.context.compiler.options.entry.map((p) => {
72+
let entries;
73+
74+
if (isWebpack5) {
75+
entries = server.middleware.context.compiler.options.entry.main.import.map(
76+
(p) => {
77+
return relative('.', p).split(sep);
78+
}
79+
);
80+
} else {
81+
entries = server.middleware.context.compiler.options.entry.map((p) => {
6482
return relative('.', p).split(sep);
65-
})
66-
).toMatchSnapshot();
83+
});
84+
}
85+
86+
expect(entries).toMatchSnapshot();
6787
expect(server.middleware.context.compiler.options.plugins).toEqual([
6888
new webpack.HotModuleReplacementPlugin(),
6989
]);

test/server/utils/updateCompiler.test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const webpack = require('webpack');
44
const updateCompiler = require('../../../lib/utils/updateCompiler');
5+
const isWebpack5 = require('../../helpers/isWebpack5');
56

67
describe('updateCompiler', () => {
78
describe('simple config, inline', () => {
@@ -36,7 +37,12 @@ describe('updateCompiler', () => {
3637
expect(compiler.hooks.entryOption.taps.length).toBe(1);
3738
expect(tapsByHMR).toEqual(0);
3839
expect(tapsByProvidePlugin).toEqual(1);
39-
expect(compiler.options.plugins).toBeUndefined();
40+
41+
if (isWebpack5) {
42+
expect(compiler.options.plugins).toEqual([]);
43+
} else {
44+
expect(compiler.options.plugins).toBeUndefined();
45+
}
4046
});
4147
});
4248

0 commit comments

Comments
 (0)