Skip to content

test: support webpack5 #2553

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

Merged
merged 1 commit into from
Apr 30, 2020
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
7 changes: 7 additions & 0 deletions test/helpers/isWebpack5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

const webpack = require('webpack');

const isWebpack5 = webpack.version[0] === '5';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this have a try-catch around it, or have all versions of webpack had a .version value?

Copy link
Member Author

@hiroppy hiroppy Apr 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, webpack4 and webpack5 have version function and we don't take care of less than v4 so it's okay.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, didn't see that this is just being used for test files


module.exports = isWebpack5;
36 changes: 28 additions & 8 deletions test/server/Server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const { noop } = require('webpack-dev-middleware/lib/util');
const Server = require('../../lib/Server');
const config = require('../fixtures/simple-config/webpack.config');
const port = require('../ports-map').Server;
const isWebpack5 = require('../helpers/isWebpack5');

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

Expand Down Expand Up @@ -34,11 +35,20 @@ describe('Server', () => {
})
);

expect(
server.middleware.context.compiler.options.entry.map((p) => {
let entries;

if (isWebpack5) {
entries = server.middleware.context.compiler.options.entry.main.import.map(
(p) => {
return relative('.', p).split(sep);
}
);
} else {
entries = server.middleware.context.compiler.options.entry.map((p) => {
return relative('.', p).split(sep);
})
).toMatchSnapshot();
});
}
expect(entries).toMatchSnapshot();
expect(server.middleware.context.compiler.options.plugins).toEqual([
new webpack.HotModuleReplacementPlugin(),
]);
Expand All @@ -59,11 +69,21 @@ describe('Server', () => {
})
);

expect(
server.middleware.context.compiler.options.entry.map((p) => {
let entries;

if (isWebpack5) {
entries = server.middleware.context.compiler.options.entry.main.import.map(
(p) => {
return relative('.', p).split(sep);
}
);
} else {
entries = server.middleware.context.compiler.options.entry.map((p) => {
return relative('.', p).split(sep);
})
).toMatchSnapshot();
});
}

expect(entries).toMatchSnapshot();
expect(server.middleware.context.compiler.options.plugins).toEqual([
new webpack.HotModuleReplacementPlugin(),
]);
Expand Down
8 changes: 7 additions & 1 deletion test/server/utils/updateCompiler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const webpack = require('webpack');
const updateCompiler = require('../../../lib/utils/updateCompiler');
const isWebpack5 = require('../../helpers/isWebpack5');

describe('updateCompiler', () => {
describe('simple config, inline', () => {
Expand Down Expand Up @@ -36,7 +37,12 @@ describe('updateCompiler', () => {
expect(compiler.hooks.entryOption.taps.length).toBe(1);
expect(tapsByHMR).toEqual(0);
expect(tapsByProvidePlugin).toEqual(1);
expect(compiler.options.plugins).toBeUndefined();

if (isWebpack5) {
expect(compiler.options.plugins).toEqual([]);
} else {
expect(compiler.options.plugins).toBeUndefined();
}
});
});

Expand Down